Skip to content
Merged
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
222b396
Add utility to utils.py
sscini Jun 27, 2025
81a595f
Ran black to update formatting
sscini Jun 27, 2025
a3504f8
Merge branch 'Pyomo:main' into add-update-model-utility
sscini Jul 1, 2025
748c732
Added example in doe to show use of util
sscini Jul 1, 2025
3e3a5b8
Modified utils based on 7/1 meeting
sscini Jul 1, 2025
403eae7
Updated example and added tests, still debugging
sscini Jul 1, 2025
1304112
Merge branch 'Pyomo:main' into add-update-model-utility
sscini Jul 1, 2025
5ea8ba5
Merge branch 'Pyomo:main' into add-update-model-utility
sscini Jul 3, 2025
df4de56
Moved utility from doe to parmest
sscini Jul 9, 2025
2b6e304
Updated test_utils, confirming they work tomorrow.
sscini Jul 14, 2025
02460d5
Ran black
sscini Jul 14, 2025
67dccc5
Updated doe utils to match new in main
sscini Jul 14, 2025
63e3a7d
Merge branch 'main' into add-update-model-utility
sscini Jul 14, 2025
692fa9e
Ran black on doe
sscini Jul 14, 2025
cb394e7
Merge branch 'add-update-model-utility' of https://github.com/sscini/…
sscini Jul 14, 2025
a4f3d1c
Ran black again after merging changes
sscini Jul 14, 2025
d2786d7
Added parmest example, fixed and added tests, ran black.
sscini Jul 14, 2025
aa3b6f1
Remove changes from doe tests
sscini Jul 14, 2025
7b390b1
Addressed comments from Dan that do not need clarification
sscini Jul 15, 2025
21db44b
Merge branch 'Pyomo:main' into add-update-model-utility
sscini Jul 28, 2025
d43721a
Updated files and added test to address comments
sscini Aug 1, 2025
dee6c38
Ran black on doe and parmest
sscini Aug 1, 2025
c013ac4
Merge branch 'Pyomo:main' into add-update-model-utility
sscini Aug 1, 2025
a25875c
Made edits to address comments, ran black
sscini Aug 1, 2025
cf37a8b
Merge branch 'Pyomo:main' into add-update-model-utility
sscini Aug 4, 2025
92f772e
Merge branch 'main' into add-update-model-utility
mrmundt Aug 4, 2025
4d1dfec
Addressed comments and ran black
sscini Aug 4, 2025
793f34a
Update updatesuffix_example.py
sscini Aug 4, 2025
a7babec
Delete scenarios.csv
sscini Aug 4, 2025
9ea7e31
Update test_utils.py
sscini Aug 4, 2025
14f7eb6
Addressed file name changes
sscini Aug 5, 2025
a47c54f
Addressed consistency changes
sscini Aug 5, 2025
0a4c9a2
Merge branch 'main' into add-update-model-utility
sscini Aug 5, 2025
6efaa0e
Merge branch 'main' into add-update-model-utility
mrmundt Aug 6, 2025
2767263
Apply suggestions from code review
blnicho Aug 6, 2025
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
44 changes: 44 additions & 0 deletions pyomo/contrib/doe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,47 @@
# pass # ToDo: Write error for suffix keys that aren't ParamData or VarData
#
# return param_list


# Adding utility to update parameter values in a model based on the suffix
def update_model_from_suffix(model, suffix_name, values):
"""
Iterate over the components (variables or parameters) referenced by the
given suffix in the model, and assign each a new value from the provided iterable.

Parameters
----------
model : pyomo.environ.ConcreteModel
The Pyomo model containing the suffix and components to update.
suffix_name : str
The name of the Suffix attribute on the model whose items will be updated.
Must be one of: 'experiment_outputs', 'experiment_inputs', 'unknown_parameters', or 'measurement_error'.
values : iterable of numbers
The new values to assign to each component referenced by the suffix. The length of this
iterable must match the number of items in the suffix.
"""
# Allowed suffix names
allowed = {

Check warning on line 123 in pyomo/contrib/doe/utils.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/utils.py#L123

Added line #L123 was not covered by tests
'experiment_outputs',
'experiment_inputs',
'unknown_parameters',
'measurement_error',
}
# Validate input is an allowed suffix name
if suffix_name not in allowed:
raise ValueError(f"suffix_name must be one of {sorted(allowed)}")

Check warning on line 131 in pyomo/contrib/doe/utils.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/utils.py#L130-L131

Added lines #L130 - L131 were not covered by tests
# Check if the model has the specified suffix
suffix_obj = getattr(model, suffix_name, None)
if suffix_obj is None:
raise AttributeError(f"Model has no attribute '{suffix_name}'")

Check warning on line 135 in pyomo/contrib/doe/utils.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/utils.py#L133-L135

Added lines #L133 - L135 were not covered by tests
# Check if the suffix is a Suffix object
items = list(suffix_obj.items())
if len(items) != len(values):
raise ValueError("values length does not match suffix length")

Check warning on line 139 in pyomo/contrib/doe/utils.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/utils.py#L137-L139

Added lines #L137 - L139 were not covered by tests
# Set the new values for the suffix items
for (comp, _), new_val in zip(items, values):

Check warning on line 141 in pyomo/contrib/doe/utils.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/utils.py#L141

Added line #L141 was not covered by tests
# Update the variable/parameter itself if it is VarData or ParamData
if isinstance(comp, (VarData, ParamData)):
comp.set_value(new_val)

Check warning on line 144 in pyomo/contrib/doe/utils.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/utils.py#L143-L144

Added lines #L143 - L144 were not covered by tests
else:
raise TypeError(f"Unsupported component type: {type(comp)}")

Check warning on line 146 in pyomo/contrib/doe/utils.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/doe/utils.py#L146

Added line #L146 was not covered by tests
Loading