Open IlanIwumbwe opened 2 months ago
Thanks for the report - this seems to be a rather long-standing bug that I was able to reproduce at least as far back as 1.1.0, and probably appeared before that. It's quite possibly somewhere in the BasisTranslator
around nested multi-block control flow. Here's a more minimal reproducer:
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
qc = QuantumCircuit(3, 1)
with qc.if_test((0, False)) as else_:
pass
with else_:
with qc.if_test((0, False)) as else2:
qc.rccx(0, 1, 2)
with else2:
pass
transpiled = transpile(qc, AerSimulator())
and if we do transpiled.draw()
, we can see that the rccx
gate survived basis translation, despite GatesInBasis
recognising that it ought to have been rewritten.
The structure of the control flow seems to matter; on my cursory testing, it seems to require at least two nested structures, both of which have more than one branch, but I don't know the cause.
Thanks for the quick response!
Environment
Benny and I found this bug
What is happening?
Unknown instruction appears in transpiled circuit sometimes. Run the code below a few times and it should fail with:
We tried to investigate this a bit, by printing out all the instructions and comparing from the version that works vs the one that doesn't. This is because we guessed that maybe some decomposition isn't being done.
The output below shows what we got. Blocks surrounded by "======" are the same, blocks left alone are different.
Working instructions:
Not working instructions:
How can we reproduce the issue?
What should happen?
Circuit should be runnable all the time
Any suggestions?
No response