P1 (7/n): MRT, shifted-jet and blocked-base GPU tests migrated
test_refinement_mrt_gpu, test_shifted_jets_gpu and test_refinement_blocked_base pass refinements/level_* lists. The three blocked-base rejection cases keep their inputs per level; base-only blocks now meet the level-list rule (blocked refined levels below) where the legacy keyword check fired before. Assertions unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
af0566db98
commit
0fcd4ac4cb
@@ -83,11 +83,10 @@ def mocked_backend(mode="periodic", fail_alloc=None):
|
||||
class BlockedBaseCPU(unittest.TestCase):
|
||||
def test_reject_before_cuda(self):
|
||||
context = Mock(activate=Mock(side_effect=AssertionError("CUDA reached")))
|
||||
for kwargs in ({"base_block": (12, 8)},
|
||||
{"base_block": (7, 8), "fine_block": FINE_BLOCK},
|
||||
{"base_block": (12,), "fine_block": FINE_BLOCK}):
|
||||
with self.subTest(kwargs=kwargs), self.assertRaises(ValueError):
|
||||
FixedPatchStepper(config("periodic"), BOUNDS, context=context, **kwargs)
|
||||
for blocks in ([(12, 8), None], [(7, 8), FINE_BLOCK], [(12,), FINE_BLOCK]):
|
||||
with self.subTest(blocks=blocks), self.assertRaises(ValueError):
|
||||
FixedPatchStepper(config("periodic"), context=context, refinements=[BOUNDS],
|
||||
level_blocks=blocks)
|
||||
context.activate.assert_not_called()
|
||||
|
||||
def test_all_arrival_rows_donors_and_kind_masks(self):
|
||||
@@ -193,9 +192,10 @@ class BlockedBaseCPU(unittest.TestCase):
|
||||
|
||||
def test_launch_order_stream_wall_constants_and_buffer_swaps(self):
|
||||
with mocked_backend("slot_reservoir") as m:
|
||||
backend = FixedPatchStepper(config("slot_reservoir"), BOUNDS, context=m["context"],
|
||||
coarse_boundary="slot_reservoir", fine_block=FINE_BLOCK,
|
||||
base_block=(3, 4), fine_objects=[circle(actuation(.002))])
|
||||
backend = FixedPatchStepper(config("slot_reservoir"), context=m["context"],
|
||||
coarse_boundary="slot_reservoir", refinements=[BOUNDS],
|
||||
level_blocks=[(3, 4), FINE_BLOCK],
|
||||
level_objects=[(), (circle(actuation(.002)),)])
|
||||
try:
|
||||
backend.initialize(state(NY, NX, 1), state(*backend.patch.fine_shape, 2))
|
||||
coarse, fine = backend._levels
|
||||
@@ -236,16 +236,16 @@ class BlockedBaseCPU(unittest.TestCase):
|
||||
for fail_at in (1, 6, 10):
|
||||
with self.subTest(fail_at=fail_at), mocked_backend(fail_alloc=fail_at) as m:
|
||||
with self.assertRaisesRegex(MemoryError, "injected allocation"):
|
||||
FixedPatchStepper(config("periodic"), BOUNDS, context=m["context"],
|
||||
fine_block=FINE_BLOCK, base_block=(3, 4))
|
||||
FixedPatchStepper(config("periodic"), context=m["context"], refinements=[BOUNDS],
|
||||
level_blocks=[(3, 4), FINE_BLOCK])
|
||||
self.assertEqual(len(m["allocations"]), fail_at)
|
||||
for allocation in m["allocations"]:
|
||||
allocation.free.assert_called_once_with()
|
||||
|
||||
def test_failed_parent_stage_cannot_publish_or_resume(self):
|
||||
with mocked_backend() as m:
|
||||
backend = FixedPatchStepper(config("periodic"), BOUNDS, context=m["context"],
|
||||
fine_block=FINE_BLOCK, base_block=(3, 4))
|
||||
backend = FixedPatchStepper(config("periodic"), context=m["context"], refinements=[BOUNDS],
|
||||
level_blocks=[(3, 4), FINE_BLOCK])
|
||||
backend.initialize(state(NY, NX, 1), state(*backend.patch.fine_shape, 2))
|
||||
m["functions"]["BlockCoalesce"].side_effect = RuntimeError("injected parent stage failure")
|
||||
current = backend._levels[0].current
|
||||
@@ -289,9 +289,10 @@ class BlockedBaseGPU(unittest.TestCase):
|
||||
for base_block in (None, *layouts):
|
||||
label = f"{mode} width={width} speed={speed} base={base_block}"
|
||||
snapshots = []
|
||||
with FixedPatchStepper(cfg, BOUNDS, context=context, coarse_boundary=mode,
|
||||
fine_block=FINE_BLOCK, base_block=base_block,
|
||||
fine_objects=() if speed is None else [circle(actuation(speed))]) as backend:
|
||||
with FixedPatchStepper(cfg, context=context, coarse_boundary=mode,
|
||||
refinements=[BOUNDS], level_blocks=[base_block, FINE_BLOCK],
|
||||
level_objects=[(), () if speed is None
|
||||
else (circle(actuation(speed)),)]) as backend:
|
||||
backend.initialize(*arrays)
|
||||
for step in (0, 1, 2, 8):
|
||||
if step == 1 and base_block is not None:
|
||||
|
||||
@@ -42,8 +42,9 @@ class RefinementMRTGPU(unittest.TestCase):
|
||||
collision="MRT", ddf_shifting=shifted)
|
||||
reference = None
|
||||
for block in ((32, 48), (8, 8), (4, 1)):
|
||||
with FixedPatchStepper(cfg, (8, 6, 40, 26), context=context, coarse_boundary=boundary,
|
||||
base_block=block, fine_block=(8, 8), fine_objects=(body,)) as backend:
|
||||
with FixedPatchStepper(cfg, context=context, coarse_boundary=boundary,
|
||||
refinements=[(8, 6, 40, 26)], level_blocks=[block, (8, 8)],
|
||||
level_objects=[(), (body,)]) as backend:
|
||||
backend.initialize(*[state(*level.shape[1:]) for level in backend._levels])
|
||||
backend.step(8)
|
||||
raw = backend._download_raw()
|
||||
@@ -63,8 +64,8 @@ class RefinementMRTGPU(unittest.TestCase):
|
||||
results = {}
|
||||
layouts = ((None, None), *((base, FINE_BLOCK) for base in (None, *BASE_BLOCKS)))
|
||||
for base_block, fine_block in layouts:
|
||||
with FixedPatchStepper(cfg, BOUNDS, context=context, fine_block=fine_block,
|
||||
base_block=base_block) as backend:
|
||||
with FixedPatchStepper(cfg, context=context, refinements=[BOUNDS],
|
||||
level_blocks=[base_block, fine_block]) as backend:
|
||||
backend.initialize(*[fixture.state(*level.shape[1:], seed) for seed, level in enumerate(backend._levels)])
|
||||
backend.step(4)
|
||||
results[base_block, fine_block] = raw(backend)
|
||||
@@ -75,9 +76,9 @@ class RefinementMRTGPU(unittest.TestCase):
|
||||
def test_shifted_all_blocked_three_level_mrt_smoke(self):
|
||||
"""Per-level shear rate omega_l = 1/(3*2**l*nu + 1/2); finite ACTIVE leaves."""
|
||||
cfg = LBMConfig(nx=16, ny=16, viscosity=.1, collision="MRT", ddf_shifting=True)
|
||||
kw = dict(fine_block=(4, 4), base_block=(4, 4), child=(8, 8, 16, 16), child_block=(4, 4))
|
||||
kw = dict(refinements=[(4, 4, 12, 12), (8, 8, 16, 16)], level_blocks=[(4, 4)] * 3)
|
||||
with CudaContext(0) as context:
|
||||
with FixedPatchStepper(cfg, (4, 4, 12, 12), context=context, **kw) as backend:
|
||||
with FixedPatchStepper(cfg, context=context, **kw) as backend:
|
||||
self.assertEqual(len(backend._level_cfgs), 3)
|
||||
for level, level_cfg in enumerate(backend._level_cfgs):
|
||||
checked = replace(level_cfg)
|
||||
|
||||
@@ -136,8 +136,8 @@ class ShiftedJetsGPU(unittest.TestCase):
|
||||
Parallel(0.),amplitude=.013)
|
||||
for rho in (.99,1.01):
|
||||
with self.subTest(rho=rho),CudaContext(0) as ctx:
|
||||
with FixedPatchStepper(cfg,(8,6,24,18),context=ctx,base_block=(4,4),fine_block=(4,4),
|
||||
fine_objects=(obj,),jets=(whole,),observe_raw_exchange=True) as run:
|
||||
with FixedPatchStepper(cfg,context=ctx,refinements=[(8,6,24,18)],level_blocks=[(4,4)]*2,
|
||||
level_objects=[(),(obj,)],level_jets=[(),(whole,)],observe_raw_exchange=True) as run:
|
||||
run._initialize_raw(initial(run,rho,u=.013,v=0.))
|
||||
expected=run._download_raw();ledger=Ledger(self,run,1)
|
||||
self.assertTrue(run._level_boundaries[1].tables['aperture'].all())
|
||||
@@ -153,7 +153,8 @@ class ShiftedJetsGPU(unittest.TestCase):
|
||||
obj=circle((16.,12.),2.15);j=drive((16.,12.),2.15)
|
||||
for rho in (.99,1.01):
|
||||
with self.subTest(rho=rho),CudaContext(0) as ctx,ExitStack() as owned:
|
||||
settings=dict(bounds=(8,6,24,18),context=ctx,base_block=(4,4),fine_block=(4,4),fine_objects=(obj,),jets=(j,))
|
||||
settings=dict(context=ctx,refinements=[(8,6,24,18)],level_blocks=[(4,4)]*2,
|
||||
level_objects=[(),(obj,)],level_jets=[(),(j,)])
|
||||
measured=owned.enter_context(FixedPatchStepper(cfg,observe_raw_exchange=True,**settings))
|
||||
plain=owned.enter_context(FixedPatchStepper(cfg,**settings))
|
||||
measured._initialize_raw(initial(measured,rho));plain._initialize_raw(initial(plain,rho))
|
||||
@@ -186,8 +187,9 @@ class ShiftedJetsGPU(unittest.TestCase):
|
||||
parents=((4,4,20,28),(24,4,44,28));a=((16,16,32,40),(56,16,72,40));b=(a[0],(60,16,76,40))
|
||||
obj=circle((12.,14.),.8);j=drive((12.,14.),.8)
|
||||
with CudaContext(0) as ctx,ExitStack() as owned:
|
||||
old=owned.enter_context(FixedPatchStepper(cfg,parents,context=ctx,base_block=(4,4),fine_block=(4,4),
|
||||
child_block=(4,4),child_rectangles_in_parent=a,child_objects=(obj,),child_jets=(j,),observe_raw_exchange=True))
|
||||
old=owned.enter_context(FixedPatchStepper(cfg,context=ctx,refinements=[parents,a],
|
||||
level_blocks=[(4,4)]*3,level_objects=[(),(),(obj,)],level_jets=[(),(),(j,)],
|
||||
observe_raw_exchange=True))
|
||||
old._initialize_raw(initial(old,.99));ledger=Ledger(self,old,2)
|
||||
for speed in (.002,-.001):old.set_jet_amplitude(0,speed,level=2);ledger.step()
|
||||
before=old._download_raw();count=old.step_count
|
||||
|
||||
Reference in New Issue
Block a user