Improve persistence and reactor dynamics
This commit is contained in:
@@ -7,6 +7,7 @@ import json
|
||||
import logging
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from threading import Event
|
||||
import time
|
||||
from typing import Callable, Iterable, Optional
|
||||
@@ -21,6 +22,11 @@ LOGGER = logging.getLogger(__name__)
|
||||
CommandProvider = Callable[[float, PlantState], Optional[ReactorCommand]]
|
||||
|
||||
|
||||
def _default_state_path() -> Path:
|
||||
custom = os.getenv("FISSION_STATE_PATH")
|
||||
return Path(custom) if custom else Path("artifacts/last_state.json")
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReactorSimulation:
|
||||
reactor: Reactor
|
||||
@@ -80,8 +86,11 @@ def main() -> None:
|
||||
timestep = 1.0 if dashboard_mode or realtime else 5.0
|
||||
|
||||
sim = ReactorSimulation(reactor, timestep=timestep, duration=duration, realtime=realtime)
|
||||
state_path = _default_state_path()
|
||||
load_path = os.getenv("FISSION_LOAD_STATE")
|
||||
save_path = os.getenv("FISSION_SAVE_STATE")
|
||||
if not load_path and state_path.exists():
|
||||
load_path = str(state_path)
|
||||
save_path = os.getenv("FISSION_SAVE_STATE") or str(state_path)
|
||||
if load_path:
|
||||
sim.start_state = reactor.load_state(load_path)
|
||||
if dashboard_mode:
|
||||
|
||||
Reference in New Issue
Block a user