Skip to content

feat: add dispensing module with Formulatrix Mantis backend#987

Open
xbtu2 wants to merge 6 commits intoPyLabRobot:v1b1from
xbtu2:feat/dispensing-mantis
Open

feat: add dispensing module with Formulatrix Mantis backend#987
xbtu2 wants to merge 6 commits intoPyLabRobot:v1b1from
xbtu2:feat/dispensing-mantis

Conversation

@xbtu2
Copy link
Copy Markdown
Contributor

@xbtu2 xbtu2 commented Apr 4, 2026

Summary

Adds a new pylabrobot/dispensing/ module for chip-based contactless liquid dispensers, following PLR's Machine/Backend architecture pattern. The Formulatrix Mantis is the first backend implementation.

New Module Structure

pylabrobot/dispensing/
├── __init__.py                    # Exports: Dispenser, DispenserBackend, DispenseOp
├── backend.py                     # ABC: DispenserBackend
├── standard.py                    # Dataclass: DispenseOp
├── dispenser.py                   # Front-end: Dispenser(Machine)
├── chatterbox.py                  # ChatterboxBackend for testing
├── dispenser_tests.py             # Front-end unit tests (6 tests)
└── mantis/
    ├── __init__.py                # Exports: MantisBackend
    ├── mantis_backend.py          # MantisBackend(DispenserBackend)
    ├── fmlx_driver.py             # Low-level FMLX protocol driver
    ├── mantis_kinematics.py       # Kinematics + map generator
    ├── mantis_constants.py        # Constants, chip paths, PPI sequences
    ├── mantis_sequence_parser.py  # Sequence file parser
    └── mantis_tests.py            # Mantis-specific unit tests (22 tests)

Design Highlights

  • Dispenser(Machine) front-end with @need_setup_finished decorator
  • DispenserBackend ABC with setup(), stop(), dispense(ops) interface
  • DispenseOp frozen dataclass (resource, volume, chip)
  • MantisBackend — full init sequence, chip lifecycle (attach/prime/dispense/detach), pressure control
  • FmlxDriver — accepts PLR's pylabrobot.io.ftdi.FTDI via dependency injection
  • Proper enumsMotorStatusCode(IntFlag) with error_mask(), PEP 8 naming
  • Configurable chip_type_map per instrument instance
  • 28 unit tests all passing
  • Chatterbox backend for device-free testing

Usage Example

from pylabrobot.dispensing import Dispenser
from pylabrobot.dispensing.mantis import MantisBackend

d = Dispenser(backend=MantisBackend(
    serial_number="M-000438",
    chip_type_map={3: "high_volume", 4: "high_volume", 5: "low_volume"},
))
await d.setup()
await d.dispense(plate["A1:H12"], volume=5.0, chip=3)
await d.stop()

Testing

28 passed in 0.14s

All pre-commit hooks pass (ruff format, ruff check, typos).

Add a new pylabrobot/dispensing/ module for chip-based contactless liquid
dispensers, following PLR's Machine/Backend architecture pattern.

New module structure:
- Dispenser front-end (Machine subclass)
- DispenserBackend ABC with setup/stop/dispense interface
- DispenseOp frozen dataclass for operation parameters
- ChatterboxBackend for device-free testing

Mantis backend (pylabrobot/dispensing/mantis/):
- MantisBackend implementing DispenserBackend
- FmlxDriver for Formulatrix FMLX protocol over FTDI
- MantisKinematics (inverse/forward kinematics for dual-arm SCARA)
- MantisMapGenerator (homography-corrected plate coordinate mapping)
- Sequence file parser for Mantis .seq files
- Constants with proper IntFlag/IntEnum types

28 unit tests (all passing).
@rickwierenga
Copy link
Copy Markdown
Member

sweet! thanks for the PR!

mind if I rebase this onto the v1b1 architecture?

- Fix isort I001: remove extra blank line in mantis_sequence_parser.py
- Fix mypy arg-type: use explicit MantisMapGenerator construction instead
  of **dict unpacking (rows/cols need int, not float)
- Fix mypy arg-type: cast coord dict values to float explicitly
- Fix mypy no-any-return: cast dict.get() results to int in motor status
  helpers
- Change get_well_coordinate return type from Dict[str, object] to
  Dict[str, Any] for correct downstream typing
- Add 'Occured' to _typos.toml (firmware protocol string, not a typo)
@rickwierenga rickwierenga changed the base branch from main to v1b1 April 6, 2026 21:39
@rickwierenga
Copy link
Copy Markdown
Member

right now the plate layout is loaded from DEFAULT_PLATE_GEOMETRY, can we load it from the associated plate instead? this way we can use our existing definitions and also automatically make it work for non 96 well for plates

@BioCam
Copy link
Copy Markdown
Collaborator

BioCam commented Apr 8, 2026

This is awsesome, @xbtu2 !
I will try it out soon

Which hardware version are you using here?
(I assume Mantis v3.3 (example) but want to check)

And which firmware version are you using?

@xbtu2
Copy link
Copy Markdown
Contributor Author

xbtu2 commented Apr 10, 2026

This is awsesome, @xbtu2 ! I will try it out soon

Which hardware version are you using here? (I assume Mantis v3.3 (example) but want to check)

And which firmware version are you using?

@BioCam i am using mantis v3.1 acc. firmware version 4.20.3

rickwierenga and others added 4 commits April 10, 2026 18:34
Drops DEFAULT_PLATE_GEOMETRY and the plate_geometry backend kwarg in
favor of computing each well's machine coordinate from its PLR Plate
parent. PLR stores wells as LFB with A1 at the back; the Mantis plate
frame has A1 at the front, so y is mirrored across plate.size_y before
the stage homography is applied. Dispense Z is kept as an explicit
backend-level calibration (dispense_z) since it is a machine property,
not a plate property.

MantisMapGenerator's row/pitch/A1 template is now dead — collapsed to
a free apply_stage_homography() function. Junk tests that only checked
types or counted loop iterations are removed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… category

Removes the dispensing category abstraction (Dispenser frontend,
DispenserBackend, DispenseOp, chatterbox) and moves the Mantis backend
under a top-level formulatrix vendor directory. MantisBackend now
inherits from MachineBackend directly and dispense() takes (wells,
volume, chip) instead of a list of DispenseOps. The per-op chip grouping
is gone since the old frontend never allowed mixed chips per call.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds a new diaphragm bulk-dispensing capability under
pylabrobot.capabilities.bulk_dispensers.diaphragm. This is the
"variable" head-format variant: callers pass parallel containers and
volumes lists. The capability validates lengths and positivity; chip
number, dispense Z-height, and prime volume travel as a BackendParams
subclass on each backend implementation. Includes a chatterbox backend
for device-free testing.

Splits the Mantis backend into the v1b1 three-layer shape:
* MantisDriver(Driver) — FTDI/FMLX connection, init sequence, motion,
  chip lifecycle, raw PPI playback, pressure init/shutdown.
* MantisDiaphragmDispenserBackend(DiaphragmDispenserBackend) —
  translates capability ops into driver calls, applies the PLR -> Mantis
  y-flip + stage homography, exposes nested DispenseParams / PrimeParams.
* Mantis(Device) — wires the driver and capability together as the
  first backend of the new diaphragm capability.

Adds user-guide walkthroughs for both the diaphragm capability and the
Mantis hello-world, plus API rst pages. Models bulk dispensing as a
mechanism × head-format matrix in the docs so future variable / 8 / 96
variants of each mechanism have a clear naming and structural slot.

Drive-by fixes:
* docs/api/pylabrobot.capabilities.rst: corrected stale currentmodule
  paths for peristaltic/syringe (.peristaltic -> .peristaltic8,
  .backend -> .backend8) — autosummary was failing to import these,
  which also blocked the {class} cross-references in user-guide pages.
* docs/user_guide/hamilton/star/index.md: fixed pre-existing toctree
  refs to nonexistent y-probing/z-probing pages (now point at the
  actual probing/{x,y,z}.ipynb files from the v1b1 merge).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants