Skip to content

Commit

Permalink
Merge pull request #493 from bknueven/fix_subgradient_main
Browse files Browse the repository at this point in the history
Bugfix: subgradient_main incorrectly runs PH
  • Loading branch information
bknueven authored Feb 19, 2025
2 parents 9413a74 + 0c8c59c commit e487023
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
16 changes: 14 additions & 2 deletions mpisppy/cylinders/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import abc
import logging
import mpisppy.log
from mpisppy.opt.subgradient import Subgradient
from mpisppy.opt.aph import APH

from mpisppy import MPI
Expand All @@ -27,6 +26,9 @@
logger = logging.getLogger("mpisppy.cylinders.Hub")

class Hub(SPCommunicator):

_hub_algo_best_bound_provider = False

def __init__(self, spbase_object, fullcomm, strata_comm, cylinder_comm, spokes, options=None):
super().__init__(spbase_object, fullcomm, strata_comm, cylinder_comm, options=options)
assert len(spokes) == self.n_spokes
Expand Down Expand Up @@ -548,7 +550,7 @@ def is_converged(self):
return False

if not self.has_outerbound_spokes:
if self.opt._PHIter == 1 and not isinstance(self.opt, Subgradient):
if self.opt._PHIter == 1 and not self._hub_algo_best_bound_provider:
global_toc(
"Without outer bound spokes, no progress "
"will be made on the Best Bound")
Expand Down Expand Up @@ -704,6 +706,16 @@ def send_nonants(self):
for idx in self.nonant_spoke_indices:
self.hub_to_spoke(nonant_send_buffer, idx)


class SubgradientHub(PHHub):

_hub_algo_best_bound_provider = True

def main(self):
""" SPComm gets attached in self.__init__ """
self.opt.subgradient_main(finalize=False)


class APHHub(PHHub):

def main(self):
Expand Down
3 changes: 0 additions & 3 deletions mpisppy/opt/subgradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ def subgradient_main(self, finalize=True):
The "trivial bound", computed by solving the model with no
nonanticipativity constraints (immediately after iter 0).
"""
return self.ph_main(finalize=finalize)

def ph_main(self, finalize=True):
# for use with the PH hub
if self.options["smoothed"] != 0:
raise RuntimeError("Cannnot use smoothing with Subgradient algorithm")
Expand Down
5 changes: 2 additions & 3 deletions mpisppy/utils/cfg_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
from mpisppy.cylinders.slam_heuristic import SlamMaxHeuristic, SlamMinHeuristic
from mpisppy.cylinders.cross_scen_spoke import CrossScenarioCutSpoke
from mpisppy.cylinders.reduced_costs_spoke import ReducedCostsSpoke
from mpisppy.cylinders.hub import PHHub
from mpisppy.cylinders.hub import APHHub
from mpisppy.cylinders.hub import PHHub, SubgradientHub, APHHub
from mpisppy.extensions.extension import MultiExtension
from mpisppy.extensions.fixer import Fixer
from mpisppy.extensions.integer_relax_then_enforce import IntegerRelaxThenEnforce
Expand Down Expand Up @@ -195,7 +194,7 @@ def subgradient_hub(cfg,
options["smoothed"] = 0

hub_dict = {
"hub_class": PHHub,
"hub_class": SubgradientHub,
"hub_kwargs": {"options": {"rel_gap": cfg.rel_gap,
"abs_gap": cfg.abs_gap,
"max_stalled_iters": cfg.max_stalled_iters}},
Expand Down

0 comments on commit e487023

Please sign in to comment.