Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit Runtime Client. Go to the latest version.

SamplerV1

class SamplerV1(backend=None, session=None, options=None)

GitHub

Class for interacting with Qiskit Runtime Sampler primitive service.

Deprecated since version 0.23

The SamplerV1 primitives have been deprecated in 0.23, released on April 15, 2024. See the V2 migration guide. for more details. The SamplerV1 support will be removed no earlier than July 15, 2024.

Qiskit Runtime Sampler primitive service calculates quasi-probability distribution 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.

Example:

from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Sampler
 
service = QiskitRuntimeService(channel="ibm_cloud")
 
# Bell Circuit
qr = QuantumRegister(2, name="qr")
cr = ClassicalRegister(2, name="cr")
qc = QuantumCircuit(qr, cr, name="bell")
qc.h(qr[0])
qc.cx(qr[0], qr[1])
qc.measure(qr, cr)
 
with Session(service, backend="ibmq_qasm_simulator") as session:
    sampler = Sampler(session=session)
 
    job = sampler.run(qc, shots=1024)
    print(f"Job ID: {job.job_id()}")
    print(f"Job result: {job.result()}")
 
    # You can run more jobs inside the session

Initializes the Sampler primitive.

Parameters

  • backend (Union[str, IBMBackend, None]) – Backend to run the primitive. This can be a backend name or an IBMBackend instance. If a name is specified, the default account (e.g. QiskitRuntimeService()) is used.

  • session (Optional[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 context manager, then the session is used. Otherwise if IBM Cloud channel is used, a default backend is selected.

  • options (Union[Dict, Options, None]) – Primitive options, see Options for detailed description. The backend keyword is still supported but is deprecated.


Attributes

options

Return options values for the sampler. :rtype: Options :returns: options

session

Return session used by this primitive.

Return type

Optional[Session]

Returns

Session used by this primitive, or None if session is not used.

version

Default value: 1


Methods

run

run(circuits, parameter_values=None, **kwargs)

GitHub

Submit a request to the sampler primitive.

Parameters

  • circuits (QuantumCircuit | Sequence[QuantumCircuit]) – A (parameterized) QuantumCircuit or a list of (parameterized) QuantumCircuit.
  • parameter_values (Sequence[float] | Sequence[Sequence[float]] | None) – Concrete parameters to be bound.
  • **kwargs – Individual options to overwrite the default primitive options.

Return type

RuntimeJob

Returns

Submitted job. The result of the job is an instance of qiskit.primitives.SamplerResult.

Raises

ValueError – Invalid arguments are given.

set_options

set_options(**fields)

GitHub

Set options values for the sampler.

Parameters

**fields – The fields to update the options

Return type

None

Was this page helpful?
Report a bug or request content on GitHub.