Skip to content

Commit

Permalink
Merge branch 'main' into add-prescient
Browse files Browse the repository at this point in the history
  • Loading branch information
lbianchi-lbl authored Apr 5, 2022
2 parents 9e0bd9f + 8310071 commit 4c86c6e
Show file tree
Hide file tree
Showing 905 changed files with 149,486 additions and 128,155 deletions.
1 change: 0 additions & 1 deletion .github/actions/run-examples/build-config-for-idaes-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ notebook:
- source: Examples/Advanced/CustomUnitModels
- source: Examples/Advanced/DataRecon
- source: Examples/MatOpt
- source: Examples/SurrMod/ALAMO
- source: Examples/SurrMod/Helmet
- source: Examples/SurrMod/PySMO
- source: Examples/Tools
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
run: |
which python
cd docs/
python build.py
python build.py --timeout 600
- name: Publish built docs
uses: actions/upload-artifact@v2
with:
Expand Down
38 changes: 29 additions & 9 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ jobs:
cat *errors.txt || echo "No error logs found"
pytest-site-packages:
name: Run tests from site-packages (non-editable) installation
name: Run tests from site-packages (non-editable) installation (${{ matrix.install-mode }})
# NOTE: using ubuntu-latest (20.04) instead of 18.04 results in failures in power_generation/carbon_capture/mea_solvent_system/unit_models/tests/test_column.py
runs-on: ubuntu-18.04
needs: [precheck]
Expand All @@ -203,6 +203,21 @@ jobs:
|| needs.precheck.outputs.workflow-trigger == 'not_pr'
|| needs.precheck.outputs.workflow-trigger == 'approved_pr'
)
strategy:
fail-fast: false
matrix:
install-mode:
- pip-default
- pip-optional
- conda-like
include:
- install-mode: pip-default
pip-install-target: '.'
- install-mode: pip-optional
pip-install-target: .[optional]
- install-mode: conda-like
pip-install-target: '.'
dependencies-to-uninstall: omlt
steps:
- uses: actions/checkout@v2
- name: Set up Conda environment
Expand All @@ -213,13 +228,18 @@ jobs:
- name: Set up idaes (non-editable installation)
uses: ./.github/actions/setup-idaes
with:
install-target: '.[optional]'
- name: Install test dependencies and run pytest in empty directory
install-target: ${{ matrix.pip-install-target }}
- name: Remove dependencies installable with pip but not with conda
# NOTE some dependencies that are installed by default with pip are not available through conda
# so they're not installed if IDAES is installed with `conda -c conda-forge -c IDAES-PSE idaes-pse`
# to ensure this scenario is handled properly, since we don't have (yet) the conda-build process integrated with the CI,
# we manually remove the "pip-but-not-conda" dependencies after installing with pip
# as an approximation of the enviroment that we'd get from `conda install`
if: matrix.dependencies-to-uninstall
run: |
pip uninstall --yes ${{ matrix.dependencies-to-uninstall }}
- name: Install and run pytest in empty directory
run: |
pushd "$(mktemp -d)"
# TODO this could be an optional [testing] dependency
pip install pytest addheader
# TODO downloading pytest.ini is still needed for the tests to pass
# eventually it will be moved to the root conftest.py so that is installed as Python code
wget https://raw.githubusercontent.com/IDAES/idaes-pse/main/pytest.ini
pytest --pyargs idaes
pip install pytest
pytest --pyargs idaes -W ignore -rs
67 changes: 55 additions & 12 deletions .pylint/idaes_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
See #1159 for more information.
"""
from dataclasses import dataclass
import sys
import functools
import logging
import time
import typing

import astroid
import pylint
from astroid.builder import extract_node, parse


Expand All @@ -21,21 +23,53 @@
_display = _notify = lambda *a, **kw: None


REFERENCE_PYLINT_VERSION = '2.8.3'
def _suppress_inference_errors(max_inferred=500) -> None:
"""
Increasing this number to suppress inference errors causing false-positives in e.g. pandas.read_csv().
The value 500 is a sufficiently high number but otherwise arbitrary.
See https://github.com/PyCQA/pylint/issues/4577 for more information.
"""
astroid.context.InferenceContext.max_inferred = int(max_inferred)


def _check_version_compatibility():
_suppress_inference_errors()

from pylint import __version__
if __version__ != REFERENCE_PYLINT_VERSION:
cmd_to_install = f"pip install pylint=={REFERENCE_PYLINT_VERSION}"
msg = (
f"WARNING: this plugin's reference version is {REFERENCE_PYLINT_VERSION}, "
f"but the currently installed pylint version is {__version__}. "
"This is not necessarily a problem; "
f"however, in case of issues, try installing the reference version using {cmd_to_install}"

@dataclass
class VersionCompat:
distr_name: str
expected: str
actual: str

@property
def cmd_to_install(self) -> str:
return f"pip install {self.distr_name}=={self.expected}"


def _check_version_compatibility() -> None:

to_check = [
VersionCompat(
distr_name="pylint",
expected="2.12.2",
actual=pylint.__version__,
),
VersionCompat(
distr_name="astroid",
expected="2.9.3",
actual=astroid.__version__,
)
print(msg, file=sys.stderr)
]

for v in to_check:
if v.actual != v.expected:
msg = (
f"WARNING: this plugin's reference version for {v.distr_name} is {v.expected}, "
f"but the currently installed version for is {v.actual}. "
"This is not necessarily a problem; "
f"however, in case of issues, try installing the reference version using {v.cmd_to_install}"
)
print(msg, file=sys.stderr)


def has_declare_block_class_decorator(cls_node, decorator_name="declare_process_block_class"):
Expand All @@ -56,7 +90,16 @@ def has_declare_block_class_decorator(cls_node, decorator_name="declare_process_
@functools.lru_cache(maxsize=1)
def get_base_class_node():
_notify('Getting base class node')
import_node = extract_node('from idaes.core.process_block import ProcessBlock; ProcessBlock')
pb_def = """
import idaes.core.base.process_block.ProcessBlock
class ProcessBlock(idaes.core.base.process_block.ProcessBlock):
# creating a stub for the __getitem__() method returning the uninferable object
# causes pylint to stop further checks on objects returned when calling [] on a derived class
# see e.g. https://github.com/PyCQA/astroid/blob/main/astroid/brain/brain_numpy_ndarray.py
# for another example of how this can be extended to create "uninferability stubs" for other methods
def __getitem__(self, *args): return uninferable
"""
import_node = astroid.extract_node(pb_def)
cls_node = next(import_node.infer())
return cls_node

Expand Down
1 change: 1 addition & 0 deletions .pylint/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
init-hook="import sys; sys.path.append('.pylint')"
load-plugins=idaes_transform
ignore-patterns=test_.*
ignore-paths=^idaes/apps/.*$,

[MESSAGES CONTROL]
disable=no-self-argument,
Expand Down
41 changes: 19 additions & 22 deletions docs/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,23 @@ def run_html(clean=True, vb=0, timeout=0, dry_run=False, nprocs=1, **kwargs):
shutil.rmtree(build_dir)
if os.path.exists(output_file):
os.unlink(output_file)
# run
if vb > 0:
verbosity = "-" + "v" * vb
else:
verbosity = "-q"
if nprocs <= 0:
nprocs_arg = "-j auto"
elif nprocs == 1:
nprocs_arg = ""
else:
nprocs_arg = f"-j {nprocs}"
args = [
"sphinx-build",
"-M",
"html",
"-M", "html",
".",
build_dir,
"-w",
output_file,
nprocs_arg,
verbosity,
"-w", output_file
]
# run
verbosity = "-q" if vb <= 0 else "-" + "v" * vb
args.append(verbosity)

if nprocs <= 0:
args.append("-j auto")
elif nprocs > 1:
args.append(f"-j {nprocs}")
# if nprocs == 1, do not specify "-j" args and fall back to sphinx-build's default

print_status(f"Run: {' '.join(args)}")
_run("html", args, timeout, dry_run)
if dry_run:
Expand Down Expand Up @@ -153,14 +148,16 @@ def _run(what, args, timeout, not_really):
return
_log.debug(f"command={command_line}")
try:
proc = subprocess.Popen(args)
res = subprocess.run(args, check=True, timeout=timeout)
except subprocess.TimeoutExpired:
raise CommandError(what, f"Timed out after {timeout} seconds")
except subprocess.CalledProcessError as e:
raise CommandError(what, f"Exited with nonzero exit code {e.returncode}")
except Exception as err:
exe = args[0]
raise CommandError(what, f"Could not run '{exe}':\n{err}")
try:
proc.wait(timeout)
except subprocess.TimeoutExpired:
raise CommandError(what, f"Timed out after {timeout} seconds")
else:
print_status(f"{what} completed with exit code {res.returncode}")


def print_header(msg: str, first: bool = False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ When using the general cubic equation of state module, users must specify the ty

.. code-block:: python
from idaes.generic_models.properties.core.eos.ceos import Cubic, CubicType
from idaes.models.properties.core.eos.ceos import Cubic, CubicType
configuration = {
"phases": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The `stoichiometry` configuration argument is used to define which components ta
Concentration Form
^^^^^^^^^^^^^^^^^^

Many common rate forms can be written using a number of different bases, such as molarity, molality or partial pressure. The `concentration_form` configuration argument is used in these cases to determine what basis to use for the concentration terms in the rate form and automatically write the correct expression (and determine units for the associated parameters. The `concentration_form` configuration argument must be an instance of a `ConcentrationForm` `Enum` (imported from idaes.generic_models.properties.core.generic.utility), and the following forms are currently available:
Many common rate forms can be written using a number of different bases, such as molarity, molality or partial pressure. The `concentration_form` configuration argument is used in these cases to determine what basis to use for the concentration terms in the rate form and automatically write the correct expression (and determine units for the associated parameters. The `concentration_form` configuration argument must be an instance of a `ConcentrationForm` `Enum` (imported from idaes.models.properties.core.generic.utility), and the following forms are currently available:

* molarity: ConcentrationForm.molarity
* activity: ConcentrationForm.activity
Expand Down
4 changes: 2 additions & 2 deletions docs/reference_guides/core/process_block.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ The core part of any IDAES Block is the build method, which contains the instruc
ProcessBlock Class
------------------

.. module:: idaes.core.process_block
.. module:: idaes.core.base.process_block

.. autofunction:: declare_process_block_class

.. autoclass:: ProcessBlock
:members:

.. module:: idaes.core.process_base
.. module:: idaes.core.base.process_base

.. autoclass:: ProcessBlockData
:members:
27 changes: 7 additions & 20 deletions docs/reference_guides/core/solvers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,9 @@ Installing PETSc
~~~~~~~~~~~~~~~~

The PETSc solver is an extra binary package, and not installed by default. If
you are using a supported Linux distribution, you can use the command
you are using a supported platform, you can use the command
``idaes get-extensions --extra petsc`` to install it.

There is no precompiled PETSc solver for Windows, but here are two options for
Windows installation. The easiest option is to run the available precompiled
Linux version via the WSL
(see :ref:`binary installation <tutorials/getting_started/binaries:Using the WSL>`
for details). Expert users may wish to compile their own solver. Source code is
available in the `idaes-ext repo <https://github.com/IDAES/idaes-ext/tree/main/petsc>`_.
If you can compile PETSc for Windows, compiling the interface is trivial (see
`PETSc's windows installation documentation <https://petsc.org/main/install/windows/>`_).

The IDAES PETSc package also includes Python modules for reading binary data
written by the PETSc solver. On Windows, some manual installation of the Python
modules is required. If you are using the WSL method to run PETSc, copy the
``petscpy`` directory from the Linux package you are using to the IDAES binary
directory. You can find the IDAES binary directory by running the command
``idaes bin-directory`` in the OS command shell (e.g. Bash, Windows CMD,
PowerShell). If IDAES is installed in a Python environment, the environment
must be active. The primary use for these Python modules is to read trajectory
files saved by the TS solver.

Registered Solvers
~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -192,6 +173,12 @@ The following function can be used to solve the DAE.

.. autofunction:: idaes.core.solvers.petsc.petsc_dae_by_time_element

Derivative values aren't returned by the PETSc solver, but they can be calculated
from the discretization equations written by Pyomo.DAE. The following function can
be used to calculate time derivatives.

.. autofunction:: idaes.core.solvers.petsc.calculate_time_derivatives

Reading Trajectory Data
"""""""""""""""""""""""

Expand Down
4 changes: 2 additions & 2 deletions docs/reference_guides/core/util/unit_costing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ Below is a simple example of how to add cost correlations to a flowsheet includi
from pyomo.environ import (ConcreteModel, SolverFactory)
from pyomo.util.calc_var_value import calculate_variable_from_constraint
from idaes.core import FlowsheetBlock
from idaes.generic_models.unit_models.heat_exchanger import \
from idaes.models.unit_models.heat_exchanger import \
(HeatExchanger, HeatExchangerFlowPattern)
from idaes.generic_models.properties import iapws95
from idaes.models.properties import iapws95
from idaes.core.util.model_statistics import degrees_of_freedom
m = ConcreteModel()
Expand Down
10 changes: 5 additions & 5 deletions docs/reference_guides/model_libraries/generic/control/pid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Proportional-Integral-Derivative (PID) Controller
=================================================

.. index::
pair: idaes.generic_models.control.controller; Proportional-Integral-Derivative (PID) Controller
pair: idaes.models.control.controller; Proportional-Integral-Derivative (PID) Controller

.. currentmodule:: idaes.generic_models.control.controller
.. currentmodule:: idaes.models.control.controller

The IDAES framework contains a basic PID control implementation, which is described
in this section.
Expand All @@ -25,10 +25,10 @@ file "pid_steam_tank_pressure.pdf."
import pyomo.environ as pyo
from pyomo.network import Arc
from idaes.core import FlowsheetBlock, MaterialBalanceType
from idaes.generic_models.unit_models import Heater, Valve
from idaes.generic_models.properties import iapws95
from idaes.models.unit_models import Heater, Valve
from idaes.models.properties import iapws95
from idaes.core.util.initialization import propagate_state
from idaes.generic_models.control.controller import (
from idaes.models.control.controller import (
PIDController,
ControllerType,
ControllerMVBoundType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Initialization

Config Block Documentation
--------------------------
.. module:: idaes.generic_models.properties.activity_coeff_models.activity_coeff_prop_pack
.. module:: idaes.models.properties.activity_coeff_models.activity_coeff_prop_pack

.. autoclass:: ActivityCoeffParameterBlock
:members:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ List of Parameters

Config Block Documentation
--------------------------
.. module:: idaes.generic_models.properties.cubic_eos.cubic_prop_pack
.. module:: idaes.models.properties.cubic_eos.cubic_prop_pack

.. autoclass:: CubicParameterData
:members:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Pure Component Helmholtz EoS
============================

.. index::
pair: idaes.generic_models.properties.helmholtz.helmholtz; HelmholtzStateBlock
pair: idaes.models.properties.helmholtz.helmholtz; HelmholtzStateBlock

.. module:: idaes.generic_models.properties.helmholtz.helmholtz
.. module:: idaes.models.properties.helmholtz.helmholtz

The Helmholtz Equation of State (EoS) classes serve as a common core for pure
component property packages where very accurate and thermodynamically consistent
Expand Down
Loading

0 comments on commit 4c86c6e

Please sign in to comment.