BaseSamplerV1
class qiskit.primitives.BaseSamplerV1(*, options=None)
Bases: BasePrimitive
, Generic
[T
]
Sampler V1 base class
Base class of Sampler that calculates quasi-probabilities of bitstrings from quantum circuits.
A sampler is initialized with an empty parameter set. The sampler is used to create a JobV1
, via the qiskit.primitives.Sampler.run()
method. This method is called with the following parameters
- quantum circuits (): list of (parameterized) quantum circuits. (a list of
QuantumCircuit
objects) - parameter values (): list of sets of parameter values to be bound to the parameters of the quantum circuits. (list of list of float)
The method returns a JobV1
object, calling qiskit.providers.JobV1.result()
yields a SamplerResult
object, which contains probabilities or quasi-probabilities of bitstrings, plus optional metadata like error bars in the samples.
Here is an example of how sampler is used.
from qiskit.primitives import Sampler
from qiskit import QuantumCircuit
from qiskit.circuit.library import RealAmplitudes
# a Bell circuit
bell = QuantumCircuit(2)
bell.h(0)
bell.cx(0, 1)
bell.measure_all()
# two parameterized circuits
pqc = RealAmplitudes(num_qubits=2, reps=2)
pqc.measure_all()
pqc2 = RealAmplitudes(num_qubits=2, reps=3)
pqc2.measure_all()
theta1 = [0, 1, 1, 2, 3, 5]
theta2 = [0, 1, 2, 3, 4, 5, 6, 7]
# initialization of the sampler
sampler = Sampler()
# Sampler runs a job on the Bell circuit
job = sampler.run(circuits=[bell], parameter_values=[[]], parameters=[[]])
job_result = job.result()
print([q.binary_probabilities() for q in job_result.quasi_dists])
# Sampler runs a job on the parameterized circuits
job2 = sampler.run(
circuits=[pqc, pqc2],
parameter_values=[theta1, theta2],
parameters=[pqc.parameters, pqc2.parameters])
job_result = job2.result()
print([q.binary_probabilities() for q in job_result.quasi_dists])
Parameters
options (dict | None) – Default options.
Attributes
options
Return options values for the estimator.
Returns
options
Methods
run
run(circuits, parameter_values=None, **run_options)
Run the job of the sampling of bitstrings.
Parameters
- circuits (QuantumCircuit | Sequence[QuantumCircuit]) – One of more circuit objects.
- parameter_values (Sequence[float] | Sequence[Sequence[float]] | 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 – Invalid arguments are given.
Return type
T
set_options
set_options(**fields)
Set options values for the estimator.
Parameters
**fields – The fields to update the options