diff --git a/qiskit/primitives/base/base_estimator.py b/qiskit/primitives/base/base_estimator.py index 1078091304ba..7406ff549b9a 100644 --- a/qiskit/primitives/base/base_estimator.py +++ b/qiskit/primitives/base/base_estimator.py @@ -22,7 +22,7 @@ circuit and observable combinations. Following construction, an estimator is used by calling its :meth:`~.BaseEstimatorV2.run` method -with a list of pubs (Primitive Unified Blocs). Each pub contains three values that, together, +with a list of pubs (Primitive Unified Blocs). Each pub contains values that, together, define a computation unit of work for the estimator to complete: * a single :class:`~qiskit.circuit.QuantumCircuit`, possibly parametrized, whose final state we @@ -30,9 +30,11 @@ * one or more observables (specified as any :class:`~.ObservablesArrayLike`, including :class:`~.Pauli`, :class:`~.SparsePauliOp`, ``str``) that specify which expectation values to - estimate, denoted :math:`H_j`, and + estimate, denoted :math:`H_j`, -* a collection parameter value sets to bind the circuit against, :math:`\theta_k`. +* a collection parameter value sets to bind the circuit against, :math:`\theta_k`, and + +* optionally, a target precision `\epsilon` to meet or exceed for each estimate. Running an estimator returns a :class:`~qiskit.providers.JobV1` object, where calling the method :meth:`qiskit.providers.JobV1.result` results in expectation value estimates and metadata @@ -77,8 +79,10 @@ # calculate [ [, # ], # [] ] + # aiming for precision to 0.02 on all estimates job2 = estimator.run( - [(psi1, [hamiltonian1, hamiltonian3], [theta1, theta3]), (psi2, hamiltonian2, theta2)] + [(psi1, [hamiltonian1, hamiltonian3], [theta1, theta3]), (psi2, hamiltonian2, theta2)], + precision=0.02 ) job_result = job2.result() print(f"The primitive-job finished with result {job_result}") @@ -358,9 +362,8 @@ def run(self, pubs: Iterable[EstimatorPubLike], precision: float | None = None) pubs: An iterable of pub-like objects, such as tuples ``(circuit, observables)`` or ``(circuit, observables, parameter_values)``. precision: The target precision for expectation value estimates of each - run :class:`.EstimatorPub` that does not specify its own - precision. If None the estimator's default precision value - will be used. + pub that does not specify its own precision. If ``None`` the + estimator's default precision value will be used. Returns: A job object that contains results. diff --git a/qiskit/primitives/containers/estimator_pub.py b/qiskit/primitives/containers/estimator_pub.py index 351f0f50564d..71df8bb11cbd 100644 --- a/qiskit/primitives/containers/estimator_pub.py +++ b/qiskit/primitives/containers/estimator_pub.py @@ -38,8 +38,6 @@ class EstimatorPub(ShapedMixin): estimator, if ``precision=None`` the estimator will determine the target precision. """ - __slots__ = ("_circuit", "_observables", "_parameter_values", "_precision", "_shape") - def __init__( self, circuit: QuantumCircuit, @@ -55,6 +53,8 @@ def __init__( observables: An observables array. parameter_values: A bindings array, if the circuit is parametric. precision: An optional target precision for expectation value estimates. + This value takes precedence over any value owed by or supplied to an + estimator. validate: Whether to validate arguments during initialization. """ super().__init__() @@ -86,7 +86,10 @@ def parameter_values(self) -> BindingsArray: @property def precision(self) -> float | None: - """The target precision for expectation value estimates (optional).""" + """The target precision for expectation value estimates (optional). + + This value takes precedence over any value owed by or supplied to an estimator. + """ return self._precision @classmethod @@ -95,7 +98,7 @@ def coerce(cls, pub: EstimatorPubLike, precision: float | None = None) -> Estima Args: pub: A compatible object for coercion. - precision: an optional default precision to use if not + precision: An optional default precision to use if not already specified by the pub-like object. Returns: