Communicating with Machines¶
Access and addressing¶
LLM-written
Connections to a machine are handled through qslib.machine.Machine.
APIs that accept a machine reference also accept a hostname string when no
password or other connection settings are needed.
|
A QuantStudio connection. |
Direct and managed transports¶
LLM-written (GPT-6, Fable 5, Claude Opus 5.5, and an unknown model)
Choose the backend when constructing a machine.
backend="scpi"(default) uses direct SCPI.backend="qslib"uses qslib-server.backend="auto"probes the qslib-server capabilities endpoint once during construction. A compatible API selects qslib-server. An unreachable endpoint or an HTTP 404 without a qslib-server error code selects SCPI. Authentication failures and incompatible API versions surface as errors.
Direct SCPI uses TLS on port 7443, which firmware 1.3.4 and later offers.
For earlier firmware or a plaintext tunnel, pass port=7000, ssl=False.
The qslib and auto modes use port 7500 by default. Set server_port to
override it and server_token to supply a bearer token. The resolved backend
holds for the life of the machine object. Reconnects reuse it and commands
surface errors from that backend. Use a machine with the SCPI backend for
raw SCPI commands.
If a mutation has an unknown outcome, QSLib raises
qslib.server.ServerOutcomeUnknown with the state resource to inspect
and, for idempotent operations, the key required to retry safely.
Machine.ensure_server() returns an existing ready service or deploys a
supplied ARMv7 binary over a Controller SCPI connection. Call it on a SCPI
machine object, then construct a qslib-backed machine for HTTP operations.
See qslib-server for the service itself, and in particular for the warning
that it uses unencrypted HTTP.
Link discovery¶
LLM-written (Fable 5, Claude Opus 5.5)
The server client bootstraps from /api/v1 alone. When the server offers a
hypermedia entry document there, request paths follow its advertised
relations, and the availability of each feature is judged from the presence
of its relation or mutation template rather than from a version number, so
client and server versions may differ and features degrade one by one with
errors naming the missing feature. Servers without an entry document are
used through fixed paths; discovery
failures never mask the error of the request that follows, and authorization
and policy errors are never bypassed.
Discovery is cached alongside capabilities and cleared by
qslib.server.ServerClient.clear_capability_cache(). One caveat: a
long-lived qslib.server.ServerClient.events() consumer that outlives a
server redeployment retains the links it resolved earlier; they remain valid
paths, but new affordances appear only after the cache is cleared or a new
client is constructed.
Connections, Access Levels, and Passwords¶
By default, as of 0.5.0, Machine automatically handles connections, disconnections, and, when possible (eg, for commands
within qslib, rather than an arbitrary Machine.run_command()), access levels.
The QuantStudio SCPI interface controls access through passwords, which have no username associated; these passwords are each associated with a maximum access level. Each connection type (usually ethernet) also has an associated default and maximum access level with no password.
The recommended settings for QSLib, which can be set through the QSLib CLI, has a connection granted Observer access by default, and Controller access without a password.
When automatic=True, which is the default, whenever code needing a connection is run, a connection will be made,
then disconnected as soon as the code is finished, if the machine wasn’t already connected. When automatic=False,
connections can be handled manually through either context managers (safer) or individual commands. For clean access, the class
provides a context manager for the connection, and the Machine.at_level() method provides a context manager for access level:
>>> with Machine('machine', 'password', max_access_level="Controller") as m:
>>> # Now connected
>>> print(m.run_status()) # runs at Observer level
>>> with m.at_level("Controller", exclusive=True):
>>> # Runs as Controller, and fails if another Controller is connected (exclusive)
>>> m.abort_run()
>>> m.drawer_open()
>>> # Now back to Observer
>>> print(m.status())
>>> # Now disconnected.
There is also the qslib.machine.Machine.ensured_connection() context manager, which will ensure that a connection exists at a particular
access level, or arrange one if it does not. The connection context manager can also be used with with m: form for a Machine
instance m that already exists, in which case it will connect and disconnect.
If you don’t want to use these, you can also use manual methods:
|
Connect using the selected backend. |
|
|
|
Close the current connection, first returning its session to Observer access. |
Note that there is no supported method on the machine’s server for removing hanging connections other than a reboot,
and AB’s software will not start runs when other connections hold Controller level. To correct this, you can restart the
instrument’s computer with qslib.machine.Machine.restart_machine() over direct SCPI.
Use machine.restart_machine(wait=True) to wait for a fresh SCPI connection to answer.
By default the method refuses to reboot during a run. A reboot also stops any qslib-server
process running on the instrument.
LLM-written (GPT-6)
qslib.machine.Machine.restart_system() restarts InstrumentServer and the
Android framework and front-panel application while the operating system stays up.
The restart briefly interrupts SCPI connections. Like restart_machine, it refuses
to restart during a run unless given force=True; its documentation describes what
the instrument then does with the run.
Utility commands¶
|
Open the machine drawer using the OPEN command. |
|
Close the machine drawer using the OPEN command. |
|
Return the drawer position from the DRAW? command. |
|
Lower/engage the plate cover, closing the drawer if needed. |
|
Return the cover position. |
|
Return the current status of the run. |
|
Return information on the status of any run. |
|
|
|
Name of current run, or None if no run is active. |
|
Abort the current run and wait for the instrument to confirm it. |
|
Stop the current run at the end of its current cycle. |
|
Pause the current run now. |
|
|
|
Resume the current run. |
|
Restart InstrumentServer and the Android framework and front-panel app. |
|
Reboot the instrument's computer over direct SCPI with Controller access. |
|
Get and set the machine's operational power (lamp, etc) as a bool. |
|
Query live ramp and optics timing for |
|
Read the plate setup of a run from its folder in the machine's experiments storage. |
|
Write the plate setup of a run to its folder in the machine's experiments storage. |
Machine.get_timing_profile(protocol) reads the active block identity,
directional ramp rates, and optics settings without changing the instrument.
The returned TimingProfile can be passed to
Protocol.estimate_timeline(). For offline block-18 vendor estimates,
use TimingProfile.for_block.
Lower-level commands¶
|
Run a SCPI command, and return the response as a string. |
|
Run an SCPI command and wait for its acknowledgement. |