Add TESBackend: data-driven KB simulation backend from measured TES beamline frames#325
Draft
FLlorente wants to merge 2 commits into
Draft
Add TESBackend: data-driven KB simulation backend from measured TES beamline frames#325FLlorente wants to merge 2 commits into
FLlorente wants to merge 2 commits into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a third simulation backend to
blop_sim, alongsideSimpleBackendandXRTBackend:TESBackendreplays 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 existingdevices.simple.KBMirrorjack devices andDetectorDeviceunchanged.docs/source/tutorials/tes-kb-jacks.md, mirroringxrt-kb-mirrors.mdbut with the four jack positions as DOFs (bounds taken from the recorded motor box viaTESBackend.motor_box()), the same marginal-FWHM evaluation function, and a fluxOutcomeConstraint.BLOP_SIM_TES_WEIGHTSor a download URL (tes_model.WEIGHTS_URL, to be filled once we publish them — hosting suggestions welcome).Two small fixes surfaced during integration:
SimBackend.__new__now accepts constructor args —SimpleBackend(noise=True)previously raisedTypeErrorunder the singleton pattern.blop_simimportsXRTBackend/TESBackendlazily, soimport blop_simno 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 runall green (ruff, pyright, mdformat, large-files); fullsrc/blop/testssuite passes (202 passed); backend output verified bit-identical to the reference tes-emulator implementation.🤖 Generated with Claude Code