Session ¶
Session(
resource_ids,
agent,
ttl_ms=4000,
tentative_ttl_ms=1000,
token=None,
trigger_count_proposer=None,
skip_lock_check=False,
)
A lease over a set of resources on a QuEL system.
Opening a session locks its resources on the server and yields a token
used for subsequent operations such as deploying instruments and
triggering. Create sessions with QuelwareClient.create_session() and use
them as an async context manager, so they are opened on entry and closed on
exit:
async with qc.create_session(["unit0:port0"]) as session:
await session.deploy_instruments("unit0:port0", definitions)
await session.trigger(instrument_ids)
results = await session.wait_for_results(instrument_ids)
Within a session, each unit has at most one run. A new trigger on a unit
replaces its run, and initializing an instrument on the unit clears it.
Other sessions on the same unit have their own runs. The session remembers
which instruments were in the last trigger on each unit, and waits only for
those. Another Session object built with the same token does not share
this record.
Build a session over a set of resources.
Normally created by QuelwareClient.create_session() rather than
directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_ids
|
Collection[ResourceId]
|
Resources to lock for the session. |
required |
agent
|
AgentContainer
|
Container providing the session and per-unit agents. |
required |
ttl_ms
|
int
|
Time-to-live, in milliseconds, of the committed lease. |
4000
|
tentative_ttl_ms
|
int
|
Time-to-live, in milliseconds, of the tentative lease held while opening. |
1000
|
token
|
SessionToken | None
|
Pre-existing session token, if resuming a session. |
None
|
trigger_count_proposer
|
TriggerCountProposer | None
|
Strategy for choosing the clock count of a synchronized multi-unit trigger. Defaults to a fixed-offset proposer aligned to a 32-count grid. |
None
|
skip_lock_check
|
bool
|
When True, skip verifying that the requested resources are locked after opening. |
False
|
Source code in quelware-client/src/quelware_client/core/_session.py
available_resource_ids
property
¶
The set of resource ids this session was created for.
token
property
¶
The session token obtained when the session was opened.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the session has not been opened yet. |
close
async
¶
Close the session and release its resources.
configure_unit
async
¶
Apply unit-wide controls to a unit and return the resulting values.
The session must hold locks on every port of unit_label and carry
the required capability; the unit must have no deployed instruments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_label
|
UnitLabel
|
The unit to configure. |
required |
controls
|
Mapping[str, str]
|
Vendor-namespaced control key/values to apply. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
The unit's control values after applying the change. |
Source code in quelware-client/src/quelware_client/core/_session.py
deploy_instruments
async
¶
Deploy instrument definitions onto a port.
Each definition's alias is automatically prefixed with the port's unit
label, so the aliases passed in must not contain a ':'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port_id
|
str | ResourceId
|
Port to deploy onto. Its unit label selects the unit. |
required |
definitions
|
Collection[InstrumentDefinition]
|
Instrument definitions to deploy. |
required |
append
|
bool
|
When True, add to the port's existing instruments instead of replacing them. |
False
|
Returns:
| Type | Description |
|---|---|
list[InstrumentInfo]
|
Information about the deployed instruments. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any definition's alias contains a |
Source code in quelware-client/src/quelware_client/core/_session.py
discard_instruments
async
¶
Remove all instruments deployed on a port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port_id
|
str | ResourceId
|
Port whose instruments to discard. Its unit label selects the unit. |
required |
Source code in quelware-client/src/quelware_client/core/_session.py
extend
async
¶
Extend the session's lease.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_ttl_ms
|
int
|
New time-to-live, in milliseconds, from now. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the server accepted the extension. |
Source code in quelware-client/src/quelware_client/core/_session.py
fetch_result
async
¶
Fetch the result of one instrument, with a single request.
Unlike wait_for_result(), this does not retry when the request times
out.
Raises:
| Type | Description |
|---|---|
NotTriggeredError
|
Immediately, if the instrument was not in the last trigger on its unit. |
Source code in quelware-client/src/quelware_client/core/_session.py
initialize
async
¶
Initialize the given instruments.
An initialized instrument is empty: armed, it plays and captures nothing until it is given a timeline again. This also clears the session's run on each of their units: no instrument on those units can be waited for until the next trigger there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument_ids
|
Collection[ResourceId]
|
Instruments to initialize. |
required |
parallel
|
bool
|
Initialize the units at the same time, the default; when False, one unit after another. Either way every unit is initialized, also after one fails, and the instruments of one unit are always initialized in one call. |
True
|
Raises:
| Type | Description |
|---|---|
UnitBusyError
|
Immediately, if a trigger or initialize of this session is already running on one of the units. |
InitializeFailedError
|
If some units failed, once every unit has finished, with the error of each unit that failed. |
Source code in quelware-client/src/quelware_client/core/_session.py
open
async
¶
Open the session, locking its resources and obtaining a token.
Unless lock checking is disabled, this also verifies that every requested resource is actually locked.
Raises:
| Type | Description |
|---|---|
ValueError
|
If some requested resources could not be locked. |
Source code in quelware-client/src/quelware_client/core/_session.py
trigger
async
¶
Arm the given instruments, then trigger them.
Arming puts the configuration of each instrument on its unit's device, as the run of the session there. Then the server schedules a trigger, at which every unit starts. If the server's trigger service is unavailable, the client triggers the units itself: a self-timed trigger for a single unit, or a clock-synchronized trigger across several.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument_ids
|
Collection[ResourceId]
|
Instruments to trigger. |
required |
wait_ms
|
int | None
|
Delay, in milliseconds, from now to when the run starts,
giving every unit time to start on it. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The clock count at which the trigger was scheduled. |
Raises:
| Type | Description |
|---|---|
UnitBusyError
|
Immediately, if a trigger or initialize of this session is already running on one of the units. |
Source code in quelware-client/src/quelware_client/core/_session.py
wait_for_result
async
¶
Wait for the result of one instrument.
Unlike wait_for_results(), this raises the instrument's own error if
it failed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument_id
|
ResourceId
|
Instrument to wait for. |
required |
timeout_sec
|
float | None
|
Maximum time to wait; |
None
|
Raises:
| Type | Description |
|---|---|
NotTriggeredError
|
Immediately, if the instrument was not in the last trigger on its unit. |
Source code in quelware-client/src/quelware_client/core/_session.py
wait_for_results
async
¶
Wait for the result of every one of the instruments of a run.
Pass the instruments given to trigger(). An instrument without a
capture window is waited for too, and its result is empty. Only the
instruments in the last trigger on each unit can be waited for, and not
after an instrument on that unit is initialized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument_ids
|
Collection[ResourceId]
|
Instruments to wait for. |
required |
timeout_sec
|
float | None
|
Bound on the whole wait; |
None
|
Returns:
| Type | Description |
|---|---|
dict[ResourceId, ResultContainer]
|
Each instrument's result. |
Raises:
| Type | Description |
|---|---|
NotTriggeredError
|
Immediately, if an instrument was not in the last trigger on its unit. |
RunFailedError
|
If any instrument failed, once all of them have finished, with the error of each that failed and the results of the others. |
TimeoutError
|
If some are still running when |