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

Pyomo doe refactor #3317

merged 203 commits into from
Aug 19, 2024

Conversation

djlaky
Copy link
Contributor

@djlaky djlaky commented Jul 12, 2024

Fixes

Pyomo.DoE interface was made more intuitive and some bugs were removed.

Summary/Motivation:

Pyomo.DoE was refactored to coincide with the new "experiment-based" structure of ParmEst. In this way, the packages should overlap with syntax and workflows using both tools should be easier to implement. Also, the existing interface was clunky and required a few bugfixes.

Changes proposed in this PR:

  • Overhaul of the Pyomo.DoE code and Class/Object structure

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

djlaky and others added 30 commits June 19, 2024 20:28
First commit for DoE refactor. Skeleton functions added for development.
Mid-way through updating the scenario generation for the finite difference of the sensitivity matrix. Added an example file from the refactor hack-a-thon in November 2023.
Worked around Block construction. Pass-by-reference issues with with Experiment object requires some sort of cloning of the model for each block.

Still working through global connecting constraints for design variables.
Finished some more edits. Will check back in tomorrow to clean and make sure the scenario generator is working properly. Need to work on whether the full model should be present or not for the central case. Could use the "global model" to be "case 0" and reassign the  values to be one of the cases.
Add functionality to test if the labeled model has the expected labels for the DoE model to be created.
Added FiniteDifferenceStep initialization to the constructor. Removed and cleaned some defunct commenting/documentation.
Significant development in create_doe_model. Modernized to new methodology. Tests to follow.
Added size checks to make sure everything is consistent before being automatically generated by the create_model function.
Made the Jacobian representation consistent with the paper as well as sources on what the sensitivity matrix should be (i.e., (n_experiment_outputs x n_parameters) such that Q^T @ Q is (n_parameters x n_parameters).
Changed how the tree is traversed so the parameter location starts after the "base_model" or "scenario_blocks[0]" keyword. This way, an arbitrary block structure should be support. This will help for making multiple instances of the DoE model (i.e., multiple simultaneous estimations or stochastic-based experiment implementation).
Also updated the test build, result.json, and experiment class example to be well-posed DoE models.
Also added documentation for the inputs.
Seems to work based on comparison to old code. Will look into this more later.
Also updated the test files and results file to match and generate the same optimal point.
Matches the old interface
Objective cons block are deactivated for the square solve as they can sometimes cause convergence issues.
Copy link

codecov bot commented Aug 14, 2024

Codecov Report

Attention: Patch coverage is 74.41860% with 44 lines in your changes missing coverage. Please review.

Project coverage is 88.60%. Comparing base (5206eee) to head (3af9d47).
Report is 236 commits behind head on main.

Files Patch % Lines
pyomo/contrib/doe/examples/reactor_example.py 26.66% 22 Missing ⚠️
...trib/doe/examples/reactor_compute_factorial_FIM.py 34.78% 15 Missing ⚠️
pyomo/contrib/doe/utils.py 75.00% 4 Missing ⚠️
pyomo/contrib/doe/__init__.py 81.25% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3317      +/-   ##
==========================================
+ Coverage   88.56%   88.60%   +0.04%     
==========================================
  Files         877      873       -4     
  Lines       99276    99133     -143     
==========================================
- Hits        87920    87840      -80     
+ Misses      11356    11293      -63     
Flag Coverage Δ
linux 86.13% <74.41%> (+0.03%) ⬆️
osx 75.80% <20.34%> (+0.04%) ⬆️
other 86.64% <74.41%> (+0.04%) ⬆️
win 83.96% <69.76%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@blnicho blnicho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the Jenkins tests pass, I think this is ready

@djlaky
Copy link
Contributor Author

djlaky commented Aug 16, 2024

Assuming the Jenkins tests pass, I think this is ready

@blnicho I added a single line to the code today to help with initialization of the models. It will also be under the "To-Dos" to safegaurd the solver call against bad solves for #3345.

outputs = [k.name for k, v in model.measurement_error.items()]
except:
raise RuntimeError(
"Experiment model does not have suffix " + '"measurement_error".'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird?

plt.pyplot.rc("ytick", labelsize=font_tick)
ax = fig.add_subplot(111)
params = {"mathtext.default": "regular"}
# plt.rcParams.update(params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover?

plt.pyplot.rc("ytick", labelsize=font_tick)
ax = fig.add_subplot(111)
params = {"mathtext.default": "regular"}
# plt.rcParams.update(params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover?

Copy link
Contributor

@mrmundt mrmundt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of lines that I think need to be removed, but they aren't essential, so approve.

@mrmundt mrmundt merged commit cb7d880 into Pyomo:main Aug 19, 2024
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

4 participants