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)
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
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
¶
Apply pending configuration and trigger the given instruments.
The instruments' configuration is applied first, then a trigger is scheduled. If the manager-side trigger service is unavailable, the client falls back to a client-side trigger: a self-timed trigger for a single unit, or a clock-synchronized trigger across multiple units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument_ids
|
Collection[ResourceId]
|
Instruments to trigger. |
required |
wait_ms
|
int | None
|
Minimum delay, in milliseconds, before the trigger fires. Gives all units time to be armed; a lower bound is enforced on the client-side fallback path. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The clock count at which the trigger was scheduled. |