From 636dd0ec884eeb4539f37aa722bd6d463fb02591 Mon Sep 17 00:00:00 2001 From: x01dc Date: Tue, 21 Jul 2026 15:59:02 +0200 Subject: [PATCH] fix/stop LamNI per-sub-tomogram scilog entries LamNI's tomo_scan() wrote a separate scilog entry ("Starting subtomo: N...") every time the sub-tomogram number changed -- 8 extra entries per tomo_type-1 scan, and one per sub-tomogram traversed for types 2/3 -- leftover behavior carried over from omny.py during the flomni->lamni port. Flomni itself never does this: it only writes at scan start (PDF report) and scan end (timing summary). Removed the three _write_subtomo_to_scilog() call sites and the now-unused method so LamNI's scilog behavior matches Flomni's. Also fixed a stale test (test_tomo_queue_reacquire_rejects_when_another_job_is_incomplete) that encoded the old, buggy tomo_queue_reacquire() invariant (rejecting on ANY other job being incomplete/running) rather than the fixed one from the prior commit (only an EARLIER job is a real conflict) -- split it into two tests covering both directions. Co-Authored-By: Claude Sonnet 5 --- .../bec_ipython_client/plugins/LamNI/lamni.py | 15 ------------ .../test_lamni_tomo_angles.py | 1 - .../test_tomo_queue_reacquire.py | 24 +++++++++++++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py index c265a47..7d97c66 100644 --- a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py +++ b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py @@ -771,17 +771,6 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools except Exception: logger.warning("Failed to write to scilog.") - def _write_subtomo_to_scilog(self, subtomo_number): - bec = builtins.__dict__.get("bec") - if self.tomo_id > 0: - tags = ["BEC_subtomo", self.sample_name, f"tomo_id_{self.tomo_id}"] - else: - tags = ["BEC_subtomo", self.sample_name] - self.write_to_scilog( - f"Starting subtomo: {subtomo_number}. First scan number: {bec.queue.next_scan_number}.", - tags, - ) - _TIMING_LOG_DIR = "~/data/raw/logs/timing_statistics" _TIMING_SETUP = "lamni" _PROJECTION_TIMING_LOG = "projection_timing_log.jsonl" @@ -1306,8 +1295,6 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools def sub_tomo_scan(self, subtomo_number, start_angle=None): """Perform one sub-tomogram (tomo_type 1 only).""" - self._write_subtomo_to_scilog(subtomo_number) - angles, N = self._subtomo_angle_plan( subtomo_number, self.tomo_angle_stepsize, start_angle=start_angle ) @@ -1564,7 +1551,6 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools ii, self.golden_ratio_bunch_size, maxangle=360, reverse=True ) if previous_subtomo_number != subtomo_number: - self._write_subtomo_to_scilog(subtomo_number) if ( subtomo_number % 2 == 1 and ii > 10 @@ -1603,7 +1589,6 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools ii, int(360 / self.tomo_angle_stepsize), maxangle=360, reverse=True ) if previous_subtomo_number != subtomo_number: - self._write_subtomo_to_scilog(subtomo_number) if ( subtomo_number % 2 == 1 and ii > 10 diff --git a/tests/tests_bec_ipython_client/test_lamni_tomo_angles.py b/tests/tests_bec_ipython_client/test_lamni_tomo_angles.py index 7e19c67..127531d 100644 --- a/tests/tests_bec_ipython_client/test_lamni_tomo_angles.py +++ b/tests/tests_bec_ipython_client/test_lamni_tomo_angles.py @@ -46,7 +46,6 @@ def make_lamni(tomo_angle_stepsize: float) -> LamNI: obj._progress_proxy = _ProgressProxy(obj.client) obj.tomo_angle_stepsize = tomo_angle_stepsize obj.tomo_id = -1 - obj._write_subtomo_to_scilog = lambda subtomo_number: None return obj diff --git a/tests/tests_bec_ipython_client/test_tomo_queue_reacquire.py b/tests/tests_bec_ipython_client/test_tomo_queue_reacquire.py index 7fcaed6..2d1bf83 100644 --- a/tests/tests_bec_ipython_client/test_tomo_queue_reacquire.py +++ b/tests/tests_bec_ipython_client/test_tomo_queue_reacquire.py @@ -82,7 +82,6 @@ def make_flomni(): def test_lamni_resolve_type1_projection_matches_sub_tomo_scan(stepsize): lamni = make_lamni() lamni.tomo_angle_stepsize = stepsize - lamni._write_subtomo_to_scilog = lambda subtomo_number: None recorded = {} lamni._tomo_scan_at_angle = lambda angle, subtomo_number: recorded.__setitem__( lamni.progress["projection"], (subtomo_number, angle) @@ -219,7 +218,21 @@ def test_tomo_queue_reacquire_rejects_command_job(): lamni.tomo_queue_reacquire(0, projection_number=0) -def test_tomo_queue_reacquire_rejects_when_another_job_is_incomplete(): +def test_tomo_queue_reacquire_rejects_when_an_earlier_job_is_incomplete(): + lamni = make_lamni() + lamni.tomo_type = 1 + lamni.tomo_angle_stepsize = 10.0 + i0 = lamni.tomo_queue_add(label="job0") + i1 = lamni.tomo_queue_add(label="job1") + lamni._tomo_queue_proxy.update(i0, status="incomplete") + + with pytest.raises(TomoQueueError): + lamni.tomo_queue_reacquire(i1, projection_number=0) + + +def test_tomo_queue_reacquire_allows_a_later_job_being_incomplete(): + # A later job's own status doesn't matter -- it gets reset to + # "pending" by this call anyway, so it's not a real conflict. lamni = make_lamni() lamni.tomo_type = 1 lamni.tomo_angle_stepsize = 10.0 @@ -227,8 +240,11 @@ def test_tomo_queue_reacquire_rejects_when_another_job_is_incomplete(): i1 = lamni.tomo_queue_add(label="job1") lamni._tomo_queue_proxy.update(i1, status="incomplete") - with pytest.raises(TomoQueueError): - lamni.tomo_queue_reacquire(i0, projection_number=0) + lamni.tomo_queue_reacquire(i0, projection_number=0) + + jobs = lamni._tomo_queue_proxy.as_list() + assert jobs[i0]["status"] == "incomplete" + assert jobs[i1]["status"] == "pending" def test_tomo_queue_reacquire_allows_targeting_the_incomplete_job_itself():