I have the following code to run an Estimator
primitive by using Qiskit Runtime. It computes the expectation value $\langle O \rangle = \langle \psi | O | \psi \rangle$ (in this example $\langle 0 | Z | 0 \rangle = 1$ with zero variance):
from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp
from qiskit_ibm_runtime import QiskitRuntimeService, Options, Session, Estimator
# prepare the state |Ψ>
qc = QuantumCircuit(1)
# define the operator/observable O
O = SparsePauliOp(['Z'])
service = QiskitRuntimeService()
backend = 'ibmq_qasm_simulator'
options = Options(resilience_level=0)
with Session(service=service, backend=backend) as session:
estimator = Estimator(session=session, options=options)
job = estimator.run(circuits=[qc], observables=[O])
print(job.result().values)
I know that Qiskit Runtime primitives can run on real IBM quantum devices but what I'm wondering whether is possible run them by using fake backends (or, more in general, custom noise models). For example, how can I run the code above on the FakeManila
backend or passing a NoiseModel
instance? Is there any other way to do that?