Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.03k stars 2.32k forks source link

Backend `NoiseModel` is not correctly loaded by the Qiskit Runtime simulator #9380

Open SimoneGasperini opened 1 year ago

SimoneGasperini commented 1 year ago

Environment

What is happening?

I tried to run an Estimator primitive program by using the Qiskit Runtime ibmq_qasm_simulator and passing a specific NoiseModel created from a real device backend. However, it seems that the simulator is not loading correctly the noise model because the expectation value I get has zero variance (I would expect a small deviation due to noise).

How can we reproduce the issue?

from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp
from qiskit_aer.noise import NoiseModel
from qiskit_ibm_runtime import QiskitRuntimeService, Options, Session, Estimator

circ = QuantumCircuit(1)
circ.x(0)
O = SparsePauliOp(['Z'])

service = QiskitRuntimeService()

backend = service.get_backend('ibm_nairobi')
noise_model = NoiseModel.from_backend(backend)

simulator = service.get_backend('ibmq_qasm_simulator')
simulator.set_options(noise_model=noise_model)

options = Options(resilience_level=0)

with Session(service=service, backend=simulator) as session:
    estimator = Estimator(session=session, options=options)
    job = estimator.run(circuits=circ, observables=O, shots=10000)

print(job.result())

EstimatorResult(values=array([-1.]), metadata=[{'variance': 0.0, 'shots': 10000}])

What should happen?

Since the quantum circuit is preparing the state $| 1 \rangle = X | 0 \rangle$ and I'm computing the expectation valued of the Pauli $Z$ operator, the result, in case of no noise, is deterministic: $\langle Z \rangle = \langle 1 | Z | 1 \rangle = -1$. However, loading the noise model as in the example above, it should be possible to observe a small deviation from this value, together with a non-zero variance.

jakelishman commented 1 year ago

@kt474, @jyu00: this feels likely to be something in Runtime to me. If so, shall we transfer it over to you?