idaes_flowsheet_processor.api
Simple flowsheet interface API
Module Contents
Classes
A variable, expression, or parameter. |
|
Key Performance Indicator |
|
An option for building/running the model. |
|
A flowsheet and its contained exported model objects. |
|
Known actions that can be run. |
|
Flowsheet Categories |
|
Abstract base class for flowsheet reports. |
|
Interface between users, UI developers, and flowsheet models. |
|
Report of the Key Performance Indicators (KPIs) for a flowsheet. |
|
Translate a simple layout specification into an HTML flex layout. |
Functions
|
Raise UnsupportedObjType if object type is not supported as an input/output |
Attributes
- idaes_flowsheet_processor.api.FSI
- exception idaes_flowsheet_processor.api.UnsupportedObjType(obj: Any, supported=None)
Inappropriate argument type.
- idaes_flowsheet_processor.api.ensure_supported(obj: object) None
Raise UnsupportedObjType if object type is not supported as an input/output
- class idaes_flowsheet_processor.api.ModelExport(/, **data: Any)
A variable, expression, or parameter.
- model_config
- class idaes_flowsheet_processor.api.KPI(/, **data: Any)
Key Performance Indicator
- class idaes_flowsheet_processor.api.ModelOption(/, **data: Any)
An option for building/running the model.
- display_values: List[Any] = []
- value: Any
- classmethod validate_value(v: Any, info: pydantic.ValidationInfo) Any
- class idaes_flowsheet_processor.api.FlowsheetExport(/, **data: Any)
A flowsheet and its contained exported model objects.
- exports: Dict[str, ModelExport]
- kpi_options: Dict
- kpi_figures: Dict
- build_options: Dict[str, ModelOption]
- add(*args: object, data: dict | ModelExport = None, **kwargs: object) object
Add a new variable (or other model object).
There are a few different ways of invoking this function. Users will typically use this form:
add(obj=<pyomo object>, name="My value name", ..etc..)
where the keywords after obj match the non-computed names in
ModelExport.If these same name/value pairs are already in a dictionary, this form is more convenient:
add(data=my_dict_of_name_value_pairs)
If you have an existing ModelExport object, you can add it more directly with:
add(my_object) # -- OR -- add(data=my_object)
- Parameters:
*args – If present, should be a single non-named argument, which is a ModelExport object. Create by adding it.
data – If present, create from this argument. If it’s a dict, create from its values just as from the kwargs. Otherwise, it should be a ModelExport object, and create by adding it.
kwargs – Name/value pairs to create a ModelExport object. Accepted names and default values are in the ModelExport.
- Raises:
KeyError – If the name of the Pyomo object is the same as an existing one, i.e. refuse to overwrite.
- add_kpi_values(name: str, values: List[float], labels: List[str], units: List[str] | None, title: str = '') None
Add a Key Performance Indicator (KPI) for a table of names and values.
- Parameters:
name – Name of the KPI
values – Numeric values
labels – Labels corresponding to values
title – Overall description
units – Descriptive units for the values (optional)
- add_kpi_barchart(name: str, values: List[float], labels: List[str], title: str, xlab: str | None = None, ylab: str | None = None, units: SyntaxWarning = 'none') None
Add a KeyPerformance Indicator (KPI) vector for a barchart.
- Parameters:
name – Name of the KPI
values – Numeric values
labels – Labels corresponding to values
title – Chart title
xlab – Label for x axis
ylab – Label for y axis
units – Units for the values, e.g., “%” if they are percentages adding to 100
- add_kpi_total(name: str, values: List[float], labels: List[str], title: str, total_label: str, units: str = '%') None
Add a Key Performance Indicator (KPI) vector with multiple values and a total
- Parameters:
name – Name of the KPI
values – Numeric values
labels – Labels corresponding to values
total_label – Label for the ‘total’ to which the values sum.
units – Units for the values, e.g., “%” if they are percentages adding to 100
- from_csv(file: str | pathlib.Path, flowsheet: object) int
Load multiple exports from the given CSV file.
CSV file format rules:
Always use a header row. The names are case-insensitive, order is not important. The ‘name’, ‘obj’, and ‘ui_units’ columns are required.
Columns names should match the non-computed names in
ModelExport. See .add() for a list.The object to export should be in a column named ‘obj’, prefixed with ‘fs.’
For units, use Pyomo units module as ‘units’, e.g., ‘mg/L’ is units.mg / units.L
For example:
name,obj,description,ui_units,display_units,rounding,is_input,input_category,is_output,output_category Leach liquid feed rate,fs.leach_liquid_feed.flow_vol[0],Leach liquid feed volumetric flow rate,units.L/units.hour,L/h,2,TRUE,Liquid feed,FALSE, Leach liquid feed H,"fs.leach_liquid_feed.conc_mass_comp[0,'H']",Leach liquid feed hydrogen mass composition,units.mg/units.L,mg/L,3,TRUE,Liquid feed,FALSE, .......etc.......
- Parameters:
file – Filename or path. If not an absolute path, start from the directory of the caller’s file.
flowsheet – Flowsheet used to evaluate the exported objects.
- Returns:
Number of exports added
- Return type:
- Raises:
IOError – if input file doesn’t exist
ValueError – Invalid data in input file (error message will have details)
- to_csv(output: io.TextIOBase | pathlib.Path | str = None) int
Write wrapped objects as CSV.
- Parameters:
output – Where to write CSV file. Can be a stream, path, or filename.
- Returns:
Number of objects written into file.
- Raises:
IOError – If path is given, and not writable
- add_option(name: str, **kwargs: object) ModelOption
Add an ‘option’ to the flowsheet that can be displayed and manipulated from the UI.
Constructs a
ModelOptioninstance with provided args and adds it to the dict of options, keyed by its name.- Parameters:
name – Name of option (internal, for accessing the option)
kwargs – Fields of
ModelOption
- class idaes_flowsheet_processor.api.Actions
Known actions that can be run. Actions that users should not run directly (unless they know what they are doing) are prefixed with an underscore.
- build = 'build'
- solve = 'solve'
- export = '_export'
- diagram = 'diagram'
- initialize = 'initialize'
- kpis = 'kpis'
- class idaes_flowsheet_processor.api.FlowsheetCategory
Flowsheet Categories
- wastewater = 'Wasterwater Recovery'
- desalination = 'Desalination'
- class idaes_flowsheet_processor.api.FlowsheetReport
Abstract base class for flowsheet reports.
This class defines the interface for generating reports from a flowsheet. Subclasses should implement the to_html method to generate the report in HTML format.
- class idaes_flowsheet_processor.api.FlowsheetInterface(fs: FlowsheetExport | None = None, do_build: Callable | None = None, do_export: Callable | None = None, do_solve: Callable | None = None, do_initialize: Callable | None = None, do_kpis: Callable | None = None, get_diagram: Callable | None = None, category: FlowsheetCategory | None = None, custom_do_param_sweep_kwargs: Dict | None = None, **kwargs: object)
Interface between users, UI developers, and flowsheet models.
- UI_HOOK = 'export_to_ui'
- MissingObject
- build(quiet=False, **kwargs: object) None
Build flowsheet
- Parameters:
quiet – If true, suppress output from the build function
**kwargs – User-defined values
- Returns:
None
- Raises:
RuntimeError – If the build fails
- solve(**kwargs: object) Any
Solve flowsheet.
- Parameters:
**kwargs – User-defined values
- Returns:
Return value of the underlying solve function
- Raises:
RuntimeError – if the solver did not terminate in an optimal solution
- get_diagram(**kwargs: object) Any | None
Return diagram image name.
- Parameters:
**kwargs – User-defined values
- Returns:
Return image file name if get_diagram function is callable. Otherwise, return none
- initialize(*args: object, **kwargs: object) Any
Run initialize function.
- Parameters:
**kwargs – User-defined values
- Returns:
Return value of the underlying initialization function. Otherwise, return none
- dict() Dict
Serialize.
- Returns:
Serialized contained FlowsheetExport object
- load(data: Dict) None
Load values from the data into corresponding variables in this instance’s FlowsheetObject.
- Parameters:
data – The input flowsheet (probably deserialized from JSON)
- select_option(option_name: str, new_option: str) None
Update flowsheet with selected option.
- Parameters:
data – The input flowsheet
option_name – Name of selected option
- Returns:
None
- add_action(action_name: str, action_func: Callable) None
Add an action for the flowsheet.
- Parameters:
action_name – Name of the action to take (see
Actions)action_func – Function to call for the action
- Returns:
None
- export_values() None
Copy current values in underlying Pyomo model into exported model.
- Side-effects:
Attribute
fs_expis modified.
- classmethod from_installed_packages(group_name: str = 'watertap.flowsheets') Dict[str, FlowsheetInterface]
Get all flowsheet interfaces defined as entry points within the Python packages installed in the environment.
This uses the
importlib.metadata.entry_points()function to fetch the list of flowsheets declared as part of a Python package distribution’s entry points under the groupgroup_name.To set up a flowsheet interface for discovery, locate your Python package distribution’s file (normally
setup.py,pyproject.toml, or equivalent) and add an entry in theentry_pointssection.For example, to add a flowsheet defined in
watertap/flowsheets/flowsheets/my_flowsheet.pyso that it can be discovered with the namemy_flowsheetwherever thewatertappackage is installed, the following should be added to WaterTAP’ssetup.py:setup( name="watertap", # other setup() sections entry_points={ "watertap.flowsheets": [ # other flowsheet entry points "my_flowsheet = watertap.flowsheets.flowsheets.my_flowsheet", ] } )
- Parameters:
group_name – The entry_points group from which the flowsheet interface modules will be populated.
- Returns:
Mapping with keys the module names and values FlowsheetInterface objects
- classmethod from_module(module: str | types.ModuleType) FlowsheetInterface | None
Get a a flowsheet interface for module.
- Parameters:
module – The module
- Returns:
A flowsheet interface or None if it failed
- report(rtype=_KPI_REPORT, **kwargs: object) FlowsheetReport
Generate and return a report for the flowsheet.
- Parameters:
report_type – Type of report to generate (any unique prefix of the report type).
kwargs – Additional keywords passed to the given report type.
- Raises:
ValueError – If a report argument is invalid
- Returns:
A flowsheet report, which will display automatically in Jupyter Notebooks.
- Return type:
- idaes_flowsheet_processor.api.WAFFLE
- idaes_flowsheet_processor.api.DONUT
- class idaes_flowsheet_processor.api.FlowsheetKPIReport(flowsheet_export: FlowsheetExport, total_type: _ChartTypes | None = None, bgcolor: str = '#ffffff', **kwargs: object)
Report of the Key Performance Indicators (KPIs) for a flowsheet.
The specification of the report is extracted from the FlowsheetExport object that is passed to the class constructor.
- VALUE_FONT_NAME_SIZE = '150%'
- VALUE_FONT_VAL_SIZE = '180%'
- VALUE_FONT_NAME_COLOR = '#666'
- VALUE_FONT_VAL_COLOR = '#66F'
- VALUE_SEP_WIDTH = '7px'
- to_html(layout: Any | None = None, **kwargs: object) str
Build the report and return as a complete <HTML> element.
- Parameters:
layout – Layout specification. See
Layoutfor format. If not given, lay out in one column.kwargs – Options for the create_* methods.
- Returns:
HTML for the report
- get_kpi_figures(**kwargs: object) dict[str, plotly.graph_objects.Figure]
“Get figures for each KPI.
- Parameters:
kwargs – Options for the create_* methods.
Returns:
- classmethod create_kpi_values(kpi, font_size: int = 24, width: int = 800, margin: int | None = None, **ignore: object) plotly.graph_objects.Figure
Create a table with values for each KPI.
- Parameters:
kpi
font_size – Font size for the table, in points
width – Width of the table in pixels
margin – Margin around the table, as a dict with keys ‘t’, ‘b’, ‘l’, ‘r’. Values in pixels.
- Returns:
Plotly Figure object with values in a table
- classmethod create_kpi_barchart(kpi: KPI, **ignore: object) plotly.graph_objects.Figure
Create a barchart from a vector of values
- Parameters:
kpi – Key performance indicator
- Returns:
Plotly Figure object with the bar chart
- classmethod create_kpi_total(kpi: KPI, total_type: _ChartTypes = WAFFLE, **ignore: object) plotly.graph_objects.Figure
Create diagram for a vector that should be represented as parts of a total. This will be either a pie (donut) chart or waffle chart.
- Parameters:
kpi – Key performance indicator
- Returns:
Plotly Figure object with the pie or waffle chart
- class idaes_flowsheet_processor.api.Layout(spec, kpis: dict[str, str])
Translate a simple layout specification into an HTML flex layout.
The specification takes the form of a (possibly nested) list of names of the KPIs to display, where the outer list is a single column and the next level are rows, then columns within each row, etc.
Some examples:
[ “kpi_one”, “kpi_two”, “kpi_three” ] will display 4 rows, each the full column width.
[[“kpi_one”, “kpi_two”, “kpi_three”]] will display 1 row with items laid out horizontally
[[“kpi_one”, “kpi_two”], [“kpi_three”, “kpi_four”]] will display a 2x2 grid
- property body
- property css