STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_layer1_bounds_fix.py
Go to the documentation of this file.
1"""Test to verify Layer 1 optimizer bounds are correct after bug fix."""
2
3import sys
4import pytest
5
6# STALE: every test here imports `Layer1OptimizerConfig` from layer1_static_optimization, a dataclass
7# that does not exist (and never did in this branch's history — `git log -S` finds no definition). The
8# Layer-1 design vector / bounds were implemented as inline lower/upper arrays built in
9# run_layer1_optimization, not a config object with min_d_pintle_m/max_* fields. These tests can never
10# import successfully as written. Skip until reimplemented against the actual bounds API (or removed).
11pytestmark = pytest.mark.skip(reason="references nonexistent Layer1OptimizerConfig; bounds are now inline arrays")
12
13
15 """Verify Layer1OptimizerConfig validates bounds correctly."""
16 from engine.optimizer.layers.layer1_static_optimization import Layer1OptimizerConfig
17
18 # Should succeed with default (now correct) bounds
19 config = Layer1OptimizerConfig()
20
21 # Verify bounds are in correct order
22 assert config.min_d_pintle_m < config.max_d_pintle_m, \
23 f"Pintle bounds swapped: min={config.min_d_pintle_m} >= max={config.max_d_pintle_m}"
24
25 assert config.min_d_orifice_m < config.max_d_orifice_m, \
26 f"Orifice bounds swapped: min={config.min_d_orifice_m} >= max={config.max_d_orifice_m}"
27
28 assert config.min_h_gap_m < config.max_h_gap_m, \
29 f"Gap bounds swapped: min={config.min_h_gap_m} >= max={config.max_h_gap_m}"
30
31 assert config.min_n_orifices <= config.max_n_orifices, \
32 f"Orifice count bounds swapped: min={config.min_n_orifices} > max={config.max_n_orifices}"
33
34 # Verify reasonable physical values
35 assert 0.020 <= config.min_d_pintle_m <= 0.030, \
36 f"Min pintle diameter should be ~25mm, got {config.min_d_pintle_m*1000:.1f}mm"
37 assert 0.070 <= config.max_d_pintle_m <= 0.090, \
38 f"Max pintle diameter should be ~80mm, got {config.max_d_pintle_m*1000:.1f}mm"
39
40 print("✓ All bounds are correctly ordered")
41 print(f" Pintle diameter: {config.min_d_pintle_m*1000:.1f}mm to {config.max_d_pintle_m*1000:.1f}mm")
42 print(f" Orifice diameter: {config.min_d_orifice_m*1000:.1f}mm to {config.max_d_orifice_m*1000:.1f}mm")
43 print(f" Gap height: {config.min_h_gap_m*1000:.1f}mm to {config.max_h_gap_m*1000:.1f}mm")
44 print(f" Orifice count: {config.min_n_orifices} to {config.max_n_orifices}")
45
46
48 """Verify __post_init__ validation catches swapped bounds."""
49 from engine.optimizer.layers.layer1_static_optimization import Layer1OptimizerConfig
50
51 # Try to create config with swapped values (should raise ValueError)
52 try:
53 bad_config = Layer1OptimizerConfig(
54 min_d_pintle_m=0.080, # Wrong: min > max
55 max_d_pintle_m=0.025, # Wrong: max < min
56 )
57 # If we get here, validation didn't work
58 assert False, "Validation should have raised ValueError for swapped bounds"
59 except ValueError as e:
60 if "Pintle diameter bounds are swapped" in str(e):
61 print("✓ Validation correctly catches swapped pintle bounds")
62 else:
63 raise
64
65 print("✓ Validation correctly catches swapped pintle bounds")
66
67
69 """Verify bounds array used by optimizer has correct order."""
70 from engine.optimizer.layers.layer1_static_optimization import Layer1OptimizerConfig
71
72 config = Layer1OptimizerConfig()
73
74 # Simulate bounds array generation from line 912-923
75 bounds = [
76 (1e-5, 3.0e-3), # A_throat (placeholder)
77 (0.95, 1.27), # Lstar
78 (6.0, 12.0), # expansion_ratio
79 (0.05, 0.15), # outer diameter (placeholder)
80 (config.min_d_pintle_m, config.max_d_pintle_m), # d_pintle_tip
81 (config.min_h_gap_m, config.max_h_gap_m), # h_gap
82 (config.min_n_orifices, config.max_n_orifices), # n_orifices
83 (config.min_d_orifice_m, config.max_d_orifice_m), # d_orifice
84 (200, 600), # P_O_start_psi (placeholder)
85 (200, 800), # P_F_start_psi (placeholder)
86 ]
87
88 # Verify all bounds have lower < upper
89 for i, (lower, upper) in enumerate(bounds):
90 assert lower <= upper, \
91 f"Bound {i} has lower ({lower}) > upper ({upper})"
92
93 # Calculate span
94 span = upper - lower
95 assert span >= 0, f"Bound {i} has negative span: {span}"
96
97 # Specifically check pintle bounds (index 4)
98 pintle_lower, pintle_upper = bounds[4]
99 assert pintle_lower == 0.025, f"Pintle lower bound should be 0.025, got {pintle_lower}"
100 assert pintle_upper == 0.080, f"Pintle upper bound should be 0.080, got {pintle_upper}"
101
102 print("✓ Bounds array is correctly ordered")
103 print(f" Pintle bounds [4]: [{pintle_lower*1000:.1f}mm, {pintle_upper*1000:.1f}mm] (span: {(pintle_upper-pintle_lower)*1000:.1f}mm)")
104
105
106if __name__ == "__main__":
107 print("="*70)
108 print("Testing Layer 1 Optimizer Bounds Fix")
109 print("="*70)
110 print()
111
113 print()
114
116 print()
117
119 print()
120
121 print("="*70)
122 print("All tests passed! ✓")
123 print("="*70)