Estimator¶
- class Estimator(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:
session (
Union
[Session
,str
,IBMBackend
,None
]) –Session in which to call the primitive.
If an instance of
qiskit_ibm_runtime.IBMBackend
class or string name of a backend is specified, a new session is created for that backend, unless a default session for the same backend and channel already exists.If
None
, a new session is created using the default saved account and a default backend (IBM Cloud channel only), unless a default session already exists.
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 estimator.
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 estimator.