You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Eliminate Python overhead in the hot simulation loop through mechanical,
behavior-preserving replacements. No architecture or physics changes.
Benchmark: 30-day simulation at 1-minute timesteps (43,560 steps) using
BEopt_example.xml + BEopt_example_schedule.csv + Denver TMY3 weather,
starting June 1 2018, with PV (5kW), Battery (6kWh/3kW), and EV (BEV
Level 2). Deterministic via seed=42.
Before: 37.67s → After: 24.86s (34.0% faster, 12.81s saved)
Function calls: 74.3M → 44.6M (40% reduction)
All 244 tests pass. Output identical within tolerances.
Changes by category:
Schedule/dispatch overhead:
- Cache DataFrame.empty as bool flag, recomputed in reset_time()
- Replace to_dict("records") iterator with array-backed dict construction
- Replace isinstance() checks with bit-flag dispatch on Equipment._kind
- Skip per-sub datetime comparisons when all sub-simulators share resolution
- Convert all_schedule_inputs membership test from list to frozenset
Unit conversion and constant caching:
- Cache pint convert() results as module-level constants for natural ventilation
- Also fixes natural ventilation area unit: ft^2 → m^2 (pre-existing bug)
- Pre-compute f-string schedule keys at init instead of per-step
Numpy small-array allocation elimination:
- Replace np.insert() with pre-allocated buffer in Water.update_model
- Replace np.array() + np.dot() biquadratic with inline scalar polynomial
- Pre-allocate np.zeros buffers in Envelope.update_inputs/update_model
- Pre-allocate surface temperature buffers for interior radiation
- Pre-allocate np.zeros/np.concatenate buffers in Water model
- Skip inputs_init.copy() in SSM when full control_signal provided
Scalar math dispatch:
- Python sum()/any() on numpy arrays → ndarray .sum()/.any()
- np.exp/np.sqrt on scalars → math.exp/math.sqrt
- Python min()/max() on numpy arrays → .min()/.max()
- Precompute vol_fractions cumulative sums in Water model
Lookup optimization:
- Dict index maps for StateSpaceModel input/output/state name lookups
- Scalar fast path for RCModel.solve_for_input (common infiltration case)
- Cache np.nonzero(~disable_speeds) in HVAC
Tests:
- Add tests for scalar solver equivalence and nat-vent unit conversion
0 commit comments