Introduction to primitives
The code on this page was developed using the following requirements. We recommend using these versions or newer.
qiskit[all]~=2.3.0 qiskit-ibm-runtime~=0.43.1
The beta release of a new execution model is now available. The directed execution model provides more flexibility when customizing your error mitigation workflow. See the Directed execution model guide for more information.
Primitives were created to simplify the most common tasks for quantum computers. Namely, sampling quantum states and calculating expectation values. The Qiskit Runtime primitives (EstimatorV2 and SamplerV2) are implementations of the Qiskit primitives base classes. They provide a more sophisticated implementation (for example, by including error mitigation) as a cloud-based service and are used to access IBM Quantum® hardware.
Estimator
The Estimator primitive computes the expectation values for one or more observables with respect to states prepared by quantum circuits. The circuits can be parametrized, as long as the parameter values are also provided as input to the primitive.
The input is an array of PUBs. Each PUB is in the format:
(<single circuit>, <one or more observables>, <optional one or more parameter values>, <optional precision>),
where the optional parameter values can be a list or a single parameter. If the input contains measurements, they are ignored.
The output is a PubResult that contains the computed expectation values per pair, and their standard errors, in PubResult form. Each PubResult contains both data and metadata.
The Estimator combines elements from observables and parameter values by following NumPy broadcasting rules as described in the Primitive inputs and outputs topic.
Sampler
The Sampler's core task is sampling the output register from the execution of one or more quantum circuits. The input circuits can be parametrized, as long as the parameter values are also provided as input to the primitive.
The input is one or more PUBs, in the format:
(<single circuit>, <one or more optional parameter value>, <optional shots>),
where there can be multiple parameter values items, and each item can be either an array or a single parameter, depending on the chosen circuit. Additionally, the input must contain measurements.
The output is counts or per-shot measurements, as PubResult objects, without weights. The result class, however, has methods to return weighted samples, such as counts. See Primitive inputs and outputs for full details.
Next steps
- Learn about the Qiskit primitives that the Qiskit Runtime primitives are based on.
- Read Get started with primitives to implement primitives in your work.
- Review detailed primitives examples.
- See Primitive inputs and outputs for detailed information.
- Practice with primitives by working through the Cost function lesson in IBM Quantum Learning.
- See the EstimatorV2 API reference and SamplerV2 API reference.