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: 24.1.0 Darwin Kernel Version 24.1.0
What is the current behavior?
There appears to be an issue with Qiskit Aer’s statevector_simulator where statevectors produced by different seed_simulator values are inconsistent.
The inconsistency can create challenges in deterministic simulations that rely on seed_simulator to generate reproducible results.
Steps to reproduce the problem
from qiskit import Aer, QuantumCircuit, transpile
import numpy as np
def try_angles_qiskit():
qc_test = QuantumCircuit(2, 2)
qc_test.u(np.pi, 1, 1, 0) # U gate with angle np.pi
qc_test.rx(np.pi**50, 0) # RX gate with a large angle
qc_test.ry(np.pi**50, 0) # RY gate with a large angle
qc_test.u(np.random.rand() * 2 * np.pi, np.random.rand() * 2 * np.pi, np.random.rand() * 2 * np.pi, 0)
qc_test.u(np.random.rand() * 2 * np.pi, np.random.rand() * 2 * np.pi, np.random.rand() * 2 * np.pi, 1)
qc_test.cx(0, 1) # CNOT between qubit 0 and qubit 1
# Measure the qubits
qc_test.measure_all()
simulator = Aer.get_backend('statevector_simulator')
transpiled_qc = transpile(qc_test, simulator)
seeds = ["42", "-42", (42), -42, 42.4, 42, b"42", "\t42\n", 2**63-1, 0, 0.0, -0.0, 1.0, -1.0, 1e3, -1e3, True, None, 330]
results = []
for seed in seeds:
job = simulator.run(transpiled_qc, seed_simulator=seed, shots=1024)
results.append(job.result().get_statevector())
for seed, sv in zip(seeds, results):
print(f"\nSeed: {seed} \n{sv}")
print("Are all statevectors equal?", all(np.allclose(results[0], r) for r in results))
print(qc_test)
return qc_test
try_angles_qiskit()
Observed Results:
For most seed values ("42", "-42", (42), -42, 42.4, 42, b"42", "\t42\n", 2**63-1, 0, 0.0, -0.0, 1.0, -1.0, 1e3, True, None, 330), the statevector remains the same:
The statevector should be deterministic for all seed values, meaning that running the simulation with the same seed value should produce the same result every time. The output should be consistent for all seeds.
Suggested solutions
The text was updated successfully, but these errors were encountered:
you must be using a broken or very old Qiskit installation, because from qiskit import Aer hasn't worked for a long time (it should be from qiskit_aer import Aer)
your huge Rx/Ry angles are meaningless noise - $\pi^{50} \approx 7.20267\dotsi,\times 10^{24}$, and at that size of value, the difference between consecutive floats is $2^{30}$, so humongously bigger than any sort of precision needed to represent an angle (not that it matters for this issue).
if you ask for the statevector after you've taken the measurement, you're going to get the collapsed form, which is subject to seed-based randomisation because it depends on the measurement taken. Remove the measure_all and you should get the results you expect.
Just for the future, too - if there's more bugs, it's helpful if you can ensure that you're providing fully deterministic reproducers. It doesn't matter here because the issues are elsewhere, but in general, putting angle-randomisation calls in the middle of circuit generation is likely to mean that we'll not be able to reproduce what you saw (and if you're looking into things, you probably want to be able to control that to reproduce the same things later anyway).
Informations
What is the current behavior?
There appears to be an issue with Qiskit Aer’s
statevector_simulator
where statevectors produced by differentseed_simulator
values are inconsistent.The inconsistency can create challenges in deterministic simulations that rely on
seed_simulator
to generate reproducible results.Steps to reproduce the problem
Observed Results:
For most seed values ("42", "-42", (42), -42, 42.4, 42, b"42", "\t42\n", 2**63-1, 0, 0.0, -0.0, 1.0, -1.0, 1e3, True, None, 330), the statevector remains the same:
However, the statevector produced by the seed -1000.0 is different:
What is the expected behavior?
The statevector should be deterministic for all seed values, meaning that running the simulation with the same seed value should produce the same result every time. The output should be consistent for all seeds.
Suggested solutions
The text was updated successfully, but these errors were encountered: