structfs.fsrunner

structfs.fsrunner#

Specialize the generic Runner class to running a flowsheet, in FlowsheetRunner.

Module Contents#

Classes#

Context

Syntactic sugar for the dictionary for the ‘context’ passed into each step of the FlowsheetRunner class.

BaseFlowsheetRunner

Specialize the base Runner to handle IDAES flowsheets.

FlowsheetRunner

Interface for running and inspecting IDAES flowsheets.

API#

class structfs.fsrunner.Context

Bases: dict

Syntactic sugar for the dictionary for the ‘context’ passed into each step of the FlowsheetRunner class.

Initialization

Initialize self. See help(type(self)) for accurate signature.

property model

The model being run.

property solver

The solver used to solve the model.

class structfs.fsrunner.BaseFlowsheetRunner(solver=None, tee=True)

Bases: structfs.runner.Runner

Specialize the base Runner to handle IDAES flowsheets.

This class pre-determine the name and order of steps to run

Attributes: STEPS: List of defined step names.

Initialization

STEPS

(‘build’, ‘set_operating_conditions’, ‘set_scaling’, ‘initialize’, ‘set_solver’, ‘solve_initial’, ‘a…

run_steps(first: str = Runner.STEP_ANY, last: str = Runner.STEP_ANY, before=None, after=None, **kwargs)

Run the steps.

Before it calls the superclass to run the steps, checks if the step name matches the build_step attribute and, if so, creates an empty Pyomo ConcreteModel to use as the base model for the flowsheet.

reset()
_create_model()
property model

Syntactic sugar to return the model.

property results

Syntactic sugar to return the results in the context.

annotate_var(variable: object, key: str = None, title: str = None, desc: str = None, units: str = None, rounding: int = 3, is_input: bool = True, is_output: bool = True, input_category: str = 'main', output_category: str = 'main') object

Annotate a Pyomo variable.

Args:

  • variable: Pyomo variable being annotated

  • key: Key for this block in dict. Defaults to object name.

  • title: Name / title of the block. Defaults to object name.

  • desc: Description of the block. Defaults to object name.

  • units: Units. Defaults to string value of native units.

  • rounding: Significant digits

  • is_input: Is this variable an input

  • is_output: Is this variable an output

  • input_category: Name of input grouping to display under

  • output_category: Name of output grouping to display under

Returns:

  • Input block (for chaining)

Raises:

  • ValueError: if is_input and is_output are both False

Example

Here is an example of annotating a single Pyomo variable. You can apply this same technique to any Pyomo, and thus IDAES, object.

from idaes.core.util.structfs.fsrunner import FlowsheetRunner
from pyomo.environ import *

def example(f: FlowsheetRunner):
    v = Var()
    v.construct()
    f.annotate_var(v, key="example", title="Example variable").fix(1)

To retrieve the annotated variables, use the annotated_vars property:

example(fr := FlowsheetRunner())
print(fr.annotated_vars)
# prints something like this:
# {'example': {'var': <pyomo.core.base.var.ScalarVar object at 0x762ffb124b40>,
# 'fullname': 'ScalarVar', 'title': 'Example variable',
# 'description': 'ScalarVar', 'units': 'dimensionless',
# 'rounding': 3, 'is_input': True, 'is_output': True, 'input_category': 'main',
# 'output_category': 'main'}}
property annotated_vars: dict[str]

Get (a copy of) the annotated variables.

class structfs.fsrunner.FlowsheetRunner(**kwargs)

Bases: structfs.fsrunner.BaseFlowsheetRunner

Interface for running and inspecting IDAES flowsheets.

Initialization

class DegreesOfFreedom(runner)

Wrapper for the UnitDofChecker action

Initialization

model()

Get the model.

__getattr__(name)

Naming the step prints a summary of that step.

__str__()
_ipython_display_()
class Timings(runner)

Wrapper for the Timer action

Initialization

property values: list[dict]

Get timing values.

property history: str

Get a text report of the timing history

__str__()
_ipython_display_()
build()

Run just the build step

solve_initial()

Perform all steps up to ‘solve_initial’

show_diagram()

Return the diagram.