From aafa05a359d19d29ede7dee177f6803f59516959 Mon Sep 17 00:00:00 2001 From: Frank14f <1515444314@qq.com> Date: Tue, 3 Nov 2026 01:18:56 +0800 Subject: [PATCH] Check observed collection clocks before labeling fields --- research/fig2_collection/run.py | 6 ++++++ tests/unit/test_fig2_collection.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/research/fig2_collection/run.py b/research/fig2_collection/run.py index f432bca..25b3a68 100644 --- a/research/fig2_collection/run.py +++ b/research/fig2_collection/run.py @@ -153,6 +153,11 @@ def check_structure(y, v, previous_y): raise RuntimeError('nonfinite structure, travel > D or speed > .025; no retuning') +def check_clock(stepper, release_clock, completed): + if stepper.step_count != release_clock+completed: + raise RuntimeError('observed solver clock differs from recorded response clock') + + def clean_field(fields, flags): """Canonical modern bit-0 fluid mask; hard-fail before nonfluid zero fill.""" ux, uy = np.asarray(fields['ux']), np.asarray(fields['uy']) @@ -365,6 +370,7 @@ def run_role(scene, role, plan, cfgpath, base, helpers, metrics, seed, initial_f force = float(cme.sum(dtype=np.float64)+wen.sum(dtype=np.float64)) sensor_sum += sensors force_sum += packed + check_clock(sim.stepper, plan['release_clock'], completed) sensors, packed = sensor_sum/plan['si'], force_sum/plan['si'] raw = np.r_[sensors*156., packed*2.].astype(np.float32) if norm is not None: diff --git a/tests/unit/test_fig2_collection.py b/tests/unit/test_fig2_collection.py index 9f1036f..b81a577 100644 --- a/tests/unit/test_fig2_collection.py +++ b/tests/unit/test_fig2_collection.py @@ -182,6 +182,11 @@ class CollectionContracts(unittest.TestCase): class SelectionContracts(unittest.TestCase): + def test_recorded_clock_must_equal_observed_solver(self): + driver.check_clock(types.SimpleNamespace(step_count=4579200),4576000,3200) + with self.assertRaisesRegex(RuntimeError,'observed solver clock'): + driver.check_clock(types.SimpleNamespace(step_count=4579201),4576000,3200) + @staticmethod def mean(ux, uy, indices): return dict(mean_ux=ux[indices].mean(axis=0), mean_uy=uy[indices].mean(axis=0))