Sampler¶
- class Sampler(session=None, options=None)[source]¶
Class for interacting with Qiskit Runtime Sampler primitive service.
Qiskit Runtime Sampler primitive service calculates probabilities or quasi-probabilities of bitstrings from quantum circuits.
The
run()
method can be used to submit circuits and parameters to the Sampler primitive.You are encouraged to use
Session
to open a session, during which you can invoke one or more primitives. Jobs submitted within a session are prioritized by the scheduler, and data is cached for efficiency.Example:
from qiskit.test.reference_circuits import ReferenceCircuits from qiskit_ibm_runtime import QiskitRuntimeService, Session, Sampler service = QiskitRuntimeService(channel="ibm_cloud") bell = ReferenceCircuits.bell() with Session(service, backend="ibmq_qasm_simulator") as session: sampler = Sampler(session=session) job = sampler.run(bell, shots=1024) print(f"Job ID: {job.job_id()}") print(f"Job result: {job.result()}") # Close the session only if all jobs are finished # and you don't need to run more in the session. session.close()
Initializes the Sampler primitive.
- Parameters:
session (
Union
[Session
,str
,IBMBackend
,None
]) –Session in which to call the primitive.
If an instance of
qiskit_ibm_runtime.IBMBackend
class or string name of a backend is specified, a new session is created for that backend, unless a default session for the same backend and channel already exists.If
None
, a new session is created using the default saved account and a default backend (IBM Cloud channel only), unless a default session already exists.
options (
Union
[Dict
,Options
,None
]) – Primitive options, seeOptions
for detailed description. Thebackend
keyword is still supported but is deprecated.
Attributes
Quantum circuits to be sampled.
Return options values for the sampler.
Parameters of quantum circuits.
Return session used by this primitive.
Methods
Sampler.run
(circuits[, parameter_values])Submit a request to the sampler primitive.
Sampler.set_options
(**fields)Set options values for the sampler.