-
Notifications
You must be signed in to change notification settings - Fork 45
Relaxed PH spoke #513
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
Merged
Merged
Relaxed PH spoke #513
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cc62ba4
add PH nonant only hub
bknueven ea4bf60
adding relaxed PH spoke
bknueven 77707a7
adding relaxed PH fixer
bknueven 9d2b3ae
only one PH log
bknueven 60ee00d
remove unneeded numpy import
bknueven 19264ef
more helpful debug statements
bknueven 4e1cf1f
explicitly point to nonant_field
bknueven 67d085c
class documentation; cleanup
bknueven 18b7f2f
adding some missing documentation (both for the PR and prior work)
bknueven 6922d53
Merge branch 'main' into relaxed_PH_spoke
bknueven 3022126
Minor fixes to documentation
bknueven a572f40
Merge branch 'main' into relaxed_PH_spoke
bknueven 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
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
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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| ############################################################################### | ||
| # mpi-sppy: MPI-based Stochastic Programming in PYthon | ||
| # | ||
| # Copyright (c) 2024, Lawrence Livermore National Security, LLC, Alliance for | ||
| # Sustainable Energy, LLC, The Regents of the University of California, et al. | ||
| # All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md for | ||
| # full copyright and license information. | ||
| ############################################################################### | ||
|
|
||
| from mpisppy.cylinders.spwindow import Field | ||
| from mpisppy.cylinders.spoke import Spoke | ||
| from mpisppy.cylinders.hub import PHHub | ||
|
|
||
| import pyomo.environ as pyo | ||
|
|
||
| class RelaxedPHSpoke(Spoke, PHHub): | ||
|
|
||
| send_fields = (*Spoke.send_fields, Field.DUALS, Field.RELAXED_NONANT, ) | ||
| receive_fields = (*Spoke.receive_fields, ) | ||
|
|
||
| @property | ||
| def nonant_field(self): | ||
| return Field.RELAXED_NONANT | ||
|
|
||
| def send_boundsout(self): | ||
| # overwrite PHHub.send_boundsout (not a hub) | ||
| return | ||
|
|
||
| def update_rho(self): | ||
| rho_factor = self.opt.options.get("relaxed_ph_rho_factor", 1.0) | ||
| if rho_factor == 1.0: | ||
| return | ||
| for s in self.opt.local_scenarios.values(): | ||
| for rho in s._mpisppy_model.rho.values(): | ||
| rho._value = rho_factor * rho._value | ||
|
|
||
| def main(self): | ||
| # relax the integers | ||
| integer_relaxer = pyo.TransformationFactory("core.relax_integer_vars") | ||
| for s in self.opt.local_scenarios.values(): | ||
| integer_relaxer.apply_to(s) | ||
|
|
||
| # setup, PH Iter0 | ||
| smoothed = self.options.get('smoothed', 0) | ||
| attach_prox = True | ||
| self.opt.PH_Prep(attach_prox=attach_prox, attach_smooth = smoothed) | ||
| trivial_bound = self.opt.Iter0() | ||
| if self.opt._can_update_best_bound(): | ||
| self.opt.best_bound_obj_val = trivial_bound | ||
|
|
||
| # update the rho | ||
| self.update_rho() | ||
|
|
||
| # rest of PH | ||
| self.opt.iterk_loop() | ||
|
|
||
| return self.opt.conv, None, trivial_bound |
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
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,119 @@ | ||||||
| ############################################################################### | ||||||
| # mpi-sppy: MPI-based Stochastic Programming in PYthon | ||||||
| # | ||||||
| # Copyright (c) 2024, Lawrence Livermore National Security, LLC, Alliance for | ||||||
| # Sustainable Energy, LLC, The Regents of the University of California, et al. | ||||||
| # All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md for | ||||||
| # full copyright and license information. | ||||||
| ############################################################################### | ||||||
| from mpisppy.extensions.extension import Extension | ||||||
| from mpisppy.utils.sputils import is_persistent | ||||||
|
|
||||||
| from mpisppy.cylinders.spwindow import Field | ||||||
|
|
||||||
| class RelaxedPHFixer(Extension): | ||||||
|
|
||||||
| def __init__(self, spobj): | ||||||
| super().__init__(spobj) | ||||||
|
|
||||||
| ph_options = spobj.options | ||||||
| ph_fixer_options = ph_options.get("relaxed_ph_fixer_options", {}) | ||||||
| self.bound_tol = ph_fixer_options.get("bound_tol", 1e-4) | ||||||
| self.verbose = ph_fixer_options.get("verbose", True) | ||||||
| self.debug = ph_fixer_options.get("debug", False) | ||||||
|
|
||||||
| self._heuristic_fixed_vars = {} | ||||||
| self._current_relaxed_nonants = None | ||||||
|
|
||||||
| def pre_iter0(self): | ||||||
| self._modeler_fixed_nonants = set() | ||||||
| self.nonant_length = self.opt.nonant_length | ||||||
| for k,s in self.opt.local_scenarios.items(): | ||||||
| for ndn_i, xvar in s._mpisppy_data.nonant_indices.items(): | ||||||
| if xvar.fixed: | ||||||
| self._modeler_fixed_nonants.add(ndn_i) | ||||||
|
|
||||||
| for k,sub in self.opt.local_subproblems.items(): | ||||||
| self._heuristic_fixed_vars[k] = 0 | ||||||
|
|
||||||
| def iter0_post_solver_creation(self): | ||||||
| # wait for relaxed iter0: | ||||||
| if self.relaxed_nonant_buf.id() == 0: | ||||||
| while not self.opt.spcomm.get_receive_buffer(self.relaxed_nonant_buf, Field.RELAXED_NONANT, self.relaxed_ph_spoke_index): | ||||||
| continue | ||||||
|
||||||
| continue | |
| time.sleep(0.01) # Reduce CPU usage during busy-wait |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.