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

Transpilation can result in rzz gates with invalid angles #2032

Open
yaelbh opened this issue Nov 10, 2024 · 3 comments
Open

Transpilation can result in rzz gates with invalid angles #2032

yaelbh opened this issue Nov 10, 2024 · 3 comments

Comments

@yaelbh
Copy link
Collaborator

yaelbh commented Nov 10, 2024

rzz angles are restricted to the range [0, pi/2], but the transpiler doesn't know it. A possible resolution is to flip the sign by adding a transpiler pass that surrounds rzz gates with negative angles by XI on both sides. This can be applied as a post translation plugin in qiskit-ibm-runtime (because the angle limitation is IBM specific).

@yaelbh
Copy link
Collaborator Author

yaelbh commented Nov 11, 2024

We should consider the case where the circuit is parametrized, and the rzz gate in the transpiled circuit is parametrized. Do you have an idea how to handle it?

@jyu00 jyu00 added the on hold label Nov 12, 2024
@jyu00 jyu00 removed the on hold label Nov 26, 2024
@yaelbh
Copy link
Collaborator Author

yaelbh commented Nov 27, 2024

Below is an example of a surprise-rzz gate, which shows up after transpilation. The user assigns say a negative value to the parameter of the unrestricted gate crz, but the transpiled circuit, containing the surprise-rzz gate won't be able to run. The pass from #2043 won't help because it doesn't address unbounded parameters.

from qiskit.circuit import QuantumCircuit, Parameter
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

from qiskit_ibm_runtime import QiskitRuntimeService


service = QiskitRuntimeService()
backend = service.backend("ibm_fez", use_fractional_gates=True)

p = Parameter("p")

circ = QuantumCircuit(2)
circ.crz(p, 0, 1)


pm = generate_preset_pass_manager(optimization_level=0, target=backend.target)
isa_circ = pm.run(circ)

print(isa_circ)

Output:


          q_0 -> 0 ────────────■─────────
                   ┌─────────┐ │ZZ(-p/2)
          q_1 -> 1 ┤ Rz(p/2) ├─■─────────
                   └─────────┘

@yaelbh
Copy link
Collaborator Author

yaelbh commented Nov 27, 2024

A couple of ideas:

  • (credit to Eli) Scan the circuit, if it contains rzz gates with unbounded parameters then drop rzz from the target gates, temporarily, during transpilation.
  • (credit to Liran) Transform the pass of Add plugin pass to support non-calibrated rzz angles #2043 into a pass that can work with unbounded parameters: the pass will generate a circuit starting with two rz gates (for each qubit), followed by an rx gates, an rzz gate, and an additional rx gate. The angles in all these gates will be expressions over the same parameter, for example for the rx gates the angle will be pi * (-pi/2 < theta < 0 or pi/2 < theta < pi). (we will also have some modulo 2pi here).

I think Liran's solution is interesting and may be doable. It sometimes makes the circuit longer. I'll check this direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants