Session¶
- class Session(service=None, backend=None, max_time=None)[source]¶
Class for creating a flexible Qiskit Runtime session.
A Qiskit Runtime
session
allows you to group a collection of iterative calls to the quantum computer. A session is started when the first job within the session is started. Subsequent jobs within the session are prioritized by the scheduler. Data used within a session, such as transpiled circuits, is also cached to avoid unnecessary overhead.You can open a Qiskit Runtime session using this
Session
class and submit jobs to one or more primitives.For example:
from qiskit.test.reference_circuits import ReferenceCircuits from qiskit_ibm_runtime import Sampler, Session, Options options = Options(optimization_level=3) with Session(backend="ibmq_qasm_simulator") as session: sampler = Sampler(session=session, options=options) job = sampler.run(circ) print(f"Sampler job ID: {job.job_id()}") print(f"Sampler 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()
Session constructor.
- Parameters:
service (
Optional
[QiskitRuntimeService
]) – Optional instance of theQiskitRuntimeService
class. IfNone
, the service associated with the backend, if known, is used. OtherwiseQiskitRuntimeService()
is used to initialize your default saved account.backend (
Union
[str
,IBMBackend
,None
]) – Optional instance ofqiskit_ibm_runtime.IBMBackend
class or string name of backend. An instance ofqiskit_ibm_provider.IBMBackend
will not work. If not specified, a backend will be selected automatically (IBM Cloud channel only).max_time (
Union
[int
,str
,None
]) – (EXPERIMENTAL setting, can break between releases without warning) Maximum amount of time, a runtime session can be open before being forcibly closed. Can be specified as seconds (int) or a string like “2h 30m 40s”. This value must be in between 300 seconds and the system imposed maximum.
- Raises:
ValueError – If an input value is invalid.
Attributes
Return service associated with this session.
Return the session ID.
Methods
Return backend for this session.
Close the session.
Session.run
(program_id, inputs[, options, ...])Run a program in the session.