From 9b68486cbe1fc69f7820af6e655e86158a6e7aed Mon Sep 17 00:00:00 2001 From: ivoryzhang Date: Sun, 22 Nov 2026 21:19:53 -0700 Subject: [PATCH] feat(labware view): layouts saved by name, and where each liquid handler is Labware view - A worktable can be saved under a name, switched to, reverted to as saved, deleted and exported. Saved layouts live in `worktable.layouts/` beside the worktable file. - The panel says "layout changed" apart from "liquids changed", and asks for a restart only when what the steps read at startup (labware names, equipment) differs from now. - The Edit layout panel shows controls only: help is behind "?", rare actions behind a menu. - Workflows and runs are not tagged with a layout. Docs - docs/liquid-handlers.md: each robot in 0.2.x, where it is in PyLabRobot 1.0.0b1, what this package's 1.0 covers, the legacy route, the version rule, and the unpublished 0.2.1 on fix/pylabrobot-below-1. - docs/opentrons-flex-control-landscape.md: what PyLabRobot 1.0.0b1 does on a Flex, Opentrons' own control routes, and the other open-source projects. Co-Authored-By: Claude Fable 5.2 --- README.md | 40 ++++- docs/liquid-handlers.md | 68 ++++++++ docs/opentrons-flex-control-landscape.md | 89 ++++++++++ plr_ivoryos/labware_view/__init__.py | 48 ++++- plr_ivoryos/labware_view/page/index.html | 172 +++++++++++++++--- plr_ivoryos/opentrons/flex.py | 22 ++- plr_ivoryos/robot.py | 192 ++++++++++++++++++-- plr_ivoryos/worktable.py | 151 +++++++++++++++- tests/test_layouts.py | 213 +++++++++++++++++++++++ 9 files changed, 941 insertions(+), 54 deletions(-) create mode 100644 docs/liquid-handlers.md create mode 100644 docs/opentrons-flex-control-landscape.md create mode 100644 tests/test_layouts.py diff --git a/README.md b/README.md index 964532e..3d51fc9 100644 --- a/README.md +++ b/README.md @@ -176,21 +176,48 @@ The original IvoryOS shows these arguments as text fields. ``` in a deck file (or `ivoryos_edge.run(__name__, plugins=[plr_ivoryos.labware_view.plugin])`) adds it -beside every page. **Edit layout** changes the worktable file as you go, with nothing to confirm: +beside every page. **Edit layout** changes the worktable file as you go, with nothing to confirm. +It shows the layout and the labware to place; the rest is under **⋯**, and **?** explains it all: -- what is mounted: the pipette on each mount or the 96-channel head, the gripper, the trash slot; +- what is mounted (**⋯ → Pipettes and gripper…**): the pipette on each mount or the 96-channel + head, the gripper, the trash slot; - drag labware from PyLabRobot's catalogue (a Flex's own tip racks, and any plate, reservoir or tube rack) onto an empty slot; drag what is there to move it, × to take it off, rename it in the list; - click a plate or reservoir, pick wells, and **Fill** them with a liquid and a volume: the `liquids` a run starts from; -- **Import a layout…** takes a worktable file you already have; the one it replaces is kept as +- **⋯ → Import a layout…** takes a worktable file you already have; the one it replaces is kept as `worktable.before-import.json`. -Steps offer added, moved or renamed labware, and changed equipment, once the deck restarts (the -panel offers the restart). The panel is the only part of this package that imports IvoryOS, and +Steps offer added, removed or renamed labware, and changed equipment, once the deck restarts (the +panel offers the restart). Moving labware, filling wells, and going back to the worktable the deck +started with need no restart. The panel is the only part of this package that imports IvoryOS, and only IvoryOS NextGen loads it. +### Saved layouts + +The worktable file is the layout in use. In **Edit layout**, the **Layout** row keeps others beside +it by name: + +- **Save as…** saves the layout in use under a name. Once it has changed, **Save** and **Revert** + appear beside its name: Save keeps the changes in the layout it came from. +- The list switches to another saved layout. If the one in use has changes that are not saved, the + panel asks first. +- **Revert** goes back to the layout as it was saved. This is how a layout is changed for one + experiment: change it, run, revert. Until then the panel says what differs, "layout changed" or + "liquids changed" (topping up a reservoir is not a different layout), and the change survives a + restart. +- **⋯ → Download** gives the layout as a file, which **Import a layout…** takes on another deck. + +Each saved layout is one worktable file in `worktable.layouts/` beside the worktable file +(`worktable.layouts/Dye dilution.json`). They are plain files, so the folder can be kept in a git +repository, and a file put there by hand is a saved layout like any other. `layouts_folder` puts +the folder somewhere else, for decks that share their layouts: + +```python +flex = Flex(simulated=True, layouts_folder="/labs/flex-layouts") +``` + --- ## Installation @@ -230,7 +257,8 @@ IvoryOS desktop app's decks do) uses the same plr-ivoryos and PyLabRobot. - **PyLabRobot 1.0 only.** The 0.2 `LiquidHandler`, its worktables for the OT-2, Hamilton and Tecan robots, and the single-purpose devices (`Scale`, `Pump`, `PlateReader`, `Sealer`, ...) are gone: they wrapped PyLabRobot's older interfaces, which 1.0 keeps only as `pylabrobot.legacy`. Saved - workflows using them need redoing. + workflows using them need redoing. Where each robot is now, and what is planned: + [docs/liquid-handlers.md](docs/liquid-handlers.md). - **The Opentrons Flex**, its mounts and gripper as instruments, and a simulated Flex. - No steps of this package's own design: no `transfer`, no "next unused tips" from a bare rack name. Steps are PyLabRobot's. diff --git a/docs/liquid-handlers.md b/docs/liquid-handlers.md new file mode 100644 index 0000000..0e82839 --- /dev/null +++ b/docs/liquid-handlers.md @@ -0,0 +1,68 @@ +# Liquid handlers: where each one is + +Checked 2026-11-22 by reading and running PyLabRobot 0.2.2 and 1.0.0b1. No robot in this table has +been run on real hardware with this package, in either line. + +## The two lines of this package + +- **0.2.x** is for PyLabRobot 0.2.x. Every robot is one instrument, PyLabRobot's old + `LiquidHandler`, with the same steps on each (`aspirate`, `dispense`, `transfer`, `pick_up_tips`, + `move_plate`, ...) and PyLabRobot's generic simulator. +- **1.0** is for PyLabRobot 1.0. Each robot has its own class and each thing mounted on it is an + instrument of its own, with PyLabRobot's step names. Only the Flex is done. + +## Robot by robot + +| Robot | This package 0.2.x | Where it is in PyLabRobot 1.0.0b1 | This package 1.0 | +| :--- | :--- | :--- | :--- | +| Opentrons Flex | not included | `pylabrobot.opentrons`: `Flex`, `FlexHead1`, `FlexHead8`, `FlexHead96`, `FlexGripper`. No simulator. | Done, with this package's simulator | +| Opentrons OT-2 | included | `pylabrobot.opentrons`: `OT2`, `OT2SingleChannelPipette`, `OT2_8ChannelPipette`. No simulator. | Not done. Needs a simulator written first. | +| Hamilton STAR, STARlet | included | `pylabrobot.hamilton.star`: `STAR`, `STARlet`, `STARPlus`, with `STARSimulationDriver` | Not done. Can be built against PyLabRobot's simulator. | +| Hamilton Prep | not included | `pylabrobot.hamilton.prep`: `Prep`, with `PrepSimulationDriver` | Not done | +| Hamilton Nimbus | included | only `pylabrobot.legacy` | Not planned | +| Hamilton Vantage | included | only `pylabrobot.legacy` | Not planned | +| Tecan EVO 100, 150, 200 | included | only `pylabrobot.legacy` | Not planned | + +Already in the 1.0 line for the OT-2 and the STAR: the worktable file builds their decks +(`OTDeck`, `STARDeck`, `STARLetDeck` in `worktable.py`), and the Labware view draws any robot. +What is missing is the driver class for each, like `opentrons/flex.py` for the Flex. + +## What the robot can do, 0.2 against 1.0 + +| | PyLabRobot 0.2.2 | PyLabRobot 1.0.0b1 | +| :--- | :--- | :--- | +| OT-2 | tips, aspirate, dispense, home | the same, plus mix, return and discard tips, move-to, and the 8-channel as its own class | +| STAR | channels, 96 head, iSWAP, CoRe grippers, autoload | the same, plus 384 head and STARPlus | + +So 1.0 is not a step down for these two. The OT-2 is thin only next to the Flex. + +## What does not carry over + +A workflow written for a 0.2 robot has to be rewritten for the same robot on 1.0: the instrument +names and the step names are different (`star.aspirate` becomes a step on one of the STAR's +parts). This is on purpose: 1.0 uses PyLabRobot's own names and does not try to make one workflow +run on two kinds of robot. + +## The legacy route + +`pylabrobot.legacy` in 1.0.0b1 still holds the old `LiquidHandler`, its backends (STAR, Vantage, +Nimbus, EVO, OT-2) and its simulator. It started and stopped on all eight old worktables; no step +was run on it. PyLabRobot marks it legacy and tells callers to move off it, and this package's 0.2 +code does not run on it as it is (14 of its 32 tests fail on 1.0.0b1). This package does not use +it. It is the only route to a Nimbus, Vantage or EVO on PyLabRobot 1.0, if someone asks for one. + +## Versions + +- The first two numbers follow PyLabRobot; the third is this package's own. +- While PyLabRobot 1.0 is in beta, each beta here (1.0.0b2, 1.0.0b3, ...) is pinned to exactly one + PyLabRobot beta. After PyLabRobot 1.0.0: `pylabrobot>=1.0,<1.1`, and 1.0.1, 1.0.2 at our pace. +- 0.2.x gets fixes only. **0.2.1 is prepared and not published**: branch + `fix/pylabrobot-below-1` requires `pylabrobot>=0.2.2,<1.0`. The published 0.2.0 has no upper + bound, so it will break when PyLabRobot 1.0 is final. On 2026-11-22 that branch passed its tests + on PyLabRobot 0.2.2 and ran a simulated STARlet and OT-2 with the current IvoryOS edge. + +## Order of work, when picked up + +1. Hamilton STAR and STARlet on 1.0 (a simulator exists). +2. Opentrons OT-2 on 1.0 (write the simulator first, as was done for the Flex). +3. Nimbus, Vantage, EVO only when someone needs one. diff --git a/docs/opentrons-flex-control-landscape.md b/docs/opentrons-flex-control-landscape.md new file mode 100644 index 0000000..113f66a --- /dev/null +++ b/docs/opentrons-flex-control-landscape.md @@ -0,0 +1,89 @@ +# Controlling an Opentrons Flex: what exists + +Notes from a survey on 2026-11-22, kept so it does not have to be repeated. It covers what +PyLabRobot 1.0.0b1 (the version this package is pinned to) does on a Flex, the ways Opentrons +itself offers to control one, and the other open-source projects found. Stars and dates are as +seen that day. + +## What PyLabRobot 1.0.0b1 covers + +Read from the installed package (`pylabrobot/opentrons`). + +**Included** + +- Connection over Ethernet or USB, runs, homing, rail lights, status bar, comments, timed waits. +- 1-, 8- and 96-channel pipettes: tips (pick up, drop, discard, presence check), aspirate, + dispense, blow out, air gap, touch tip, configure for volume, move to a well or a coordinate. + Liquid level probing on the 1- and 8-channel; `mix` and single-nozzle use on the 8-channel. +- Gripper: `move_labware(resource, to_slot)`, slot to slot only, including staging slots A4 to D4. + Also low-level `move_to_position`, `grip`, `ungrip`. +- Labware: any PyLabRobot definition is converted and uploaded to the robot; official Opentrons + tip racks are used as they are. +- Reading what is attached: pipettes, gripper, modules, deck fixtures. +- `Flex.send_command(command_type, params)`: any robot command by name. It validates nothing and + does not update PyLabRobot's tip, volume or labware tracking. +- `labware_moved_off_deck` and `reload_labware`, for labware a person or another arm moved. + +**Not included** (no code found) + +- Running a module: Heater-Shaker, Temperature Module, Thermocycler, Magnetic Block, Absorbance + Plate Reader, Flex Stacker. Attached modules can be listed, not driven. +- Moving labware onto a module or an adapter with the gripper, and pick-up or drop offsets. +- Lids, the waste chute. +- Opentrons liquid classes, and the robot's saved labware offsets (Labware Position Check). +- Pausing until a person resumes. +- Uploading or running an Opentrons protocol file: PyLabRobot sends one command at a time. + +The OT-2 class is much thinner than the Flex one (not thinner than the OT-2 in PyLabRobot 0.2: +see [liquid-handlers.md](liquid-handlers.md)): connect, home, and single- or 8-channel pipettes +with aspirate, dispense, mix, tips and move-to. Thermocyclers (Opentrons, Inheco, Thermo Fisher) exist only under +`pylabrobot.legacy`, which this package does not use. + +## What Opentrons itself offers + +- **Protocol API** (`opentrons.protocol_api`): a Python file with a `run(protocol)` function, + uploaded and run as a whole. Covers every module, lids, adapters, the waste chute. A run can be + paused, resumed and stopped from outside, and the Flex has an error-recovery state for some + failures, but what the run does next cannot be changed once it has started. +- **HTTP API** (the robot-server, port 31950): protocol upload and runs (`/protocols`, `/runs`, + `/runs/{id}/actions`), result files (`/dataFiles`), and **single commands** posted to a run with + no protocol (`/runs/{id}/commands`). Every Protocol API call has a command underneath + (`heaterShaker/closeLabwareLatch`, `absorbanceReader/read`, `moveLabware` to a module, ...). + This is the interface PyLabRobot uses, and what `send_command` passes through to. + Reference: +- **Jupyter on the robot**: Protocol API calls one cell at a time + (). Labware offsets have to be + set by hand in this mode. Not a route this package takes. +- **Definitions**: labware, deck and module geometry are JSON files in Opentrons' `shared-data` + (). A custom labware is the same kind of file, uploaded + with a protocol. On GitHub the Flex is called `ot3`. + +## Other open-source projects + +Found by GitHub repository search, GitHub code search for module commands +(`"heaterShaker/closeLabwareLatch"`, `"absorbanceReader/read"`, `"flexStacker/retrieve"`), and web +search. None is widely adopted. + +| Project | What it is | Flex and modules | Seen 2026-11-22 | +| :--- | :--- | :--- | :--- | +| [AccelerationConsortium/opentrons-flex](https://github.com/AccelerationConsortium/opentrons-flex) | SiLA 2 connector (UniteLabs CDK) that runs on the Flex in place of the robot-server; has a simulator | Heater-Shaker, Absorbance Plate Reader, Stacker, Temperature Module, Thermocycler, lids, gripper moves; can keep the HTTP API available | 3 stars, pushed 2026-11-02, no license file | +| [AccelerationConsortium/opentrons-ot2](https://github.com/AccelerationConsortium/opentrons-ot2) | The same idea for the OT-2 | OT-2 | 6 stars, pushed 2026-10-14, no license file | +| [usnistgov/AFL-automation](https://github.com/usnistgov/AFL-automation) (`AFL/automation/prepare/OT2HTTPDriver.py`) | Lab framework with a driver that posts single commands to the HTTP API and keeps deck state | Written for the OT-2; loads modules, moves labware | 19 stars, pushed 2026-11-13 | +| [AD-SDL/ot2_module](https://github.com/AD-SDL/ot2_module) | Node for Argonne's MADSci framework | README says OT-2 and Flex; depth not checked | 1 star, pushed 2026-10-29 | +| [rickwierenga/opentrons-python-api](https://github.com/rickwierenga/opentrons-python-api) | Thin wrapper around the HTTP API (used by PyLabRobot's legacy OT-2 backend) | Describes itself as incomplete | 11 stars, pushed 2025-11-26, MIT | +| [FlorianBauer/ot2-controller](https://github.com/FlorianBauer/ot2-controller) | SiLA 2 controller | OT-2 only | 15 stars, pushed 2023-06-04, Apache-2.0 | +| [Hendricks-Laboratory/OT2Control](https://github.com/Hendricks-Laboratory/OT2Control) | OT-2 control software | OT-2 only | 8 stars, pushed 2026-11-16, no license file | +| [Opentrons/opentrons-integration-tools](https://github.com/Opentrons/opentrons-integration-tools) | Opentrons' own guides for external devices | Guides, not a driver | 34 stars, pushed 2023-08-30 | +| [y3rsh/flex-talk](https://github.com/y3rsh/flex-talk) | TypeScript client for the Flex HTTP API | Not checked | 0 stars, pushed 2026-03-29 | + +Several MCP servers for Opentrons also exist (for example +[yerbymatey/opentrons-mcp](https://github.com/yerbymatey/opentrons-mcp)); they generate or submit +protocols and are not drivers. + +## What this means for this package + +A step for something PyLabRobot does not wrap (a Heater-Shaker, the plate reader, a lid) does not +have to wait for PyLabRobot: the robot command exists, and `send_command` sends it. Such a step +would be this package's own to write and maintain, PyLabRobot would not track labware it moves, +and it cannot be tested without a Flex that has the module, since the simulator here does not model +modules. diff --git a/plr_ivoryos/labware_view/__init__.py b/plr_ivoryos/labware_view/__init__.py index 94ef5c6..f8192b3 100644 --- a/plr_ivoryos/labware_view/__init__.py +++ b/plr_ivoryos/labware_view/__init__.py @@ -8,25 +8,35 @@ up while it runs. With "Edit layout" it changes the worktable the way a person changes the real one, saved to its worktable file: what is mounted on the robot, drag labware from PyLabRobot's catalogue onto a place (or a carrier onto the tracks), drag what is there to move it, rename or -remove it, fill wells with a liquid, or import a layout someone already has. Nothing moves. +remove it, fill wells with a liquid, or import a layout someone already has. A layout is saved +under a name, switched to, gone back to as it was saved, and downloaded as a file. Nothing moves. Only IvoryOS NextGen loads this module, and it provides `ivoryos_edge`; the rest of plr-ivoryos does not import it. Served at /plugins/labware/ (page), /plugins/labware/api/{layout,state, -catalog,edit} and /plugins/labware/events. +catalog,edit,export} and /plugins/labware/events. """ +import json import os +from typing import Optional +from urllib.parse import quote -from fastapi.responses import FileResponse, JSONResponse +from fastapi.responses import FileResponse, JSONResponse, Response from ivoryos_edge.plugins import Plugin plugin = Plugin("Labware", id="labware", page="page", placement="panel-right", icon="grid-3x3") # Worktables changed since this process started: steps offer the change only after a restart, and a -# page opened (or reloaded) in between should still say so. +# page opened (or reloaded) in between should still say so. Only for a worktable that does not say +# itself whether it still is what the deck started with (`deck.restart_needed`). _restart_pending: set = set() +def _needs_restart(name: str, found: dict) -> bool: + told = (found.get("deck") or {}).get("restart_needed") + return told if isinstance(told, bool) else name in _restart_pending + + def _call(instrument, method: str, *args): found = getattr(instrument, method, None) if not callable(found): @@ -50,8 +60,9 @@ def _worktables() -> dict: def layout() -> dict: - return {"worktables": {name: found for name, (_, found) in _worktables().items()}, - "restart_needed": sorted(_restart_pending)} + worktables = {name: found for name, (_, found) in _worktables().items()} + return {"worktables": worktables, + "restart_needed": sorted(name for name, found in worktables.items() if _needs_restart(name, found))} def state() -> dict: @@ -66,7 +77,8 @@ def on_event(event, name=name, instrument=instrument): # A change to the worktable itself means the page reads the layout again. plugin.publish({"worktable": name, "event": event, "state": _call(instrument, "__ivoryos_labware_state__") or {}, - "relayout": event.get("action") in ("move", "layout")}) + # "load" too: filling wells changes whether a saved layout still matches. + "relayout": event.get("action") in ("move", "layout", "load")}) _call(instrument, "__ivoryos_labware_events__", on_event) @@ -92,6 +104,23 @@ def get_pylabrobot(worktable: str, part: str = "layout"): return FileResponse(path, media_type="application/json", filename=os.path.basename(path)) +@plugin.router.get("/api/export") +def get_export(worktable: str, layout: Optional[str] = None): + """A layout as a file, as a download: the one in use, or a saved one by name. It is the file + "Import a layout" takes.""" + found = _worktables().get(worktable) + give = getattr(found[0], "__ivoryos_labware_export__", None) if found else None + if not callable(give): + return JSONResponse(status_code=404, content={"error": "This worktable cannot be downloaded."}) + try: + result = give(layout or None) + except ValueError as e: + return JSONResponse(status_code=404, content={"error": str(e)}) + filename = str(result.get("filename") or "worktable.json") + return Response(json.dumps(result.get("layout") or {}, indent=2) + "\n", media_type="application/json", + headers={"Content-Disposition": f"attachment; filename*=UTF-8''{quote(filename)}"}) + + @plugin.router.get("/api/catalog") def get_catalog(): """Per worktable: what can be put on it and which robots it can become. Empty lists for one @@ -119,6 +148,7 @@ def edit(change: dict): result = result if isinstance(result, dict) else {} if result.get("restart", True): _restart_pending.add(str(change.get("worktable"))) - return {"layout": layout(), "catalog": get_catalog()["worktables"], "state": state(), - "restart_needed": bool(result.get("restart", True)), "name": result.get("name"), + now = layout() + return {"layout": now, "catalog": get_catalog()["worktables"], "state": state(), + "restart_needed": str(change.get("worktable")) in now["restart_needed"], "name": result.get("name"), "kept": os.path.basename(result["kept"]) if result.get("kept") else None} diff --git a/plr_ivoryos/labware_view/page/index.html b/plr_ivoryos/labware_view/page/index.html index ca5f2fa..138e051 100644 --- a/plr_ivoryos/labware_view/page/index.html +++ b/plr_ivoryos/labware_view/page/index.html @@ -39,6 +39,23 @@ .act { border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); border-radius: 7px; padding: 3px 10px; font-weight: 600; } .act:disabled { opacity: .45; cursor: default; } .plain { border: 1px solid var(--line); background: transparent; border-radius: 7px; padding: 3px 10px; } + .plain:disabled { opacity: .45; cursor: default; } + a.plain { text-decoration: none; color: inherit; display: inline-block; } + #layoutline { margin: -2px 0 8px; } + #layoutline b { color: var(--ink); font-weight: 600; } + .changed { color: var(--warn-fg); } + #editor .ask { background: var(--soft); border-radius: 8px; padding: 7px 9px; } + #editor .help { background: var(--soft); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; } + #editor .help p:last-child { margin-bottom: 0; } + .spacer { flex: 1; } + .icon { min-width: 28px; padding: 3px 8px; font-weight: 600; } + .icon.on { background: var(--accent-soft); color: var(--accent-fg); border-color: var(--accent); } + .menu { position: relative; } + .items { position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; min-width: 180px; display: flex; flex-direction: column; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 6px 20px rgba(0,0,0,.14); } + .items button, .items a { text-align: left; border: none; background: transparent; border-radius: 6px; padding: 5px 9px; color: inherit; text-decoration: none; white-space: nowrap; } + .items button:hover, .items a:hover { background: var(--soft); } + .items hr { width: 100%; border: none; border-top: 1px solid var(--line); margin: 4px 0; } + .items .danger { color: var(--err-fg); } .note { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; padding: 7px 9px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-fg); font-size: 12px; } .note.error { background: var(--err-bg); color: var(--err-fg); } .note.info { background: var(--soft); color: var(--ink); } @@ -116,6 +133,7 @@

Labware

connecting +
@@ -125,6 +143,8 @@

Labware

+ +