test: add bounded square shear orientation diagnostic

This commit is contained in:
TRON committed 2026-10-18 23:48:18 -07:00
1 parent 70c83b7233
commit afa8f6aca1
4 files changed
+394 -14

No files matched your search

+46 -14
View File
@@ -27,6 +27,8 @@ TWIN_SHEAR = "twin_shear_n128" # depth-2 twin: nested L0->L1 boxes without L2
SHEAR_TWIN_SHA256 = "1cbf37f18e89aea577581631c4565f51e68d22a3739b698816ef64acbf2b2bb4"
WIDE_X_SHEAR = "wide_x_shear_n128" # one projected x-gap-width contrast
SHEAR_WIDE_X_SHA256 = "13d16ba355117e2d074edccd9dc5d694c2fc13c673a0abdfca6401f6ed917733"
AXIS_SQUARE = "axis_square_shear_n128" # short four-face orientation diagnostic
SHEAR_AXIS_SQUARE_SHA256 = "0baffa6eb99c268ce998d90300c993d45bb3b7b27c524b636874d75808bd0a8c"
POSTG_SHEAR = "postg_shear_n128" # initialization-only three-case counterfactual
SHEAR_POSTG_SHA256 = "9c909fa013c092490ee21532e3125b2a78a4c5102c7a1bdc0e76986d3f0ef903"
SHEAR_PROBES_SHA256 = "e2e6490d281cc275f448dc6d6ea7b9b4407cc74a51e9256b86c08c8626b89b76" # signed interface-probe mechanism diagnostic
@@ -125,6 +127,13 @@ def verify_source(repo, revision, flow="taylor_green", probes=False):
or hashlib.sha256(module.read_bytes()).hexdigest() != SHEAR_PROBES_SHA256):
raise RuntimeError("Wrong shear_probes module checkout or content")
result["shear_probes_sha256"] = SHEAR_PROBES_SHA256
if flow == "shear_axis_square":
import shear_axis_square
module = harness / "shear_axis_square.py"
if (Path(shear_axis_square.__file__).resolve() != module
or hashlib.sha256(module.read_bytes()).hexdigest() != SHEAR_AXIS_SQUARE_SHA256):
raise RuntimeError("Wrong shear_axis_square module checkout or content")
result["shear_axis_square_sha256"] = SHEAR_AXIS_SQUARE_SHA256
if flow == "shear_postg":
import shear_postg
module = harness / "shear_postg.py"
@@ -153,7 +162,7 @@ def verify_source(repo, revision, flow="taylor_green", probes=False):
or hashlib.sha256(module.read_bytes()).hexdigest() != SHEAR_NESTED_SHA256):
raise RuntimeError("Wrong shear_nested module checkout or content")
result["shear_nested_sha256"] = SHEAR_NESTED_SHA256
if flow in ("shear_wave", "shear_nested", "shear_twin", "shear_wide_x", "shear_postg"):
if flow in ("shear_wave", "shear_nested", "shear_twin", "shear_wide_x", "shear_postg", "shear_axis_square"):
import shear_wave
module = harness / "shear_wave.py"
if (Path(shear_wave.__file__).resolve() != module
@@ -228,16 +237,18 @@ def main():
p.add_argument("--explosion", choices=["constant", "projected_linear"], default="constant")
p.add_argument("--diagnostic",
choices=[SCALED_DIAGNOSTIC, SCALED_SHEAR, NESTED_SHEAR, TWIN_SHEAR,
WIDE_X_SHEAR, POSTG_SHEAR],
WIDE_X_SHEAR, POSTG_SHEAR, AXIS_SQUARE],
help="explicit four-case N256/fine512 same-placement diagnostic "
"(scaled_n256: Taylor-Green; scaled_shear_n256: shear wave) or the "
"fixed three-level/two-region shear preset (nested_shear_n128) "
"or its depth-2 twin (twin_shear_n128), or the single projected "
"x-gap-width contrast (wide_x_shear_n128), or three-case POST-G "
"initialization counterfactual (postg_shear_n128)")
"initialization counterfactual (postg_shear_n128), or short square "
"orientation diagnostic (axis_square_shear_n128)")
p.add_argument("--probe-trace", action="store_true",
help="signed interface-probe trace (nested U128/U512/projected d3, "
"twin projected d2, wide-x projected d3, POST-G three-case set); "
"twin projected d2, wide-x projected d3, POST-G three-case set, "
"axis-square four-case set); "
"mechanism diagnostic, no gates")
p.add_argument("--final-snapshot", action="store_true",
help="nested_shear_n128 projected depth-3 only: final macro snapshot")
@@ -245,10 +256,11 @@ def main():
help="also save 65 scalar pressure samples at t*=k*.001875, k=0..64")
p.add_argument("--flow", choices=["taylor_green", "shear_wave"], default="taylor_green")
args = p.parse_args()
axis_square = args.diagnostic == AXIS_SQUARE
nested = args.diagnostic == NESTED_SHEAR
wide_x = args.diagnostic == WIDE_X_SHEAR
postg = args.diagnostic == POSTG_SHEAR
if (wide_x or postg) and not args.probe_trace:
if (wide_x or postg or axis_square) and not args.probe_trace:
p.error(f"{args.diagnostic} requires --probe-trace")
if args.flow == "shear_wave" and (args.re != 100 or (args.depth == 3 and not (nested or wide_x or postg))
or args.early_pressure):
@@ -259,9 +271,13 @@ def main():
(WIDE_X_SHEAR, 128, 3, "projected_linear"),
(POSTG_SHEAR, 128, 1, "constant"), (POSTG_SHEAR, 512, 1, "constant"),
(POSTG_SHEAR, 128, 3, "projected_linear")}
if axis_square:
import shear_axis_square
probe_cases.update((AXIS_SQUARE, n, depth, scheme)
for _, n, depth, scheme in shear_axis_square.CASES)
if args.probe_trace and (args.final_snapshot or (
args.diagnostic, args.n, args.depth, args.explosion) not in probe_cases):
p.error("--probe-trace requires a fixed nested, twin, wide-x or POST-G case, "
p.error("--probe-trace requires a fixed nested, twin, wide-x, POST-G or axis-square case, "
"without --final-snapshot")
if args.final_snapshot and not (nested and args.depth == 3
and args.explosion == "projected_linear"):
@@ -272,7 +288,12 @@ def main():
if args.explosion != "constant" and args.depth != 2 and not (nested or wide_x or postg):
p.error("projected_linear requires depth 2")
twin = args.diagnostic == TWIN_SHEAR
if nested or twin or wide_x or postg:
if axis_square:
preset = shear_axis_square
if args.flow != "shear_wave" or (args.re, args.n, args.depth, args.explosion) not in preset.CASES:
p.error("axis_square_shear_n128 requires one of its four Re100 shear cases")
initial, metrics, limits, initialization = preset.initial, preset.metrics, {}, preset.INITIALIZATION
elif nested or twin or wide_x or postg:
import shear_nested
import shear_twin
import shear_wide_x
@@ -304,7 +325,7 @@ def main():
p.error("--run-gpu and exactly one explicit CUDA_VISIBLE_DEVICES are required")
repo = args.repo.resolve()
sys.path[:0] = [str(repo / "src"), str(repo)]
source_flow = ("shear_postg" if postg else "shear_wide_x" if wide_x else "shear_nested" if nested
source_flow = ("shear_axis_square" if axis_square else "shear_postg" if postg else "shear_wide_x" if wide_x else "shear_nested" if nested
else "shear_twin" if twin else args.flow)
source = verify_source(repo, args.expected_revision, source_flow, probes=args.probe_trace)
runtime = runtime_source(repo)
@@ -322,7 +343,7 @@ def main():
cfg = config(args.n, args.re)
if args.depth == 1:
refinements = []
elif nested or twin or wide_x or postg:
elif nested or twin or wide_x or postg or axis_square:
refinements = [list(level) for level in preset.REFINEMENTS]
else:
refinements = rectangles(args.n, args.depth)
@@ -330,6 +351,8 @@ def main():
np.testing.assert_array_equal(leaf_partition(h), np.ones((args.n, args.n)))
masks = [k == ACTIVE for k in h.kinds]
main_steps, early_steps = sample_steps(args.n, args.early_pressure)
if axis_square:
main_steps = [0, preset.case_steps(args.n)[-1]]
report = dict(
schema=1,
source=source,
@@ -357,7 +380,7 @@ def main():
cuda_visible_devices=selected,
device_id=0,
limits=limits,
workload=workload(masks, round(TIMES[-1] * args.n / U)),
workload=workload(masks, main_steps[-1]),
rows=[],
early_pressure=dict(enabled=args.early_pressure, rows=[],
sampled_max_pressure_l2=None),
@@ -365,14 +388,19 @@ def main():
)
if args.flow != "taylor_green":
import shear_wave
report.update(flow=args.flow, mode=list(shear_wave.MODE),
polarization=shear_wave.E.tolist(), angle_deg=shear_wave.ANGLE_DEG,
phase=shear_wave.PHI, eps=shear_wave.eps(args.n))
wave = preset if axis_square else shear_wave
report.update(flow=args.flow, mode=list(wave.MODE),
polarization=wave.E.tolist(), angle_deg=wave.ANGLE_DEG,
phase=wave.PHI, eps=wave.eps(args.n))
if args.diagnostic:
report["diagnostic"] = args.diagnostic
if postg:
report.update(initialization_id=preset.INITIALIZATION_ID, qualification_eligible=False,
screening_scope="descriptive scalar screens only; no qualification assessor")
if axis_square:
report.update(initialization_id=preset.INITIALIZATION_ID, qualification_eligible=False,
reference_harness=None, historical_baseline_revision=None,
screening_scope="no numerical gates; short orientation diagnostic")
args.output.parent.mkdir(parents=True, exist_ok=True)
def save():
temporary = args.output.with_suffix(args.output.suffix + ".tmp")
@@ -410,6 +438,8 @@ def main():
probe_steps = set()
if args.probe_trace:
import shear_probes
if axis_square:
shear_probes = preset
probe_root = dict(zip(shear_probes.case_steps(args.n), shear_probes.STEPS))
probe_steps = set(probe_root)
probes = shear_probes.select(masks, args.n)
@@ -491,7 +521,7 @@ def main():
report.update(
completed=True,
seconds=time.monotonic() - started,
screening_pass=all(
screening_pass=None if axis_square else all(
row[key] <= limit for row in report["rows"] for key, limit in limits.items()
),
)
@@ -502,6 +532,8 @@ def main():
),
flush=True,
)
if axis_square:
return int("error" in report["probe_trace"])
return 0 if report["screening_pass"] else 1