qiskit-aer
qiskit-aer copied to clipboard
Inconsistent Statevector Results with seed_simulator
Informations
- Qiskit Aer version: 0.15.1
- Python version: 3.12.6
- 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:
Statevector([-0. +0.j , 0.36316625+0.93172436j,
0. +0.j , -0. +0.j ],
dims=(2, 2))
However, the statevector produced by the seed -1000.0 is different:
Statevector([-0. +0.j , 0. +0.j ,
0.6132849+0.78986178j, -0. +0.j ],
dims=(2, 2))
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.