Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpiler fails to simplify gates with parameters #13442

Open
natestemen opened this issue Nov 14, 2024 · 3 comments
Open

Transpiler fails to simplify gates with parameters #13442

natestemen opened this issue Nov 14, 2024 · 3 comments
Labels
type: feature request New feature or request

Comments

@natestemen
Copy link

Environment

  • Qiskit version: 1.2.4
  • Python version: 3.12.7
  • Operating system: MacOS Sonoma 14.2.1

What is happening?

The qiskit transpiler is failing to simplify/combine like gates where one of them is symbolic.

How can we reproduce the issue?

from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes Optimize1qGatesDecomposition

import numpy as np

x = Parameter("x")

test = QuantumCircuit(1)
test.rz(np.pi/2, 0)
test.rz(x, 0)
test.rz(np.pi/2, 0)

pm = PassManager(
    [
        Optimize1qGatesDecomposition(target=backend.target),
    ]
)

circuit = pm.run(test)

print(circuit)

#    ┌─────────┐┌───────┐┌─────────┐
# q: ┤ Rz(π/2) ├┤ Rz(x) ├┤ Rz(π/2) ├
#    └─────────┘└───────┘└─────────┘

What should happen?

I expected the three gates to be combined into a single $R_z$ gate.

print(circuit)

#    ┌───────────┐
# q: ┤ Rz(x + π) ├
#    └───────────┘

Any suggestions?

cc @willzeng

@natestemen natestemen added the bug Something isn't working label Nov 14, 2024
@Cryoris
Copy link
Contributor

Cryoris commented Nov 15, 2024

We exclude parameterized gates from 1-qubit gate optimizations, since handling the symbolic expressions that could emerge can become a bottleneck. In your particular case the expression is simple, but that can change in larger circuits. Instead it would likely be faster to re-compile the circuit, once all values are fully assigned.

@Cryoris Cryoris added type: feature request New feature or request and removed bug Something isn't working labels Nov 15, 2024
@natestemen
Copy link
Author

Makes sense! I was just surprised because it doesn't allow for me to get accurate understanding of the depth of my circuit ahead of parameter binding.

@Cryoris
Copy link
Contributor

Cryoris commented Nov 18, 2024

Yes that's correct, though binding to dummy parameters should be fast if you're interested in the circuit properties before sending it off to the hardware.

As side note, if you run the full transpile function it should be able to merge the 2 non-parameterized RZ gates into one, since the commutation analysis knows how to handle parameterized gates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants