qiskit-aer icon indicating copy to clipboard operation
qiskit-aer copied to clipboard

Estimator with approximation=True gives poor approximation

Open kevinsung opened this issue 1 year ago • 2 comments

Informations

  • Qiskit Aer version: 0.13.0
  • Python version: 3.10.12
  • Operating system: Arch Linux

What is the current behavior?

I initialize a noise model from a fake backend. I run the estimator with a simple circuit and observable. The ideal expectation value is 1.0. approximation=True gives 0.981. approximation=False gives 0.916.

Steps to reproduce the problem

from qiskit import QuantumCircuit
from qiskit.providers.fake_provider import FakeGuadalupeV2
from qiskit.quantum_info import SparsePauliOp
from qiskit_aer.primitives import Estimator
from qiskit_aer.noise import NoiseModel


qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)

observable = SparsePauliOp("ZZ")

fake_backend = FakeGuadalupeV2()
noise_model = NoiseModel.from_backend(fake_backend)

print("approximation=True")
estimator = Estimator(backend_options=dict(noise_model=noise_model), approximation=True)
job = estimator.run(qc, [observable])
result = job.result()
exp_value = result.values[0]
print(exp_value)
print()

print("approximation=False")
estimator = Estimator(backend_options=dict(noise_model=noise_model), approximation=False)
job = estimator.run(qc, [observable], shots=100000)
result = job.result()
exp_value = result.values[0]
print(exp_value)
approximation=True
[/tmp/ipykernel_93816/3992086219.py:18](https://file+.vscode-resource.vscode-cdn.net/tmp/ipykernel_93816/3992086219.py:18): DeprecationWarning: ``qiskit_aer.primitives.estimator.Estimator.__init__()``'s argument ``approximation`` is deprecated as of qiskit-aer 0.13. It will be removed no earlier than 3 months after the release date. approximation=True will be default in the future.
  estimator = Estimator(backend_options=dict(noise_model=noise_model), approximation=True)
0.9817418982111457

approximation=False
[/tmp/ipykernel_93816/3992086219.py:26](https://file+.vscode-resource.vscode-cdn.net/tmp/ipykernel_93816/3992086219.py:26): DeprecationWarning: ``qiskit_aer.primitives.estimator.Estimator.__init__()``'s argument ``approximation`` is deprecated as of qiskit-aer 0.13. It will be removed no earlier than 3 months after the release date. approximation=True will be default in the future.
  estimator = Estimator(backend_options=dict(noise_model=noise_model), approximation=False)
[/tmp/ipykernel_93816/3992086219.py:26](https://file+.vscode-resource.vscode-cdn.net/tmp/ipykernel_93816/3992086219.py:26): DeprecationWarning: Option approximation=False is deprecated as of qiskit-aer 0.13. It will be removed no earlier than 3 months after the release date. Instead, use BackendEstmator from qiskit.primitives.
  estimator = Estimator(backend_options=dict(noise_model=noise_model), approximation=False)
0.91606

What is the expected behavior?

Should be a better approximation.

Suggested solutions

kevinsung avatar Nov 03 '23 22:11 kevinsung

Here's another example. approximation=True gives 0.822. approximation=False gives 0.515.

from qiskit.circuit.library import EfficientSU2
from qiskit.providers.fake_provider import FakeGuadalupeV2
from qiskit.quantum_info import SparsePauliOp
from qiskit_aer.primitives import Estimator
from qiskit_aer.noise import NoiseModel

n_qubits = 10
qc = EfficientSU2(n_qubits)
observable = SparsePauliOp("Z" * n_qubits)
params = [0.1] * qc.num_parameters

fake_backend = FakeGuadalupeV2()
noise_model = NoiseModel.from_backend(fake_backend)

print("approximation=True")
estimator = Estimator(backend_options=dict(noise_model=noise_model), approximation=True)
job = estimator.run(qc, [observable], params)
result = job.result()
exp_value = result.values[0]
print(exp_value)
print()

print("approximation=False")
estimator = Estimator(
    backend_options=dict(noise_model=noise_model), approximation=False
)
job = estimator.run(qc, [observable], params, shots=100000)
result = job.result()
exp_value = result.values[0]
print(exp_value)
approximation=True
[/tmp/ipykernel_167962/2694009822.py:16](https://file+.vscode-resource.vscode-cdn.net/tmp/ipykernel_167962/2694009822.py:16): DeprecationWarning: ``qiskit_aer.primitives.estimator.Estimator.__init__()``'s argument ``approximation`` is deprecated as of qiskit-aer 0.13. It will be removed no earlier than 3 months after the release date. approximation=True will be default in the future.
  estimator = Estimator(backend_options=dict(noise_model=noise_model), approximation=True)
0.8223240822533419

approximation=False
[/tmp/ipykernel_167962/2694009822.py:24](https://file+.vscode-resource.vscode-cdn.net/tmp/ipykernel_167962/2694009822.py:24): DeprecationWarning: ``qiskit_aer.primitives.estimator.Estimator.__init__()``'s argument ``approximation`` is deprecated as of qiskit-aer 0.13. It will be removed no earlier than 3 months after the release date. approximation=True will be default in the future.
  estimator = Estimator(
[/tmp/ipykernel_167962/2694009822.py:24](https://file+.vscode-resource.vscode-cdn.net/tmp/ipykernel_167962/2694009822.py:24): DeprecationWarning: Option approximation=False is deprecated as of qiskit-aer 0.13. It will be removed no earlier than 3 months after the release date. Instead, use BackendEstmator from qiskit.primitives.
  estimator = Estimator(
0.51516

kevinsung avatar Nov 07 '23 14:11 kevinsung

This is not a bug. This approximation method ignores measurement errors. It should be explicitly written in the documentation.

(I have an idea for a method to take in the error, but it takes time.)

ikkoham avatar Nov 07 '23 15:11 ikkoham