Skip to content
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

Bug on expectation value calculated with Estimator primitive #13715

Open
jvscursulim opened this issue Jan 22, 2025 · 2 comments
Open

Bug on expectation value calculated with Estimator primitive #13715

jvscursulim opened this issue Jan 22, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@jvscursulim
Copy link

jvscursulim commented Jan 22, 2025

Environment

  • Qiskit version: 1.2.4
  • Python version: 3.11.10
  • Operating system: Ubuntu 24.04.1 LTS

What is happening?

I was using Estimator to compute the expectation value of some observables, however I noticed that for some observables composed only by X, the result obtained with Estimator does not match with the result by the method expectation_value() from Statevector and calculations done by hand. The expectation value for some cases should be +1 or -1, but the results are equal to 0.

How can we reproduce the issue?

import numpy as np

from qiskit.circuit import QuantumCircuit, QuantumRegister
from qiskit.quantum_info import SparsePauliOp, Statevector
from qiskit_aer.primitives import EstimatorV2 as Estimator

stabilizers = [SparsePauliOp(data=["IZIZ"], coeffs=np.array([1.0])),
               SparsePauliOp(data=["ZIZI"], coeffs=np.array([1.0])),
               SparsePauliOp(data=["XXXX"], coeffs=np.array([1.0]))]

qubits = QuantumRegister(size=4, name="qubits")

qc = QuantumCircuit(qubits)
qc.h(qubit=qubits[0])
for i in range(1,4):
    qc.cx(control_qubit=qubits[0], target_qubit=qubits[i])

estimator = Estimator()
estimator_results = estimator.run(pubs=[(qc, stabilizer) for stabilizer in stabilizers]).result()

print("Noiseless experiment")
for idx, stabilizer in enumerate(stabilizers):
    print(f"Stabilizer - {stabilizer.paulis.to_labels()} - Expected value: {estimator_results[idx].data.evs}")

sv = Statevector(qc)
print(sv.expectation_value(stabilizers[-1]))

What should happen?

The expectation value of the SparsePauliOp(data=["XXXX"], coeffs=np.array([1.0])) should be equal to +1.0 when we calculate it with Estimator and with a quantum circuit that creates the following quantum state $\vert\psi\rangle = \frac{1}{\sqrt{2}}(\vert0000\rangle + \vert1111\rangle)$.

Any suggestions?

No response

@jvscursulim jvscursulim added the bug Something isn't working label Jan 22, 2025
@Cryoris
Copy link
Contributor

Cryoris commented Jan 22, 2025

What version of qiskit-aer are you using? For me the snippet above produces the following which seems correct (also on qiskit==1.2.4):

Noiseless experiment
Stabilizer - ['IZIZ'] - Expected value: 1.0
Stabilizer - ['ZIZI'] - Expected value: 1.0
Stabilizer - ['XXXX'] - Expected value: 1.0
(0.9999999999999998+0j)

@jvscursulim
Copy link
Author

I'm using qiskit-aer-gpu==0.15.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants