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:
1 parent
af0566db98
commit
0fcd4ac4cb
3 files changed
+30
-26
No files matched your search
@@ -83,11 +83,10 @@ def mocked_backend(mode="periodic", fail_alloc=None):
|
|||||||
class BlockedBaseCPU(unittest.TestCase):
|
class BlockedBaseCPU(unittest.TestCase):
|
||||||
def test_reject_before_cuda(self):
|
def test_reject_before_cuda(self):
|
||||||
context = Mock(activate=Mock(side_effect=AssertionError("CUDA reached")))
|
context = Mock(activate=Mock(side_effect=AssertionError("CUDA reached")))
|
||||||
for kwargs in ({"base_block": (12, 8)},
|
for blocks in ([(12, 8), None], [(7, 8), FINE_BLOCK], [(12,), FINE_BLOCK]):
|
||||||
{"base_block": (7, 8), "fine_block": FINE_BLOCK},
|
with self.subTest(blocks=blocks), self.assertRaises(ValueError):
|
||||||
{"base_block": (12,), "fine_block": FINE_BLOCK}):
|
FixedPatchStepper(config("periodic"), context=context, refinements=[BOUNDS],
|
||||||
with self.subTest(kwargs=kwargs), self.assertRaises(ValueError):
|
level_blocks=blocks)
|
||||||
FixedPatchStepper(config("periodic"), BOUNDS, context=context, **kwargs)
|
|
||||||
context.activate.assert_not_called()
|
context.activate.assert_not_called()
|
||||||
|
|
||||||
def test_all_arrival_rows_donors_and_kind_masks(self):
|
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):
|
def test_launch_order_stream_wall_constants_and_buffer_swaps(self):
|
||||||
with mocked_backend("slot_reservoir") as m:
|
with mocked_backend("slot_reservoir") as m:
|
||||||
backend = FixedPatchStepper(config("slot_reservoir"), BOUNDS, context=m["context"],
|
backend = FixedPatchStepper(config("slot_reservoir"), context=m["context"],
|
||||||
coarse_boundary="slot_reservoir", fine_block=FINE_BLOCK,
|
coarse_boundary="slot_reservoir", refinements=[BOUNDS],
|
||||||
base_block=(3, 4), fine_objects=[circle(actuation(.002))])
|
level_blocks=[(3, 4), FINE_BLOCK],
|
||||||
|
level_objects=[(), (circle(actuation(.002)),)])
|
||||||
try:
|
try:
|
||||||
backend.initialize(state(NY, NX, 1), state(*backend.patch.fine_shape, 2))
|
backend.initialize(state(NY, NX, 1), state(*backend.patch.fine_shape, 2))
|
||||||
coarse, fine = backend._levels
|
coarse, fine = backend._levels
|
||||||
@@ -236,16 +236,16 @@ class BlockedBaseCPU(unittest.TestCase):
|
|||||||
for fail_at in (1, 6, 10):
|
for fail_at in (1, 6, 10):
|
||||||
with self.subTest(fail_at=fail_at), mocked_backend(fail_alloc=fail_at) as m:
|
with self.subTest(fail_at=fail_at), mocked_backend(fail_alloc=fail_at) as m:
|
||||||
with self.assertRaisesRegex(MemoryError, "injected allocation"):
|
with self.assertRaisesRegex(MemoryError, "injected allocation"):
|
||||||
FixedPatchStepper(config("periodic"), BOUNDS, context=m["context"],
|
FixedPatchStepper(config("periodic"), context=m["context"], refinements=[BOUNDS],
|
||||||
fine_block=FINE_BLOCK, base_block=(3, 4))
|
level_blocks=[(3, 4), FINE_BLOCK])
|
||||||
self.assertEqual(len(m["allocations"]), fail_at)
|
self.assertEqual(len(m["allocations"]), fail_at)
|
||||||
for allocation in m["allocations"]:
|
for allocation in m["allocations"]:
|
||||||
allocation.free.assert_called_once_with()
|
allocation.free.assert_called_once_with()
|
||||||
|
|
||||||
def test_failed_parent_stage_cannot_publish_or_resume(self):
|
def test_failed_parent_stage_cannot_publish_or_resume(self):
|
||||||
with mocked_backend() as m:
|
with mocked_backend() as m:
|
||||||
backend = FixedPatchStepper(config("periodic"), BOUNDS, context=m["context"],
|
backend = FixedPatchStepper(config("periodic"), context=m["context"], refinements=[BOUNDS],
|
||||||
fine_block=FINE_BLOCK, base_block=(3, 4))
|
level_blocks=[(3, 4), FINE_BLOCK])
|
||||||
backend.initialize(state(NY, NX, 1), state(*backend.patch.fine_shape, 2))
|
backend.initialize(state(NY, NX, 1), state(*backend.patch.fine_shape, 2))
|
||||||
m["functions"]["BlockCoalesce"].side_effect = RuntimeError("injected parent stage failure")
|
m["functions"]["BlockCoalesce"].side_effect = RuntimeError("injected parent stage failure")
|
||||||
current = backend._levels[0].current
|
current = backend._levels[0].current
|
||||||
@@ -289,9 +289,10 @@ class BlockedBaseGPU(unittest.TestCase):
|
|||||||
for base_block in (None, *layouts):
|
for base_block in (None, *layouts):
|
||||||
label = f"{mode} width={width} speed={speed} base={base_block}"
|
label = f"{mode} width={width} speed={speed} base={base_block}"
|
||||||
snapshots = []
|
snapshots = []
|
||||||
with FixedPatchStepper(cfg, BOUNDS, context=context, coarse_boundary=mode,
|
with FixedPatchStepper(cfg, context=context, coarse_boundary=mode,
|
||||||
fine_block=FINE_BLOCK, base_block=base_block,
|
refinements=[BOUNDS], level_blocks=[base_block, FINE_BLOCK],
|
||||||
fine_objects=() if speed is None else [circle(actuation(speed))]) as backend:
|
level_objects=[(), () if speed is None
|
||||||
|
else (circle(actuation(speed)),)]) as backend:
|
||||||
backend.initialize(*arrays)
|
backend.initialize(*arrays)
|
||||||
for step in (0, 1, 2, 8):
|
for step in (0, 1, 2, 8):
|
||||||
if step == 1 and base_block is not None:
|
if step == 1 and base_block is not None:
|
||||||
|
|||||||
@@ -42,8 +42,9 @@ class RefinementMRTGPU(unittest.TestCase):
|
|||||||
collision="MRT", ddf_shifting=shifted)
|
collision="MRT", ddf_shifting=shifted)
|
||||||
reference = None
|
reference = None
|
||||||
for block in ((32, 48), (8, 8), (4, 1)):
|
for block in ((32, 48), (8, 8), (4, 1)):
|
||||||
with FixedPatchStepper(cfg, (8, 6, 40, 26), context=context, coarse_boundary=boundary,
|
with FixedPatchStepper(cfg, context=context, coarse_boundary=boundary,
|
||||||
base_block=block, fine_block=(8, 8), fine_objects=(body,)) as backend:
|
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.initialize(*[state(*level.shape[1:]) for level in backend._levels])
|
||||||
backend.step(8)
|
backend.step(8)
|
||||||
raw = backend._download_raw()
|
raw = backend._download_raw()
|
||||||
@@ -63,8 +64,8 @@ class RefinementMRTGPU(unittest.TestCase):
|
|||||||
results = {}
|
results = {}
|
||||||
layouts = ((None, None), *((base, FINE_BLOCK) for base in (None, *BASE_BLOCKS)))
|
layouts = ((None, None), *((base, FINE_BLOCK) for base in (None, *BASE_BLOCKS)))
|
||||||
for base_block, fine_block in layouts:
|
for base_block, fine_block in layouts:
|
||||||
with FixedPatchStepper(cfg, BOUNDS, context=context, fine_block=fine_block,
|
with FixedPatchStepper(cfg, context=context, refinements=[BOUNDS],
|
||||||
base_block=base_block) as backend:
|
level_blocks=[base_block, fine_block]) as backend:
|
||||||
backend.initialize(*[fixture.state(*level.shape[1:], seed) for seed, level in enumerate(backend._levels)])
|
backend.initialize(*[fixture.state(*level.shape[1:], seed) for seed, level in enumerate(backend._levels)])
|
||||||
backend.step(4)
|
backend.step(4)
|
||||||
results[base_block, fine_block] = raw(backend)
|
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):
|
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."""
|
"""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)
|
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 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)
|
self.assertEqual(len(backend._level_cfgs), 3)
|
||||||
for level, level_cfg in enumerate(backend._level_cfgs):
|
for level, level_cfg in enumerate(backend._level_cfgs):
|
||||||
checked = replace(level_cfg)
|
checked = replace(level_cfg)
|
||||||
|
|||||||
@@ -136,8 +136,8 @@ class ShiftedJetsGPU(unittest.TestCase):
|
|||||||
Parallel(0.),amplitude=.013)
|
Parallel(0.),amplitude=.013)
|
||||||
for rho in (.99,1.01):
|
for rho in (.99,1.01):
|
||||||
with self.subTest(rho=rho),CudaContext(0) as ctx:
|
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),
|
with FixedPatchStepper(cfg,context=ctx,refinements=[(8,6,24,18)],level_blocks=[(4,4)]*2,
|
||||||
fine_objects=(obj,),jets=(whole,),observe_raw_exchange=True) as run:
|
level_objects=[(),(obj,)],level_jets=[(),(whole,)],observe_raw_exchange=True) as run:
|
||||||
run._initialize_raw(initial(run,rho,u=.013,v=0.))
|
run._initialize_raw(initial(run,rho,u=.013,v=0.))
|
||||||
expected=run._download_raw();ledger=Ledger(self,run,1)
|
expected=run._download_raw();ledger=Ledger(self,run,1)
|
||||||
self.assertTrue(run._level_boundaries[1].tables['aperture'].all())
|
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)
|
obj=circle((16.,12.),2.15);j=drive((16.,12.),2.15)
|
||||||
for rho in (.99,1.01):
|
for rho in (.99,1.01):
|
||||||
with self.subTest(rho=rho),CudaContext(0) as ctx,ExitStack() as owned:
|
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))
|
measured=owned.enter_context(FixedPatchStepper(cfg,observe_raw_exchange=True,**settings))
|
||||||
plain=owned.enter_context(FixedPatchStepper(cfg,**settings))
|
plain=owned.enter_context(FixedPatchStepper(cfg,**settings))
|
||||||
measured._initialize_raw(initial(measured,rho));plain._initialize_raw(initial(plain,rho))
|
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))
|
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)
|
obj=circle((12.,14.),.8);j=drive((12.,14.),.8)
|
||||||
with CudaContext(0) as ctx,ExitStack() as owned:
|
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),
|
old=owned.enter_context(FixedPatchStepper(cfg,context=ctx,refinements=[parents,a],
|
||||||
child_block=(4,4),child_rectangles_in_parent=a,child_objects=(obj,),child_jets=(j,),observe_raw_exchange=True))
|
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)
|
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()
|
for speed in (.002,-.001):old.set_jet_amplitude(0,speed,level=2);ledger.step()
|
||||||
before=old._download_raw();count=old.step_count
|
before=old._download_raw();count=old.step_count
|
||||||
|
|||||||
Reference in new issue
Block a user