What are Qiskit primitives?

What are Qiskit primitives?

Qiskit primitives are Python objects that can produce measurement results from a collection of quantum circuits, circuit parameters, and observables.


Primitives in Qiskit have evolved over the years, with the first stable release of Qiskit in February 2024 introducing their latest rendition: V2 primitives. There are two types of V2 primitives to be aware of:

  • StatevectorSampler: can sample the output quantum state from the quantum circuit in the computational basis. For instance, if we have a circuit represented by a unitary $U$, StatevectorSampler can sample $U \vert 0 \rangle$.
  • StatevectorEstimator: can estimate expectation values of observables with respect to the output quantum state of the quantum circuit. For instance, if we have a circuit represented by a unitary $U$ and an observable $O$ we'd like to measure, StatevectorEstimator calculates $\langle 0 \vert U^\dagger O U \vert 0 \rangle$.

After either a StatevectorSampler or StatevectorEstimator primitive have been created, they each have a run() method that can be called to trigger the calculation of the desired measurement results. Their respective run() methods both require a list of Primitive Unified Blocs — or "pubs" — that define the computational work for the primitive to calculate. Both StatevectorSampler and StatevectorEstimator primitives can run pubs that are tuples containing a Qiskit QuantumCircuit and a list of circuit parameters (if applicable). In the case of StatevectorEstimator, the tuple can also contain a list of observables whose expectation values we want to calculate.

If you're having trouble converting your code that has V1 primitives to something that uses V2 primitives, you can consult Qiskit's migration guide.