Measurement procedures
A procedure is a measurement that you can start from the dashboard: a scan over frequencies, a series of recordings at different angles, a pump-down. You write it as an async Python function. LabOrchestra makes a form for its parameters, runs it in a process of its own, shows its progress, and lets you pause it or abort it safely.
Write one
Section titled “Write one”Put a file into the procedures/ folder of the workspace:
from laborchestra import procedure
@procedure(devices=["rf"])async def detuning_scan(lab, offsets_khz: list[float], duration_s: float = 60): """Records at several detunings from the current frequency.
Args: offsets_khz: the detunings, in kHz duration_s: how long each recording lasts, in seconds """ base = lab.rf.state["channels"][0]["frequency"] try: for i, offset in enumerate(lab.progress(offsets_khz)): await lab.rf.set_frequency(0, base + offset * 1e3) async with lab.recording(f"scan {i:03d}", tags={"offset_khz": offset}): await lab.sleep(duration_s) finally: await lab.rf.set_frequency(0, base) # also when the procedure is abortedIt appears on the Procedures page as soon as you save the file.


- The first parameter is the
lab. It gives you the devices (lab.rf), and what a run adds:lab.progress(items),lab.sleep(seconds),lab.status("text"),lab.recording(name, tags). Every call of a device waits until the device is done. - The other parameters make the form. Their type hints decide the field:
bool,int,float,str,list[float]and so on; a default makes a field optional. TheArgs:section of the docstring becomes the hints under the fields. devices=[...]lists every device the procedure uses. The procedure may call no others, and while it runs, these devices are reserved against other procedures. People and scripts can still use them: manual input stays possible at all times.- A recording block ends the recording, however the block ends. If a procedure dies with a recording open, the server stops it and notes in its header that it was interrupted.
- What the function returns is shown as the result of the run.
Run it
Section titled “Run it”-
On the Procedures page, click Run… next to the procedure.


-
Fill in the form and click Start.
-
The page shows the run: its progress (
lab.progress), what it is doing (lab.status), its log, and the parameters it was started with.

- Pause takes effect at the next
lab.sleep, the next step oflab.progress, the next call of a device, or the next recording. The clock oflab.sleepstops while the run is paused. - Abort cancels the function: its
finallyblocks run. If it has not ended after 30 seconds (settingabort_grace_s), the process is killed. Kill now kills it at once, without cleanup. - A run ends as finished, failed (with the error and its traceback), aborted, or crashed (the process died without a report). A run shows its outcome once its process is gone and its devices are free, so whoever sees “finished” can start the next one.
- The last 180 days of runs are kept: procedure, parameters, who started it, outcome.
The same from a script:
run = lab.start_procedure("detuning_scan", offsets_khz=[-200, 0, 200], duration_s=10)lab.wait_for_run(run["id"])Presets: the same parameters with one click
Section titled “Presets: the same parameters with one click”A preset is a procedure with saved parameters. In the run dialog, Save as preset… keeps the values; the procedure page then shows the preset as a button. LabOrchestra ships presets for the timed recordings: 30 seconds, 1, 2.5, 5, 10, 20 and 30 minutes.
On the dashboard, the Procedure widget is a button with an arrow: the button repeats the preset that was used last, the arrow lists the others (and Set parameters…). It shows progress and an abort button while it runs. The Record button of the recording bar has the same arrow for the timed recordings.
Presets of your lab are saved in presets.json in the workspace, a plain file you can keep in git. A preset that leaves a required parameter open asks for it when you start it.
Start a procedure when something happens
Section titled “Start a procedure when something happens”@procedure(on="recording.finished") starts the procedure by itself after every recording, for example to analyse it or to upload it:
@procedure(on="recording.finished")async def analyse(lab, event: dict | None = None): path = event["path"] # the recording that has just been closed ...| Event | When |
|---|---|
recording.finished |
a recording ended; its files are closed |
recording.discarded |
a recording was thrown away |
snapshot.saved |
a snapshot was saved |
device.error |
a device went into an error |
A parameter named event receives what the server knows about it: name, path, header, tags, started_by, end_reason, time, and for device.error the device and the error. The procedure is its own process and starts after the files are closed, so it never delays or fails a recording. It starts with the name event:<name> as its caller.
A procedure that starts a recording from its own trigger would trigger itself again. Avoid that. If a triggered procedure declares a device that another run has reserved, it is not started, and the log says so (there is no queue). An analysis usually needs no devices: the recording has all states.
Not yet
Section titled “Not yet”Synchronous (non-async) procedures, procedures that start other procedures, queues, schedules by time of day.
See the Python reference for everything the lab of a procedure can do.
Something wrong or missing on this page? Open a GitHub issue or use the form (no account needed).