Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyomo doe refactor #3317

Merged
merged 203 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 200 commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
e32f29e
Adding new DoE object and skeleton functions
djlaky Jun 20, 2024
c7a4da0
Refactoring scenario generation
djlaky Jun 20, 2024
6631c48
Further progress on generating FD scenarios
djlaky Jun 20, 2024
9535062
Scenario generator appears to work
djlaky Jun 20, 2024
ea1b2d6
Added a check_model_labels function
djlaky Jun 25, 2024
caa1949
Cleaned and standardized scenario generation
djlaky Jun 25, 2024
37e554b
Fixed forward and backward case for scenario generation
djlaky Jun 25, 2024
125ce85
More cleanup
djlaky Jun 25, 2024
5ba9576
Removed unnecessary function
djlaky Jun 25, 2024
e5d62f3
Updating create model
djlaky Jun 25, 2024
097638d
Added comment
djlaky Jun 25, 2024
1379aba
Added checks for input FIM, jacobian, labels
djlaky Jun 26, 2024
bb26bdf
Update Jacobian representation
djlaky Jun 26, 2024
258ebfd
Added functionality for incoming block-models
djlaky Jun 26, 2024
b13826c
Slight language update for readability
djlaky Jun 26, 2024
c2ffbe5
Slight cleaning
djlaky Jun 26, 2024
516d52c
Updating refactor test functions
djlaky Jun 26, 2024
0644b02
Small typo fix in create_doe_model
djlaky Jun 27, 2024
51026f7
Create objective functionadded
djlaky Jul 1, 2024
c3247e3
Blank space removal
djlaky Jul 1, 2024
4ed74f3
Moved most attributes to constructor
djlaky Jul 1, 2024
7defa33
Updating example to compare against old code
djlaky Jul 1, 2024
bf81b6c
Updated run_doe to perform experimental design
djlaky Jul 1, 2024
eb08ba7
Added FIM prior update function
djlaky Jul 2, 2024
d5a9dbc
Started adding full factorial exploration function.
djlaky Jul 2, 2024
e050d4e
Adding kaug functionality to new interface
djlaky Jul 2, 2024
7e37cc2
Fixed k_aug method for new interface
djlaky Jul 2, 2024
4930c95
Simplified kaug method and added obj cons block
djlaky Jul 3, 2024
2f4c5bd
Added compute_FIM method
djlaky Jul 3, 2024
f136602
Added description for rescale_FIM
djlaky Jul 3, 2024
fc6cbac
Made compute_FIM more flexible
djlaky Jul 3, 2024
5592723
Added full factorial design space exploration
djlaky Jul 3, 2024
5dd133c
Fixed Cholesky bug, added L initiailization
djlaky Jul 4, 2024
6724fbe
Added small check for FIM rescaling function
djlaky Jul 5, 2024
d98ce6a
Added sequential compute_FIM method.
djlaky Jul 5, 2024
45ba264
Merge branch 'Pyomo:main' into pyomo-doe-refactor
djlaky Jul 5, 2024
1b9b08f
Updated grid search
djlaky Jul 5, 2024
14ee132
Made the full factorial return the data structure
djlaky Jul 5, 2024
e2f16d0
Added results object
djlaky Jul 5, 2024
08a9630
Fixed bug in sequential compute FIM
djlaky Jul 6, 2024
5ba54c8
Refactored factorial design plotting function
djlaky Jul 6, 2024
16aa150
Small updates on results and objective naming
djlaky Jul 10, 2024
0822e0d
Removing deprecated code
djlaky Jul 11, 2024
18e3bd2
Updated init.py to remove deprecated dependencies
djlaky Jul 11, 2024
f46f06d
Updated variable names to be more readable
djlaky Jul 11, 2024
2476c3b
Updated test file with naming changes
djlaky Jul 11, 2024
9a71ad7
Added more results data
djlaky Jul 11, 2024
4c50c64
Removed stale imports, updated ordering
djlaky Jul 11, 2024
43ae0ba
Ran Black
djlaky Jul 11, 2024
37e3899
Removing old files
djlaky Jul 11, 2024
936cc4c
Removing more files
djlaky Jul 11, 2024
3e8c5e0
Wrote solving tests
djlaky Jul 11, 2024
53384ae
Adding placeholder files for other tests
djlaky Jul 11, 2024
25753d4
Added checks that FIM, Q, and L are consistent after solve
djlaky Jul 12, 2024
cdebfe9
Added build testing functions
djlaky Jul 12, 2024
a751f96
Ran Black
djlaky Jul 12, 2024
ea528eb
Added user initialization check, Ran Black
djlaky Jul 12, 2024
85d116a
Merge branch 'Pyomo:main' into pyomo-doe-refactor
djlaky Jul 12, 2024
1113b67
Delete pyomo/contrib/doe/tests/test_reactor_example.py
djlaky Jul 12, 2024
7d5c562
Delete pyomo/contrib/doe/tests/test_example.py
djlaky Jul 12, 2024
7a9e0c9
Delete pyomo/contrib/doe/tests/test_fim_doe.py
djlaky Jul 12, 2024
ccc0be6
Corrected flags and added new test file for model building
djlaky Jul 12, 2024
31ede58
Added some error tests
djlaky Jul 12, 2024
a66bd62
Updated model to have good imports
djlaky Jul 12, 2024
fe74e73
Updated all asserts to be raises; Added tests
djlaky Jul 12, 2024
da285a9
Delete pyomo/contrib/doe/redesign directory
djlaky Jul 12, 2024
fa1615d
Ran Black
djlaky Jul 12, 2024
6871ba6
Fixed small typo
djlaky Jul 12, 2024
4a341f6
Delete pyomo/contrib/doe/examples/PyomoDoE-plots.ipynb
djlaky Jul 12, 2024
3ec88c0
Delete pyomo/contrib/doe/examples/debugging_compute_FIM.ipynb
djlaky Jul 12, 2024
de535f4
Delete pyomo/contrib/doe/examples/reactor_optimize_doe_DJL.py
djlaky Jul 12, 2024
c8ef2dd
Ran Black
djlaky Jul 12, 2024
65519e2
Merge branch 'pyomo-doe-refactor' of https://github.com/djlaky/pyomo …
djlaky Jul 12, 2024
5c89e4a
Ran Black with correct command with flags
Jul 15, 2024
8bbf084
Fixed typos
Jul 15, 2024
615329d
Ran Black again
Jul 15, 2024
5c82a57
Fixed another typo
Jul 15, 2024
d13f94b
Removing commented lines from example files
Jul 15, 2024
0625cec
Added ipopt check for build, which initializes the model using ipopt
Jul 15, 2024
ae34d07
Merge branch 'main' into pyomo-doe-refactor
mrmundt Jul 17, 2024
7670063
Added test for rescale FIM function
Jul 18, 2024
7ad1005
Fixed bug and added test for compute FIM seq with back/forw
Jul 18, 2024
2b645c7
Adding test for model that is poorly posed
Jul 18, 2024
f1ae5df
Ran Black
Jul 18, 2024
ce4d04c
Updated main
Jul 18, 2024
858aafc
Added tests for update_FIM
Jul 18, 2024
2555900
Add update_FIM error check
Jul 18, 2024
ca32fc5
Added tests for get values functions without blocks
Jul 18, 2024
5864e68
Adding tests for multi experiment not implemented and scenario buildi…
Jul 18, 2024
11af005
Adding tests for bad FD values
Jul 18, 2024
ae9d288
Added tests for bad objective builds
Jul 18, 2024
06a0f50
Changed one run to use objective type
Jul 18, 2024
cc4eec0
Added not implemented error for unknown parameter value updating
Jul 18, 2024
a389d4f
Delete pyomo/contrib/doe/examples directory
djlaky Jul 18, 2024
e6feef6
Add test for bad option in compute FIM method
Jul 18, 2024
f1df9be
Removed bad files, have to rewrite OnlineDocs soon
Jul 18, 2024
76e06c5
Fixed determinant obj without cholesky, added tests.
Jul 18, 2024
fe60179
Merge branch 'main' into pyomo-doe-refactor
mrmundt Jul 22, 2024
930ac20
Added scipy availability flag for kaug test
djlaky Jul 23, 2024
33121af
Fixed typo
djlaky Jul 23, 2024
9b0d416
Started updating documentation (doe.rst).
djlaky Jul 23, 2024
08884e3
Updated ParmEst reference
djlaky Jul 23, 2024
29d8d43
Fixed typo in doe.rst
djlaky Jul 23, 2024
3e3bfc5
Merge branch 'Pyomo:main' into pyomo-doe-refactor
djlaky Jul 23, 2024
f7b5f57
Added examples and figure saving capabilities
Jul 23, 2024
3211d4d
Fixed documentation, cleaned example files
Jul 23, 2024
462a75a
Fixing literalinclude statements
Jul 23, 2024
087eaad
Fixing literalinclude statements again
Jul 23, 2024
328bc83
Added examples to init
Jul 24, 2024
e3a00cf
Added missing init file
Jul 24, 2024
070ab31
Add experiment and result json file for examples
djlaky Jul 24, 2024
45b7f87
Add Pyomo disclaimer and clean examples codes
djlaky Jul 24, 2024
b203356
Added Pyomo statement to test files
djlaky Jul 24, 2024
52557f2
Add more Pyomo statements to test files
djlaky Jul 24, 2024
24c4d6e
Updated test files to use experiment class, Ran Black
djlaky Jul 24, 2024
834088f
Updated documentation with recent changes
djlaky Jul 24, 2024
b5992ec
Updated documentation typo
djlaky Jul 31, 2024
735c932
Adding functionality to use Params instead of Vars
djlaky Aug 2, 2024
f038bc2
Commented out new Param to Var code
djlaky Aug 2, 2024
087e7be
ran black and typos
Aug 2, 2024
e2e469b
Revert reactor experiment for update
djlaky Aug 5, 2024
ce6d92e
Updated experiment to be inherited from `parmest`
djlaky Aug 5, 2024
4d23cd8
Update experiment inputs key as None
djlaky Aug 5, 2024
19251d5
Simplify component identification in doe
djlaky Aug 5, 2024
e097811
Update variable fixing readability in doe
djlaky Aug 5, 2024
73140d8
Change setattr to add_component
djlaky Aug 5, 2024
96b0a99
Update import order
djlaky Aug 5, 2024
4679cb7
Added unique component naming if model is provided
djlaky Aug 5, 2024
20e5ae6
Added unique block addition to user models for doe tasks
djlaky Aug 5, 2024
c06bfa5
Fixed potential bug
djlaky Aug 5, 2024
cba2b47
Made L_LB more verbose
djlaky Aug 5, 2024
93706d0
Updated ``det`` to be more verbose
djlaky Aug 5, 2024
c36cedb
Made ``args`` more verbose
djlaky Aug 5, 2024
ddc8ec8
Added naming map for results object
djlaky Aug 5, 2024
2c22203
Updated import order for test files
djlaky Aug 5, 2024
c2967cd
Remove stale Enum structures
djlaky Aug 5, 2024
383cbc7
Ran black and typos
Aug 5, 2024
c28d103
Clean up init file
Aug 7, 2024
52433f4
Updating example with feedback
Aug 7, 2024
678b28d
Made imports explicit
Aug 9, 2024
1920965
Made imports explicit in other tests
Aug 9, 2024
afd01bb
Added shortcut function for test arguments
Aug 9, 2024
b66a6c5
Simplified decorator to class
Aug 9, 2024
c6aafd2
Cleaned up reactor experiment example
Aug 12, 2024
b8b911c
Added else to rescale function, commented params function
Aug 12, 2024
a9b1b03
Edited language in documentation
Aug 12, 2024
9d5fa4c
Fixed fragile line numbers for reactor exp in documentation
Aug 12, 2024
8d95492
Clarified text in documentation
Aug 12, 2024
26921e0
Remove more line number fragility in documentation
Aug 12, 2024
9462cee
Combined example files and updated documentation with change
Aug 12, 2024
77a1bc5
Add context manager, remove np.isclose in tests
Aug 12, 2024
ef5c9ba
Reused reactor experiment in tests, fixed bug in experiment
Aug 12, 2024
353e769
Edited small phrase in documentation
Aug 12, 2024
b2106a0
Removing unused import
Aug 12, 2024
16873d0
Remove tests result.json dependency
Aug 12, 2024
2b2c33f
Delete pyomo/contrib/doe/tests/experiment_class_example.py
djlaky Aug 12, 2024
c18f2c6
Delete pyomo/contrib/doe/tests/result.json
djlaky Aug 12, 2024
cb7d925
Delete pyomo/contrib/doe/experiment.py
djlaky Aug 12, 2024
e0226b0
Update pyomo/contrib/doe/tests/test_doe_build.py
djlaky Aug 12, 2024
27ed006
Revert "Update pyomo/contrib/doe/tests/test_doe_build.py"
djlaky Aug 12, 2024
451fdff
Revert "Delete pyomo/contrib/doe/tests/experiment_class_example.py"
djlaky Aug 12, 2024
514a032
Revert "Delete pyomo/contrib/doe/tests/result.json"
djlaky Aug 12, 2024
d078c4f
Revert "Delete pyomo/contrib/doe/experiment.py"
djlaky Aug 12, 2024
a8957a5
Removed string-based location of components
Aug 12, 2024
3f57d1c
Updated shoddy tests to check real values
Aug 12, 2024
e0c9a0b
Added depracation error message
Aug 12, 2024
2bb20b1
resolving merge conflict
djlaky Aug 12, 2024
a4d25c2
Fixed typo in doe.py
djlaky Aug 12, 2024
e78842a
Delete pyomo/contrib/doe/tests/test_example.py
djlaky Aug 12, 2024
b036e26
Delete pyomo/contrib/doe/tests/test_fim_doe.py
djlaky Aug 12, 2024
c5a4301
Delete pyomo/contrib/doe/tests/test_reactor_example.py
djlaky Aug 12, 2024
8ec6500
Delete pyomo/contrib/doe/tests/experiment_class_example.py
djlaky Aug 12, 2024
f6c3fcb
Delete pyomo/contrib/doe/tests/result.json
djlaky Aug 12, 2024
31f93e5
Delete pyomo/contrib/doe/experiment.py
djlaky Aug 12, 2024
4e771ec
Remove idaes import from documentation
djlaky Aug 13, 2024
94e981d
Update solving test file to have assertFoo
djlaky Aug 13, 2024
324146d
Moved has numpy decorator to class level
djlaky Aug 13, 2024
9c52690
Updated language in comments and URL
djlaky Aug 13, 2024
d8307a7
Removed safe naming for later discussion
djlaky Aug 13, 2024
ec93a2b
Added solver safeguarding TODO
djlaky Aug 13, 2024
3541460
Added TODOs and added error to unreachable code
djlaky Aug 13, 2024
b2899fb
Fixed out of scope 'model' references
djlaky Aug 13, 2024
137572a
Fixed more out of scope `model` references
djlaky Aug 13, 2024
b067bd1
Fixed check model labels function
djlaky Aug 13, 2024
f71d4c7
Added missing docstring inputs
djlaky Aug 13, 2024
08e6618
Added TODO for solve failure message on user model
djlaky Aug 13, 2024
fdd0583
Ran Black
djlaky Aug 13, 2024
1b9729a
Added more verbose TODO tasks
djlaky Aug 13, 2024
57a8a81
Delete .vs directory
djlaky Aug 13, 2024
0b08aef
Remove other user-defined model unique naming
djlaky Aug 13, 2024
7aab583
Revert accidental find and replace in tests
djlaky Aug 13, 2024
b1214a7
Updated documentation comment to be more verbose
djlaky Aug 13, 2024
6db5023
Change assertTrue to assertEqual in test build
djlaky Aug 13, 2024
0c566c9
Change assertTrue to assertEqual in test solve
djlaky Aug 13, 2024
485e0fc
Update test file with os.path and pyomo.fileutils
djlaky Aug 13, 2024
919f234
Moving deprecation error away from doe.py
djlaky Aug 13, 2024
ca1f39e
Add comments to tests that don't assert anything
djlaky Aug 14, 2024
f4ff8b7
Ran Black
djlaky Aug 14, 2024
fc00af0
Added deprecation warning/error for old interface
djlaky Aug 14, 2024
24bd55e
Remove URL for URL checker for now
djlaky Aug 14, 2024
ecc24bf
Reverting previous change.
djlaky Aug 14, 2024
6505f5b
Add solve to help with initialization of DoE model
djlaky Aug 16, 2024
3af9d47
Merge branch 'Pyomo:main' into pyomo-doe-refactor
djlaky Aug 16, 2024
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
160 changes: 54 additions & 106 deletions doc/OnlineDocs/contributed_packages/doe/doe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,64 +116,14 @@ In order to solve problems of the above, Pyomo.DoE implements the 2-stage stocha

Pyomo.DoE Required Inputs
--------------------------------
The required inputs to the Pyomo.DoE solver are the following:
The required input to the Pyomo.DoE solver is an ``Experiment`` object. The experiment object must have a ``get_labeled_model`` function which returns a Pyomo model with four ``Suffix`` components identifying the parts of the model used in MBDoE analysis. This is in line with the convention used in the parameter estimation tool, `Parmest <https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html>`_. The four ``Suffix`` components are:

* A function that creates the process model
* Dictionary of parameters and their nominal value
* A measurement object
* A design variables object
* A Numpy ``array`` containing the Prior FIM
* Optimization solver

Below is a list of arguments that Pyomo.DoE expects the user to provide.

parameter_dict : ``dictionary``
A ``dictionary`` of parameter names and values. If they are an indexed variable, put the variable name and index in a nested ``Dictionary``.

design_variables: ``DesignVariables``
A ``DesignVariables`` of design variables, provided by the DesignVariables class.
If this design var is independent of time (constant), set the time to [0]

measurement_variables : ``MeasurementVariables``
A ``MeasurementVariables`` of the measurements, provided by the MeasurementVariables class.

create_model : ``function``
A ``function`` returning a deterministic process model.

prior_FIM : ``array``
An ``array`` defining the Fisher information matrix (FIM) for prior experiments, default is a zero matrix.

Pyomo.DoE Solver Interface
---------------------------

.. figure:: uml.png
:scale: 25 %


.. autoclass:: pyomo.contrib.doe.doe.DesignOfExperiments
:members: __init__, stochastic_program, compute_FIM, run_grid_search

.. Note::
``stochastic_program()`` includes the following steps:
#. Build two-stage stochastic programming optimization model where scenarios correspond to finite difference approximations for the Jacobian of the response variables with respect to calibrated model parameters
#. Fix the experiment design decisions and solve a square (i.e., zero degrees of freedom) instance of the two-stage DOE problem. This step is for initialization.
#. Unfix the experiment design decisions and solve the two-stage DOE problem.

.. autoclass:: pyomo.contrib.doe.measurements.MeasurementVariables
:members: __init__, add_variables

.. autoclass:: pyomo.contrib.doe.measurements.DesignVariables
:members: __init__, add_variables

.. autoclass:: pyomo.contrib.doe.scenario.ScenarioGenerator
:special-members: __init__

.. autoclass:: pyomo.contrib.doe.result.FisherResults
:members: __init__, result_analysis

.. autoclass:: pyomo.contrib.doe.result.GridSearchResult
:special-members: __init__
* ``experiment_inputs`` - The experimental design decisions
* ``experiment_outputs`` - The values measured during the experiment
* ``measurement_error`` - The error associated with individual values measured during the experiment
* ``unknown_parameters`` - Those parameters in the model that are estimated using the measured values during the experiment

An example ``Experiment`` object that builds and labels the model is shown in the next few sections.

Pyomo.DoE Usage Example
-----------------------
Expand Down Expand Up @@ -203,89 +153,87 @@ The goal of MBDoE is to optimize the experiment design variables :math:`\boldsym
The observation errors are assumed to be independent both in time and across measurements with a constant standard deviation of 1 M for each species.


Step 0: Import Pyomo and the Pyomo.DoE module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Step 0: Import Pyomo and the Pyomo.DoE module and create an ``Experiment`` class
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. doctest::

>>> # === Required import ===
>>> import pyomo.environ as pyo
>>> from pyomo.dae import ContinuousSet, DerivativeVar
>>> from pyomo.contrib.doe import DesignOfExperiments, MeasurementVariables, DesignVariables
>>> from pyomo.contrib.doe import DesignOfExperiments
>>> import numpy as np

.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_experiment.py
:start-after: ========================
:end-before: End constructor definition

Step 1: Define the Pyomo process model
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The process model for the reaction kinetics problem is shown below.
The process model for the reaction kinetics problem is shown below. We build the model without any data or discretization.

.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_kinetics.py
:language: python
:pyobject: create_model
.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_experiment.py
:start-after: Create flexible model without data
:end-before: End equation definition

.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_kinetics.py
:language: python
:pyobject: disc_for_measure
Step 2: Finalize the Pyomo process model
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. note::
The model requires at least two options: "block" and "global". Both options requires the pass of a created empty Pyomo model.
With "global" option, only design variables and their time sets need to be defined;
With "block" option, a full model needs to be defined.
Here we add data to the model and finalize the discretization. This step is required before the model can be labeled.

.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_experiment.py
:start-after: End equation definition
:end-before: End model finalization

Step 2: Define the inputs for Pyomo.DoE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_compute_FIM.py
:language: python
:start-at: # Control time set
:end-before: ### Compute
Step 3: Label the information needed for DoE analysis
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We label the four important groups as defined before.

Step 3: Compute the FIM of a square MBDoE problem
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_experiment.py
:start-after: End model finalization
:end-before: End model labeling

This method computes an MBDoE optimization problem with no degree of freedom.
Step 4: Implement the ``get_labeled_model`` method
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This method can be accomplished by two modes, ``direct_kaug`` and ``sequential_finite``.
``direct_kaug`` mode requires the installation of the solver `k_aug <https://github.com/dthierry/k_aug>`_.
This method utilizes the previous 3 steps and is used by `Pyomo.DoE` to build the model to perform optimal experimental design.

.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_compute_FIM.py
:language: python
:start-after: ### Compute the FIM
:end-before: # test result
.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_experiment.py
:start-after: End constructor definition
:end-before: Create flexible model without data

Step 4: Exploratory analysis (Enumeration)
Step 5: Exploratory analysis (Enumeration)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exploratory analysis is suggested to enumerate the design space to check if the problem is identifiable,
i.e., ensure that D-, E-optimality metrics are not small numbers near zero, and Modified E-optimality is not a big number.

Pyomo.DoE accomplishes the exploratory analysis with the ``run_grid_search`` function.
It allows users to define any number of design decisions. Heatmaps can be drawn by two design variables, fixing other design variables.
1D curve can be drawn by one design variable, fixing all other variables.
The function ``run_grid_search`` enumerates over the design space, each MBDoE problem accomplished by ``compute_FIM`` method.
Therefore, ``run_grid_search`` supports only two modes: ``sequential_finite`` and ``direct_kaug``.
Pyomo.DoE can perform exploratory sensitivity analysis with the ``compute_FIM_full_factorial`` function.
The ``compute_FIM_full_factorial`` function generates a grid over the design space as specified by the user. Each grid point represents an MBDoE problem solved using ``compute_FIM`` method. In this way, sensitivity of the FIM over the design space can be evaluated.

.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_grid_search.py
:language: python
:pyobject: main
The following code executes the above problem description:

Successful run of the above code shows the following figure:
.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_example.py
:start-after: Read in file
:end-before: End sensitivity analysis

.. figure:: grid-1.png
:scale: 35 %
An example output of the code above, a design exploration for the initial concentration and temperature as experimental design variables with 9 values, produces the four figures summarized below:

A heatmap shows the change of the objective function, a.k.a. the experimental information content, in the design region. Horizontal and vertical axes are two design variables, while the color of each grid shows the experimental information content. Taking the Fig. Reactor case - A optimality as example, A-optimality shows that the most informative region is around $C_{A0}=5.0$ M, $T=300.0$ K, while the least informative region is around $C_{A0}=1.0$ M, $T=700.0$ K.
.. figure:: FIM_sensitivity.png
:scale: 50 %

Step 5: Gradient-based optimization
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A heatmap shows the change of the objective function, a.k.a. the experimental information content, in the design space. Horizontal and vertical axes are the two experimental design variables, while the color of each grid shows the experimental information content. For A optimality (top left subfigure), the figure shows that the most informative region is around :math:`C_{A0}=5.0` M, :math:`T=300.0` K, while the least informative region is around :math:`C_{A0}=1.0` M, :math:`T=700.0` K.

Step 6: Performing an optimal experimental design
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Pyomo.DoE accomplishes gradient-based optimization with the ``stochastic_program`` function for A- and D-optimality design.
In step 5, the DoE object was constructed to perform an exploratory sensitivity analysis. The same object can be used to design an optimal experiment with a single line of code.

This function solves twice: It solves the square version of the MBDoE problem first, and then unfixes the design variables as degree of freedoms and solves again. In this way the optimization problem can be well initialized.
.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_example.py
:start-after: Begin optimal DoE
:end-before: Print out a results summary

.. literalinclude:: ../../../../pyomo/contrib/doe/examples/reactor_optimize_doe.py
:language: python
:pyobject: main
When run, the optimal design is an initial concentration of 5.0 mol/L and an initial temperature of 494 K with all other temperatures being 300 K. The corresponding log-10 determinant of the FIM is 13.75


43 changes: 39 additions & 4 deletions pyomo/contrib/doe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,42 @@
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________
from .measurements import MeasurementVariables, DesignVariables, VariablesWithIndices
from .doe import DesignOfExperiments, CalculationMode, ObjectiveLib, ModelOptionLib
from .scenario import ScenarioGenerator, FiniteDifferenceStep
from .result import FisherResults, GridSearchResult
from .doe import DesignOfExperiments, ObjectiveLib, FiniteDifferenceStep
from .utils import rescale_FIM

# Deprecation errors for old Pyomo.DoE interface classes and structures
from pyomo.common.deprecation import deprecated

deprecation_message = (
"Pyomo.DoE has been refactored. The current interface utilizes Experiment "
"objects that label unknown parameters, experiment inputs, experiment outputs "
"and measurement error. This avoids string-based naming which is fragile. For "
"instructions to use the new interface, please see the Pyomo.DoE under the contributed "
"packages documentation at "
# "`https://pyomo.readthedocs.io/en/latest/contributed_packages/doe/doe.html`"
blnicho marked this conversation as resolved.
Show resolved Hide resolved
)


@deprecated(
"Use of MeasurementVariables in Pyomo.DoE is no longer supported.",
version='6.7.4.dev0',
)
class MeasurementVariables:
def __init__(self, *args):
raise RuntimeError(deprecation_message)

Check warning on line 33 in pyomo/contrib/doe/__init__.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/__init__.py#L33

Added line #L33 was not covered by tests


@deprecated(
"Use of DesignVariables in Pyomo.DoE is no longer supported.", version='6.7.4.dev0'
)
class DesignVariables:
def __init__(self, *args):
raise RuntimeError(deprecation_message)

Check warning on line 41 in pyomo/contrib/doe/__init__.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/__init__.py#L41

Added line #L41 was not covered by tests


@deprecated(
"Use of ModelOptionLib in Pyomo.DoE is no longer supported.", version='6.7.4.dev0'
)
class ModelOptionLib:
def __init__(self, *args):
raise RuntimeError(deprecation_message)

Check warning on line 49 in pyomo/contrib/doe/__init__.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/__init__.py#L49

Added line #L49 was not covered by tests
Loading
Loading