-
Notifications
You must be signed in to change notification settings - Fork 561
Implementing multistart version of theta_est using multiple sampling methods #3575
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
sscini
wants to merge
37
commits into
Pyomo:main
Choose a base branch
from
sscini:multistart-in-parmest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+450
−4
Draft
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
cdd7d52
Work on multistart implement 4/23 morning
sscini eca0ba8
Finished first draft of pseudocode for multistart
sscini 2160aec
Fixed logical errors in pseudocode
sscini 266beea
Started implementing review comments 4/30
sscini b877ada
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini 9f1ffe5
Work on edits, 5/1/25
sscini 43f1ab3
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini ea067c8
Made edits, still debugging
sscini 3b839ef
Addressed some comments in code. Still working through example to debug
sscini 3a7aa1d
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini c688f2d
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini 50c36bc
Got dataframe formatted, still working on executing Q_opt
sscini 8e5f078
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini f4c7018
Working code, adding features 6/2/25
sscini 4444e6d
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini e788000
Added questions for next round of reviews
sscini 4429caf
Merge branch 'multistart-in-parmest' of https://github.com/sscini/pyo…
sscini f071718
Removed diagnostic tables to simplify output
sscini 9b1545d
Work from Wednesday of Sprint week
sscini 80079cb
Create Simple_Multimodal_Multistart.ipynb
sscini 1695519
New features Thursday morning
sscini 0634014
First successful running multistart feature, before Alex recommended …
sscini a959346
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini 04a9096
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini 06e0a72
Ran black, removed temp example
sscini 6b3ee40
Added utility to update model using suffix values
sscini 5cadfac
Work on Friday 6/27 applying PR comments
sscini 922fd57
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini 1be2d9e
Addressed some reviewer comments and ran black.
sscini 56800f5
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini 05381c5
Updated argument for theta_est_multistart
sscini 5b4f9c1
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini 07ae1e8
Addressed majority of review comments. State before 7/8 dev meeting
sscini 33d838f
Fixing conflict
sscini 65a9cff
Merge branch 'main' into multistart-in-parmest
sscini 90093df
Merge branch 'Pyomo:main' into multistart-in-parmest
sscini e7b2df1
Added in TODO items based on Dan morning meeting
sscini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ def ef_nonants(ef): | |
|
|
||
|
|
||
| def _experiment_instance_creation_callback( | ||
| scenario_name, node_names=None, cb_data=None | ||
| scenario_name, node_names=None, cb_data=None, fix_vars=False, | ||
| ): | ||
| """ | ||
| This is going to be called by mpi-sppy or the local EF and it will call into | ||
|
|
@@ -107,6 +107,8 @@ def _experiment_instance_creation_callback( | |
| that is the "callback" value. | ||
| "BootList" is None or bootstrap experiment number list. | ||
| (called cb_data by mpisppy) | ||
| fix_vars: `bool` If True, the theta variables are fixed to the values | ||
| provided in the cb_data["ThetaVals"] dictionary. | ||
|
|
||
|
|
||
| Returns: | ||
|
|
@@ -217,16 +219,22 @@ def _experiment_instance_creation_callback( | |
| # This is the only way I see to pass the theta values to the model | ||
| # Can we add an optional argument to fix them or not? | ||
| # Curently, thetavals provided are fixed if not None | ||
| # Suggested fix in this function and _Q_at_theta | ||
| if "ThetaVals" in outer_cb_data: | ||
| thetavals = outer_cb_data["ThetaVals"] | ||
|
|
||
| # dlw august 2018: see mea code for more general theta | ||
| for name, val in thetavals.items(): | ||
| theta_cuid = ComponentUID(name) | ||
| theta_object = theta_cuid.find_component_on(instance) | ||
| if val is not None: | ||
| if val is not None and fix_vars is True: | ||
| # print("Fixing",vstr,"at",str(thetavals[vstr])) | ||
| theta_object.fix(val) | ||
| # ADDED OPTION: Set initial value, but do not fix | ||
| elif val is not None and fix_vars is False: | ||
| # print("Setting",vstr,"to",str(thetavals[vstr])) | ||
| theta_object.set_value(val) | ||
| theta_object.unfix() | ||
| else: | ||
| # print("Freeing",vstr) | ||
| theta_object.unfix() | ||
|
|
@@ -829,7 +837,7 @@ def _Q_at_theta(self, thetavals, initialize_parmest_model=False): | |
|
|
||
| # start block of code to deal with models with no constraints | ||
| # (ipopt will crash or complain on such problems without special care) | ||
| instance = _experiment_instance_creation_callback("FOO0", None, dummy_cb) | ||
| instance = _experiment_instance_creation_callback("FOO0", None, dummy_cb,) | ||
| try: # deal with special problems so Ipopt will not crash | ||
| first = next(instance.component_objects(pyo.Constraint, active=True)) | ||
| active_constraints = True | ||
|
|
@@ -846,7 +854,7 @@ def _Q_at_theta(self, thetavals, initialize_parmest_model=False): | |
|
|
||
| for snum in scenario_numbers: | ||
| sname = "scenario_NODE" + str(snum) | ||
| instance = _experiment_instance_creation_callback(sname, None, dummy_cb) | ||
| instance = _experiment_instance_creation_callback(sname, None, dummy_cb, fix_vars=True) | ||
| model_theta_names = self._expand_indexed_unknowns(instance) | ||
|
|
||
| if initialize_parmest_model: | ||
|
|
@@ -1214,11 +1222,14 @@ def theta_est_multistart( | |
|
|
||
| # # Check if the objective value is better than the best objective value | ||
| # # Set a very high initial best objective value | ||
| best_objectiveval = np.inf | ||
| best_theta = np.inf | ||
| if i == 0: | ||
| # Initialize best objective value and theta | ||
| best_objectiveval = np.inf | ||
| best_theta = np.inf | ||
| # Check if the final objective value is better than the best found so far | ||
| if final_objectiveval < best_objectiveval: | ||
| best_objectiveval = objectiveval | ||
| best_theta = theta_vals_current | ||
| best_theta = converged_theta.values | ||
|
|
||
| print(f"Restart {i+1}/{n_restarts}: Objective Value = {final_objectiveval}, Theta = {converged_theta}") | ||
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 would support having utility methods
_fix_unknown_parametersand_fix_experiment_inputslive within theExperimentclass. These methods could havefix=Trueas a default, andfix=Falsewould unfix.