Aracılığıyla paylaş


SessionHost Class

A protocol to allow other objects to "host" a session. For example, a target object can host an open session and have all jobs that are being submitted through it to be associated with that session.

Example (job 1 to 3 will be associated the session "MySession"):


   with target.open_session(name="MySession") as session:
        job1 = target.submit(input_data=input_data, job_name="Job 1")
        job2 = target.submit(input_data=input_data, job_name="Job 2")
        job3 = target.submit(input_data=input_data, job_name="Job 3")
Inheritance
SessionHost

Constructor

SessionHost(*args, **kwargs)

Methods

get_latest_session_id

Get the latest (open) session id associated with this object. This id is used to associate jobs to the latest (open) session.

open_session

Opens a session and associates all future job submissions to that session until the session is closed (which happens automatically after exiting a with block).

Example (job 1 to 3 will be associated the session "MySession"):


   with target.open_session(name="MySession") as session:
        job1 = target.submit(input_data=input_data, job_name="Job 1")
        job2 = target.submit(input_data=input_data, job_name="Job 2")
        job3 = target.submit(input_data=input_data, job_name="Job 3")

Note: If the session host (usually a target or qiskit backend) already has a session associated with it (in the latest_session property), then this method will first attempt to close that session before opening a new one.

get_latest_session_id

Get the latest (open) session id associated with this object. This id is used to associate jobs to the latest (open) session.

get_latest_session_id() -> str | None

Returns

Type Description

The latest session id.

open_session

Opens a session and associates all future job submissions to that session until the session is closed (which happens automatically after exiting a with block).

Example (job 1 to 3 will be associated the session "MySession"):


   with target.open_session(name="MySession") as session:
        job1 = target.submit(input_data=input_data, job_name="Job 1")
        job2 = target.submit(input_data=input_data, job_name="Job 2")
        job3 = target.submit(input_data=input_data, job_name="Job 3")

Note: If the session host (usually a target or qiskit backend) already has a session associated with it (in the latest_session property), then this method will first attempt to close that session before opening a new one.

open_session(details: SessionDetails | None = None, id: str | None = None, name: str | None = None, job_failure_policy: str | SessionJobFailurePolicy | None = None, **kwargs) -> Session

Parameters

Name Description
details

Session details model, containing the session id, name, job_failure_policy, provider_id and target. Either this parameter should be passed containing all the session detail values, the same values should be passed as individual parameters.

default value: None
id

The id of the session. If not passed, one random uuid will used.

default value: None
name

The name of the session. If not passed, the name will be session-{session-id}.

default value: None
job_failure_policy

The policy that determines when a session would fail, close and not accept further jobs.

default value: None

Returns

Type Description

The session object with updated details after its opening.

Attributes

latest_session

Get the latest (open) session associated with this object.

Returns

Type Description

The latest session object.