Skip to main contentIBM Quantum Documentation
Qiskit IBM Provider is deprecated. See the migration guide to use Qiskit Runtime.


class Session(max_time=None, session_id=None)

GitHub(opens in a new tab)

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 one or more jobs.

For example::

from qiskit_ibm_provider import IBMProvider

# Bell Circuit qr = QuantumRegister(2, name=”qr”) cr = ClassicalRegister(2, name=”cr”) qc = QuantumCircuit(qr, cr, name=”bell”) qc.h(qr[0])[0], qr[1]) qc.measure(qr, cr)

backend = IBMProvider().get_backend(“ibmq_qasm_simulator”) backend.open_session()

job = print(f”Job ID: {job.job_id()}”) print(f”Result: {job.result()}”) # Close the session only if all jobs are finished and # you don’t need to run more in the session. backend.cancel_session()

Session can also be used as a context manager:

with backend.open_session() as session:
    job =
    assert job.job_id() == session.session_id

Session constructor.


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.


ValueError – If an input value is invalid.



Return the status of the session.

Return type



True if the session is active, False otherwise.


Return the session ID.

Return type



Session ID. None until a job runs in the session.




GitHub(opens in a new tab)

Set the session._active status to False

Return type


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