amos f611da1e57 Batch 24: add 23 calibrated tasks written from Bos seed directions
Batch 24 (20261102-C-bos-seed-24) screened all 3078 Bos seed queries.
Only 23 themes were in scope (pure user-space reliability, at most one
task per theme); the rest were single operations or explanations,
installs and networking, system administration, ROS2, board-only or GUI
requests. Two finished drafts were withdrawn as too close to existing
tasks. Seeds supply direction only: all sources, contracts and tests are
new, and no task shares more than 14 characters with its seed text.

Each task passed the local gate and the trace6 Docker gate (5 runs per
sample class). Claude rebuilt the catalog from the calibration receipts:
23/23 USABLE. 16 of 23 are C/C++.

Only the task directories are taken; the batch worktree's lowered disk
floor in rollout/core.py stays out of main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 17:21:50 +08:00

112 lines
4.4 KiB
Python

"""State transition, step sequence, and aggregate balances."""
from dataclasses import dataclass
from decimal_units import ZERO, sum_energy
from dispatch_actions import energy_inputs, select_actions, conservation_errors
@dataclass
class Ledger:
soc: object
fuel: object
tick: int
rows: list
demand_total: object
solar_total: object
charged_total: object
discharged_total: object
grid_total: object
generator_total: object
unmet_total: object
spilled_total: object
previous_grid: object
@classmethod
def start(cls, initial_soc, fuel):
return cls(initial_soc, fuel, 0, [], ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO)
def apply(self, config, period):
inputs = energy_inputs(config, period, self.soc, self.fuel)
budget = max(ZERO, inputs.grid_limit - self.previous_grid)
actions = select_actions(inputs, budget)
problems = conservation_errors(inputs, actions)
if problems:
raise ArithmeticError('energy ledger: ' + ','.join(problems))
row = PeriodRecord(self.tick, period, inputs, actions)
self.rows.append(row)
self.soc = actions.soc_after
self.fuel = actions.fuel_after
self.previous_grid = actions.grid_to_load
self.tick += 1
self.demand_total += inputs.demand
self.solar_total += inputs.solar
self.charged_total += actions.pv_to_battery
self.discharged_total += actions.battery_to_load
self.grid_total += actions.grid_to_load
self.generator_total += actions.generator_to_load
self.unmet_total += actions.unmet
self.spilled_total += actions.pv_spill
return row
def run(self, scenario):
for period in scenario.periods:
self.apply(scenario.config, period)
self.audit(scenario)
return self
def audit(self, scenario):
if self.tick != len(scenario.periods):
raise ArithmeticError('period count mismatch')
if self.soc != scenario.config.initial_soc + self.charged_total - self.discharged_total:
raise ArithmeticError('final storage mismatch')
if self.demand_total != sum_energy(row.inputs.demand for row in self.rows):
raise ArithmeticError('load total mismatch')
if self.solar_total != sum_energy(row.inputs.solar for row in self.rows):
raise ArithmeticError('solar total mismatch')
if self.fuel != scenario.config.fuel_kwh - self.generator_total:
raise ArithmeticError('final fuel mismatch')
if self.demand_total != sum_energy(row.energy_balance() for row in self.rows):
raise ArithmeticError('demand conservation mismatch')
if self.solar_total != sum_energy(row.solar_balance() for row in self.rows):
raise ArithmeticError('solar conservation mismatch')
for row in self.rows:
if not row.is_balanced():
raise ArithmeticError('period conservation mismatch')
if row.battery_balance() != row.actions.soc_after:
raise ArithmeticError('period storage mismatch')
if row.fuel_balance() != row.actions.fuel_after:
raise ArithmeticError('period fuel mismatch')
def totals(self):
return {'demand': self.demand_total, 'solar': self.solar_total,
'charged': self.charged_total, 'discharged': self.discharged_total,
'grid': self.grid_total, 'generator': self.generator_total,
'unmet': self.unmet_total,
'spilled': self.spilled_total, 'final_soc': self.soc,
'final_fuel': self.fuel}
@dataclass(frozen=True)
class PeriodRecord:
index: int
period: object
inputs: object
actions: object
def energy_balance(self):
return self.actions.pv_to_load + self.actions.battery_to_load + self.actions.grid_to_load + self.actions.generator_to_load + self.actions.unmet
def solar_balance(self):
return self.actions.pv_to_load + self.actions.pv_to_battery + self.actions.pv_spill
def battery_balance(self):
return self.inputs.soc + self.actions.pv_to_battery - self.actions.battery_to_load
def is_balanced(self):
return self.energy_balance() == self.inputs.demand and self.solar_balance() == self.inputs.solar
def fuel_balance(self):
return self.inputs.fuel - self.actions.generator_to_load