feat(flomni): fix tomo-queue move allow-list, drop idgap stub, add foptz+shift action
CI for csaxs_bec / test (push) Successful in 3m10s
CI for csaxs_bec / test (push) Successful in 3m10s
Queue-control "command job" changes: - Remove the "optimize_idgap" stub action (not commissioned, always a no-op) from both Flomni's and LamNI's action registry, and delete the now-dead TomoQueueMixin.optimize_idgap() method. - Fix the "move" action's device allow-list: "mokev" doesn't exist in the current device config at all -- the real energy device is "ccm_energy" (LamNI's copy already had this right). Also drop "ftray" (sample transfer tray), which was only ever there as a sim-testable move target. - Add a new "move_foptz_with_shift" action: moves foptz (the FZP optics-Z stage) and sets the compensating manual_shift_x/manual_shift_y in one atomic step. foptz is deliberately NOT in the plain move allow-list -- moving it shifts the aligned scan center (interferometer mirrors aren't perfectly parallel to the beam), so this is the only way to queue a foptz move, specifically so the compensating shift can never be forgotten. - The foptz target is validated against the device's real, live limits (not a hand-duplicated static number) both in the GUI spinbox's range and in the CLI's add-time validation, so a queued job can't raise when it executes unattended later; a defense-in-depth check also exists at execution time. Retargeted the e2e command-job tests from ftray to foptz (now the only sim-testable move-adjacent path) and updated the AI_docs testing/GUI-testing notes to match the new action set. Also fixes a pre-existing, unrelated broken import (plugins.omny.omny_general_tools -> plugins.OMNY_shared.omny_general_tools, already broken on main) in _bootstrap.py/test_tomo_queue.py/ test_tomo_queue_command_jobs.py that was blocking omny_e2e_tests collection entirely, needed to actually verify this change's own test rewrites. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NPZ9gzN2rt3wgiMnTKyrug
This commit is contained in:
1 parent
cf66e0d1ec
commit
437d9e7559
9 files changed
+208
-130
No files matched your search
@@ -175,9 +175,11 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools
|
||||
}
|
||||
|
||||
# Named-action registry for tomo-queue command jobs -- identical to
|
||||
# flomni's, since both actions (move, optimize_idgap) are beamline-wide,
|
||||
# not flomni-specific hardware. See TomoQueueMixin._queue_action_move()/
|
||||
# optimize_idgap() for the implementations.
|
||||
# flomni's plain "move" action, since it's beamline-wide, not
|
||||
# flomni-specific hardware. flomni also has a "move_foptz_with_shift"
|
||||
# action for its own FZP optics-Z stage; lamni has no equivalent
|
||||
# hardware, so it isn't mirrored here. See
|
||||
# TomoQueueMixin._queue_action_move() for the implementation.
|
||||
_TOMO_QUEUE_ACTIONS = {
|
||||
"move": {
|
||||
"func": "_queue_action_move",
|
||||
@@ -185,21 +187,6 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools
|
||||
"help": "Move device(s) to absolute position(s).",
|
||||
"params": {"positions": {"type": "device_positions"}},
|
||||
},
|
||||
"optimize_idgap": {
|
||||
"func": "optimize_idgap",
|
||||
"idempotent": True,
|
||||
"help": "Scan idgap over a search range and move to the peak. STUB: no-op.",
|
||||
"params": {
|
||||
"search_range": {
|
||||
"type": "float",
|
||||
"default": 0.5,
|
||||
"min": 0.0,
|
||||
"max": 2.0,
|
||||
"unit": "mm",
|
||||
"label": "Search range",
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def _describe_tomo_job_line(self, job: dict) -> str:
|
||||
|
||||
@@ -586,6 +586,11 @@ class TomoQueueMixin:
|
||||
if not isinstance(value, (int, float)) or isinstance(value, bool):
|
||||
raise ValueError(f"{action_name}.{name} must be a number, got {value!r}.")
|
||||
lo, hi = field.get("min"), field.get("max")
|
||||
device_name = field.get("device_limits_from")
|
||||
if device_name is not None:
|
||||
device = self.device_manager.devices.get(device_name)
|
||||
if device is not None:
|
||||
lo, hi = device.limits
|
||||
if lo is not None and value < lo:
|
||||
raise ValueError(f"{action_name}.{name}={value} is below the minimum {lo}.")
|
||||
if hi is not None and value > hi:
|
||||
@@ -618,23 +623,6 @@ class TomoQueueMixin:
|
||||
args += [dev[name], target]
|
||||
umv(*args)
|
||||
|
||||
def optimize_idgap(self, search_range: float = 0.5) -> None:
|
||||
"""Scan idgap over +/- search_range around its current position and
|
||||
move to the peak of <signal not yet decided>.
|
||||
|
||||
STUB -- not implemented. The peak-detection signal/device is not yet
|
||||
decided (see flomni's AI_docs/TOMO_QUEUE_COMMAND_JOBS_PLAN.md section
|
||||
10). This is the ONLY place that needs to change to make this a real
|
||||
action: the registry entry, resume policy, and (eventually) GUI
|
||||
wiring already treat it as a normal idempotent compound action, so
|
||||
dropping in the real scan-and-move-to-peak logic here (or swapping
|
||||
which device/signal it reads) is a self-contained change.
|
||||
"""
|
||||
print(
|
||||
f"optimize_idgap(search_range={search_range}): not yet implemented -- "
|
||||
"peak-detection signal not yet decided. No-op."
|
||||
)
|
||||
|
||||
def _describe_tomo_queue_actions(self) -> dict:
|
||||
"""Serializable description of the action registry + move allow-list.
|
||||
|
||||
|
||||
@@ -41,8 +41,10 @@ support on top of it:
|
||||
registry `Flomni.__init__` publishes) so its action dropdown and
|
||||
per-action fields always match whatever's actually in `flomni.py` — no
|
||||
hardcoded mirror. Lets you add steps in order (action + its own fields
|
||||
only — a device dropdown and target for `move`, a bounded spinbox for
|
||||
`optimize_idgap`'s `search_range`), remove a step, reorder steps within
|
||||
only — a device dropdown and target for `move`, three bounded spinboxes
|
||||
for `move_foptz_with_shift`'s `foptz_target`/`manual_shift_x`/
|
||||
`manual_shift_y`, the first of which ranges over `foptz`'s live device
|
||||
limits rather than a static number), remove a step, reorder steps within
|
||||
the job (move up/down), and set a label + idempotent flag (defaults to
|
||||
"every step idempotent" ANDed, same as the CLI, until you touch the
|
||||
checkbox yourself). On confirm it produces a job dict byte-for-byte
|
||||
@@ -50,7 +52,8 @@ support on top of it:
|
||||
2. **Command-job-aware queue table.** `TomoQueueDialog`'s table gained a
|
||||
"Details" column; a command job shows `CMD` in the Type column and its
|
||||
step summary + idempotency marker in Details (e.g.
|
||||
`move{'positions': {'mokev': 6.2}} > optimize_idgap{'search_range': 0.5} [idem]`
|
||||
`move{'positions': {'ccm_energy': 6.2}} > move_foptz_with_shift{'foptz_target':
|
||||
15.0, 'manual_shift_x': 1.0, 'manual_shift_y': -2.0} [idem]`
|
||||
— literally the same string `flomni.tomo_queue_show()` prints).
|
||||
3. **Self-describing tomo jobs.** "Add current params to queue" now stamps
|
||||
`"kind": "tomo"` and a fresh `"id"` on the job it writes, matching what
|
||||
@@ -201,19 +204,22 @@ file is exactly how a regression sneaks in.
|
||||
## 4. Test plan — new: command-job builder
|
||||
|
||||
6. Click **"Add command…"**. Confirm the dialog opens with an **action
|
||||
dropdown showing `move` and `optimize_idgap`** (or whatever's currently
|
||||
in `flomni.py`'s `_TOMO_QUEUE_ACTIONS` — if you've added a third action
|
||||
since this was written, it should appear automatically with no GUI
|
||||
change needed; that's the point of reading the live registry).
|
||||
dropdown showing `move` and `move_foptz_with_shift`** (or whatever's
|
||||
currently in `flomni.py`'s `_TOMO_QUEUE_ACTIONS` — if you've added a
|
||||
third action since this was written, it should appear automatically with
|
||||
no GUI change needed; that's the point of reading the live registry).
|
||||
7. With `move` selected, confirm the field area shows a **device dropdown**
|
||||
(should list `mokev`, `idgap`, `ftray` per the current allow-list) and a
|
||||
**numeric target field**. Pick a device, set a target, click **"Add
|
||||
step"**. Confirm a line appears in the step list above, formatted like
|
||||
`move{'positions': {'mokev': 6.2}}`.
|
||||
8. Switch the action dropdown to `optimize_idgap`. Confirm the field area
|
||||
now shows a single **search_range** spinbox pre-filled with `0.5`,
|
||||
range-limited (try typing outside 0–2, confirm the widget clamps it
|
||||
rather than accepting it). Click **"Add step"**.
|
||||
(should list `ccm_energy`, `idgap` per the current allow-list -- `foptz`
|
||||
is deliberately absent, see point 8) and a **numeric target field**. Pick
|
||||
a device, set a target, click **"Add step"**. Confirm a line appears in
|
||||
the step list above, formatted like `move{'positions': {'ccm_energy': 6.2}}`.
|
||||
8. Switch the action dropdown to `move_foptz_with_shift`. Confirm the field
|
||||
area now shows three spinboxes: **foptz target (absolute)**,
|
||||
**Compensating manual_shift_x**, **Compensating manual_shift_y**. Confirm
|
||||
the foptz-target spinbox's range reflects `foptz`'s *live* device limits
|
||||
(try typing a value past the real limit, confirm the widget clamps it
|
||||
rather than accepting it -- this is the live-limit lookup, not a static
|
||||
number). Fill in all three and click **"Add step"**.
|
||||
9. Confirm the **idempotent checkbox auto-checked itself** after both adds
|
||||
(both current actions default to idempotent=True). Uncheck it by hand,
|
||||
then add another step — confirm it **stays unchecked** (your override
|
||||
@@ -250,9 +256,10 @@ file is exactly how a regression sneaks in.
|
||||
## 6. Test plan — mixed queue, end to end
|
||||
|
||||
17. Build a small realistic sequence via the GUI only: a tomo job ("Add
|
||||
current params to queue"), then a command job (e.g. a `move` on
|
||||
`ftray` if you're on the sim — `mokev`/`idgap` only exist on the real
|
||||
front-end, see plan section 3.1), then another tomo job.
|
||||
current params to queue"), then a command job (e.g. a `move_foptz_with_shift`
|
||||
step if you're on the sim — `ccm_energy`/`idgap` only exist on the real
|
||||
front-end, `foptz` is the only queue-movable device in the sim config),
|
||||
then another tomo job.
|
||||
18. From the CLI, run `flomni.tomo_queue_execute()`. Confirm: the tomo job
|
||||
runs, the command job actually moves the device (check
|
||||
`dev.<device>.readback.get()` before/after), and the second tomo job
|
||||
|
||||
@@ -264,8 +264,8 @@ interruptible mid-scan for the crash-resume tests (§4, B5).
|
||||
10. **✅ Add-time validation rejects bad steps, and rejects them without landing
|
||||
anything in the queue.** `test_add_command_validation_errors`. Unknown action,
|
||||
a device not on the `move` allow-list, an out-of-range/wrong-type
|
||||
`optimize_idgap.search_range`, and an unknown kwarg are each rejected with the
|
||||
expected `ValueError`; afterward the queue is confirmed still empty.
|
||||
`move_foptz_with_shift.foptz_target`, and an unknown kwarg are each rejected
|
||||
with the expected `ValueError`; afterward the queue is confirmed still empty.
|
||||
11. **✅ Execution-time allow-list re-check is the real safety boundary.**
|
||||
`test_move_execution_time_allowlist_recheck`. A job with a disallowed device
|
||||
appended directly (bypassing `tomo_queue_add_command`) is refused by
|
||||
@@ -278,10 +278,13 @@ interruptible mid-scan for the crash-resume tests (§4, B5).
|
||||
`test_show_and_webpage_survive_command_job`. A command job (no `params` key)
|
||||
renders its step summary + idempotency marker in both, instead of `KeyError`ing.
|
||||
14. **✅ Back-compat + real dispatch, combined.**
|
||||
`test_legacy_job_no_kind_defaults_to_tomo_and_command_moves_ftray`. A `kind`-less
|
||||
`test_legacy_job_no_kind_defaults_to_tomo_and_command_moves_foptz`. A `kind`-less
|
||||
legacy queue entry still runs as a tomogram; in the same mixed-queue run, a
|
||||
command job actually moves a device (`ftray`, the sim-testable stand-in for
|
||||
`mokev`/`idgap` — see the plan doc §3.1) via the real `move` action path.
|
||||
command job actually moves `foptz` and sets the compensating
|
||||
`manual_shift_x`/`manual_shift_y` via the real `move_foptz_with_shift` action
|
||||
path (the only sim-movable path now that `ftray` is no longer in the move
|
||||
allow-list; `foptz` is also the real device this action exists for, unlike
|
||||
`ftray`'s old sim-only stand-in role).
|
||||
15. **✅ Non-idempotent resume prompts exactly once, and respects "no".**
|
||||
`test_non_idempotent_command_resume_prompts`. A command job flagged
|
||||
`idempotent=False`, left `incomplete`, triggers the resume prompt (distinct from
|
||||
@@ -294,13 +297,14 @@ interruptible mid-scan for the crash-resume tests (§4, B5).
|
||||
16. One queued tomogram end-to-end on the real instrument, to confirm the sim's
|
||||
timing/progress semantics match reality closely enough that resume lands on the
|
||||
right angle.
|
||||
17. `move` on `mokev`/`idgap` end-to-end — neither device is in the flomni sim
|
||||
config (see the plan doc §3.1), so Step 2's `move` action itself has only been
|
||||
sim-exercised via `ftray`, never against the real devices it's actually for.
|
||||
17. `move` on `ccm_energy`/`idgap` end-to-end — neither device is in the flomni
|
||||
sim config, so Step 2's `move` action itself has only been sim-exercised via
|
||||
add-time validation (which doesn't require real movement), never a real
|
||||
execute() against these two devices.
|
||||
|
||||
**Gate:** A–D passed on the sim (16/16 tests total). **Steps 1 and 2 are verified
|
||||
enough to build Step 3 (the GUI) on.** E remains open, and blocks calling `move` on
|
||||
`mokev`/`idgap` production-ready.
|
||||
**Gate:** A–D passed on the sim. **Steps 1 and 2 are verified enough to build
|
||||
Step 3 (the GUI) on.** E remains open, and blocks calling `move` on
|
||||
`ccm_energy`/`idgap` production-ready.
|
||||
|
||||
### A gotcha found testing Step 2 (not a Step-2 bug)
|
||||
|
||||
@@ -348,11 +352,14 @@ still just its design.
|
||||
- **Registry entry = 4 things:** bound method name, `idempotent` default, help string,
|
||||
and a **params schema** (possibly empty).
|
||||
- **Result-dependent logic lives INSIDE a named action, never across queue steps.**
|
||||
E.g. "scan idgap, move to peak" is ONE action (`optimize_idgap`) whose method does
|
||||
the scan, finds the peak, and moves — *not* three queue steps. The queue therefore
|
||||
never has to carry runtime values between steps; `kwargs` stays plain JSON. A
|
||||
compound action may take parameters (e.g. `search_range`), declared in its params
|
||||
schema like any other.
|
||||
E.g. a hypothetical "scan idgap, move to peak" action would be ONE action whose
|
||||
method does the scan, finds the peak, and moves — *not* three queue steps. The
|
||||
queue therefore never has to carry runtime values between steps; `kwargs` stays
|
||||
plain JSON. The same "bundle, don't split" idea also applies to a compound action
|
||||
with no runtime-dependent result but a correctness-critical pairing of writes --
|
||||
`move_foptz_with_shift` (moves `foptz` + sets the compensating
|
||||
`manual_shift_x`/`manual_shift_y` atomically, deliberately not reachable as two
|
||||
separate steps) is the concrete example currently in the registry.
|
||||
- **Publish the registry via a global var** (`tomo_queue_actions`) on `Flomni.__init__`
|
||||
so the GUI builds its dropdowns/forms from it — no hardcoded mirror to drift (the
|
||||
`QUEUE_PARAM_NAMES` mirror between `flomni.py` and `tomo_params.py` already has this
|
||||
@@ -399,9 +406,10 @@ Guarded against command jobs (`job.get("kind", "tomo") == "tomo"` before touchin
|
||||
## 6. Open questions for Mirko — all resolved
|
||||
|
||||
- **The final action set and device allow-list**, see `TOMO_QUEUE_COMMAND_JOBS_PLAN.md`
|
||||
§10 — `move` + `optimize_idgap` only, `_TOMO_QUEUE_MOVE_DEVICES = {mokev, idgap}`.
|
||||
One detail (`optimize_idgap`'s peak-detection signal) deferred to the
|
||||
implementation session, not blocking.
|
||||
§10 — originally `move` + `optimize_idgap`, `_TOMO_QUEUE_MOVE_DEVICES = {mokev,
|
||||
idgap}`. Superseded since: `optimize_idgap` was removed (never commissioned, stayed
|
||||
a no-op stub), `mokev` was fixed to the real device name `ccm_energy`, and a new
|
||||
`move_foptz_with_shift` action was added (see §4D10/§4D14 above for its tests).
|
||||
- **`_TOMO_QUEUE_PARAM_NAMES` renamed to `_TOMO_SCAN_PARAM_NAMES`** (it reads live
|
||||
properties, not queue state — the old name was misleading). Done in `flomni.py`;
|
||||
the `tomo_params.py` comment referencing it by name was updated too (the
|
||||
|
||||
@@ -4455,14 +4455,15 @@ class Flomni(
|
||||
# Curated allow-list for the "move" queue action -- NOT "any device in
|
||||
# dev". Only devices actually reconfigured between tomograms belong here;
|
||||
# this is the difference between a reconfiguration tool and a remote
|
||||
# control for the whole endstation. mokev/idgap are real front-end
|
||||
# devices (bl_frontend.yaml, not the flomni sim config); ftray (sample
|
||||
# transfer tray, harmless to move, untouched by tomo-scan code) is
|
||||
# included so the move action has a sim-testable target.
|
||||
# control for the whole endstation. ccm_energy/idgap are real front-end
|
||||
# devices (bl_frontend.yaml/bl_optics_hutch.yaml, not the flomni sim
|
||||
# config). foptz is deliberately NOT here -- it has its own dedicated
|
||||
# "move_foptz_with_shift" action below so the compensating
|
||||
# manual_shift_x/y correction can never be forgotten (see that action's
|
||||
# docstring).
|
||||
_TOMO_QUEUE_MOVE_DEVICES = {
|
||||
"mokev": {"label": "Energy", "unit": "keV"},
|
||||
"ccm_energy": {"label": "Energy", "unit": "keV"},
|
||||
"idgap": {"label": "Undulator gap", "unit": "mm"},
|
||||
"ftray": {"label": "Sample transfer tray (sim-testable)", "unit": "mm"},
|
||||
}
|
||||
|
||||
# Named-action registry for tomo-queue command jobs. Each entry maps a
|
||||
@@ -4484,23 +4485,83 @@ class Flomni(
|
||||
"help": "Move device(s) to absolute position(s).",
|
||||
"params": {"positions": {"type": "device_positions"}},
|
||||
},
|
||||
"optimize_idgap": {
|
||||
"func": "optimize_idgap",
|
||||
"idempotent": True,
|
||||
"help": "Scan idgap over a search range and move to the peak. STUB: no-op.",
|
||||
"move_foptz_with_shift": {
|
||||
"func": "_queue_action_move_foptz_with_shift",
|
||||
"idempotent": True, # absolute move + absolute param set, re-runs harmlessly
|
||||
"help": (
|
||||
"Move foptz (FZP optics-Z) to an absolute target and set the "
|
||||
"compensating manual_shift_x/manual_shift_y in the same step -- "
|
||||
"changing foptz shifts the aligned scan center, so this is the "
|
||||
"only way to queue a foptz move."
|
||||
),
|
||||
"params": {
|
||||
"search_range": {
|
||||
"foptz_target": {
|
||||
"type": "float",
|
||||
"default": 0.5,
|
||||
"default": 17.0,
|
||||
"min": 0.0,
|
||||
"max": 2.0,
|
||||
"max": 27.0,
|
||||
"unit": "mm",
|
||||
"label": "Search range",
|
||||
}
|
||||
"label": "foptz target (absolute)",
|
||||
# Live ophyd limits (dev.foptz.limits) are checked at add
|
||||
# time (CommandJobBuilderDialog._build_field_widget /
|
||||
# TomoQueueMixin._validate_action_kwargs) and again at
|
||||
# execution time (_queue_action_move_foptz_with_shift) --
|
||||
# min/max above are only the static fallback if the live
|
||||
# device can't be reached.
|
||||
"device_limits_from": "foptz",
|
||||
},
|
||||
"manual_shift_x": {
|
||||
"type": "float",
|
||||
"default": 0.0,
|
||||
"min": -10.0,
|
||||
"max": 10.0,
|
||||
"unit": "um",
|
||||
"label": "Compensating manual_shift_x",
|
||||
},
|
||||
"manual_shift_y": {
|
||||
"type": "float",
|
||||
"default": 0.0,
|
||||
"min": -50.0,
|
||||
"max": 50.0,
|
||||
"unit": "um",
|
||||
"label": "Compensating manual_shift_y",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def _queue_action_move_foptz_with_shift(
|
||||
self, foptz_target: float, manual_shift_x: float, manual_shift_y: float
|
||||
) -> None:
|
||||
"""Move foptz and set the compensating manual_shift_x/y together.
|
||||
|
||||
foptz changes the FZP-to-sample distance, which shifts the aligned
|
||||
scan center (interferometer mirrors aren't perfectly parallel to the
|
||||
beam) -- bundling the compensating shift into this one action is
|
||||
deliberate: foptz is NOT in _TOMO_QUEUE_MOVE_DEVICES, so this is the
|
||||
only way to queue a foptz move, precisely so the shift can't be
|
||||
forgotten.
|
||||
|
||||
FUTURE: manual_shift_x/y could be auto-suggested from a calibration
|
||||
proportional to the change in foptz, instead of typed in by hand --
|
||||
deliberately out of scope here.
|
||||
|
||||
Re-checks foptz's live limits at execution time too (not just add
|
||||
time, see TomoQueueMixin._validate_action_kwargs) -- the actual
|
||||
safety boundary, since a value could have arrived via the CLI,
|
||||
bypassing the add-time check, or the limits could have changed
|
||||
since the job was queued.
|
||||
"""
|
||||
lo, hi = dev.foptz.limits
|
||||
if not (lo <= foptz_target <= hi):
|
||||
raise ValueError(
|
||||
f"Queue move_foptz_with_shift: foptz_target={foptz_target} is "
|
||||
f"outside foptz's current limits ({lo}, {hi})."
|
||||
)
|
||||
umv(dev.foptz, foptz_target)
|
||||
self.manual_shift_x = manual_shift_x
|
||||
self.manual_shift_y = manual_shift_y
|
||||
|
||||
def _describe_tomo_job_line(self, job: dict) -> str:
|
||||
"""flomni's tomo_queue_show() one-line summary: fov/type/step/ctime/range.
|
||||
|
||||
|
||||
@@ -2191,7 +2191,16 @@ class CommandJobBuilderDialog(QDialog):
|
||||
if field_type == "float":
|
||||
w = QDoubleSpinBox()
|
||||
w.setDecimals(4)
|
||||
w.setRange(field.get("min", -1e9), field.get("max", 1e9))
|
||||
lo, hi = field.get("min", -1e9), field.get("max", 1e9)
|
||||
device_name = field.get("device_limits_from")
|
||||
if device_name is not None:
|
||||
device = self._client.device_manager.devices.get(device_name)
|
||||
if device is not None:
|
||||
try:
|
||||
lo, hi = device.limits
|
||||
except Exception:
|
||||
pass # fall back to the static schema min/max above
|
||||
w.setRange(lo, hi)
|
||||
w.setValue(field.get("default", 0.0))
|
||||
return w
|
||||
if field_type == "device_positions":
|
||||
|
||||
@@ -25,7 +25,7 @@ from csaxs_bec.bec_ipython_client.plugins.flomni import flomni as flomni_module
|
||||
from csaxs_bec.bec_ipython_client.plugins.flomni.flomni_webpage_generator import (
|
||||
FlomniWebpageGenerator,
|
||||
)
|
||||
from csaxs_bec.bec_ipython_client.plugins.omny.omny_general_tools import OMNYTools
|
||||
from csaxs_bec.bec_ipython_client.plugins.OMNY_shared.omny_general_tools import OMNYTools
|
||||
|
||||
|
||||
class _NoOpSciLogMessage:
|
||||
|
||||
@@ -65,7 +65,7 @@ def test_empty_and_all_done_queue_are_noops(flomni_sim, monkeypatch, capsys):
|
||||
flomni = flomni_sim
|
||||
|
||||
prompt_calls = []
|
||||
from csaxs_bec.bec_ipython_client.plugins.omny.omny_general_tools import OMNYTools
|
||||
from csaxs_bec.bec_ipython_client.plugins.OMNY_shared.omny_general_tools import OMNYTools
|
||||
|
||||
monkeypatch.setattr(
|
||||
OMNYTools, "yesno", lambda self, *a, **k: prompt_calls.append((a, k)) or True
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
"""Step 2 -- command jobs. See AI_docs/TOMO_QUEUE_COMMAND_JOBS_PLAN.md.
|
||||
|
||||
mokev/idgap (the real curated move targets) aren't in the flomni sim config
|
||||
(simulated_flomni.yaml) -- only on the real front end (bl_frontend.yaml), so
|
||||
the real device-moving path here is exercised against `ftray` (sample
|
||||
transfer tray), added to _TOMO_QUEUE_MOVE_DEVICES specifically for this
|
||||
sim-testability, per TOMO_QUEUE_TESTING.md.
|
||||
ccm_energy/idgap (the plain "move" allow-list) aren't in the flomni sim
|
||||
config (simulated_flomni.yaml) -- only on the real front end
|
||||
(bl_frontend.yaml/bl_optics_hutch.yaml). Tests that only exercise add-time
|
||||
validation/rendering (no tomo_queue_execute()) reference idgap for that
|
||||
reason, while tests that actually execute the queue use the dedicated
|
||||
"move_foptz_with_shift" action against foptz, which IS in the sim config
|
||||
and is the only queue-movable path for foptz (it is deliberately excluded
|
||||
from the plain "move" allow-list, see flomni.py's _TOMO_QUEUE_MOVE_DEVICES).
|
||||
"""
|
||||
|
||||
import datetime
|
||||
@@ -13,8 +16,8 @@ import uuid
|
||||
import pytest
|
||||
from _queue_helpers import FAST_STEPSIZE, add_short_job
|
||||
|
||||
FTRAY_A = -50.0
|
||||
FTRAY_B = -10.0
|
||||
FOPTZ_A = 15.0
|
||||
FOPTZ_B = 5.0
|
||||
|
||||
|
||||
def test_add_command_validation_errors(flomni_sim):
|
||||
@@ -28,12 +31,18 @@ def test_add_command_validation_errors(flomni_sim):
|
||||
|
||||
with pytest.raises(ValueError, match="above the maximum"):
|
||||
flomni.tomo_queue_add_command(
|
||||
{"action": "optimize_idgap", "kwargs": {"search_range": 99.0}}
|
||||
{
|
||||
"action": "move_foptz_with_shift",
|
||||
"kwargs": {"foptz_target": 99.0, "manual_shift_x": 0.0, "manual_shift_y": 0.0},
|
||||
}
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="must be a number"):
|
||||
flomni.tomo_queue_add_command(
|
||||
{"action": "optimize_idgap", "kwargs": {"search_range": "wide"}}
|
||||
{
|
||||
"action": "move_foptz_with_shift",
|
||||
"kwargs": {"foptz_target": "far", "manual_shift_x": 0.0, "manual_shift_y": 0.0},
|
||||
}
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="has no parameter"):
|
||||
@@ -74,23 +83,25 @@ def test_move_execution_time_allowlist_recheck(flomni_sim):
|
||||
def test_tomo_queue_actions_global_var_matches_registry(flomni_sim):
|
||||
flomni = flomni_sim
|
||||
published = flomni.client.get_global_var("tomo_queue_actions")
|
||||
assert set(published["actions"]) == {"move", "optimize_idgap"}
|
||||
assert published["move_devices"]["ftray"]["unit"] == "mm"
|
||||
assert set(published["actions"]) == {"move", "move_foptz_with_shift"}
|
||||
assert published["move_devices"]["idgap"]["unit"] == "mm"
|
||||
assert published["actions"]["move"]["idempotent"] is True
|
||||
assert published["actions"]["optimize_idgap"]["params"]["search_range"]["default"] == 0.5
|
||||
assert (
|
||||
published["actions"]["move_foptz_with_shift"]["params"]["foptz_target"]["default"] == 17.0
|
||||
)
|
||||
|
||||
|
||||
def test_show_and_webpage_survive_command_job(flomni_sim, capsys):
|
||||
flomni = flomni_sim
|
||||
flomni.tomo_queue_add_command(
|
||||
{"action": "move", "kwargs": {"positions": {"ftray": FTRAY_A}}},
|
||||
label="move ftray",
|
||||
{"action": "move", "kwargs": {"positions": {"idgap": 6.0}}},
|
||||
label="move idgap",
|
||||
idempotent=True,
|
||||
)
|
||||
capsys.readouterr()
|
||||
jobs = flomni.tomo_queue_show()
|
||||
out = capsys.readouterr().out
|
||||
assert "CMD move{'positions': {'ftray': -50.0}}" in out
|
||||
assert "CMD move{'positions': {'idgap': 6.0}}" in out
|
||||
assert "[idem]" in out
|
||||
assert jobs[0]["kind"] == "command"
|
||||
|
||||
@@ -100,7 +111,7 @@ def test_show_and_webpage_survive_command_job(flomni_sim, capsys):
|
||||
assert "isCommand" in html # the rendering branch exists; full JS isn't executed here
|
||||
|
||||
|
||||
def test_legacy_job_no_kind_defaults_to_tomo_and_command_moves_ftray(flomni_sim):
|
||||
def test_legacy_job_no_kind_defaults_to_tomo_and_command_moves_foptz(flomni_sim):
|
||||
"""B-style back-compat + the real command-job execution path, combined
|
||||
into one mixed-queue run to keep the (only) real scan in this file to
|
||||
one job.
|
||||
@@ -109,12 +120,12 @@ def test_legacy_job_no_kind_defaults_to_tomo_and_command_moves_ftray(flomni_sim)
|
||||
bec = flomni.client
|
||||
|
||||
# Start from a known position, not whatever a previous test run happened
|
||||
# to leave ftray at -- ftray's position is real device-server state that
|
||||
# to leave foptz at -- foptz's position is real device-server state that
|
||||
# persists across separate pytest invocations, unlike the tomo_queue/
|
||||
# tomo_progress global vars the flomni_sim fixture snapshots/restores.
|
||||
flomni._queue_action_move({"ftray": FTRAY_B})
|
||||
ftray_before = bec.device_manager.devices.ftray.readback.get()
|
||||
assert ftray_before == pytest.approx(FTRAY_B)
|
||||
flomni._queue_action_move_foptz_with_shift(FOPTZ_B, 0.0, 0.0)
|
||||
foptz_before = bec.device_manager.devices.foptz.readback.get()
|
||||
assert foptz_before == pytest.approx(FOPTZ_B)
|
||||
|
||||
add_short_job(flomni, "legacy_tomo", FAST_STEPSIZE)
|
||||
# Simulate a queue entry written before the "kind" field existed.
|
||||
@@ -123,41 +134,48 @@ def test_legacy_job_no_kind_defaults_to_tomo_and_command_moves_ftray(flomni_sim)
|
||||
bec.set_global_var("tomo_queue", jobs)
|
||||
|
||||
flomni.tomo_queue_add_command(
|
||||
{"action": "move", "kwargs": {"positions": {"ftray": FTRAY_A}}}, label="move ftray"
|
||||
)
|
||||
flomni.tomo_queue_add_command(
|
||||
{"action": "optimize_idgap", "kwargs": {"search_range": 0.5}}, label="idgap stub"
|
||||
{
|
||||
"action": "move_foptz_with_shift",
|
||||
"kwargs": {"foptz_target": FOPTZ_A, "manual_shift_x": 1.0, "manual_shift_y": -2.0},
|
||||
},
|
||||
label="move foptz",
|
||||
)
|
||||
|
||||
flomni.tomo_queue_execute()
|
||||
|
||||
jobs = flomni._tomo_queue_proxy.as_list()
|
||||
assert [j["status"] for j in jobs] == ["done", "done", "done"]
|
||||
assert [j["status"] for j in jobs] == ["done", "done"]
|
||||
# Still no "kind" key -- proves it ran (and got marked done) via the
|
||||
# back-compat default, not that execute() silently added one.
|
||||
assert "kind" not in jobs[0]
|
||||
assert "params" in jobs[0]
|
||||
assert jobs[1]["kind"] == "command"
|
||||
|
||||
ftray_after = bec.device_manager.devices.ftray.readback.get()
|
||||
assert ftray_after == pytest.approx(FTRAY_A)
|
||||
assert ftray_after != pytest.approx(ftray_before)
|
||||
foptz_after = bec.device_manager.devices.foptz.readback.get()
|
||||
assert foptz_after == pytest.approx(FOPTZ_A)
|
||||
assert foptz_after != pytest.approx(foptz_before)
|
||||
assert flomni.manual_shift_x == pytest.approx(1.0)
|
||||
assert flomni.manual_shift_y == pytest.approx(-2.0)
|
||||
|
||||
|
||||
def test_non_idempotent_command_resume_prompts(flomni_sim, monkeypatch):
|
||||
flomni = flomni_sim
|
||||
bec = flomni.client
|
||||
ftray = bec.device_manager.devices.ftray
|
||||
foptz = bec.device_manager.devices.foptz
|
||||
|
||||
# Use the same real move path the "move" action itself uses, rather than
|
||||
# the device's underlying ophyd object directly (ftray's BEC wrapper is
|
||||
# a Positioner here, unlike fsamx's DeviceBase -- no .obj to reach for).
|
||||
flomni._queue_action_move({"ftray": FTRAY_B})
|
||||
start = ftray.readback.get()
|
||||
assert start == pytest.approx(FTRAY_B)
|
||||
# Use the same real move path the "move_foptz_with_shift" action itself
|
||||
# uses, rather than the device's underlying ophyd object directly
|
||||
# (foptz's BEC wrapper is a Positioner here, unlike fsamx's DeviceBase --
|
||||
# no .obj to reach for).
|
||||
flomni._queue_action_move_foptz_with_shift(FOPTZ_B, 0.0, 0.0)
|
||||
start = foptz.readback.get()
|
||||
assert start == pytest.approx(FOPTZ_B)
|
||||
|
||||
index = flomni.tomo_queue_add_command(
|
||||
{"action": "move", "kwargs": {"positions": {"ftray": FTRAY_A}}},
|
||||
{
|
||||
"action": "move_foptz_with_shift",
|
||||
"kwargs": {"foptz_target": FOPTZ_A, "manual_shift_x": 0.0, "manual_shift_y": 0.0},
|
||||
},
|
||||
label="non-idempotent move",
|
||||
idempotent=False,
|
||||
)
|
||||
@@ -165,7 +183,7 @@ def test_non_idempotent_command_resume_prompts(flomni_sim, monkeypatch):
|
||||
flomni._tomo_queue_proxy.update_by_id(job_id, status="incomplete")
|
||||
|
||||
prompts = []
|
||||
from csaxs_bec.bec_ipython_client.plugins.omny.omny_general_tools import OMNYTools
|
||||
from csaxs_bec.bec_ipython_client.plugins.OMNY_shared.omny_general_tools import OMNYTools
|
||||
|
||||
def _yesno(resume_answer):
|
||||
# tomo_queue_execute()'s own top-level "OK to start?" confirmation
|
||||
@@ -180,11 +198,11 @@ def test_non_idempotent_command_resume_prompts(flomni_sim, monkeypatch):
|
||||
|
||||
return _fn
|
||||
|
||||
# "no" -> must not re-run: ftray stays put, job still ends up "done".
|
||||
# "no" -> must not re-run: foptz stays put, job still ends up "done".
|
||||
monkeypatch.setattr(OMNYTools, "yesno", _yesno(False))
|
||||
flomni.tomo_queue_execute()
|
||||
assert len(prompts) == 1
|
||||
assert ftray.readback.get() == pytest.approx(start)
|
||||
assert foptz.readback.get() == pytest.approx(start)
|
||||
assert flomni._tomo_queue_proxy.as_list()[0]["status"] == "done"
|
||||
|
||||
# Re-arm as incomplete and try again with "yes" -> must re-run.
|
||||
@@ -192,5 +210,5 @@ def test_non_idempotent_command_resume_prompts(flomni_sim, monkeypatch):
|
||||
monkeypatch.setattr(OMNYTools, "yesno", _yesno(True))
|
||||
flomni.tomo_queue_execute()
|
||||
assert len(prompts) == 2
|
||||
assert ftray.readback.get() == pytest.approx(FTRAY_A)
|
||||
assert foptz.readback.get() == pytest.approx(FOPTZ_A)
|
||||
assert flomni._tomo_queue_proxy.as_list()[0]["status"] == "done"
|
||||
Reference in new issue
Block a user