qiskit
qiskit copied to clipboard
Transpilation Failure at Optimization Level 3
Environment
- Qiskit version: 1.0.2
- Python version: 3.10.9
- Operating system: MacOS 14.4
What is happening?
qiskit.transpile with optimization_level=3 fails to transpile this circuit:
circ = qiskit.QuantumCircuit(3, 1)
circ.swap(1, 2)
circ.measure(1, 0)
circ.measure(0, 0)
How can we reproduce the issue?
To reproduce the issue, execute the following code:
import qiskit
circ = qiskit.QuantumCircuit(3, 1)
circ.swap(1, 2)
circ.measure(1, 0)
circ.measure(0, 0)
print(qiskit.transpile(circ, optimization_level=3))
Running this code results in ValueError:
File "qiskit/transpiler/passes/optimization/optimize_swap_before_measure.py", line 65, in run
new_measure_qarg = swap_qargs[swap_qargs.index(old_measure_qarg) - 1]
ValueError: tuple.index(x): x not in tuple
What should happen?
The circuit should be transpiled without any errors.
Any suggestions?
No response
Thanks for the report. I was just looking into this and made #12128 to point out a few more things I'd spotted in OptimizeSwapBeforeMeasure, but as I was doing that, I found a bunch more places where the pass really doesn't seem to have the correct behaviour. There's changes coming in Rustworkx 0.15 that should let us do this efficiently rather more soundly - at the moment, I'm a bit worried that there's more soundness holes in OptimizeSwapBeforeMeasure.
This issue also affects 0.46