Persist manual control and pump states
This commit is contained in:
@@ -77,6 +77,7 @@ class ControlSystem:
|
|||||||
"control": {
|
"control": {
|
||||||
"setpoint_mw": self.setpoint_mw,
|
"setpoint_mw": self.setpoint_mw,
|
||||||
"rod_fraction": self.rod_fraction,
|
"rod_fraction": self.rod_fraction,
|
||||||
|
"manual_control": self.manual_control,
|
||||||
},
|
},
|
||||||
"plant": plant_state.to_dict(),
|
"plant": plant_state.to_dict(),
|
||||||
"metadata": metadata or {},
|
"metadata": metadata or {},
|
||||||
@@ -94,6 +95,7 @@ class ControlSystem:
|
|||||||
control = data.get("control", {})
|
control = data.get("control", {})
|
||||||
self.setpoint_mw = control.get("setpoint_mw", self.setpoint_mw)
|
self.setpoint_mw = control.get("setpoint_mw", self.setpoint_mw)
|
||||||
self.rod_fraction = control.get("rod_fraction", self.rod_fraction)
|
self.rod_fraction = control.get("rod_fraction", self.rod_fraction)
|
||||||
|
self.manual_control = control.get("manual_control", self.manual_control)
|
||||||
plant = PlantState.from_dict(data["plant"])
|
plant = PlantState.from_dict(data["plant"])
|
||||||
LOGGER.info("Loaded plant state from %s", path)
|
LOGGER.info("Loaded plant state from %s", path)
|
||||||
return plant, data.get("metadata", {}), data.get("health")
|
return plant, data.get("metadata", {}), data.get("health")
|
||||||
|
|||||||
@@ -461,6 +461,21 @@ class Reactor:
|
|||||||
if health:
|
if health:
|
||||||
self.health_monitor.load_snapshot(health)
|
self.health_monitor.load_snapshot(health)
|
||||||
LOGGER.info("Reactor state restored from %s", filepath)
|
LOGGER.info("Reactor state restored from %s", filepath)
|
||||||
|
# Back-fill pump state lists for compatibility.
|
||||||
|
if not plant.primary_pumps or len(plant.primary_pumps) < 2:
|
||||||
|
plant.primary_pumps = [
|
||||||
|
PumpState(active=self.primary_pump_active, flow_rate=plant.primary_loop.mass_flow_rate / 2, pressure=plant.primary_loop.pressure)
|
||||||
|
for _ in range(2)
|
||||||
|
]
|
||||||
|
if not plant.secondary_pumps or len(plant.secondary_pumps) < 2:
|
||||||
|
plant.secondary_pumps = [
|
||||||
|
PumpState(
|
||||||
|
active=self.secondary_pump_active,
|
||||||
|
flow_rate=plant.secondary_loop.mass_flow_rate / 2,
|
||||||
|
pressure=plant.secondary_loop.pressure,
|
||||||
|
)
|
||||||
|
for _ in range(2)
|
||||||
|
]
|
||||||
if len(plant.turbines) < len(self.turbines):
|
if len(plant.turbines) < len(self.turbines):
|
||||||
ambient = constants.ENVIRONMENT_TEMPERATURE
|
ambient = constants.ENVIRONMENT_TEMPERATURE
|
||||||
while len(plant.turbines) < len(self.turbines):
|
while len(plant.turbines) < len(self.turbines):
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ def test_reactor_initial_state_is_cold():
|
|||||||
|
|
||||||
def test_state_save_and_load_roundtrip(tmp_path: Path):
|
def test_state_save_and_load_roundtrip(tmp_path: Path):
|
||||||
reactor = Reactor.default()
|
reactor = Reactor.default()
|
||||||
|
reactor.control.manual_control = True
|
||||||
sim = ReactorSimulation(reactor, timestep=5.0, duration=15.0)
|
sim = ReactorSimulation(reactor, timestep=5.0, duration=15.0)
|
||||||
sim.log()
|
sim.log()
|
||||||
save_path = tmp_path / "plant_state.json"
|
save_path = tmp_path / "plant_state.json"
|
||||||
@@ -32,6 +33,9 @@ def test_state_save_and_load_roundtrip(tmp_path: Path):
|
|||||||
sim.last_state.core.fuel_temperature
|
sim.last_state.core.fuel_temperature
|
||||||
)
|
)
|
||||||
assert restored_reactor.control.rod_fraction == reactor.control.rod_fraction
|
assert restored_reactor.control.rod_fraction == reactor.control.rod_fraction
|
||||||
|
assert restored_reactor.control.manual_control == reactor.control.manual_control
|
||||||
|
assert len(restored_state.primary_pumps) == 2
|
||||||
|
assert len(restored_state.secondary_pumps) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_health_monitor_flags_core_failure():
|
def test_health_monitor_flags_core_failure():
|
||||||
|
|||||||
Reference in New Issue
Block a user