qiskit-documentation/docs/api/qiskit/qiskit.primitives.BackendSa...

126 lines
5.9 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: BackendSampler
description: API reference for qiskit.primitives.BackendSampler
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.primitives.BackendSampler
---
# BackendSampler
<Class id="qiskit.primitives.BackendSampler" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.1/qiskit/primitives/backend_sampler.py#L33-L213" signature="qiskit.primitives.BackendSampler(backend, options=None, bound_pass_manager=None, skip_transpilation=False)" modifiers="class">
Bases: [`BaseSamplerV1`](qiskit.primitives.BaseSamplerV1 "qiskit.primitives.base.base_sampler.BaseSamplerV1")\[[`PrimitiveJob`](qiskit.primitives.PrimitiveJob "qiskit.primitives.primitive_job.PrimitiveJob")\[[`SamplerResult`](qiskit.primitives.SamplerResult "qiskit.primitives.base.sampler_result.SamplerResult")]]
A `BaseSampler` implementation that provides an interface for leveraging the sampler interface from any backend.
This class provides a sampler interface from any backend and doesnt do any measurement mitigation, it just computes the probability distribution from the counts. It facilitates using backends that do not provide a native `BaseSampler` implementation in places that work with `BaseSampler`. However, if youre using a provider that has a native implementation of `BaseSampler`, it is a better choice to leverage that native implementation as it will likely include additional optimizations and be a more efficient implementation. The generic nature of this class precludes doing any provider- or backend-specific optimizations.
Initialize a new BackendSampler
**Parameters**
* **backend** ([*BackendV1*](qiskit.providers.BackendV1 "qiskit.providers.BackendV1") *|*[*BackendV2*](qiskit.providers.BackendV2 "qiskit.providers.BackendV2")) Required: the backend to run the sampler primitive on
* **options** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.12)") *| None*) Default options.
* **bound\_pass\_manager** ([*PassManager*](qiskit.transpiler.PassManager "qiskit.transpiler.PassManager") *| None*) An optional pass manager to run after parameter binding.
* **skip\_transpilation** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)")) If this is set to True the internal compilation of the input circuits is skipped and the circuit objects will be directly executed when this objected is called.
**Raises**
[**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.12)") If backend is not provided
## Attributes
### backend
<Attribute id="qiskit.primitives.BackendSampler.backend">
Returns: The backend which this sampler object based on
</Attribute>
### options
<Attribute id="qiskit.primitives.BackendSampler.options">
Return options values for the estimator.
**Returns**
options
</Attribute>
### preprocessed\_circuits
<Attribute id="qiskit.primitives.BackendSampler.preprocessed_circuits">
Preprocessed quantum circuits produced by preprocessing :returns: List of the transpiled quantum circuit
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if the instance has been closed.
</Attribute>
### transpile\_options
<Attribute id="qiskit.primitives.BackendSampler.transpile_options">
Return the transpiler options for transpiling the circuits.
</Attribute>
### transpiled\_circuits
<Attribute id="qiskit.primitives.BackendSampler.transpiled_circuits">
Transpiled quantum circuits. :returns: List of the transpiled quantum circuit
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if the instance has been closed.
</Attribute>
## Methods
### run
<Function id="qiskit.primitives.BackendSampler.run" github="https://github.com/Qiskit/qiskit/tree/stable/1.1/qiskit/primitives/base/base_sampler.py#L110-L141" signature="run(circuits, parameter_values=None, **run_options)">
Run the job of the sampling of bitstrings.
**Parameters**
* **circuits** ([*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") *| Sequence\[*[*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")*]*) One of more circuit objects.
* **parameter\_values** (*Sequence\[*[*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.12)")*] | Sequence\[Sequence\[*[*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.12)")*]] | None*) Parameters to be bound to the circuit.
* **run\_options** Backend runtime options used for circuit execution.
**Returns**
The job object of the result of the sampler. The i-th result corresponds to `circuits[i]` evaluated with parameters bound as `parameter_values[i]`.
**Raises**
[**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.12)") Invalid arguments are given.
**Return type**
T
</Function>
### set\_options
<Function id="qiskit.primitives.BackendSampler.set_options" github="https://github.com/Qiskit/qiskit/tree/stable/1.1/qiskit/primitives/base/base_primitive.py#L39-L45" signature="set_options(**fields)">
Set options values for the estimator.
**Parameters**
**\*\*fields** The fields to update the options
</Function>
### set\_transpile\_options
<Function id="qiskit.primitives.BackendSampler.set_transpile_options" github="https://github.com/Qiskit/qiskit/tree/stable/1.1/qiskit/primitives/backend_sampler.py#L121-L130" signature="set_transpile_options(**fields)">
Set the transpiler options for transpiler. :param \*\*fields: The fields to update the options.
**Returns**
self.
**Raises**
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") if the instance has been closed.
</Function>
</Class>