Skip to content

Commit

Permalink
update base class reno
Browse files Browse the repository at this point in the history
  • Loading branch information
ihincks committed Jan 19, 2024
1 parent 39ef087 commit 7718d7e
Showing 1 changed file with 29 additions and 42 deletions.
71 changes: 29 additions & 42 deletions releasenotes/notes/primitives-v2-df871c0c6ac0b94a.yaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,46 @@
---
features:
- |
Version 2 of the primitives was introduced. The emphasis of this new version is on performing
vectorized calls to the primitive run methods, so that sweeps over parameter value sets and
observables can be efficiently specified and targetted against a single parametric circuit.
.. code: python
from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.primitives import StatevectorEstimator
import numpy as np
circuit = QuantumCircuit(2)
circuit.h(0)
circuit.rz(Parameter("a"), 0
circuit.h(0)
circuit.cx(0, 1)
# define three observables
observables = ["XX", "YY", "ZZ"]
# define a sweep over parameter values, where the second axis, in this example, is broadcasted
# against observables, and the third axis is over parameters in the circuit (just one)
params = np.linspace(-np.pi, np.pi, 100).reshape(100, 1, 1)
# estimate the expectation value for all 300 combinations of observables and parameter values,
# where the pub result will have shape (100, 3)
estimator = StatevectorEstimator([(circuit, observables, parameters)])
The estimator has gained a ``precision`` argument in the run method that specifies the targetted
precision of the expectation value estimates. The sampler has moved ``shots`` out of the options
and into the arguments of the run method. The sampler has also been changed to return the outputs
(e.g. bitstrings) from every shot, rather than providing a Counts-like return.
Version 2 of the primitives was introduced via a new base class for both the sampler and the
estimator, along with new container types for their inputs and outputs. The emphasis of this new
version is on performing vectorized calls to the primitive ``run()`` methods, so that sweeps
over parameter value sets and observables can be efficiently specified. See
:class:`~.StatevectorSampler` and :class:`~.StatevectorEstimator` for reference implementations
of the V2 primitives.
Moreover, the estimator has gained a ``precision`` argument in the :meth:`~.BaseEstimatorV2.run`
method that specifies the targeted precision of the expectation value estimates. Analagously,
the sampler has moved ``shots`` out of the options and into the arguments of the
:meth:`~.BaseSamplerV2.run` method. The sampler has also been changed to return the outputs
(e.g. bitstrings) from every shot, rather than providing a :class:`~.Counts`-like return, and
also to store data from separate :class:`~.ClassicalRegister`\s . This enables derived classes
to implement sampler support for circuits with classical control flow.
New classes introduced as a part of the new version include
The primitive V2 base classes are:
* an abstract base class :class:`.BaseSamplerV2` with reference implementation :class:`.StatevectorSampler` and
* an abstract base class :class:`.BaseEstimatorV2` with reference implementation :class:`.StatevectorEstimator`,
* :class:`.BaseSamplerV2`
* :class:`.BaseEstimatorV2`
along with a collection of container types to help define the inputs and outputs:
The new container types which are used for inputs and outputs are:
* :class:`.SamplerPub`\: primitive unified bloc (PUB) of sampler inputs
* :class:`.EstimatorPub`\: Primitive unified bloc (PUB) of estimator inputs
* :class:`.BindingsArray`\: an array-valued collection of parameter value sets to bind against a circuit
* :class:`.BindingsArray`\: an array-valued collection of parameter value sets to bind against a
circuit
* :class:`.ObservablesArray`\: an array-valued collection of observables
* :class:`.PubResult`\: the data and metadata resulting from a single PUB's execution
* :class:`.DataBin`\: A namespace to hold data from a single PUB's execution
* :class:`.BitArray`\: an array-valued collection of bitstrings in a dense format
* :class:`.PrimitiveResult`: an iterable of :class:`.PubResult`\s along with metadata
Some of the above types have corresponding union types that define exactly which formats are natively compatible
with their associated class for automatic coersion:
Some of the above types have corresponding union types that define exactly which formats are
natively compatible with their associated class for automatic coersion:
* :class:`.EstimatorPubLike`\: accepts a circuit and an observables-like, and optionionally bindings-array-like
and shots
* :class:`.EstimatorPubLike`\: accepts a circuit and an observables-like, and optionionally
bindings-array-like and shots
* :class:`.SamplerPubLike`\: accepts a circuit and optionally bindingns-array-like and shots
* :class:`.ObservablesArrayLike`\: accepts :class:`.SparsePauliOp`, dictionaries, strings of Paulis, etc.
* :class:`.BindingsArrayLike`\: accepts NumPy arrays, lists of floats, dictionaries with parameter names, etc.
* :class:`.ObservablesArrayLike`\: accepts :class:`.SparsePauliOp`, dictionaries, strings of
Paulis, etc.
* :class:`.BindingsArrayLike`\: accepts NumPy arrays, lists of floats, dictionaries with
parameter names, etc.

0 comments on commit 7718d7e

Please sign in to comment.