Skip to main contentIBM Quantum Documentation

SamplerV2

SamplerV2(backend=None, session=None, options=None)

GitHub(opens in a new tab)

Class for interacting with Qiskit Runtime Sampler primitive service.

This class supports version 2 of the Sampler interface, which uses different input and output formats than version 1.

Qiskit Runtime Sampler primitive returns the sampled result according to the specified output type. For example, it returns a bitstring for each shot if measurement level 2 (bits) is requested.

The run() method can be used to submit circuits and parameters to the Sampler primitive.

Initializes the Sampler primitive.

Parameters

  • backend (Union[str, IBMBackend, None]) – Backend to run the primitive. This can be a backend name or an IBMBackend instance. If a name is specified, the default account (e.g. QiskitRuntimeService()) is used.

  • session (Optional[Session]) –

    Session in which to call the primitive.

    If both session and backend are specified, session takes precedence. If neither is specified, and the primitive is created inside a qiskit_ibm_runtime.Session context manager, then the session is used. Otherwise if IBM Cloud channel is used, a default backend is selected.

  • options (Union[Dict, SamplerOptions, None]) – Sampler options, see SamplerOptions for detailed description.

Raises

NotImplementedError – If “q-ctrl” channel strategy is used.


Attributes

options

SamplerOptions

Return options

Return type

TypeVar(OptionsT, bound= BaseOptions)

session

Return session used by this primitive.

Return type

Optional[Session]

Returns

Session used by this primitive, or None if session is not used.

version

= 2


Methods

run

run(pubs, *, shots=None)

GitHub(opens in a new tab)

Submit a request to the sampler primitive.

Parameters

  • pubs (Iterable[SamplerPubLike]) – An iterable of pub-like objects. For example, a list of circuits or tuples (circuit, parameter_values).
  • shots (int | None) – The total number of shots to sample for each sampler pub that does not specify its own shots. If None, the primitive’s default shots value will be used, which can vary by implementation.

Return type

RuntimeJobV2

Returns

Submitted job. The result of the job is an instance of qiskit.primitives.containers.PrimitiveResult.

Raises

ValueError – Invalid arguments are given.

Was this page helpful?
Report a bug or request content on GitHub.