96 lines
3.9 KiB
Plaintext
96 lines
3.9 KiB
Plaintext
---
|
||
title: SamplerV2 (latest version)
|
||
description: API reference for qiskit_ibm_runtime.SamplerV2 in the latest version of qiskit-ibm-runtime
|
||
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.36/qiskit_ibm_runtime/sampler.py#L44-L124" signature="SamplerV2(mode=None, options=None)" modifiers="class">
|
||
Bases: `BasePrimitiveV2`\[[`SamplerOptions`](options-sampler-options "qiskit_ibm_runtime.options.sampler_options.SamplerOptions")], `Sampler`, [`BaseSamplerV2`](/api/qiskit/qiskit.primitives.BaseSamplerV2 "(in Qiskit v1.3)")
|
||
|
||
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** (*Optional\[Union\[BackendV1, BackendV2,* [*Session*](session "qiskit_ibm_runtime.Session")*,* [*Batch*](batch "qiskit_ibm_runtime.Batch")*]]*) –
|
||
|
||
The execution mode used to make the primitive query. It can be:
|
||
|
||
* A `Backend` if you are using job mode.
|
||
* A [`Session`](session "qiskit_ibm_runtime.Session") if you are using session execution mode.
|
||
* A [`Batch`](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`.
|
||
|
||
* **options** (*Optional\[Union\[Dict,* [*SamplerOptions*](options-sampler-options "qiskit_ibm_runtime.options.SamplerOptions")*]]*) – Sampler options, see `SamplerOptions` for detailed description.
|
||
|
||
## Attributes
|
||
|
||
### mode
|
||
|
||
<Attribute id="qiskit_ibm_runtime.SamplerV2.mode">
|
||
Return the execution mode used by this primitive.
|
||
|
||
**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
|
||
</Attribute>
|
||
|
||
### version
|
||
|
||
<Attribute id="qiskit_ibm_runtime.SamplerV2.version" attributeValue="2" />
|
||
|
||
## Methods
|
||
|
||
### backend
|
||
|
||
<Function id="qiskit_ibm_runtime.SamplerV2.backend" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.36/qiskit_ibm_runtime/base_primitive.py#L210-L212" signature="backend()">
|
||
Return the backend the primitive query will be run on.
|
||
|
||
**Return type**
|
||
|
||
BackendV1 | BackendV2
|
||
</Function>
|
||
|
||
### run
|
||
|
||
<Function id="qiskit_ibm_runtime.SamplerV2.run" github="https://github.com/Qiskit/qiskit-ibm-runtime/tree/stable/0.36/qiskit_ibm_runtime/sampler.py#L88-L110" 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.
|
||
|
||
**Returns**
|
||
|
||
Submitted job. The result of the job is an instance of `qiskit.primitives.containers.PrimitiveResult`.
|
||
|
||
**Raises**
|
||
|
||
**ValueError** – Invalid arguments are given.
|
||
|
||
**Return type**
|
||
|
||
[RuntimeJobV2](runtime-job-v2 "qiskit_ibm_runtime.RuntimeJobV2")
|
||
</Function>
|
||
</Class>
|
||
|