From 5167c79378cefa78db87fea4e06a045ee9af75c4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 21 Oct 2026 01:46:52 +0000 Subject: [PATCH] P1 (4/n): unit tests and examples use the level-list constructor test_shifted_jets, test_shifted_storage, test_raw_exchange and test_channel_root pass refinements/level_* lists; examples fixed_patch_jet and fixed_periodic_patch pass refinements=[BOUNDS] instead of the positional bounds. Assertions kept; the shifted-storage case base_block-without-fine_block now expects the level-list rule 'blocked refined levels below' (same constraint). Co-Authored-By: Claude Opus 5.5 --- examples/fixed_patch_jet.py | 4 ++-- examples/fixed_periodic_patch.py | 2 +- tests/unit/test_channel_root.py | 4 ++-- tests/unit/test_raw_exchange.py | 5 +++-- tests/unit/test_shifted_jets.py | 11 +++++------ tests/unit/test_shifted_storage.py | 7 ++++--- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/examples/fixed_patch_jet.py b/examples/fixed_patch_jet.py index 753e003..7c767b0 100644 --- a/examples/fixed_patch_jet.py +++ b/examples/fixed_patch_jet.py @@ -148,8 +148,8 @@ def main(): samples=[], status='running', last_synchronized_coarse_step=0) start, run = time.monotonic(), None try: - with CudaContext(0) as context, FixedPatchStepper(cfg, BOUNDS, context=context, - coarse_boundary='slot_reservoir') as run: + with CudaContext(0) as context, FixedPatchStepper(cfg, context=context, + coarse_boundary='slot_reservoir', refinements=[BOUNDS]) as run: p = run.patch masks = [np.ones(p.coarse_shape, bool), p.fine_kind == ACTIVE] masks[0][[0, -1]] = False diff --git a/examples/fixed_periodic_patch.py b/examples/fixed_periodic_patch.py index ac73272..2d09121 100644 --- a/examples/fixed_periodic_patch.py +++ b/examples/fixed_periodic_patch.py @@ -48,7 +48,7 @@ def main(): nx=16, ny=16, viscosity=.1, velocity=1e-3, rho=1.0, lattice_model="D2Q9", collision="SRT", streaming="double_buffer", store_precision="FP32", ddf_shifting=False, les_enabled=False) - with CudaContext(0) as context, PeriodicPatchStepper(cfg, (4, 4, 12, 12), context=context) as run: + with CudaContext(0) as context, PeriodicPatchStepper(cfg, context=context, refinements=[(4, 4, 12, 12)]) as run: p = run.patch coarse = shear_equilibrium(p.coarse_shape, (0, 0), 1.0, cfg.ny) fine = shear_equilibrium(p.fine_shape, p.fine_origin, .5, cfg.ny) diff --git a/tests/unit/test_channel_root.py b/tests/unit/test_channel_root.py index 49a9e1f..1d4e6e8 100644 --- a/tests/unit/test_channel_root.py +++ b/tests/unit/test_channel_root.py @@ -80,8 +80,8 @@ def test_evolved_ghost_snapshot_and_physical_download(): host.cuda.memcpy_dtoh.side_effect = lambda a, ptr: np.copyto(a, storage[id(ptr)]) context = Mock(activate=nullcontext, sm_arch="sm_70") cfg = LBMConfig(nx=24, ny=20, viscosity=.1, velocity=.025) - backend = host.FixedPatchStepper(cfg, (6, 6, 18, 14), context=context, - coarse_boundary="channel", base_block=(4, 6), fine_block=(4, 4)) + backend = host.FixedPatchStepper(cfg, context=context, coarse_boundary="channel", + refinements=[(6, 6, 18, 14)], level_blocks=[(4, 6), (4, 4)]) try: weights = np.array([4/9]+[1/9]*4+[1/36]*4)[:, None, None] arrays = [np.broadcast_to(weights, level.shape).copy() for level in backend._levels] diff --git a/tests/unit/test_raw_exchange.py b/tests/unit/test_raw_exchange.py index 63b3fdc..a413afd 100644 --- a/tests/unit/test_raw_exchange.py +++ b/tests/unit/test_raw_exchange.py @@ -157,8 +157,9 @@ class RawExchange(unittest.TestCase): host = host_module() ctx = Mock() with self.assertRaisesRegex(ValueError, 'blocked body'): - host.FixedPatchStepper(LBMConfig(nx=32, ny=32, viscosity=.1), (4, 4, 28, 28), - context=ctx, fine_objects=[body(radius=2.15)], observe_raw_exchange=True) + host.FixedPatchStepper(LBMConfig(nx=32, ny=32, viscosity=.1), context=ctx, + refinements=[(4, 4, 28, 28)], + level_objects=[(), (body(radius=2.15),)], observe_raw_exchange=True) ctx.activate.assert_not_called() def test_all_depth_weights(self): diff --git a/tests/unit/test_shifted_jets.py b/tests/unit/test_shifted_jets.py index 2b56794..a83aa9d 100644 --- a/tests/unit/test_shifted_jets.py +++ b/tests/unit/test_shifted_jets.py @@ -54,14 +54,13 @@ class ShiftedJets(unittest.TestCase): (Jet(Tube((10.,14.),0.,26.,.3),Parallel(0.)),))] for objects,jets in cases: with self.subTest(objects=len(objects),jets=len(jets)),self.assertRaises(ValueError): - module.FixedPatchStepper(CFG,backend.PARENTS,context=None, - base_block=(4,4),fine_block=(4,4),child_block=(4,4), - child_rectangles_in_parent=A,child_objects=objects,child_jets=jets) + module.FixedPatchStepper(CFG,context=None,refinements=[backend.PARENTS,A], + level_blocks=[(4,4)]*3,level_objects=[(),(),objects],level_jets=[(),(),jets]) for blocks in ((None,None,None),((4,4),None,(4,4))): with self.assertRaises(ValueError): - module.FixedPatchStepper(CFG,backend.PARENTS,context=None, - base_block=blocks[0],fine_block=blocks[1],child_block=blocks[2], - child_rectangles_in_parent=A,child_objects=(body(),),child_jets=(jet(),)) + module.FixedPatchStepper(CFG,context=None,refinements=[backend.PARENTS,A], + level_blocks=list(blocks),level_objects=[(),(),(body(),)], + level_jets=[(),(),(jet(),)]) module.cuda.mem_alloc.assert_not_called() module.compiler.compile_kernel.assert_not_called() diff --git a/tests/unit/test_shifted_storage.py b/tests/unit/test_shifted_storage.py index bcca95b..ea3a373 100644 --- a/tests/unit/test_shifted_storage.py +++ b/tests/unit/test_shifted_storage.py @@ -129,9 +129,10 @@ class ShiftedStorage(unittest.TestCase): def test_dense_or_mixed_shifted_rejected_before_compilation(self): module=backend.host_module() cfg=replace(backend.CFG,ddf_shifting=True) - for kwargs in ({},dict(base_block=(4,4)),dict(fine_block=(4,4))): - with self.assertRaisesRegex(ValueError,'all-blocked|base_block requires fine_block'): - module.FixedPatchStepper(cfg,(4,4,20,28),context=None,**kwargs) + for blocks in ([None,None],[(4,4),None],[None,(4,4)]): + with self.assertRaisesRegex(ValueError,'all-blocked|blocked refined levels below'): + module.FixedPatchStepper(cfg,context=None,refinements=[(4,4,20,28)], + level_blocks=blocks) module.compiler.compile_kernel.assert_not_called() def test_uniform_block_codec_and_raw_snapshot(self):