You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ilan and I found this issue when testing our circuit with specific transpiler passes:
When passing a specific circuit through the HoareOptimizer(), there seems to be a change to the semantics of the circuit.
How can we reproduce the issue?
Running the code below will produce 2 state-vectors: one before passing the circuit through HoareOptimizer() and one after. They are not the same, and the subsequent circuit print shows that a CX gate was removed where it shouldn't have.
fromqiskitimportQuantumCircuitfromhelpers.qiskit_helpersimportsimulate_circuitfromqiskit.transpiler.passesimport*fromqiskit.transpiler.passmanagerimportPassManagerfromnumpyimportvdotfromqiskit.quantum_infoimportStatevectorfromqiskitimportQuantumCircuitdefsimulate_circuit(qc : QuantumCircuit):
state=Statevector.from_int(0, 2**qc.num_qubits)
state=state.evolve(qc)
returnstatemain_circ=QuantumCircuit(3)
# Applying gates main_circ.cx(1, 0)
main_circ.x(2)
main_circ.x(0)
main_circ.cx(2, 0)
passes=PassManager(
[HoareOptimizer()]
)
pass_circ=passes.run(main_circ)
sv0=simulate_circuit(main_circ)
sv1=simulate_circuit(pass_circ)
# Compare the circuit statevector before and after the passif(round(abs(vdot(sv0, sv1)), 6) !=1):
print("Failed test!\n")
print(sv0)
print(sv1)
else:
print("Passed test!\n")
print(main_circ)
print(pass_circ)
The circuit before optimization:
┌───┐┌───┐┌───┐
q_0: ┤ X ├┤ X ├┤ X ├
└─┬─┘└───┘└─┬─┘
q_1: ──■─────────┼──
┌───┐ │
q_2: ┤ X ├───────■──
└───┘
The circuit after:
┌───┐
q_0: ┤ X ├
└───┘
q_1: ─────
┌───┐
q_2: ┤ X ├
└───┘
What should happen?
The circuit should have been optimized in a way that produced the same resulting state-vector.
Might be related to this issue #4981 that was closed.
Any suggestions?
No response
The text was updated successfully, but these errors were encountered:
Thanks for reporting the problem. I have not tested this for Qiskit 1.2, but in the current development branch the bug manifested as a DAGCircuitError exception. There was indeed a problem, and I have checked in a fix in #13083. As I have commented in the fix, the code is very messy and I would not be surprised if there were many other bugs as well, please keep reporting these if you find them. The code would probably benefit from a complete rewrite, in addition to porting it to Rust :).
One other small comment: the equality for two Statevectors already takes some tolerance into account, so you can directly check whether sv0 == sv1 instead of computing the dot product of sv0 and sv1.
Environment
What is happening?
Ilan and I found this issue when testing our circuit with specific transpiler passes:
When passing a specific circuit through the
HoareOptimizer()
, there seems to be a change to the semantics of the circuit.How can we reproduce the issue?
Running the code below will produce 2 state-vectors: one before passing the circuit through
HoareOptimizer()
and one after. They are not the same, and the subsequent circuit print shows that a CX gate was removed where it shouldn't have.The circuit before optimization:
The circuit after:
What should happen?
The circuit should have been optimized in a way that produced the same resulting state-vector.
Might be related to this issue #4981 that was closed.
Any suggestions?
No response
The text was updated successfully, but these errors were encountered: