A Rust-native re-implementation of the bluesky acquisition stack — RunEngine, devices, plans, document sinks — built so a beamline data-acquisition daemon can run without dragging a Python interpreter onto the IOC host.
bsrs emits the bluesky event-model documents verbatim, so the existing
Python ecosystem (databroker, Tiled, bluesky-kafka, BestEffortCallback)
consumes them unchanged. You can swap one piece at a time — see
Migration patterns below.
bluesky.run_engine.RunEngineparity — typedMsgenum, full state machine (Idle / Running / Paused / Aborting / Halted), pause/resume, suspenders, preprocessors, callbacks, baseline, run keys, contingency.- ophyd-async-style devices with a sync facade so the same plan code
works in both worlds.
#[derive(Device)]+#[signal(...)]on PV paths, no Python. - Drop-in EPICS CA + PVA backends via
epics-ca-rs/epics-pva-rswith sharded process-singleton registries, in-flight de-dup, RAII subscription tokens, and zero-copy NTNDArray decode for detector frames. bsrs qs-manager— bluesky-queueserver-compatible daemon speaking JSON-RPC-over-0MQ on the same control / document ports yourqserverclients already talk to. ~30 RPC methods implemented.bsrs qs repl— attach-to-running-daemon Lua REPL.motor:inspect(),motor:set(1.5):wait(),RE:run(count({det1}, 100))against a live daemon, no Python needed.- Document sinks for the bluesky Python ecosystem: JSONL, ZMQ
(msgpack/JSON, bluesky
Publisherenvelope), Tiled (HTTP), Kafka, HDF5 (NeXus-flavored frame writer), Hdf5/Binary frame sinks for the D21 multi-process layout. - Lua dev surface —
bsrs replfor offline plan prototyping; the#[lua_methods]attribute macro auto-exposes Rust device methods to the daemon Lua state with no manual mlua wiring. - Operational features —
bsrs doctorenv probe,bsrs migratestate-dir migration tool,permissions.tomlRBAC for the JSON-RPC surface, Prometheus/metricslistener, criterion benches.
Build:
git clone https://github.com/physwkim/bsrs
cd bsrs
cargo build --release
ln -s "$PWD/target/release/bsrs" ~/.local/bin/Sanity-check the environment:
bsrs doctor
[ ok ] tokio runtime (multi-thread)
[ ok ] EPICS_CA_ADDR_LIST = 192.168.50.255
[warn] EPICS_CA_AUTO_ADDR_LIST = NOLocal Lua REPL — fastest path to running a plan:
$ bsrs repl
bsrs> det1 = soft_detector("det1")
bsrs> RE:run(count({det1}, 5))
exit_status=success run_uid=8e3f...
bsrs> m1 = soft_motor("m1", 0.0)
bsrs> RE:run(scan({det1}, m1, 0, 10, 11))
exit_status=success run_uid=...Production daemon + attached REPL:
# terminal 1: start the queueserver-compatible daemon
$ bsrs qs-manager --soft-detectors 2 --soft-motors 2
# terminal 2: attach a Lua shell to the running daemon
$ bsrs qs repl
qs> m1:inspect()
=> {readback=0, setpoint=0, type="SoftMotor", units="mm", connected=true, ...}
qs> m1:set(1.5):wait()
qs> m1:inspect().readback
=> 1.5
qs> RE:run(count({det1}, 100))
=> exit_status=success run_uid=...bsrs is a single crate plus a proc-macro companion. Each module has a single responsibility; boundaries are designed so a downstream user can swap one implementation without touching the others.
crates/bsrs library + `bsrs` binary (feature: cli)
├── core Msg, Status, errors, runtime
├── engine RunEngine, state machine, suspenders, preprocessors
├── event_model Document types: RunStart, EventDescriptor, Event, RunStop, ...
├── plans bp.* / bps.* / bpp.* mirrors (count, scan, grid_scan, ...)
├── protocols_sync Movable, Triggerable, Stageable, Readable (sync facade)
├── protocols_async ophyd-async-style traits over async fns
├── devices SoftMotor, SoftDetector, NDSimDetector, ...
├── backends SignalBackend over EPICS CA / PVA (features: ca, pva)
├── callbacks Document sinks: jsonl, zmq, tiled, kafka
├── stream FrameSink/FrameSource: hdf5, binary, pva
├── qs bluesky-queueserver-compatible daemon (feature: qs)
├── host Lua host runtime + CA/PVA devices (feature: host)
└── bin/bsrs CLI: qs-manager, qs, repl, doctor, migrate, frame-source
crates/bsrs-derive #[derive(Device)], #[lua_methods] proc-macros
The Document plane and the frame plane are kept separate. Frame bytes
never travel through the Document plane — StreamResource /
StreamDatum carry only path / shape descriptors, while the bytes
flow FrameSource → FramePipe → FrameSink locally. This is what
makes the "RunEngine on the IOC host" deployment shape work.
bsrs is a drop-in replacement at the Document boundary. Three common migration patterns:
- Keep bluesky-queueserver, swap the worker. Replace
start-re-managerwithbsrs qs-manager. Existingqserver/ web UI /RemoteDispatcherconsumers connect unchanged. - Keep
bluesky.RunEnginein Python, swap the document plumbing. Run bsrs's RunEngine in a small Rust helper, ZMQ- publish to your PythonRemoteDispatchersetup. Same wire format asbluesky.callbacks.zmq. - Native bsrs end-to-end. New beamlines without a bluesky /
ophyd commitment.
bsrs replfor development,bsrs qs-managerfor production.
Plan-code translation table and full migration guide: book/src/migration.md.
All flags below are features of the bsrs crate:
| Feature | Adds |
|---|---|
ca / pva |
live EPICS CA / PVA backends (default; opt out for stubs) |
zmq |
bluesky Publisher envelope sink |
tiled |
HTTP register + metadata patch; Lua tiled.* namespace |
kafka |
pure-Rust rskafka crate, no librdkafka |
hdf5 |
rust-hdf5 frame writer, NeXus layout |
qs |
bluesky-queueserver-compatible daemon module |
metrics |
Prometheus /metrics endpoint |
host |
Lua host runtime (mlua bridge) |
cli |
bsrs binary: qs-manager, qs, repl, doctor, migrate |
frame-source |
wire PVA + HDF5 into bsrs frame-source |
blop |
beamline optimization plans (blop port), see doc/11-blop.md |
blop-bridge |
drive an out-of-process optimizer (Ax) over ZMQ |
The default build is small and dependency-light. CI builds and tests each opt-in feature on every push.
Hosted book: https://physwkim.github.io/bsrs/ — quickstart, migration, CLI tour, operational runbook, architecture overview (mdbook source).
Design notes (numbered for read-in-order):
doc/00-vision.mddoc/01-architecture.mddoc/02-event-model.mddoc/03-runengine.mddoc/04-devices.mddoc/05-streaming.mddoc/06-rules.mddoc/07-milestones.mddoc/08-decisions.mddoc/09-references.mddoc/10-roadmap.md— tracked open itemsdoc/11-blop.md— beamline optimization (blop port)