Skip to content

Commit

Permalink
Merge branch 'main' into update_dl_doc
Browse files Browse the repository at this point in the history
  • Loading branch information
adowling2 authored Feb 16, 2023
2 parents 3074b65 + b30c054 commit 8367219
Show file tree
Hide file tree
Showing 18 changed files with 1,357 additions and 314 deletions.
3 changes: 3 additions & 0 deletions docs/explanations/modeling_extensions/diagnostics/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ Degeneracy Hunter
Degeneracy Hunter is a collection of tools for diagnostics of mathematical programs. The core ideas behind Degeneracy Hunter are explained here: https://www.sciencedirect.com/science/article/pii/B9780444635785501304

Degeneracy Hunter is currently included in IDAES for beta testing purposes. This page will be updated as part of the official release. If you would like to help test Degeneracy Hunter, please look at the example notebook available here: https://github.com/IDAES/examples-pse/pull/21 Please report any thoughts, questions or bugs to: adowling@nd.edu

Full documentation of the available methods can be :ref:`found here<reference_guides/core/util/model_diagnostics:Degeneracy Hunter>`.

1 change: 1 addition & 0 deletions docs/reference_guides/core/util/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
dyn_utils
initialization
misc
model_diagnostics
model_serializer
model_statistics
phase_equilibria
Expand Down
22 changes: 22 additions & 0 deletions docs/reference_guides/core/util/model_diagnostics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Model Diagnostic Functions
==========================

The IDAES toolset contains a number of utility functions which can be useful for identifying modeling issues and debugging solver issues.

.. contents:: Contents
:depth: 2

Degeneracy Hunter
^^^^^^^^^^^^^^^^^

.. autoclass:: idaes.core.util.model_diagnostics.DegeneracyHunter
:members:


Available Methods
^^^^^^^^^^^^^^^^^

.. automodule:: idaes.core.util.model_diagnostics
:exclude-members: DegeneracyHunter
:members:

42 changes: 21 additions & 21 deletions idaes/apps/uncertainty_propagation/tests/test_uncertainties.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,31 @@
# Please see the files COPYRIGHT.md and LICENSE.md for full copyright and
# license information.
#################################################################################
import sys
import os
from unittest.mock import patch

sys.path.append(os.path.abspath("..")) # current folder is ~/tests
import numpy as np
import pandas as pd
from scipy import sparse
import pytest
from pytest import approx

from pyomo.environ import (
ConcreteModel,
Constraint,
exp,
Objective,
SolverFactory,
Suffix,
Var,
)
import pyomo.contrib.parmest.parmest as parmest

from idaes.apps.uncertainty_propagation.uncertainties import (
quantify_propagate_uncertainty,
propagate_uncertainty,
clean_variable_name,
)
from pyomo.opt import SolverFactory
from pyomo.environ import *
import pyomo.contrib.parmest.parmest as parmest

ipopt_available = SolverFactory("ipopt").available()
kaug_available = SolverFactory("k_aug").available()
dotsens_available = SolverFactory("dot_sens").available()
ipopt_available = SolverFactory("ipopt").available(exception_flag=False)
kaug_available = SolverFactory("k_aug").available(exception_flag=False)
dotsens_available = SolverFactory("dot_sens").available(exception_flag=False)


@pytest.mark.skipif(not ipopt_available, reason="The 'ipopt' command is not available")
Expand Down Expand Up @@ -67,7 +70,7 @@ def SSE(model, data):
rooney_biegler_model, rooney_biegler_model_opt, data, variable_name, SSE
)

assert results.obj == approx(4.331711213656886)
assert results.obj == pytest.approx(4.331711213656886, abs=1e-8, rel=1e-8)
np.testing.assert_array_almost_equal(
results.theta, [19.142575284617866, 0.53109137696521]
)
Expand All @@ -80,7 +83,9 @@ def SSE(model, data):
np.testing.assert_array_almost_equal(
results.cov, np.array([[6.30579403, -0.4395341], [-0.4395341, 0.04193591]])
)
assert results.propagation_f == pytest.approx(5.45439337747349)
assert results.propagation_f == pytest.approx(
5.45439337747349, abs=1e-8, rel=1e-8
)

@pytest.mark.component
def test_quantify_propagate_uncertainty2(self):
Expand Down Expand Up @@ -111,14 +116,13 @@ def SSE(model, data):
model_uncertain.obj = Objective(
expr=model_uncertain.asymptote
* (1 - exp(-model_uncertain.rate_constant * 10)),
sense=minimize,
)

results = quantify_propagate_uncertainty(
rooney_biegler_model, model_uncertain, data, variable_name, SSE
)

assert results.obj == approx(4.331711213656886)
assert results.obj == pytest.approx(4.331711213656886, abs=1e-8, rel=1e-8)
np.testing.assert_array_almost_equal(
results.theta, [19.142575284617866, 0.53109137696521]
)
Expand Down Expand Up @@ -165,7 +169,6 @@ def SSE(model, data):
model_uncertain.obj = Objective(
expr=model_uncertain.asymptote
* (1 - exp(-model_uncertain.rate_constant * 10)),
sense=minimize,
)

propagate_results = propagate_uncertainty(
Expand Down Expand Up @@ -215,9 +218,7 @@ def test_propagate_uncertainty1(self):
m.con2 = Constraint(expr=m.x2 + m.x3 - m.p2 == 0)

# Define objective
m.obj = Objective(
expr=m.p1 * m.x1 + m.p2 * (m.x2**2) + m.p1 * m.p2, sense=minimize
)
m.obj = Objective(expr=m.p1 * m.x1 + m.p2 * (m.x2**2) + m.p1 * m.p2)

### Solve optimization model
opt = SolverFactory("ipopt", tee=True)
Expand Down Expand Up @@ -422,7 +423,6 @@ def SSE(model, data):
model_uncertain.obj = Objective(
expr=model_uncertain.asymptote
* (1 - exp(-model_uncertain.rate_constant * 10)),
sense=minimize,
)
with pytest.raises(TypeError):
propagate_results = propagate_uncertainty(1, theta, cov, variable_name)
Expand Down
2 changes: 1 addition & 1 deletion idaes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"amd64": "x86_64",
"arm64": "aarch64",
}
# Set of extra binary packages and basic build platforom where available
# Set of extra binary packages and basic build platform where available
extra_binaries = {
"petsc": base_platforms,
}
Expand Down
Loading

0 comments on commit 8367219

Please sign in to comment.