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

Parmest update of util convert_params_to_vars. #3339

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

smartin71
Copy link
Contributor

Fixes # .

Summary/Motivation:

This is step 1 of a set of internal changes to parmest related to issue:
#3252

Changes proposed in this PR:

  • Revamped util function convert_params_to_vars to avoid the use of parameter names as strings.
  • Now using component IDs both internally to the convert function and in the API.

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.

@blnicho blnicho self-requested a review August 13, 2024 18:50
Copy link
Member

@jsiirola jsiirola left a 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.

pyomo/contrib/parmest/utils/model_utils.py Outdated Show resolved Hide resolved
pyomo/contrib/parmest/utils/model_utils.py Outdated Show resolved Hide resolved
pyomo/contrib/parmest/utils/model_utils.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Aug 16, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.53%. Comparing base (7f779ab) to head (7ea02db).
Report is 158 commits behind head on main.

Files Patch % Lines
pyomo/contrib/parmest/utils/model_utils.py 90.90% 1 Missing ⚠️
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     
Flag Coverage Δ
linux 86.05% <93.33%> (+0.01%) ⬆️
osx 75.63% <6.66%> (-0.03%) ⬇️
other 86.55% <93.33%> (+0.01%) ⬆️
win 83.86% <93.33%> (+0.02%) ⬆️

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.

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'

pyomo/contrib/parmest/parmest.py Outdated Show resolved Hide resolved
pyomo/contrib/parmest/tests/test_utils.py Outdated Show resolved Hide resolved
pyomo/contrib/parmest/utils/model_utils.py Outdated Show resolved Hide resolved
pyomo/contrib/parmest/utils/model_utils.py Outdated Show resolved Hide resolved

# Param
if theta_object.is_parameter_type():

# Delete Param, add Var
vals = theta_object.extract_values()
model.del_component(theta_object)
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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).

pyomo/contrib/parmest/utils/model_utils.py Outdated Show resolved Hide resolved
@mrmundt mrmundt requested review from jsiirola and blnicho October 8, 2024 18:58
@mrmundt
Copy link
Contributor

mrmundt commented Oct 8, 2024

@blnicho - Do you think you'll have time to look over this one before the Monday patch?

@shermanjasonaf
Copy link
Contributor

Does this fix #3375?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants