preset_passmanager transpilation bug if used >2 times with optimisation level 3: transpiled circuit is different and refers to unknown registers #11861
Qiskit version: 0.46.0 (appears also in 0.42; couldn't try it in 1.0.0 as I have another issue with the 'basic_simulator' backend)
Python version: 3.9
Operating system: Linux (kali-linux) and Windows 11
What is happening?
Hello,
As part of a research project, I have developed multi-step quantum algorithms and implemented them in Qiskit. In every step, I transpile a circuit first then run it on the backend (qasm_simulator). This can be simplified as (I do not wish to publish the full code directly as it is yet to be published):
This works fine with optimisation levels 0, 1 and 2. With optimisation level 3, it works fine if I only use the pass_manager once or twice per algorithm, i.e., if I replace at most 2 transpilations in any algorithm. The pass_manager returns virtually the same transpiled circuit as that returned by qiskit.transpile().
However, with optimisation level 3, if I replace an additional occurence of qiskit.transpile() by the pass_manager transpilation, the transpiled circuit is completely different. While the circuit transpiled by qiskit.transpile() is made of the correct number of qubits (4 in the example) and contains only H, X, P, U, U2, U3 and measurement gates, the circuit transpiled by the pass_manager contains fewer qubits (3 here) and also contains Ry gates. The depth is also much shorter. See below the circuits used in the example, and notice how the qubits of the wrongly transpiled circuit refer to another register (which is not created in the algorithm).
Interestingly, this issue happens consistently, whatever transpilation step I replace.
I can show/share my code in private with IBM staff. As mentioned, it is part of a yet-to-be-published research project. I had a meeting with Matthew Treinish in November who had a glimpse of it.
What should happen?
The circuit transpiled by the pass_manager should be virtually similar (or of similar 'quality') as that transpiled by qiskit.transpile().
Any suggestions?
I have tried to find the origin of the issue myself but could not pinpoint it. I reckon it is a niche problem but it might hide a bigger, underlying issue.
_An additional question I might have in the meantime is, how much speed-up could I expect from using the pass_manager rather than qiskit.transpile() when my transpilation options are always the same? Specifically, when transpiling a total of 400 circuits that use 5 qubits._
Thanks for the help and for the great work on Qiskit!
Environment
What is happening?
Hello,
As part of a research project, I have developed multi-step quantum algorithms and implemented them in Qiskit. In every step, I transpile a circuit first then run it on the backend (qasm_simulator). This can be simplified as (I do not wish to publish the full code directly as it is yet to be published):
I then post-process the counts dictionary to obtain the required information. The algorithms and every step work as expected and intended.
In order to reduce computation time, I was suggested by IBM staff to use a
pass_manager
generated asMy transpilation-run step then becomes
This works fine with optimisation levels 0, 1 and 2. With optimisation level 3, it works fine if I only use the
pass_manager
once or twice per algorithm, i.e., if I replace at most 2 transpilations in any algorithm. Thepass_manager
returns virtually the same transpiled circuit as that returned byqiskit.transpile()
.However, with optimisation level 3, if I replace an additional occurence of
qiskit.transpile()
by thepass_manager
transpilation, the transpiled circuit is completely different. While the circuit transpiled byqiskit.transpile()
is made of the correct number of qubits (4 in the example) and contains only H, X, P, U, U2, U3 and measurement gates, the circuit transpiled by thepass_manager
contains fewer qubits (3 here) and also contains Ry gates. The depth is also much shorter. See below the circuits used in the example, and notice how the qubits of the wrongly transpiled circuit refer to another register (which is not created in the algorithm).Interestingly, this issue happens consistently, whatever transpilation step I replace.
Circuits used in the example:
Original (not transpiled) circuit
Circuit transpiled by
qiskit.transpile()
(correct transpiled circuit)Circuit transpiled by the
pass_manager
How can we reproduce the issue?
I can show/share my code in private with IBM staff. As mentioned, it is part of a yet-to-be-published research project. I had a meeting with Matthew Treinish in November who had a glimpse of it.
What should happen?
The circuit transpiled by the
pass_manager
should be virtually similar (or of similar 'quality') as that transpiled byqiskit.transpile()
.Any suggestions?
I have tried to find the origin of the issue myself but could not pinpoint it. I reckon it is a niche problem but it might hide a bigger, underlying issue.
_An additional question I might have in the meantime is, how much speed-up could I expect from using the
pass_manager
rather thanqiskit.transpile()
when my transpilation options are always the same? Specifically, when transpiling a total of 400 circuits that use 5 qubits._Thanks for the help and for the great work on Qiskit!