150 lines
6.7 KiB
Plaintext
150 lines
6.7 KiB
Plaintext
---
|
||
title: EstimatorV2 (v0.29)
|
||
description: API reference for qiskit_ibm_runtime.EstimatorV2 in qiskit-ibm-runtime v0.29
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit_ibm_runtime.EstimatorV2
|
||
---
|
||
|
||
# EstimatorV2
|
||
|
||
<Class id="qiskit_ibm_runtime.EstimatorV2" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.29/qiskit_ibm_runtime/estimator.py#L46-L230" signature="EstimatorV2(mode=None, backend=None, session=None, options=None)" modifiers="class">
|
||
Class for interacting with Qiskit Runtime Estimator primitive service.
|
||
|
||
Qiskit Runtime Estimator primitive service estimates expectation values of quantum circuits and observables.
|
||
|
||
The [`run()`](#qiskit_ibm_runtime.EstimatorV2.run "qiskit_ibm_runtime.EstimatorV2.run") can be used to submit circuits, observables, and parameters to the Estimator primitive.
|
||
|
||
Following construction, an estimator is used by calling its [`run()`](#qiskit_ibm_runtime.EstimatorV2.run "qiskit_ibm_runtime.EstimatorV2.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`](/api/qiskit/qiskit.circuit.QuantumCircuit "(in Qiskit v1.2)"), possibly parametrized, whose final state we define as $\psi(\theta)$,
|
||
* one or more observables (specified as any `ObservablesArrayLike`, including `Pauli`, `SparsePauliOp`, `str`) that specify which expectation values to estimate, denoted $H_j$, and
|
||
* a 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.
|
||
|
||
```python
|
||
from qiskit.circuit.library import RealAmplitudes
|
||
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 = RealAmplitudes(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(backend=backend)
|
||
|
||
# calculate [ <psi(theta1)|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** (`Union`\[[`BackendV1`](/api/qiskit/qiskit.providers.BackendV1 "(in Qiskit v1.2)"), [`BackendV2`](/api/qiskit/qiskit.providers.BackendV2 "(in Qiskit v1.2)"), [`Session`](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.session.Session"), [`Batch`](qiskit_ibm_runtime.Batch "qiskit_ibm_runtime.batch.Batch"), `str`, `None`]) –
|
||
|
||
The execution mode used to make the primitive query. It can be:
|
||
|
||
* A `Backend` if you are using job mode.
|
||
* A [`Session`](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.Session") if you are using session execution mode.
|
||
* A [`Batch`](qiskit_ibm_runtime.Batch "qiskit_ibm_runtime.Batch") if you are using batch execution mode.
|
||
|
||
Refer to the [Qiskit Runtime documentation](/guides/execution-modes). for more information about the `Execution modes`.
|
||
|
||
* **backend** (`Union`\[`str`, [`BackendV1`](/api/qiskit/qiskit.providers.BackendV1 "(in Qiskit v1.2)"), [`BackendV2`](/api/qiskit/qiskit.providers.BackendV2 "(in Qiskit v1.2)"), `None`]) – (DEPRECATED) Backend to run the primitive. This can be a backend name or an [`IBMBackend`](qiskit_ibm_runtime.IBMBackend "qiskit_ibm_runtime.IBMBackend") instance. If a name is specified, the default account (e.g. `QiskitRuntimeService()`) is used.
|
||
|
||
* **session** (`Optional`\[[`Session`](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.session.Session")]) –
|
||
|
||
(DEPRECATED) Session in which to call the primitive.
|
||
|
||
If both `session` and `backend` are specified, `session` takes precedence. If neither is specified, and the primitive is created inside a [`qiskit_ibm_runtime.Session`](qiskit_ibm_runtime.Session "qiskit_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`, [`EstimatorOptions`](qiskit_ibm_runtime.options.EstimatorOptions "qiskit_ibm_runtime.options.estimator_options.EstimatorOptions"), `None`]) – Estimator options, see `EstimatorOptions` for detailed description.
|
||
|
||
**Raises**
|
||
|
||
**NotImplementedError** – If “q-ctrl” channel strategy is used.
|
||
|
||
## Attributes
|
||
|
||
### mode
|
||
|
||
<Attribute id="qiskit_ibm_runtime.EstimatorV2.mode">
|
||
Return the execution mode used by this primitive.
|
||
|
||
**Return type**
|
||
|
||
Optional\[[Session](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.Session") | [Batch](qiskit_ibm_runtime.Batch "qiskit_ibm_runtime.Batch")]
|
||
|
||
**Returns**
|
||
|
||
Mode used by this primitive, or `None` if an execution mode is not used.
|
||
</Attribute>
|
||
|
||
### options
|
||
|
||
<Attribute id="qiskit_ibm_runtime.EstimatorV2.options">
|
||
Return options
|
||
|
||
**Return type**
|
||
|
||
`TypeVar`(`OptionsT`, bound= `BaseOptions`)
|
||
</Attribute>
|
||
|
||
### session
|
||
|
||
<Attribute id="qiskit_ibm_runtime.EstimatorV2.session">
|
||
Return session used by this primitive.
|
||
|
||
**Return type**
|
||
|
||
`Optional`\[[`Session`](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.session.Session")]
|
||
|
||
**Returns**
|
||
|
||
Session used by this primitive, or `None` if session is not used.
|
||
</Attribute>
|
||
|
||
### version
|
||
|
||
<Attribute id="qiskit_ibm_runtime.EstimatorV2.version" attributeValue="2" />
|
||
|
||
## Methods
|
||
|
||
### run
|
||
|
||
<Function id="qiskit_ibm_runtime.EstimatorV2.run" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.29/qiskit_ibm_runtime/estimator.py#L170-L193" signature="run(pubs, *, precision=None)">
|
||
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.
|
||
|
||
**Return type**
|
||
|
||
[RuntimeJobV2](qiskit_ibm_runtime.RuntimeJobV2 "qiskit_ibm_runtime.RuntimeJobV2")
|
||
|
||
**Returns**
|
||
|
||
Submitted job.
|
||
|
||
**Raises**
|
||
|
||
**ValueError** – if precision value is not strictly greater than 0.
|
||
</Function>
|
||
</Class>
|
||
|