-
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
incorrect statevector simulation using qiskit & qiskit-aer #13778
Comments
Does the same happen if you're using the the built-in |
print(f"err between native sv & qiskit-aer: {abs(sv-native_sv).sum()}")
# in qiskit 1.2.4, gives 4.207136026297062e-14
# in qiskit 1.3.0, gives 4.17854036971304 So summary:
|
Digging into this a bit: print(f"Equivalent? {Statevector(circuit).equiv(Statevector(sv)}") it should print IIRC we expect all passes to preserve global phase, so there is something wrong here in the decomposition of the controlled unitary. To fix this on your end you can just force the transpiler to fully unroll the circuit, that seems to still be correct: circ = transpile(circuit, basis_gates=["u", "cx"]) |
Here's a more minimal reproducer (note the failure depends on the seed) from qiskit import QuantumCircuit, transpile
from qiskit.circuit.library import UnitaryGate
from qiskit.quantum_info import random_unitary, Operator
from qiskit_aer import AerSimulator
import numpy as np
rand_unitary = random_unitary(4, seed=73)
gate = UnitaryGate(rand_unitary).control(1)
circuit = QuantumCircuit(3)
circuit.h(0)
circuit.append(gate, [0, 2, 1])
print(circuit.draw())
sim = AerSimulator(method="statevector")
circ = transpile(circuit, sim)
print("equal?", Operator(circuit) == Operator(circ)) # False
print("equiv?", Operator(circuit).equiv(Operator(circ))) # True |
A simplified version:
|
Environment
mirror ticket from Qiskit/qiskit-aer#2271 for visibility
What is happening?
For a fixed QuantumCircuit with custom unitary gate matrix, QiskitAer is producing different statevector simulation results for qiskit v.1.2.4 and v.1.3.0
How can we reproduce the issue?
Using
qiskit-aer=0.15.1
, run the following script withqiskit==1.2.4
andqiskit==1.3.0
will reproduce different statevector resultsWhat should happen?
The gate matrices defining the custom unitary gates are identical between
qiskit==1.2.4
andqiskit==1.3.0
and therefore the returned statevector should be the same. On my end I have the following results:qiskit==1.2.4
qiskit==1.3.0
From our experiment, I believe the results from
qiskit=1.2.4
are correct. There might be some parsing issue betweenqiskit-aer
andqiskit==1.3.0
Any suggestions?
No response
The text was updated successfully, but these errors were encountered: