94 lines
3.8 KiB
Plaintext
94 lines
3.8 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.22/qiskit_ibm_runtime/sampler.py#L46-L136" signature="SamplerV2(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**
|
||
|
||
* **backend** (`Union`\[`str`, [`IBMBackend`](qiskit_ibm_runtime.IBMBackend "qiskit_ibm_runtime.ibm_backend.IBMBackend"), `None`]) – 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")]) –
|
||
|
||
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
|
||
|
||
### 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.22/qiskit_ibm_runtime/sampler.py#L96-L123" 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>
|
||
|