Skip to content

Pyomo. DoE: Sensitivity initialization #3639

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

Draft
wants to merge 81 commits into
base: main
Choose a base branch
from

Conversation

smondal13
Copy link

@smondal13 smondal13 commented Jun 23, 2025

Fixes # .

Summary/Motivation:

  • Initializing the model to a previously solved point in the design space can help the model converge at another point in the design space for sensitivity analysis
  • Better error messages in the method can help the user in debugging
  • Saving the file can be helpful if the model takes a long time to solve or if the user wants it.
  • The pattern generator in the utils.py file can be used in other cases where it can help with the initialization

Changes proposed in this PR:

  • Added a new method compute_FIM_factorial() in Pyomo.DoE for sensitivity initialization
  • Added snake_traversal_grid_sampling() in utils.py that will help generate an update scheme for initialization

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.

…alue checking in compute_FIM_full_factorial()
… doe object that uses the "reactor_experiment" example in doe directory. Also added the png files to gitignore that are stored when "reactor_example.py" is run.
…M_metrics.py` instead of importing idaes, only the solvers are imported.
…IM() staticmethod of DesignOfExperiments class
… in compute_FIM_full_factorial that is ready to be deleted.
…_FIM_full_factorial()` which was replaced by function call `_compute_FIM_metrics()`
…ght that will be helpful for the user to understand the method.
@smondal13
Copy link
Author

@adowling2 @djlaky, this draft PR is ready for initial review.

@adowling2
Copy link
Member

Does this PR depend on changes in #3575?

Copy link
Member

@adowling2 adowling2 left a comment

Choose a reason for hiding this comment

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

@smondal13 I left some initial comments.

@@ -0,0 +1,267 @@
# ___________________________________________________________________________
Copy link
Member

Choose a reason for hiding this comment

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

@smondal13 Why are your creating a new utils file instead of updating the current one? There might be a point of confusion regarding branches in git.

Copy link
Author

@smondal13 smondal13 Jul 1, 2025

Choose a reason for hiding this comment

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

This issue is resolved now. merged the utils file from my previous PR # 3525.

@@ -1617,6 +1628,221 @@ def compute_FIM_full_factorial(

return self.fim_factorial_results

def compute_FIM_factorial(
Copy link
Member

Choose a reason for hiding this comment

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

Was this function already in Pyomo.DoE somewhere else?

Copy link
Author

Choose a reason for hiding this comment

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

No, I created this method. I do not see the same name anywhere else.

Copy link
Author

Choose a reason for hiding this comment

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

@adowling2, we have compute_FIM_full_factorial(). I have not changed that method, rather I have added a new method. Maybe we can show a deprecation warning for compute_FIM_full_factorial()

# design_map_keys so that design_point can be constructed correctly in the loop.
des_ranges = [design_values[k.name] for k in design_map_keys]
if change_one_design_at_a_time:
factorial_points = generate_snake_zigzag_pattern(*des_ranges)
Copy link
Member

Choose a reason for hiding this comment

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

Let's brainstorm different sensitivity analysis sequences we might use. We can then define an enum.

@@ -100,3 +100,43 @@ def rescale_FIM(FIM, param_vals):
# pass # ToDo: Write error for suffix keys that aren't ParamData or VarData
#
# return param_list


def generate_snake_zigzag_pattern(*lists):
Copy link
Member

Choose a reason for hiding this comment

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

Let's come up with a better name. I do not think of "snake" as a technical term.

yield (value,) + sub_pattern

# Start the recursion at the first list (depth 0) with an initial sum of 0.
yield from _generate_recursive(depth=0, index_sum=0)
Copy link
Member

Choose a reason for hiding this comment

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

How are we going to test this function? IMO, the next step is to develop some tests for this. That way, as you try to run the sensitivity analysis for an example, you are least know this part of the code is correct.

Copy link
Author

Choose a reason for hiding this comment

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

@adowling2 , I did check it manually before. I have recently added a test for this in test_utils.py for up to 3 variables, and also for different array-like structures. From the test, it works the way we want.

@smondal13 smondal13 changed the title Sensitivity initialization in Pyomo. DoE Pyomo. DoE: Sensitivity initialization Jun 25, 2025
@smondal13
Copy link
Author

@adowling2 , @djlaky This PR is ready for design review.

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

Successfully merging this pull request may close these issues.

5 participants