-
Notifications
You must be signed in to change notification settings - Fork 525
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
Parmest update of util convert_params_to_vars. #3339
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good, but there is a big performance bug that should be addressed.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3339 +/- ##
========================================
Coverage 88.52% 88.53%
========================================
Files 868 868
Lines 98436 98771 +335
========================================
+ Hits 87144 87450 +306
- Misses 11292 11321 +29
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this still needs some work. There are some bugs in this function when params to be converted to vars live on blocks. This PR didn't necessarily introduce the bugs but I think we should fix them while we're overhauling this function. Here is a small example demonstrating one of the bugs:
from pyomo.environ import *
from pyomo.contrib.parmest.utils import convert_params_to_vars
m = ConcreteModel()
m.p1 = Param(initialize=1, mutable=True)
m.b = Block()
m.b.p2 = Param(initialize=2, mutable=True)
param_cuids = [ComponentUID(m.p1), ComponentUID(m.b.p2)]
m2 = convert_params_to_vars(m, param_cuids)
this fails with an AttributeError
:
AttributeError: 'ScalarParam' object has no attribute 'unfix'
|
||
# Param | ||
if theta_object.is_parameter_type(): | ||
|
||
# Delete Param, add Var | ||
vals = theta_object.extract_values() | ||
model.del_component(theta_object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will work on hierarchical models. I think we need to add more tests for edge cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I fixed this and added a test.
param_names = indexed_param_names | ||
# Update the list of param_CUIDs if the parameters were indexed | ||
if len(indexed_param_CUIDs) > 0: | ||
param_CUIDs = indexed_param_CUIDs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we replace param_CUIDs
here instead of extending it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to replace it because it might not have the indexed variables, only the main variable. For example "theta" (param_CUIDs) vs. "theta[asymptote]" and "theta[rate_constant]" (indexed_param_CUIDs).
@blnicho - Do you think you'll have time to look over this one before the Monday patch? |
Does this fix #3375? |
Fixes # .
Summary/Motivation:
This is step 1 of a set of internal changes to parmest related to issue:
#3252
Changes proposed in this PR:
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: