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
Operating system: Ubuntu 22.04 LTS on Windows 11 WSL
What is happening?
Ilan and I have found a possible miscompilation caused by the transpiler.
The resulting state-vector of the circuit after putting it through transpile() changes abruptly after optimization level has been set to above 2, thereby also changing the states of the circuit upon measurement.
How can we reproduce the issue?
fromqiskitimportQuantumCircuitfromqiskit.transpilerimportgenerate_preset_pass_managerfromqiskit.quantum_infoimportStatevectorfromnumpyimportvdotdefsimulate_circuit(qc : QuantumCircuit):
state=Statevector.from_int(0, 2**qc.num_qubits)
state=state.evolve(qc)
returnstatedefcompare_statevectors(qc : QuantumCircuit):
# Need to set the seed for consistent transpiler pass results across optimisation levelsoptions= {'seed_transpiler': 1235}
sv0=simulate_circuit(qc)
# Code for checking different levels of optimization levels and if they are the sameforiinrange(4):
pass_manager=generate_preset_pass_manager(optimization_level=i, **options)
transpiled_circuit=pass_manager.run(qc)
sv=simulate_circuit(transpiled_circuit)
# Uncomment to see statevector# print(sv) if(sv0==sv):
print("Level ", i, " passed")
else:
print("Failed level ", i, ". Dot product is: " , abs(vdot(sv0, sv)), "\n")
subcirc2=QuantumCircuit(2)
subcirc2.z(0)
subcirc2.h(0)
subcirc2.z(0)
subcirc2.s(1)
subcirc2=subcirc2.to_gate().control(1)
main_circ=QuantumCircuit(4)
main_circ.h(0)
main_circ.append(subcirc2,[0, 2, 3])
main_circ.append(subcirc2,[0, 2, 3])
main_circ.append(subcirc2,[0, 2, 3])
main_circ.h(2)
compare_statevectors(main_circ)
Running the above code will reveal that the state-vectors are different when the optimization level is above 2. The results will also be the same if the circuit was instead run on AerBackend, with optimization levels 2 and 3 producing very different measured states than levels 0 and 1.
This is done on the latest version of qiskit (1.3.0), which we have compiled from source to get the latest fixes. However, it seems like this issue is also present in version 1.2.0.
What should happen?
The circuit should not have a different state-vector after putting it through the transpiler.
Any suggestions?
No response
The text was updated successfully, but these errors were encountered:
It looks like #12704 introduced this bug, after Consolidate2qBlocks it appears the unitary is not correct anymore. Though this is quite fragile to reproduce, e.g. removing the h gate from the subcircuit or from the main_circuit the unitary is still correct.
Environment
What is happening?
Ilan and I have found a possible miscompilation caused by the transpiler.
The resulting state-vector of the circuit after putting it through
transpile()
changes abruptly after optimization level has been set to above 2, thereby also changing the states of the circuit upon measurement.How can we reproduce the issue?
Running the above code will reveal that the state-vectors are different when the optimization level is above 2. The results will also be the same if the circuit was instead run on
AerBackend
, with optimization levels 2 and 3 producing very different measured states than levels 0 and 1.This is done on the latest version of qiskit (1.3.0), which we have compiled from source to get the latest fixes. However, it seems like this issue is also present in version 1.2.0.
What should happen?
The circuit should not have a different state-vector after putting it through the transpiler.
Any suggestions?
No response
The text was updated successfully, but these errors were encountered: