structfs.runner_actions#
Predefined Actions for the generic Runner.
Module Contents#
Classes#
|
Simple step/run timer action. |
|
Check degrees of freedom on unit models. |
|
Capture the solver output. |
|
Extract and format model variables. |
|
Action to generate a Mermaid diagram after the run. |
Data#
|
API#
- class structfs.runner_actions.Timer(runner, **kwargs)
Bases:
structfs.runner.ActionSimple step/run timer action.
Initialization
Constructor.
Args: runner: Associated Runner object kwargs: Additional optional arguments for Action constructor
Attributes: step_times: Dict with key step name and value a list of timings for that step run_times: List of timings for a run (sequence of steps)
- class Report(/, **data: Any)
Bases:
pydantic.BaseModelReport returned by report() method.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.
- before_step(step_name)
- after_step(step_name)
- before_run()
- after_run()
- __len__()
- get_history() list[dict]
Summarize timings
Returns: Summary of timings (in seconds) for each run in
run_times: - ‘run’: Time for the run - ‘steps’: dict of{<step_name>: <time(sec)>}- ‘inclusive’: total time spent in the steps - ‘exclusive’: difference between run time and inclusive time
- _get_summary(i)
- summary(stream=None, run_idx=-1) str | None
Summary of the timings.
Args: stream: Output stream, with
write()method. Return a string if None. run_idx: Index of run, -1 meaning “last one”Returns: str: If output stream was None, the text summary; otherwise None
- _ipython_display_()
- report() Report
Report the timings.
Returns: The report object
- structfs.runner_actions.UnitDofType
None
- class structfs.runner_actions.UnitDofChecker(runner: structfs.fsrunner.FlowsheetRunner, flowsheet: str, steps: Union[str, list[str]], step_func: Optional[collections.abc.Callable[[str, structfs.runner_actions.UnitDofType], None]] = None, run_func: Optional[collections.abc.Callable[[dict[str, structfs.runner_actions.UnitDofType], int], None]] = None, **kwargs)
Bases:
structfs.runner.ActionCheck degrees of freedom on unit models.
After a (caller-named) step or steps, check the degrees of freedom on each unit model by the method of fixing the inlet, applying the
degrees_of_freedom()function, and unfixing the inlet again. The calculated values are saved and passed to an optional caller-provided function.At the end of a run, the degrees of freedom for the entire model are checked, saved, and passed to an optional function.
Initialization
Constructor.
Args: runner: Associated Runner object (provided by
add_action) flowsheet: Variable name for flowsheet, e.g. “fs” steps: Step or steps at which to run the checking action step_func: Function to call with calculated DoF values for one step. Takes name of step and dictionary with per-unit degrees of freedom (seeUnitDofTypealias). run_func: Function to call with calculated DoF values for each step, as well as overall model DoF. kwargs: Additional optional arguments for Action constructorRaises: ValueError: if
stepslist is empty, or no callback functions provided- class Report(/, **data: Any)
Bases:
pydantic.BaseModelReport on degrees of freedom in a model.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model: int
‘Field(…)’
- after_step(step_name: str)
- after_run()
Actions performed after a run.
- _get_flowsheet()
- static _is_unit_model(block)
- summary(stream=sys.stdout, step=None)
Readable summary of the degrees of freedom.
Args: stream: Output stream, with
write()method. Return a string if None. step: Specific step to summarize, otherwise all steps.Returns: The summary as a string if
streamwas None, otherwise None
- _ipython_display_()
- get_dof() dict[str, structfs.runner_actions.UnitDofType]
Get degrees of freedom
Returns: dict[str, UnitDofType]: Mapping of step name to per-unit DoF when the step completed.
- get_dof_model() int
Get degrees of freedom for the model.
Returns: int: Last calculated DoF for the model.
- steps(only_with_data: bool = False) list[str]
Get list of steps for which unit degrees of freedom are calculated.
Args: only_with_data: If True, do not return steps with no data
Returns: list of step names
- report() Report
Machine-readable report of degrees of freedom.
Returns: Report object
- static _get_dof(block, fix_inlets: bool = True)
- class structfs.runner_actions.CaptureSolverOutput(runner, **kwargs)
Bases:
structfs.runner.ActionCapture the solver output.
Initialization
- before_step(step_name: str)
Action performed before the step.
- after_step(step_name: str)
Action performed after the step.
- _is_solve_step(name: str)
- report() dict
Machine-readable report with solver output.
Returns: Report dict, {‘solver_logs’: “
”}
- class structfs.runner_actions.ModelVariables(runner, **kwargs)
Bases:
structfs.runner.ActionExtract and format model variables.
Initialization
- class Report(/, **data: Any)
Bases:
pydantic.BaseModelReport for ModelVariables.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- variables: dict
‘Field(…)’
- after_run()
Actions performed after the run.
- _extract_vars(m)
- static _is_var(c)
- static _is_param(c)
- report() Report
Report containing model variable values.
- class structfs.runner_actions.MermaidDiagram
Bases:
structfs.runner.ActionAction to generate a Mermaid diagram after the run.
- class Report(/, **data: Any)
Bases:
pydantic.BaseModelReport containing a Mermaid diagram.
Initialization
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.
- after_run()
Build Mermaid diagram after the run.
- report() Report | dict
Report containing the Mermaid diagram.
Returns: Report object if idaes_connectivity is active, otherwise an empty dictionary