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

Variances for non-commuting observables are wrong #1751

Closed
austingmhuang opened this issue Jun 14, 2024 · 1 comment
Closed

Variances for non-commuting observables are wrong #1751

austingmhuang opened this issue Jun 14, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@austingmhuang
Copy link

Describe the bug
Given some observable that has non-commuting elements e.g. "IX" + "IZ", the variances that is used to compute the standard error is incorrect

Steps to reproduce
Define some circuit e.g.

qc = QuantumCircuit(2)
qc.rx(np.pi/3, 0)
qc.rz(np.pi/3, 0)

Then define your observable (SparsePauliOp)
observable = SparsePauliOp(["IX", "IZ"])

Check answer to find that it is not the expected result. Since we cannot get the variance directly from the device, we compute the variance from the standard error. In the source code, the standard error is computed from the variance that is measured, so this is just reversing that step.

res = estimator.run([(qc, observable)])
var = (res.result()[0].data.stds/res.result()[0].metadata["target_precision"]) ** 2 ## 1.2167353630065918

Expected behavior
var should be around 0.43

Suggested solutions
Account for covariance when calculating variances of non-commuting observables.

Additional Information
You can verify that the variance is wrong by computing the variance manually.
Using Var(A+B) = E((A+B)^2) - (E(A+B))^2
var = estimator.run([(qc, observable.dot(observable))]).result()[0].data.evs - estimator.run([(qc, observable)]).result()[0].data.evs ** 2

  • qiskit-ibm-runtime version: 0.23
  • Python version: 3.11.9
  • Operating system: macOS
@Cryoris
Copy link
Contributor

Cryoris commented Aug 9, 2024

Can this be closed since Qiskit/qiskit#12670 is merged or do you prefer to wait until the fix is release in the upcoming 1.2 release (it's already available in the release candidate)?

@mberna mberna closed this as completed Aug 28, 2024
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

4 participants