Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Ian Hincks <[email protected]>
  • Loading branch information
chriseclectic and ihincks authored Jan 16, 2024
1 parent 395df61 commit 13b8689
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 10 additions & 7 deletions qiskit/primitives/base/base_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
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
define as :math:`\psi(\theta)`,
* 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
Expand Down Expand Up @@ -77,8 +79,10 @@
# calculate [ [<psi1(theta1)|H1|psi1(theta1)>,
# <psi1(theta3)|H3|psi1(theta3)>],
# [<psi2(theta2)|H2|psi2(theta2)>] ]
# 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}")
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions qiskit/primitives/containers/estimator_pub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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__()
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 13b8689

Please sign in to comment.