1"""In-memory application state for config and runner."""
4from typing
import Optional, Tuple
10 """Holds the current config and runner instance.
12 The two are one pair: the runner is built from the config. Solves run in the thread pool
13 (``backend.session.run_compute``) while the config endpoints replace the pair, so a solve
14 takes ``snapshot()`` once and uses only that, and ``set_config`` swaps both at once.
18 self.
config: Optional[PintleEngineConfig] =
None
19 self.
runner: Optional[PintleEngineRunner] =
None
23 def set_config(self, config: PintleEngineConfig, config_path: Optional[str] =
None) ->
None:
24 """Set config and create a new runner instance.
26 The runner is built first -- seconds, for a propellant whose CEA cache has to load --
27 and the pair swapped together after, so nothing reads the new config beside the old
28 runner while it builds. A runner that fails to build leaves the old pair in place.
34 if config_path
is not None:
37 def snapshot(self) -> Tuple[Optional[PintleEngineConfig], Optional[PintleEngineRunner]]:
38 """The config and the runner built from it, read together.
40 A solve takes this once. Reading ``self.config`` again after the solve would pick up a
41 config written while it ran, and report one design's numbers against another's.
47 """Check if a config is loaded."""
48 return self.
config is not None and self.
runner is not None
Tuple[Optional[PintleEngineConfig], Optional[PintleEngineRunner]] snapshot(self)
None set_config(self, PintleEngineConfig config, Optional[str] config_path=None)
Optional[PintleEngineRunner] runner
Optional[str] config_path
Optional[PintleEngineConfig] config