from qiskit import QuantumCircuit
from qiskit.quantum_info.operators import SparsePauliOp
from qiskit_aer.primitives import Estimator
qc = QuantumCircuit(2)
op = SparsePauliOp(["XY", "XX"], coeffs=[0.5, 0.2j])
estimator1 = Estimator(run_options={"shots": 1000})
estimator2 = Estimator(approximation=True, run_options={"shots": None})
print("Estimator with shot noise")
print(estimator1.run(qc, op).result().values)
print(estimator1.run(qc, op).result().values)
print()
print("Estimator without shot noise")
print(estimator2.run(qc, op).result().values)
print(estimator2.run(qc, op).result().values)
What is the expected behavior?
The expected behavior is to give the noiseless result instead of throwing an error.
Suggested solutions
I looked into the source code of qiskit_aer and found the following code (in qiskit_aer.primitives.estimator beginning on line 454):
if shots is None:
circuit.save_expectation_value(observable, self._layouts[i])
else:
for term_ind, pauli in enumerate(observable.paulis):
circuit.save_expectation_value(
pauli, self._layouts[i], label=str(term_ind)
)
It looks like when shot=None and approximation=True, it saves the expectation value differently than when there is shot-noise.
Informations
What is the current behavior?
Throws the following error:
Steps to reproduce the problem
What is the expected behavior?
The expected behavior is to give the noiseless result instead of throwing an error.
Suggested solutions
I looked into the source code of
qiskit_aer
and found the following code (inqiskit_aer.primitives.estimator
beginning on line 454):It looks like when
shot=None
andapproximation=True
, it saves the expectation value differently than when there is shot-noise.