Estimator¶
- class Estimator(backend=None, session=None, options=None)[source]¶
Class for interacting with Qiskit Runtime Estimator primitive service.
Qiskit Runtime Estimator primitive service estimates expectation values of quantum circuits and observables.
The
run()
can be used to submit circuits, observables, and parameters to the Estimator primitive.You are encouraged to use
Session
to open a session, during which you can invoke one or more primitives. Jobs submitted within a session are prioritized by the scheduler, and data is cached for efficiency.Example:
from qiskit.circuit.library import RealAmplitudes from qiskit.quantum_info import SparsePauliOp from qiskit_ibm_runtime import QiskitRuntimeService, Estimator service = QiskitRuntimeService(channel="ibm_cloud") psi1 = RealAmplitudes(num_qubits=2, reps=2) H1 = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)]) H2 = SparsePauliOp.from_list([("IZ", 1)]) H3 = SparsePauliOp.from_list([("ZI", 1), ("ZZ", 1)]) with Session(service=service, backend="ibmq_qasm_simulator") as session: estimator = Estimator(session=session) theta1 = [0, 1, 1, 2, 3, 5] # calculate [ <psi1(theta1)|H1|psi1(theta1)> ] psi1_H1 = estimator.run(circuits=[psi1], observables=[H1], parameter_values=[theta1]) print(psi1_H1.result()) # calculate [ <psi1(theta1)|H2|psi1(theta1)>, <psi1(theta1)|H3|psi1(theta1)> ] psi1_H23 = estimator.run( circuits=[psi1, psi1], observables=[H2, H3], parameter_values=[theta1]*2 ) print(psi1_H23.result()) # Close the session only if all jobs are finished # and you don't need to run more in the session session.close()
Initializes the Estimator primitive.
- Parameters:
backend (
Union
[str
,IBMBackend
,None
]) – Backend to run the primitive. This can be a backend name or anIBMBackend
instance. If a name is specified, the default account (e.g.QiskitRuntimeService()
) is used.session (
Union
[Session
,str
,IBMBackend
,None
]) –Session in which to call the primitive.
If both
session
andbackend
are specified,session
takes precedence. If neither is specified, and the primitive is created inside aqiskit_ibm_runtime.Session
context manager, then the session is used. Otherwise if IBM Cloud channel is used, a default backend is selected.options (
Union
[Dict
,Options
,None
]) – Primitive options, seeOptions
for detailed description. Thebackend
keyword is still supported but is deprecated.
Attributes
Quantum circuits that represents quantum states.
Observables to be estimated.
Return options values for the sampler.
Parameters of the quantum circuits.
Return session used by this primitive.
Methods
Estimator.run
(circuits, observables[, ...])Submit a request to the estimator primitive.
Estimator.set_options
(**fields)Set options values for the sampler.