-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Environment
- Qiskit version: 1.2.0
- Python version: 3.10.12
- Operating system: Ubuntu 23.10 LTS
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.
from qiskit import QuantumCircuit
from helpers.qiskit_helpers import simulate_circuit
from qiskit.transpiler.passes import *
from qiskit.transpiler.passmanager import PassManager
from numpy import vdot
from qiskit.quantum_info import Statevector
from qiskit import QuantumCircuit
def simulate_circuit(qc : QuantumCircuit):
state = Statevector.from_int(0, 2**qc.num_qubits)
state = state.evolve(qc)
return state
main_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 pass
if(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
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working