-
Notifications
You must be signed in to change notification settings - Fork 43
Subgradient hub #487
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
Subgradient hub #487
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d3ca9ea
initial pass at subgradient hub
bknueven d38b29d
allow subgradient to update its best bound, if we have no additional …
bknueven 98c2a07
fixing missing variable when verbose=True
bknueven 7c8423e
being more careful about reporting iteration 0 bounds
bknueven c600440
fixing naming per code review
bknueven c3c3d7b
add a blurb on subgradient
bknueven b90a975
add subgradient hub example
bknueven 8a12381
factoring out ph_main
bknueven 0f8ae21
Merge branch 'main' into subgradient_hub
bknueven c1b1eca
rename SUBGRAD to subgradient_hub
bknueven 4eca998
Merge branch 'main' into subgradient_hub
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
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,131 @@ | ||
############################################################################### | ||
# 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. | ||
############################################################################### | ||
|
||
import mpisppy.phbase | ||
import mpisppy.MPI as _mpi | ||
|
||
_global_rank = _mpi.COMM_WORLD.Get_rank() | ||
|
||
class Subgradient(mpisppy.phbase.PHBase): | ||
""" Subgradient Algorithm """ | ||
|
||
def subgradient_main(self, finalize=True): | ||
""" Execute the subgradient algorithm. | ||
|
||
Args: | ||
finalize (bool, optional, default=True): | ||
If True, call `PH.post_loops()`, if False, do not, | ||
and return None for Eobj | ||
|
||
Returns: | ||
tuple: | ||
Tuple containing | ||
|
||
conv (float): | ||
The convergence value (not easily interpretable). | ||
Eobj (float or `None`): | ||
If `finalize=True`, this is the expected, weighted | ||
objective value. This value is not directly useful. | ||
If `finalize=False`, this value is `None`. | ||
trivial_bound (float): | ||
The "trivial bound", computed by solving the model with no | ||
nonanticipativity constraints (immediately after iter 0). | ||
""" | ||
verbose = self.options['verbose'] | ||
smoothed = self.options['smoothed'] | ||
if smoothed != 0: | ||
raise RuntimeError("Cannnot use smoothing with Subgradient algorithm") | ||
self.PH_Prep(attach_prox=False, attach_smooth=smoothed) | ||
|
||
if (verbose): | ||
print('Calling Subgradient Iter0 on global rank {}'.format(_global_rank)) | ||
trivial_bound = self.Iter0() | ||
# set self.best_bound_obj_val if we don't have any additional fixed variables | ||
if self._can_update_best_bound(): | ||
self.best_bound_obj_val = trivial_bound | ||
if (verbose): | ||
print('Completed Subgradient Iter0 on global rank {}'.format(_global_rank)) | ||
|
||
self.iterk_loop() | ||
|
||
if finalize: | ||
Eobj = self.post_loops(self.extensions) | ||
else: | ||
Eobj = None | ||
|
||
return self.conv, Eobj, trivial_bound | ||
|
||
def ph_main(self, finalize=True): | ||
# for working with a PHHub | ||
return self.subgradient_main(finalize=finalize) | ||
|
||
def solve_loop(self, | ||
solver_options=None, | ||
use_scenarios_not_subproblems=False, | ||
dtiming=False, | ||
dis_W=False, | ||
dis_prox=False, | ||
gripe=False, | ||
disable_pyomo_signal_handling=False, | ||
tee=False, | ||
verbose=False, | ||
need_solution=True, | ||
): | ||
""" Loop over `local_subproblems` and solve them in a manner | ||
dicated by the arguments. | ||
|
||
In addition to changing the Var values in the scenarios, this function | ||
also updates the `_PySP_feas_indictor` to indicate which scenarios were | ||
feasible/infeasible. | ||
|
||
Args: | ||
solver_options (dict, optional): | ||
The scenario solver options. | ||
use_scenarios_not_subproblems (boolean, optional): | ||
If True, solves individual scenario problems, not subproblems. | ||
This distinction matters when using bundling. Default is False. | ||
dtiming (boolean, optional): | ||
If True, reports solve timing information. Default is False. | ||
dis_W (boolean, optional): | ||
If True, duals weights (Ws) are disabled before solve, then | ||
re-enabled after solve. Default is False. | ||
dis_prox (boolean, optional): | ||
If True, prox terms are disabled before solve, then | ||
re-enabled after solve. Default is False. | ||
gripe (boolean, optional): | ||
If True, output a message when a solve fails. Default is False. | ||
disable_pyomo_signal_handling (boolean, optional): | ||
True for asynchronous PH; ignored for persistent solvers. | ||
Default False. | ||
tee (boolean, optional): | ||
If True, displays solver output. Default False. | ||
verbose (boolean, optional): | ||
If True, displays verbose output. Default False. | ||
need_solution (boolean, optional): | ||
If True, raises an exception if a solution is not available. | ||
Default True | ||
""" | ||
super().solve_loop( | ||
solver_options=solver_options, | ||
use_scenarios_not_subproblems=use_scenarios_not_subproblems, | ||
dtiming=dtiming, | ||
dis_W=dis_W, | ||
dis_prox=dis_prox, | ||
gripe=gripe, | ||
disable_pyomo_signal_handling=disable_pyomo_signal_handling, | ||
tee=tee, | ||
verbose=verbose, | ||
need_solution=need_solution, | ||
) | ||
|
||
# set self.best_bound_obj_val if we don't have any additional fixed variables | ||
if self._can_update_best_bound(): | ||
self.best_bound_obj_val = self.Ebound(verbose) | ||
|
||
|
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
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.