-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingmod: transpilerIssues and PRs related to TranspilerIssues and PRs related to Transpiler
Milestone
Description
Environment
- Qiskit version: 1.3.0, main
- Python version: 3.12.8
- Operating system: macOS 15.1.1
What is happening?
Transpilation with optimization level 2 and 3 results in a incorrect circuit for circuits with RY gate with a small angle.
Note that the following code does not have issue with 1.2.4.
How can we reproduce the issue?
from qiskit import QuantumCircuit, generate_preset_pass_manager, __version__
from qiskit.quantum_info import Operator
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.ry(1e-6, 1)
qc.cx(0, 1)
pm = generate_preset_pass_manager(optimization_level=2)
tqc = pm.run(qc)
print(__version__)
print(qc)
print(tqc)
print("equivalent?", Operator(qc).equiv(tqc))
2.0.0.dev0+841cb29
┌───┐
q_0: ┤ H ├──■─────────────────■──
└───┘┌─┴─┐┌───────────┐┌─┴─┐
q_1: ─────┤ X ├┤ Ry(1e-06) ├┤ X ├
└───┘└───────────┘└───┘
┌───┐
q_0: ────┤ H ├────
┌───┴───┴───┐
q_1: ┤ Ry(1e-06) ├
└───────────┘
equivalent? False
1.3.0
┌───┐
q_0: ┤ H ├──■─────────────────■──
└───┘┌─┴─┐┌───────────┐┌─┴─┐
q_1: ─────┤ X ├┤ Ry(1e-06) ├┤ X ├
└───┘└───────────┘└───┘
┌───┐
q_0: ────┤ H ├────
┌───┴───┴───┐
q_1: ┤ Ry(1e-06) ├
└───────────┘
equivalent? False
1.2.4
┌───┐
q_0: ┤ H ├──■─────────────────■──
└───┘┌─┴─┐┌───────────┐┌─┴─┐
q_1: ─────┤ X ├┤ Ry(1e-06) ├┤ X ├
└───┘└───────────┘└───┘
┌───┐
q_0: ┤ H ├──■─────────────────■──
└───┘┌─┴─┐┌───────────┐┌─┴─┐
q_1: ─────┤ X ├┤ Ry(1e-06) ├┤ X ├
└───┘└───────────┘└───┘
equivalent? True
What should happen?
The transpiled circuit should be same as the input circuit as 1.2.4 does.
Another example
The following example fails with 1.2.4, 1.3.0, and main branch probably due to a similar reason.
from qiskit import QuantumCircuit, generate_preset_pass_manager, __version__
from qiskit.circuit.library import PauliEvolutionGate
from qiskit.quantum_info import SparsePauliOp, Operator
qc = QuantumCircuit(2)
op = SparsePauliOp(["XX"], coeffs=[1])
evo = PauliEvolutionGate(op, 1e-6)
qc.append(evo, qargs=qc.qregs[0])
pm = generate_preset_pass_manager(optimization_level=2, basis_gates=["rz", "cx", "sx", "x"])
tqc = pm.run(qc)
print(__version__)
print(qc)
print(tqc)
print("equivalent?", Operator(qc).equiv(tqc))
2.0.0.dev0+841cb29
┌─────────────────────┐
q_0: ┤0 ├
│ exp(-it XX)(1e-06) │
q_1: ┤1 ├
└─────────────────────┘
global phase: π/2
q_0: ─────────────────────────────────────────────────
┌─────────┐┌────┐┌─────────────┐┌────┐┌─────────┐
q_1: ┤ Rz(π/2) ├┤ √X ├┤ Rz(-3.1416) ├┤ √X ├┤ Rz(π/2) ├
└─────────┘└────┘└─────────────┘└────┘└─────────┘
equivalent? False
1.2.4
┌─────────────────────┐
q_0: ┤0 ├
│ exp(-it XX)(1e-06) │
q_1: ┤1 ├
└─────────────────────┘
global phase: π/2
q_0: ─────────────────────────────────────────────────
┌─────────┐┌────┐┌─────────────┐┌────┐┌─────────┐
q_1: ┤ Rz(π/2) ├┤ √X ├┤ Rz(-3.1416) ├┤ √X ├┤ Rz(π/2) ├
└─────────┘└────┘└─────────────┘└────┘└─────────┘
equivalent? False
Any suggestions?
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingmod: transpilerIssues and PRs related to TranspilerIssues and PRs related to Transpiler