EstimatorV2¶
- class EstimatorV2(mode=None, options=None)[source]¶
Bases:
BasePrimitiveV2[EstimatorOptions],Estimator,BaseEstimatorV2Class 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.Following construction, an estimator is used by calling its
run()method with a list of PUBs (Primitive Unified Blocs). Each PUB contains four values that, together, define a computation unit of work for the estimator to complete:a single
QuantumCircuit, possibly parametrized, whose final state we define as \(\psi(\theta)\),one or more observables (specified as any
ObservablesArrayLike, includingPauli,SparsePauliOp,str) that specify which expectation values to estimate, denoted \(H_j\), anda collection parameter value sets to bind the circuit against, \(\theta_k\).
an optional target precision for expectation value estimates.
Here is an example of how the estimator is used.
from qiskit.circuit.library import real_amplitudes from qiskit.quantum_info import SparsePauliOp from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager from qiskit_ibm_runtime import QiskitRuntimeService, EstimatorV2 as Estimator service = QiskitRuntimeService() backend = service.least_busy(operational=True, simulator=False) psi = real_amplitudes(num_qubits=2, reps=2) hamiltonian = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)]) theta = [0, 1, 1, 2, 3, 5] pm = generate_preset_pass_manager(backend=backend, optimization_level=1) isa_psi = pm.run(psi) isa_observables = hamiltonian.apply_layout(isa_psi.layout) estimator = Estimator(mode=backend) # calculate [ <psi(theta)|hamiltonian|psi(theta)> ] job = estimator.run([(isa_psi, isa_observables, [theta])]) pub_result = job.result()[0] print(f"Expectation values: {pub_result.data.evs}")
Initializes the Estimator primitive.
- Parameters:
mode (Optional[Union[BackendV2, Session, Batch, str]]) –
The execution mode used to make the primitive query. It can be:
A
Backendif you are using job mode.A
Sessionif you are using session execution mode.A
Batchif you are using batch execution mode.
Refer to the Qiskit Runtime documentation. for more information about the
Execution modes.options (Optional[Union[Dict, EstimatorOptions]]) – Estimator options, see
EstimatorOptionsfor detailed description.
Attributes
- mode¶
Return the execution mode used by this primitive.
- Returns:
Mode used by this primitive, or
Noneif an execution mode is not used.
- options¶
Return options
- version = 2¶
Methods
- run(pubs, *, precision=None)[source]¶
Submit a request to the estimator primitive.
- Parameters:
pubs (Iterable[EstimatorPubLike]) – An iterable of pub-like (primitive unified bloc) objects, such as tuples
(circuit, observables)or(circuit, observables, parameter_values).precision (float | None) – The target precision for expectation value estimates of each run Estimator Pub that does not specify its own precision. If None the estimator’s default precision value will be used.
- Returns:
Submitted job.
- Raises:
ValueError – if precision value is not strictly greater than 0.
- Return type: