118 lines
5.1 KiB
Plaintext
118 lines
5.1 KiB
Plaintext
---
|
||
title: SamplerV2
|
||
description: API reference for qiskit_ibm_runtime.SamplerV2
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit_ibm_runtime.SamplerV2
|
||
---
|
||
|
||
# SamplerV2
|
||
|
||
<Class id="qiskit_ibm_runtime.SamplerV2" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.29/qiskit_ibm_runtime/sampler.py#L46-L172" signature="SamplerV2(mode=None, backend=None, session=None, options=None)" modifiers="class">
|
||
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()`](#qiskit_ibm_runtime.SamplerV2.run "qiskit_ibm_runtime.SamplerV2.run") method can be used to submit circuits and parameters to the Sampler primitive.
|
||
|
||
Initializes the Sampler primitive.
|
||
|
||
**Parameters**
|
||
|
||
* **mode** (`Union`\[[`BackendV1`](/api/qiskit/qiskit.providers.BackendV1 "(in Qiskit v1.2)"), [`BackendV2`](/api/qiskit/qiskit.providers.BackendV2 "(in Qiskit v1.2)"), [`Session`](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.session.Session"), [`Batch`](qiskit_ibm_runtime.Batch "qiskit_ibm_runtime.batch.Batch"), `str`, `None`]) –
|
||
|
||
The execution mode used to make the primitive query. It can be:
|
||
|
||
* A `Backend` if you are using job mode.
|
||
* A [`Session`](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.Session") if you are using session execution mode.
|
||
* A [`Batch`](qiskit_ibm_runtime.Batch "qiskit_ibm_runtime.Batch") if you are using batch execution mode.
|
||
|
||
Refer to the [Qiskit Runtime documentation](/guides/execution-modes). for more information about the `Execution modes`.
|
||
|
||
* **backend** (`Union`\[`str`, [`BackendV1`](/api/qiskit/qiskit.providers.BackendV1 "(in Qiskit v1.2)"), [`BackendV2`](/api/qiskit/qiskit.providers.BackendV2 "(in Qiskit v1.2)"), `None`]) – (DEPRECATED) Backend to run the primitive. This can be a backend name or an [`IBMBackend`](qiskit_ibm_runtime.IBMBackend "qiskit_ibm_runtime.IBMBackend") instance. If a name is specified, the default account (e.g. `QiskitRuntimeService()`) is used.
|
||
|
||
* **session** (`Optional`\[[`Session`](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.session.Session")]) –
|
||
|
||
(DEPRECATED) 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`](qiskit_ibm_runtime.Session "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`](qiskit_ibm_runtime.options.SamplerOptions "qiskit_ibm_runtime.options.sampler_options.SamplerOptions"), `None`]) – Sampler options, see `SamplerOptions` for detailed description.
|
||
|
||
**Raises**
|
||
|
||
**NotImplementedError** – If “q-ctrl” channel strategy is used.
|
||
|
||
## Attributes
|
||
|
||
### mode
|
||
|
||
<Attribute id="qiskit_ibm_runtime.SamplerV2.mode">
|
||
Return the execution mode used by this primitive.
|
||
|
||
**Return type**
|
||
|
||
Optional\[[Session](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.Session") | [Batch](qiskit_ibm_runtime.Batch "qiskit_ibm_runtime.Batch")]
|
||
|
||
**Returns**
|
||
|
||
Mode used by this primitive, or `None` if an execution mode is not used.
|
||
</Attribute>
|
||
|
||
### options
|
||
|
||
<Attribute id="qiskit_ibm_runtime.SamplerV2.options" attributeTypeHint="SamplerOptions">
|
||
Return options
|
||
|
||
**Return type**
|
||
|
||
`TypeVar`(`OptionsT`, bound= `BaseOptions`)
|
||
</Attribute>
|
||
|
||
### session
|
||
|
||
<Attribute id="qiskit_ibm_runtime.SamplerV2.session">
|
||
Return session used by this primitive.
|
||
|
||
**Return type**
|
||
|
||
`Optional`\[[`Session`](qiskit_ibm_runtime.Session "qiskit_ibm_runtime.session.Session")]
|
||
|
||
**Returns**
|
||
|
||
Session used by this primitive, or `None` if session is not used.
|
||
</Attribute>
|
||
|
||
### version
|
||
|
||
<Attribute id="qiskit_ibm_runtime.SamplerV2.version" attributeValue="2" />
|
||
|
||
## Methods
|
||
|
||
### run
|
||
|
||
<Function id="qiskit_ibm_runtime.SamplerV2.run" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.29/qiskit_ibm_runtime/sampler.py#L134-L156" signature="run(pubs, *, shots=None)">
|
||
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](qiskit_ibm_runtime.RuntimeJobV2 "qiskit_ibm_runtime.RuntimeJobV2")
|
||
|
||
**Returns**
|
||
|
||
Submitted job. The result of the job is an instance of `qiskit.primitives.containers.PrimitiveResult`.
|
||
|
||
**Raises**
|
||
|
||
**ValueError** – Invalid arguments are given.
|
||
</Function>
|
||
</Class>
|
||
|