ogstools.core.simulation_controller module#
- class ogstools.core.simulation_controller.SimulationStatus[source]#
Bases:
EnumEnumeration of possible simulation states.
- Attributes:
not_started: Simulation has not been started yet. running: Simulation is currently executing. paused: Simulation is paused (interactive mode only). done: Simulation completed successfully. error: Simulation terminated with an error.
- not_started = 0#
- running = 1#
- paused = 2#
- done = 3#
- error = 4#
- unknown = 5#
- class ogstools.core.simulation_controller.SimulationController[source]#
Bases:
ABCAbstract base class for controlling OGS simulation execution.
Provides a unified interface for running simulations, whether in interactive stepwise mode or batch mode. Handles signal interruption (SIGINT, SIGTERM) and manages simulation status.
Concrete implementations: - OGSInteractiveController: For stepwise execution control - OGSNativeController: For batch execution
Initialize a SimulationController.
- Parameters:
- Status#
alias of
SimulationStatus
- property is_interrupted: bool#
Check if an interrupt signal was received and reset the flag.
- Returns:
True if SIGINT or SIGTERM was received, False otherwise.
- abstractmethod terminate()[source]#
Terminate the simulation immediately.
- Return type:
- Returns:
True if termination was successful, False otherwise.
- abstract property status: SimulationStatus#
Get the current simulation status.
- Returns:
Current SimulationStatus.
- abstractmethod status_str()[source]#
Get a human-readable status string.
- Return type:
- Returns:
String describing the current simulation state.
- plot_log(log_data='step_start_time', time_y_axis_type='linear', time_window_length=0, iteration_window_length=0, update_interval=2.0, notebook=False)[source]#
Open the interactive Bokeh monitoring dashboard for this simulation.
By default this launches the same dashboard as the
ogsmonitorcommand line tool, in a real browser tab, which renders reliably across notebook environments (plain Jupyter, JupyterLab, VS Code’s Jupyter extension, …). Passnotebook=Trueto instead embed the plot directly in the notebook cell’s output.- Parameters:
log_data (
str|list[list[str]]) – Plot type. Can be a single string or a list of list of strings. E.g., [[‘step_start_time’, ‘step_size’], [‘assembly_time’, ‘linear_solver_time’]]time_y_axis_type (
str) – Type of the y-axis (‘linear’ or ‘log’) for simulation time-based data.time_window_length (
int) – Length of the time window (number of timesteps) for the plot. 0 Plots the whole log file.iteration_window_length (
int) – Length of the iteration window (number of iterations) for the plot. 0 Plots the whole log file.update_interval (
float) – Interval in seconds between plot updates.notebook (
bool) –If True, embed the plot in the notebook cell via Bokeh’s
push_notebook()instead of opening a browser tab. A background thread redraws it everyupdate_intervalseconds until the simulation ends orterminate()is called; the call itself returns immediately.Warning
Bokeh’s
push_notebook()live updates do not work in VS Code’s Jupyter extension: this is an unresolved upstream limitation (bokeh/jupyter_bokeh#199), not something ogstools can work around. The plot draws once but never animates there. It works correctly in classic Jupyter and JupyterLab. In VS Code, use the defaultnotebook=False(browser tab) instead.
- Return type:
- Returns:
The running Bokeh server subprocess when
notebook=False. It is also closed byterminate(); call.terminate()on it directly for earlier, standalone control. Returns None whennotebook=True— useterminate()to stop it early.