Skip to content

Commit 8ecfb8d

Browse files
authored
Merge pull request #485 from bknueven/fix_xhatshuffle
XhatShuffleInnerBound: always try at least two scenarios
2 parents 4f0d94f + 3bbbb32 commit 8ecfb8d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

mpisppy/cylinders/xhatshufflelooper_bounder.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ def _vb(msg):
121121
_vb(" Begin epoch")
122122
scenario_cycler.begin_epoch()
123123

124+
# always try at least two for each set of nonants
125+
# so we continue to explore the scenarios and
126+
# do not stall out on a single scenario because
127+
# the hub is moving very fast
128+
next_scendict = scenario_cycler.get_next()
129+
if next_scendict is not None:
130+
_vb(f" Trying next {next_scendict}")
131+
update = self.try_scenario_dict(next_scendict)
132+
if update:
133+
_vb(f" Updating best to {next_scendict}")
134+
scenario_cycler.best = next_scendict["ROOT"]
135+
124136
next_scendict = scenario_cycler.get_next()
125137
if next_scendict is not None:
126138
_vb(f" Trying next {next_scendict}")
@@ -140,13 +152,14 @@ def __init__(self, shuffled_scenarios,nonleaves,reverse,iter_step):
140152
root_kids = nonleaves['ROOT'].kids if 'ROOT' in nonleaves else None
141153
if root_kids is None or len(root_kids)==0 or root_kids[0].is_leaf:
142154
self._multi = False
143-
self._iter_shift = 1 if iter_step is None else iter_step
155+
self._iter_shift = 0 if iter_step is None else iter_step
144156
self._use_reverse = False #It is useless to reverse for 2stage SP
145157
else:
146158
self._multi = True
147159
self.BF0 = len(root_kids)
148160
self._nonleaves = nonleaves
149-
161+
# TODO: is this right for multistage, or should the default be
162+
# 0 like in the two-stage case?
150163
self._iter_shift = self.BF0 if iter_step is None else iter_step
151164
self._use_reverse = True if reverse is None else reverse
152165
self._reversed = False #Do we iter in reverse mode ?
@@ -189,7 +202,7 @@ def _add_sname_to_node(ndn):
189202
filling_idx +=1
190203
filling_idx %= self._num_scenarios
191204

192-
def create_nodescen_dict(self):
205+
def _create_nodescen_dict(self):
193206
'''
194207
Creates an attribute nodescen_dict.
195208
Keys are nonleaf names, values are local scenario names
@@ -203,7 +216,7 @@ def create_nodescen_dict(self):
203216
self.nodescen_dict = dict()
204217
self._fill_nodescen_dict(self._nonleaves.keys())
205218

206-
def update_nodescen_dict(self,snames_to_remove):
219+
def _update_nodescen_dict(self,snames_to_remove):
207220
'''
208221
WARNING: _cur_ROOTscen must be up to date when calling this method
209222
'''
@@ -230,7 +243,7 @@ def _begin_normal_epoch(self):
230243
self._shuffled_snames = [s[1] for s in self._shuffled_scenarios]
231244
self._original_order = [s[0] for s in self._shuffled_scenarios]
232245
self._cur_ROOTscen = self._shuffled_snames[0] if self.best is None else self.best
233-
self.create_nodescen_dict()
246+
self._create_nodescen_dict()
234247

235248
self._scenarios_this_epoch = set()
236249

@@ -239,7 +252,7 @@ def _begin_reverse_epoch(self):
239252
self._shuffled_snames = [s[1] for s in reversed(self._shuffled_scenarios)]
240253
self._original_order = [s[0] for s in reversed(self._shuffled_scenarios)]
241254
self._cur_ROOTscen = self._shuffled_snames[0] if self.best is None else self.best
242-
self.create_nodescen_dict()
255+
self._create_nodescen_dict()
243256

244257
self._scenarios_this_epoch = set()
245258

@@ -270,9 +283,9 @@ def _iter_scen(self):
270283
#Updating scenarios
271284
self._cur_ROOTscen = self._shuffled_snames[self._cycle_idx]
272285
if old_idx<self._cycle_idx:
273-
scens_to_remove = self._shuffled_snames[old_idx:self._cycle_idx]
286+
scens_to_remove = set(self._shuffled_snames[old_idx:self._cycle_idx])
274287
else:
275-
scens_to_remove = self._shuffled_snames[old_idx:]+self._shuffled_snames[:self._cycle_idx]
276-
self.update_nodescen_dict(scens_to_remove)
288+
scens_to_remove = set(self._shuffled_snames[old_idx:]+self._shuffled_snames[:self._cycle_idx])
289+
self._update_nodescen_dict(scens_to_remove)
277290

278291

0 commit comments

Comments
 (0)