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

Incorrect expectation values for the identity observable #58

Closed
1 task done
mberna opened this issue Jan 25, 2024 · 2 comments
Closed
1 task done

Incorrect expectation values for the identity observable #58

mberna opened this issue Jan 25, 2024 · 2 comments
Assignees
Labels
DC-4 Difficulty class 4/5 → Multidomain knowledge enhancement New non-feature request (e.g. performance) feature New feature request PL-1 Priority level 1/5 → High

Comments

@mberna
Copy link

mberna commented Jan 25, 2024

Device

MacBook Pro

OS

macOS Sonoma 14.0

Python version

3.11.7

Release version or branch/commit

1.2.2

What is the current behavior?

The expectation values returned by the ZNEEstimator are not correct for this particular example. I'm including the results of the "reference implementation" of the Estimator in qiskit.primitives and the exp values differ greatly.

What is the expected behavior?

Expectation values return by the ZNEEstimator are similar to the reference implementation.

Steps to reproduce the problem

from qiskit.circuit.library import RealAmplitudes
from qiskit.quantum_info import SparsePauliOp
from qiskit.primitives import BackendEstimator, Estimator as RefEstimator
from qiskit.providers.fake_provider import FakeBogota
from zne import zne, ZNEStrategy
from zne.noise_amplification import TwoQubitAmplifier

ZNEEstimator = zne(BackendEstimator)
fake_nairobi = FakeBogota()

circuit = RealAmplitudes(num_qubits=5, reps=2, entanglement="full")
num_parameters = circuit.num_parameters
observable = SparsePauliOp("IIIII")
parameter_values = [[0] * num_parameters]

# Reference estimator
ref_job = RefEstimator().run(circuit, observable, parameter_values)
ref_result = ref_job.result()
print("ref result:", ref_result.values)

# ZNE estimator
zne_strategy = ZNEStrategy(noise_factors=[1, 3, 5], noise_amplifier=TwoQubitAmplifier())
zne_estimator = ZNEEstimator(backend=fake_nairobi)
zne_job = zne_estimator.run(circuit, observable, parameter_values, zne_strategy=zne_strategy)
zne_result = zne_job.result()
print("zne result", zne_result.values)

Context

Tested this example with different versions of the library and the 1.0.0 was the last version that produced correct results.

Suggestions

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@mberna mberna added bug Something isn't working triage Pending assessment labels Jan 25, 2024
@pedrorrivero pedrorrivero self-assigned this Jan 25, 2024
@pedrorrivero
Copy link
Member

pedrorrivero commented Feb 1, 2024

Thanks for reporting this @mberna, read below for my initial assessment (c.c. @1ucian0).

Note

Because of the nature of this issue, it is very limited in scope and unlikely to affect anything other than trivial computations or misuses of the tool (e.g. to mitigate errors on a zero-noise/ideal simulator and under especial circumstances).

Observations

  1. Due to the observable being the trivial one (i.e. identity III...) the expectation value is always 1.0 with variance 0.0 regardless of the circuit, (level of) noise, or anything else. Because of such null variance, the scipy.curvefit extrapolation fails while trying to compute the induced error bar —a feature that came out in version 1.1.0.

  2. Real world cases where the variance is zero are highly unlikely to occur —if they ever do— since they arise in scenarios where the computation is fully deterministic: a condition that is rarely met for expectation value calculations via sampling even in the absence of noise (i.e. only if the state is an eigenstate of the observable and measurement takes place in an eigenbasis).

  3. In the following line you are requesting to amplify the noise only on two-qubit gates:

    zne_strategy = ZNEStrategy(noise_factors=[1, 3, 5], noise_amplifier=TwoQubitAmplifier())

    Since there are no such gates in your circuit (before decomposition), the noise amplification fails with a warning:

    UserWarning: Noise amplification is not performed since none of the gates are folded.
  4. TwoQubitAmplifier is the default behavior if no explicit amplifier is passed since version 1.0.0rc0 —improving upon the previous default CxAmplifier which only addresses CNOT gates. This is especially intended for use with already transpiled circuits, where all gates are going to be either one or two-qubit gates. For this particular case, something like the vanilla LocalFoldingAmplifier or GlobalFoldingAmplifier would be more suited.

Next steps

  • Update extrapolator(s) to handle zero variance smoothly, introducing support for the identity observable.
  • Build a new MultiQubitAmplifier which will amplify noise in all gates with num_qubits > 1.
  • Set such MultiQubitAmplifier as the new default in ZNEStrategy.

Please, let me know if you agree to this and I will proceed.

@pedrorrivero pedrorrivero added DC-4 Difficulty class 4/5 → Multidomain knowledge PL-1 Priority level 1/5 → High enhancement New non-feature request (e.g. performance) feature New feature request and removed triage Pending assessment bug Something isn't working labels Feb 1, 2024
@pedrorrivero pedrorrivero changed the title Incorrect expectation values returned by ZNEEstimator Incorrect expectation values for the identity observable Feb 1, 2024
@mberna
Copy link
Author

mberna commented Feb 2, 2024

  • Update extrapolator(s) to handle zero variance smoothly, introducing support for the identity observable.

I would prioritize this step over the other two. The rest sounds good to me.

pedrorrivero added a commit that referenced this issue Feb 5, 2024
<!--
⚠️ If you do not respect this template, your pull request will be
closed.
⚠️ Your pull request title should be short detailed and understandable
for all.
⚠️ Also, please add a release note file using reno if the change needs
to be
  documented in the release notes.
⚠️ If your pull request fixes an open issue, please link to the issue.

- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the CONTRIBUTING document.
-->

### Summary
Adds support for zero variance inputs in `OLSExtrapolator` and classes
implementing such interface.


### Details and comments
Builds towards solving issue #58
pedrorrivero added a commit that referenced this issue Feb 5, 2024
<!--
⚠️ If you do not respect this template, your pull request will be
closed.
⚠️ Your pull request title should be short detailed and understandable
for all.
⚠️ Also, please add a release note file using reno if the change needs
to be
  documented in the release notes.
⚠️ If your pull request fixes an open issue, please link to the issue.

- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the CONTRIBUTING document.
-->

### Summary
Add new `MultiQubitAmplifier` facade to perform noise amplification on
all multi-qubit gates.


### Details and comments
Builds towards solving issue #58
pedrorrivero added a commit that referenced this issue Feb 5, 2024
<!--
⚠️ If you do not respect this template, your pull request will be
closed.
⚠️ Your pull request title should be short detailed and understandable
for all.
⚠️ Also, please add a release note file using reno if the change needs
to be
  documented in the release notes.
⚠️ If your pull request fixes an open issue, please link to the issue.

- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the CONTRIBUTING document.
-->

### Summary
Update default amplifier in `ZNEStrategy` to act on all multi-qubit
gates (i.e. `MultiQubitAmplifier`) instead of just two-qubit gates (i.e.
`TwoQubitAmplifier`).


### Details and comments
Builds towards solving #58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DC-4 Difficulty class 4/5 → Multidomain knowledge enhancement New non-feature request (e.g. performance) feature New feature request PL-1 Priority level 1/5 → High
Projects
None yet
Development

No branches or pull requests

2 participants