-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
QPY invalid payload generation via compose()
or QuantumCircuit.control()
#9746
Comments
For anyone experiencing this you can work around this failure by changing: qc.compose(qc0.control(1), [0,1,2], inplace=True)
qc.compose(qc1.control(1), [0,1,2], inplace=True) to qc.append(qc0.control(1), [0,1,2])
qc.append(qc1.control(1), [0,1,2]) |
I think something's a bit odd about If I change |
Hmm, that seems odd qpy shouldn't care about it being wrapped in a custom instruction. I wonder if it's the same bug as #8941 where the controlled gates are ending up with the same names and that's causing issues. |
I'm suspicious that there's a mistake in the recursive handling, when there's multiple custom instructions that all contain other custom instructions. I'm fairly confident the issue happens during the QPY dump, not the read. I instrumented |
Hi all, thanks for looking into this issue ! The workaround proposed above (with From what I could understand, when Thanks again ! |
The key to the workaround I suggested in #9746 (comment) is that it's using the
which decomposed looks like:
and another layer deeper is:
|
The workaround uses I don't believe there's anything wrong with the QPY format itself, but I am suspicious that the recursive handling of custom gates (of which this is an example) might be skipping one of the necessary circuits when there's several compound custom gates in succession. |
Oh I didn't notice the |
Interestingly, as of 0.25.0, QPY now throws an error during the re-load, which might suggest where the underlying bug was:
(or alternatively I broke something with #10392) |
Oh no wait, sorry, I totally forgot what the top comment says - the error's the exact same. That's what I get for trying to come back to an issue after a couple of months and not taking the time to re-read everything properly. |
I've got it: it's a bug in outputting the custom operations for a circuit that contains more than one; the breadth-first search through the new operations wasn't actually going breadth-first, it was only going through the new custom operations that appear from the last gate in the outer circuit because it was overwriting gates from before. It's not actually anything to do with |
Environment
What is happening?
Running
compose()
withinplace=True
from an input generated withQuantumCircuit.control()
leads to a circuit that when qpy serialized is not load-able. This points to an internal state that doesn't match the actual data of the instruction object. I expect the mismatch is caused by the number of arguments or qubits the gate reported in qc which is incorrectThe specific failure in this case is:
How can we reproduce the issue?
What should happen?
This should not error during the
load()
callAny suggestions?
I believe something about the compose call is corrupting the internal state of the circuit which is leading to a QPY payload that has a mismatch between a size
The text was updated successfully, but these errors were encountered: