Skip to content

Commit

Permalink
Bethany's changed, not including block/hierarchical model changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
smartin71 committed Aug 20, 2024
1 parent 394a6d6 commit 0545ecf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyomo/contrib/parmest/parmest.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def TotalCost_rule(model):
)

# Convert theta Params to Vars, and unfix theta Vars
theta_CUIDs = [v for k, v in model.unknown_parameters.items()]
theta_CUIDs = list(model.unknown_parameters.values())
parmest_model = utils.convert_params_to_vars(model, theta_CUIDs, fix_vars=False)

return parmest_model
Expand Down
4 changes: 2 additions & 2 deletions pyomo/contrib/parmest/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_convert_param_to_var(self):
exp = ReactorDesignExperiment(data, 0)
instance = exp.get_labeled_model()

param_CUIDs = [v for k, v in instance.unknown_parameters.items()]
param_CUIDs = list(instance.unknown_parameters.values())
m_vars = parmest.utils.convert_params_to_vars(
instance, param_CUIDs, fix_vars=True
)
Expand Down Expand Up @@ -120,7 +120,7 @@ def label_model(self):
exp = RooneyBieglerExperimentIndexedParams(self.data.loc[0, :])
instance = exp.get_labeled_model()

param_CUIDs = [v for k, v in instance.unknown_parameters.items()]
param_CUIDs = list(instance.unknown_parameters.values())
m_vars = parmest.utils.convert_params_to_vars(
instance, param_CUIDs, fix_vars=True
)
Expand Down
9 changes: 4 additions & 5 deletions pyomo/contrib/parmest/utils/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def convert_params_to_vars(model, param_CUIDs=None, fix_vars=False):
vals = theta_object.extract_values()

# get indexed Params
param_theta_objects = [theta_obj for _, theta_obj in theta_object.items()]

# get indexed Param names
param_theta_objects = list(theta_object.values())
# get indexed Param CUIDs
indexed_param_CUIDs.extend(
ComponentUID(theta_obj) for theta_obj in theta_object.values()
)
Expand Down Expand Up @@ -135,8 +135,7 @@ def convert_params_to_vars(model, param_CUIDs=None, fix_vars=False):

# Convert Params to Vars in Expressions
for expr in model.component_data_objects(pyo.Expression):
if expr.active and any(
ComponentUID(v) in param_CUIDs_set
if any(ComponentUID(v) in param_CUIDs_set
for v in identify_mutable_parameters(expr)
):
new_expr = replace_expressions(expr=expr, substitution_map=substitution_map)
Expand Down

0 comments on commit 0545ecf

Please sign in to comment.