Skip to content

Add TESBackend: data-driven KB simulation backend from measured TES beamline frames#325

Draft
FLlorente wants to merge 2 commits into
bluesky:mainfrom
FLlorente:tes-emulator-sim-backend
Draft

Add TESBackend: data-driven KB simulation backend from measured TES beamline frames#325
FLlorente wants to merge 2 commits into
bluesky:mainfrom
FLlorente:tes-emulator-sim-backend

Conversation

@FLlorente

Copy link
Copy Markdown

This adds a third simulation backend to blop_sim, alongside SimpleBackend and XRTBackend:

  • TESBackend replays an emulator trained on 28,561 measured detector frames (complete 13⁴ KB-jack grid of the NSLS-II TES beamline at 3 keV), so the beam an agent optimizes has the real machine's astigmatism, non-Gaussian streaks, and flux variation. It reuses the existing devices.simple.KBMirror jack devices and DetectorDevice unchanged.
  • Tutorial docs/source/tutorials/tes-kb-jacks.md, mirroring xrt-kb-mirrors.md but with the four jack positions as DOFs (bounds taken from the recorded motor box via TESBackend.motor_box()), the same marginal-FWHM evaluation function, and a flux OutcomeConstraint.
  • Weights: the trained weights (16 MB, derived from measured data) are not committed — they resolve at runtime from BLOP_SIM_TES_WEIGHTS or a download URL (tes_model.WEIGHTS_URL, to be filled once we publish them — hosting suggestions welcome).

Two small fixes surfaced during integration:

  1. SimBackend.__new__ now accepts constructor args — SimpleBackend(noise=True) previously raised TypeError under the singleton pattern.
  2. blop_sim imports XRTBackend/TESBackend lazily, so import blop_sim no longer fails on hosts where pyopencl finds no OpenCL devices (e.g. macOS), and torch is only required when the TES backend is used.

Checks: pre-commit run all green (ruff, pyright, mdformat, large-files); full src/blop/tests suite passes (202 passed); backend output verified bit-identical to the reference tes-emulator implementation.

🤖 Generated with Claude Code

FLlorente and others added 2 commits July 17, 2026 16:29
…frames

A third simulation backend alongside SimpleBackend and XRTBackend: replays an
emulator trained on 28,561 measured detector frames (complete 13^4 KB-jack grid
of the NSLS-II TES beamline, 3 keV), so the optimized beam response includes
real astigmatism, non-Gaussian streaks and flux variation. Reuses the existing
simple KBMirror jack devices and DetectorDevice unchanged, plus a tutorial
(tes-kb-jacks.md) mirroring xrt-kb-mirrors.md with four jack DOFs.

The trained weights (16 MB, derived from measured data) are not committed;
they are resolved from BLOP_SIM_TES_WEIGHTS / a download URL at runtime.

Also two small fixes surfaced while integrating:
- SimBackend.__new__ now accepts constructor args (SimpleBackend(noise=True)
  previously raised TypeError under the singleton pattern).
- blop_sim imports XRTBackend/TESBackend lazily, so importing blop_sim no
  longer fails on hosts where pyopencl finds no OpenCL devices (macOS) and
  does not require torch unless the TES backend is used.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The docs build executes every tutorial; tes-kb-jacks.md needs the trained
emulator weights, which are not yet hosted anywhere CI can reach. Render the
page without execution for now; drop the exclusion once WEIGHTS_URL is set.

Co-Authored-By: Claude Opus 4.8 (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.

1 participant