Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
needs: code-formatting
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
python-version: ["3.11", "3.12", "3.13", "3.14"]

steps:
- name: Set up Conda environment
Expand Down
10 changes: 10 additions & 0 deletions addheader.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Usage:
# addheader -c addheader.yml
---
root: src
text: file_header.txt
patterns:
- "*.py"
verbose: 1
sep-len: 80
...
2 changes: 1 addition & 1 deletion docs/api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@
"source": [
"\n",
"See the pre-defined actions in the\n",
"{py:mod}`runner_actions <idaes_fi.structfs.runner_actions>`\n",
"{py:mod}`actions <idaes_fi.structfs.actions>`\n",
"module, and their usage in the {py:class}`FlowsheetRunner <idaes_fi.structfs.fsrunner.FlowsheetRunner>` \n",
"class, for more examples."
]
Expand Down
14 changes: 14 additions & 0 deletions file_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Process Optimization and Modeling for Minerals Sustainability (PrOMMiS) Copyright (c) 2023-2026

“Process Optimization and Modeling for Minerals Sustainability (PrOMMiS)” was produced under the DOE
Process Optimization and Modeling for Minerals Sustainability (“PrOMMiS”) initiative, and is
copyrighted by the software owners: The Regents of the University of California, through Lawrence
Berkeley National Laboratory, National Technology & Engineering Solutions of Sandia, LLC through
Sandia National Laboratories, Carnegie Mellon University, University of Notre Dame, and West
Virginia University Research Corporation.

NOTICE. This Software was developed under funding from the U.S. Department of Energy and the
U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted
for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license
in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
publicly and display publicly, and to permit other to do so.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ build-backend = "setuptools.build_meta"
[project]
name = "idaes-fi"
version = "0.1.0"
description = "Library modules and API for the IDAES Flowsheet Inspector user interface."
description = "Library modules and API for the Flowsheet Inspector user interface."
readme = "README.md"
requires-python = ">=3.10"
license = { file = "LICENSE.md" }
authors = [
{ name = "PrOMMiS contributors" },
]
keywords = ["idaes", "flowsheet", "process-modeling"]
keywords = ["idaes", "prommis", "flowsheet", "process-modeling"]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]

dependencies = [
Expand Down
17 changes: 17 additions & 0 deletions src/idaes_fi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#################################################################################
# Process Optimization and Modeling for Minerals Sustainability (PrOMMiS) Copyright (c) 2023-2026
#
# “Process Optimization and Modeling for Minerals Sustainability (PrOMMiS)” was produced under the DOE
# Process Optimization and Modeling for Minerals Sustainability (“PrOMMiS”) initiative, and is
# copyrighted by the software owners: The Regents of the University of California, through Lawrence
# Berkeley National Laboratory, National Technology & Engineering Solutions of Sandia, LLC through
# Sandia National Laboratories, Carnegie Mellon University, University of Notre Dame, and West
# Virginia University Research Corporation.
#
# NOTICE. This Software was developed under funding from the U.S. Department of Energy and the
# U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted
# for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license
# in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
# publicly and display publicly, and to permit other to do so.
#
#################################################################################
"""Top-level package for idaes-fi."""

__all__ = ["__version__"]
Expand Down
27 changes: 16 additions & 11 deletions src/idaes_fi/compute_diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# -*- coding: utf-8 -*-
#################################################################################
# The Institute for the Design of Advanced Energy Systems Integrated Platform
# Framework (IDAES IP) was produced under the DOE Institute for the
# Design of Advanced Energy Systems (IDAES).
# Process Optimization and Modeling for Minerals Sustainability (PrOMMiS) Copyright (c) 2023-2026
#
# “Process Optimization and Modeling for Minerals Sustainability (PrOMMiS)” was produced under the DOE
# Process Optimization and Modeling for Minerals Sustainability (“PrOMMiS”) initiative, and is
# copyrighted by the software owners: The Regents of the University of California, through Lawrence
# Berkeley National Laboratory, National Technology & Engineering Solutions of Sandia, LLC through
# Sandia National Laboratories, Carnegie Mellon University, University of Notre Dame, and West
# Virginia University Research Corporation.
#
# NOTICE. This Software was developed under funding from the U.S. Department of Energy and the
# U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted
# for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license
# in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
# publicly and display publicly, and to permit other to do so.
#
# Copyright (c) 2018-2026 by the software owners: The Regents of the
# University of California, through Lawrence Berkeley National Laboratory,
# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon
# University, West Virginia University Research Corporation, et al.
# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md
# for full copyright and license information.
#################################################################################
"""
Compute diagnostics values and return as Pydantic data models.
Expand Down Expand Up @@ -352,7 +357,7 @@ def all_as_obj(self) -> dict[str, BaseModel]:
"""Same as `all_as_dict` except each top-level value is an object instead of a dict.

Note that the keys returned here should match the attributes
of `idaes_fi.structfs.runner_actions.Diagnostics.Report`.
of `idaes_fi.structfs.actions.Diagnostics.Report`.

Returns:
dict: Diagnostics data with string keys and Pydantic model object values
Expand Down Expand Up @@ -545,7 +550,7 @@ def _set_variables(
if un_func is None:
u = str(v.get_units())
# replace 'None' with an empty string
# -- to match `runner_actions.ModelVariables`
# -- to match `actions.ModelVariables`
if u == "None":
u = ""
else:
Expand Down
23 changes: 14 additions & 9 deletions src/idaes_fi/gitutil.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#################################################################################
# The Institute for the Design of Advanced Energy Systems Integrated Platform
# Framework (IDAES IP) was produced under the DOE Institute for the
# Design of Advanced Energy Systems (IDAES).
# Process Optimization and Modeling for Minerals Sustainability (PrOMMiS) Copyright (c) 2023-2026
#
# “Process Optimization and Modeling for Minerals Sustainability (PrOMMiS)” was produced under the DOE
# Process Optimization and Modeling for Minerals Sustainability (“PrOMMiS”) initiative, and is
# copyrighted by the software owners: The Regents of the University of California, through Lawrence
# Berkeley National Laboratory, National Technology & Engineering Solutions of Sandia, LLC through
# Sandia National Laboratories, Carnegie Mellon University, University of Notre Dame, and West
# Virginia University Research Corporation.
#
# NOTICE. This Software was developed under funding from the U.S. Department of Energy and the
# U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted
# for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license
# in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
# publicly and display publicly, and to permit other to do so.
#
# Copyright (c) 2018-2026 by the software owners: The Regents of the
# University of California, through Lawrence Berkeley National Laboratory,
# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon
# University, West Virginia University Research Corporation, et al.
# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md
# for full copyright and license information.
#################################################################################
"""
Git utility code
Expand Down
17 changes: 17 additions & 0 deletions src/idaes_fi/scripts/copy_template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
#!/usr/bin/env python3
#################################################################################
# Process Optimization and Modeling for Minerals Sustainability (PrOMMiS) Copyright (c) 2023-2026
#
# “Process Optimization and Modeling for Minerals Sustainability (PrOMMiS)” was produced under the DOE
# Process Optimization and Modeling for Minerals Sustainability (“PrOMMiS”) initiative, and is
# copyrighted by the software owners: The Regents of the University of California, through Lawrence
# Berkeley National Laboratory, National Technology & Engineering Solutions of Sandia, LLC through
# Sandia National Laboratories, Carnegie Mellon University, University of Notre Dame, and West
# Virginia University Research Corporation.
#
# NOTICE. This Software was developed under funding from the U.S. Department of Energy and the
# U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted
# for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license
# in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
# publicly and display publicly, and to permit other to do so.
#
#################################################################################
"""
Instantiate model from template
"""
Expand Down
23 changes: 14 additions & 9 deletions src/idaes_fi/structfs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#################################################################################
# The Institute for the Design of Advanced Energy Systems Integrated Platform
# Framework (IDAES IP) was produced under the DOE Institute for the
# Design of Advanced Energy Systems (IDAES).
# Process Optimization and Modeling for Minerals Sustainability (PrOMMiS) Copyright (c) 2023-2026
#
# “Process Optimization and Modeling for Minerals Sustainability (PrOMMiS)” was produced under the DOE
# Process Optimization and Modeling for Minerals Sustainability (“PrOMMiS”) initiative, and is
# copyrighted by the software owners: The Regents of the University of California, through Lawrence
# Berkeley National Laboratory, National Technology & Engineering Solutions of Sandia, LLC through
# Sandia National Laboratories, Carnegie Mellon University, University of Notre Dame, and West
# Virginia University Research Corporation.
#
# NOTICE. This Software was developed under funding from the U.S. Department of Energy and the
# U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted
# for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license
# in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
# publicly and display publicly, and to permit other to do so.
#
# Copyright (c) 2018-2026 by the software owners: The Regents of the
# University of California, through Lawrence Berkeley National Laboratory,
# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon
# University, West Virginia University Research Corporation, et al.
# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md
# for full copyright and license information.
#################################################################################

import logging
Expand Down
23 changes: 14 additions & 9 deletions src/idaes_fi/structfs/action_base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#################################################################################
# The Institute for the Design of Advanced Energy Systems Integrated Platform
# Framework (IDAES IP) was produced under the DOE Institute for the
# Design of Advanced Energy Systems (IDAES).
# Process Optimization and Modeling for Minerals Sustainability (PrOMMiS) Copyright (c) 2023-2026
#
# “Process Optimization and Modeling for Minerals Sustainability (PrOMMiS)” was produced under the DOE
# Process Optimization and Modeling for Minerals Sustainability (“PrOMMiS”) initiative, and is
# copyrighted by the software owners: The Regents of the University of California, through Lawrence
# Berkeley National Laboratory, National Technology & Engineering Solutions of Sandia, LLC through
# Sandia National Laboratories, Carnegie Mellon University, University of Notre Dame, and West
# Virginia University Research Corporation.
#
# NOTICE. This Software was developed under funding from the U.S. Department of Energy and the
# U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted
# for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license
# in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
# publicly and display publicly, and to permit other to do so.
#
# Copyright (c) 2018-2026 by the software owners: The Regents of the
# University of California, through Lawrence Berkeley National Laboratory,
# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon
# University, West Virginia University Research Corporation, et al.
# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md
# for full copyright and license information.
#################################################################################
"""
Base class for runner actions.
Expand Down
62 changes: 62 additions & 0 deletions src/idaes_fi/structfs/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#################################################################################
# Process Optimization and Modeling for Minerals Sustainability (PrOMMiS) Copyright (c) 2023-2026
#
# “Process Optimization and Modeling for Minerals Sustainability (PrOMMiS)” was produced under the DOE
# Process Optimization and Modeling for Minerals Sustainability (“PrOMMiS”) initiative, and is
# copyrighted by the software owners: The Regents of the University of California, through Lawrence
# Berkeley National Laboratory, National Technology & Engineering Solutions of Sandia, LLC through
# Sandia National Laboratories, Carnegie Mellon University, University of Notre Dame, and West
# Virginia University Research Corporation.
#
# NOTICE. This Software was developed under funding from the U.S. Department of Energy and the
# U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted
# for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license
# in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
# publicly and display publicly, and to permit other to do so.
#
#################################################################################

"""Runner action implementations."""

from importlib import import_module

__all__ = [
"CaptureSolverOutput",
"Diagnostics",
"GetSolverResults",
"MermaidDiagram",
"ModelVariables",
"SolverActionBase",
"SolverResult",
"StreamTable",
"Timer",
"UnitDofChecker",
"UnitDofType",
]

_EXPORT_MODULES = {
"CaptureSolverOutput": "solver",
"Diagnostics": "solver",
"GetSolverResults": "solver",
"MermaidDiagram": "mermaid_diagram",
"ModelVariables": "model_variables",
"SolverActionBase": "solver",
"SolverResult": "solver",
"StreamTable": "stream_table",
"Timer": "timer",
"UnitDofChecker": "unit_dof_checker",
"UnitDofType": "unit_dof_checker",
}


# Lazy-load allows you to not install dependencies
# for actions that you never import and use
def __getattr__(name):
try:
module_name = _EXPORT_MODULES[name]
except KeyError as err:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from err
module = import_module(f".{module_name}", __name__)
value = getattr(module, name)
globals()[name] = value
return value
87 changes: 87 additions & 0 deletions src/idaes_fi/structfs/actions/mermaid_diagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#################################################################################
# Process Optimization and Modeling for Minerals Sustainability (PrOMMiS) Copyright (c) 2023-2026
#
# "Process Optimization and Modeling for Minerals Sustainability (PrOMMiS)" was produced under the DOE
# Process Optimization and Modeling for Minerals Sustainability ("PrOMMiS") initiative, and is
# copyrighted by the software owners: The Regents of the University of California, through Lawrence
# Berkeley National Laboratory, National Technology & Engineering Solutions of Sandia, LLC through
# Sandia National Laboratories, Carnegie Mellon University, University of Notre Dame, and West
# Virginia University Research Corporation.
#
# NOTICE. This Software was developed under funding from the U.S. Department of Energy and the
# U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted
# for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license
# in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
# publicly and display publicly, and to permit other to do so.
#
#################################################################################
"""Mermaid diagram action."""

from pydantic import BaseModel

from ..action_base import Action

try:
from idaes_connectivity.base import Connectivity, Mermaid
except ImportError:
Connectivity = None


class MermaidDiagram(Action):
"""Action to generate a Mermaid diagram after the run."""

class Report(BaseModel):
"""Report containing a Mermaid diagram."""

diagram: list[str] #: each item is one line

def __init__(self, runner, **kwargs):
"""Initialize Mermaid diagram generation settings.

Args:
runner: Runner that owns this action.
**kwargs: Additional keyword arguments passed to `Action`.
"""
super().__init__(runner, **kwargs)
self._images = False # TODO: make this configurable
self._model_root_split = []
self.diagram = None

def show_unit_images(self, value: bool):
"""Whether Mermaid displays images for units.

Args:
value: If true, display images. Otherwise, don't.
"""
self._images = bool(value)

def set_model_root(self, path: str):
"""Set path to root of model to display (default is model itself).

Args:
path: Dotted path like "fs" or "fs.component"
"""
self._model_root_split = path.split(".")

def after_run(self):
"""Build Mermaid diagram after the run."""
if Connectivity is None:
self.diagram = None
else:
root = self._runner.model
for p in self._model_root_split:
root = getattr(root, p)
conn = Connectivity(input_model=root)
self.diagram = Mermaid(conn, component_images=self._images)

def report(self) -> Report | dict:
"""Report containing the Mermaid diagram.

Returns:
Report object if idaes_connectivity is active, otherwise
an empty dictionary
"""
if self.diagram is None:
return {}
mermaid_lines = self.diagram.write(None).split("\n")
return self.Report(diagram=mermaid_lines)
Loading
Loading