Open zlatko-minev opened 4 months ago
This bug reproduces on my end as well. I'm using qiskit_aer 0.13.3
, i.e. an older version than above, but still seeing the same issue.
I played with one of the offending random circuits to look for clues, in case it helps the next person to work on this.
Here is a circuit that shows the problem:
These results should match, but don't:
Now I think we can interpret the final CNOT + measurement as a measurement of ZZ on qubits 0 and 1.
So it seems that should not be affected by the final S gate on qubit 1, which commutes with ZZ.
However, removing that gate changes the result of the stabilizer method:
If the above reasoning is correct, then the stabilizer method is incorrectly processing (at least) that S gate.
Here is code to build this bug-reproducing circuit:
qc = QuantumCircuit(5,1)
qc.h([2,4])
qc.cx(2,0)
qc.s(0)
qc.cx(4,2)
qc.h(0)
qc.cx(2,3)
qc.s(4)
qc.cx(1,0)
qc.h([3,4])
qc.cx(3,2)
qc.h(3)
qc.cx(0,3)
qc.cx(3,1)
qc.s(0)
qc.s(1) # this one
qc.h(0)
qc.s(0)
qc.cx(4,0)
qc.cx(0,1)
qc.measure(1,0)
Thank you, Andrew. This is great.
I would label this as a high priority item since it's used all parts of our stack and demo testing for PEC utility and 5K scale
Here is a much simpler circuit that reproduces the problem:
qc = QuantumCircuit(3,1)
qc.h([0,1])
qc.cx(1,2)
qc.cy(0,1)
qc.cy(0,2)
qc.h(0)
qc.measure(0,0)
I found source of problem and I'm now fixing it
Wonderful thank you!
Thank you @doichanj for your quick work on this!
Do you know what conditions would cause the stabilizer simulator to give the wrong answer? This info could help decide whether recent simulations need to be re-run with the fix. No worries if not.
Informations
What is the current behavior?
Expectation values or counts of Clifford circuits that should be +1 or -1 are sometimes flipped.
Steps to reproduce the problem
What is the expected behavior?
The stabilizer should agree with statvec, density matrix, etc. @smajumderibm and I find that this is not always the case.
Suggested solutions