35 """chamber_solver / closure must reach the accelerator, not just be able to.
37 runner.evaluate -> chamber_solver._accel_chamber_pc -> accel.chamber_solve,
38 and the Brent residual -> closure.flows -> accel.solve.
40 from engine
import accel
43 calls = {
"chamber_solve": 0,
"solve": 0}
45 real = getattr(accel, name)
46 def counting(*a, _r=real, _n=name, **k):
49 monkeypatch.setattr(accel, name, counting)
51 r = PintleEngineRunner(cfg)
52 res = r.evaluate(4.0e6, 4.0e6, P_ambient=PA, silent=
True)
53 assert res
is not None and res[
"Pc"] > 0
55 assert sum(calls.values()) > 0, (
56 "runner.evaluate completed without reaching the accelerator at all -- the "
57 f
"call sites have been bypassed (counts={calls}). Everything still "
58 "'passes' because Python silently produces the same numbers, just ~120x "
64 """The Layer-1 seam: EVERY candidate must go through accel.evaluate.
66 Asserts a RATIO, not merely a non-zero count. A count-only check would pass
67 if one candidate went through the accelerator and the next thousand did not.
68 Measured ratio is exactly 1.000 -- every candidate -- so the 0.9 floor has
69 real margin while still failing hard (ratio 0.0) on a bypass.
71 Runs a genuine one-iteration smoke optimization rather than calling the
72 accelerator directly, because the thing under test is the WIRING.
74 from engine
import accel
78 n = {
"cand": 0,
"accel": 0}
79 real_ec, real_ev = L1._eval_candidate, accel.evaluate
81 def counting_candidate(x):
85 def counting_evaluate(*a, **k):
87 return real_ev(*a, **k)
89 base = copy.deepcopy(cfg)
90 req = base.design_requirements.model_dump()
91 req[
"layer1_random_seed"] = 0
92 pcfg = {
"mode":
"optimizer_controlled",
93 "max_lox_pressure_psi": float(req[
"max_lox_tank_pressure_psi"]),
94 "max_fuel_pressure_psi": float(req[
"max_fuel_tank_pressure_psi"])}
96 L1._get_num_workers =
lambda c: 1
97 L1._eval_candidate, accel.evaluate = counting_candidate, counting_evaluate
99 L1.run_layer1_optimization(
100 copy.deepcopy(base), PintleEngineRunner(copy.deepcopy(base)), req,
101 target_burn_time=float(req.get(
"target_burn_time", 6.0)),
102 tolerances={
"thrust": 0.10,
"apogee": 0.15}, pressure_config=pcfg,
103 layer1_smoke=
True, layer1_max_iterations=1, layer1_cma_restarts=1)
105 L1._eval_candidate, accel.evaluate = real_ec, real_ev
107 assert n[
"cand"] > 0,
"no candidates were evaluated -- the smoke run did nothing"
108 ratio = n[
"accel"] / n[
"cand"]
109 assert ratio >= 0.9, (
110 f
"only {n['accel']}/{n['cand']} candidates ({ratio:.1%}) went through the "
111 "accelerator -- the Layer-1 inner-loop fast path is bypassed. The optimizer "
112 "still produces correct results on the Python path, which is why no other "
118 """The chug seam: stability analysis must reach accel.chug_margin_fast.
120 Separate from the others because it is reached through
121 comprehensive_stability_analysis rather than the chamber solve, so a bypass
122 there is invisible to every check above. Chug is ~53x accelerated and is the
123 dominant per-evaluation stability cost, so silently dropping to Python here
124 is a large regression with no wrong answer to give it away.
126 from engine
import accel
130 real = accel.chug_margin_fast
132 def counting(*a, **k):
136 monkeypatch.setattr(accel,
"chug_margin_fast", counting)
137 r = PintleEngineRunner(cfg)
138 res = r.evaluate(4.0e6, 4.0e6, P_ambient=PA, silent=
True)
139 assert res
is not None
141 assert n[
"calls"] > 0, (
142 "stability analysis ran without reaching accel.chug_margin_fast -- the "
143 "compiled chug sweep is bypassed and the ~53x slower Python sweep is "
144 "running instead, with identical numbers."