Skip to content

Commit 5589d8e

Browse files
committed
switch to receive_ paradigm for nonant bounds
1 parent 912195c commit 5589d8e

File tree

6 files changed

+22
-25
lines changed

6 files changed

+22
-25
lines changed

Diff for: mpisppy/cylinders/fwph_spoke.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def sync(self):
2828
self.bound = self.opt._local_bound
2929

3030
# Update the nonant bounds, if possible
31-
self.update_nonant_bounds()
31+
self.receive_nonant_bounds()
3232

3333
def finalize(self):
3434
# The FWPH spoke can call "finalize" before it

Diff for: mpisppy/cylinders/hub.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def sync(self):
249249
self.send_boundsout()
250250
self.receive_outerbounds()
251251
self.receive_innerbounds()
252-
self.update_nonant_bounds()
252+
self.receive_nonant_bounds()
253253
if self.opt.extensions is not None:
254254
self.opt.extobject.sync_with_spokes()
255255

@@ -259,7 +259,7 @@ def sync_with_spokes(self):
259259
def sync_bounds(self):
260260
self.receive_outerbounds()
261261
self.receive_innerbounds()
262-
self.update_nonant_bounds()
262+
self.receive_nonant_bounds()
263263
self.send_boundsout()
264264

265265
def sync_extensions(self):
@@ -362,7 +362,7 @@ def sync(self, send_nonants=True):
362362
self.send_nonants()
363363
self.receive_outerbounds()
364364
self.receive_innerbounds()
365-
self.update_nonant_bounds()
365+
self.receive_nonant_bounds()
366366
# in case LShaped ever gets extensions
367367
if getattr(self.opt, "extensions", None) is not None:
368368
self.opt.extobject.sync_with_spokes()

Diff for: mpisppy/cylinders/lagrangian_bounder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def lagrangian_prep(self):
2020

2121
def lagrangian(self, need_solution=True):
2222
# update the nonant bounds, if possible, for a tighter relaxation
23-
self.update_nonant_bounds()
23+
self.receive_nonant_bounds()
2424
verbose = self.opt.options['verbose']
2525
# This is sort of a hack, but might help folks:
2626
if "ipopt" in self.opt.options["solver_name"]:

Diff for: mpisppy/cylinders/reduced_costs_spoke.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ def lagrangian(self, need_solution=True):
134134
return bound
135135

136136
def extract_and_store_reduced_costs(self):
137+
# if it's time, don't bother
138+
if self.got_kill_signal():
139+
return
140+
137141
self.opt.Compute_Xbar()
138142
# NaN will signal that the x values do not agree in
139143
# every scenario, we can't extract an expected reduced
@@ -206,13 +210,11 @@ def extract_and_store_reduced_costs(self):
206210
)
207211

208212
def extract_and_store_updated_nonant_bounds(self, lr_outer_bound):
209-
# update the best bound from the hub
210-
# as a side effect, calls update_receive_buffers
211-
# TODO: fix this side effect
213+
# if it's time, don't bother
212214
if self.got_kill_signal():
213215
return
214216

215-
self.update_innerbounds()
217+
self.receive_innerbounds()
216218

217219
if math.isinf(self.BestInnerBound):
218220
# can do anything with no bound

Diff for: mpisppy/cylinders/spcommunicator.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,16 @@ def get_receive_buffer(self,
394394
buf._is_new = False
395395
return False
396396

397-
def update_nonant_bounds(self):
398-
""" update the bounds on the nonanticipative variables based on
399-
Field.NONANT_LOWER_BOUNDS and Field.NONANT_UPPER_BOUNDS. The lower and
400-
upper bound buffers should be up-to-date, which can be done by calling
401-
`SPCommunicator.update_receive_buffers`.
397+
def receive_nonant_bounds(self):
398+
""" receive the bounds on the nonanticipative variables based on
399+
Field.NONANT_LOWER_BOUNDS and Field.NONANT_UPPER_BOUNDS. Updates the
400+
NONANT_LOWER_BOUNDS and NONANT_UPPER_BOUNDS buffers, and if new,
401+
updates the corresponding Pyomo nonant variables
402402
"""
403403
bounds_modified = 0
404-
for _, _, recv_buf in self.receive_field_spcomms[Field.NONANT_LOWER_BOUNDS]:
405-
if not recv_buf.is_new():
404+
for idx, _, recv_buf in self.receive_field_spcomms[Field.NONANT_LOWER_BOUNDS]:
405+
is_new = self.get_receive_buffer(recv_buf, Field.NONANT_LOWER_BOUNDS, idx)
406+
if not is_new:
406407
break
407408
for s in self.opt.local_scenarios.values():
408409
for ci, (ndn_i, xvar) in enumerate(s._mpisppy_data.nonant_indices.items()):
@@ -412,8 +413,9 @@ def update_nonant_bounds(self):
412413
if recv_buf[ci] > xvarlb:
413414
xvar.lb = recv_buf[ci]
414415
bounds_modified += 1
415-
for _, _, recv_buf in self.receive_field_spcomms[Field.NONANT_UPPER_BOUNDS]:
416-
if not recv_buf.is_new():
416+
for idx, _, recv_buf in self.receive_field_spcomms[Field.NONANT_UPPER_BOUNDS]:
417+
is_new = self.get_receive_buffer(recv_buf, Field.NONANT_UPPER_BOUNDS, idx)
418+
if not is_new:
417419
break
418420
for s in self.opt.local_scenarios.values():
419421
for ci, (ndn_i, xvar) in enumerate(s._mpisppy_data.nonant_indices.items()):

Diff for: mpisppy/cylinders/spoke.py

-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ def main(self):
3939
"""
4040
pass
4141

42-
def update_receive_buffers(self):
43-
for (key, recv_buf) in self.receive_buffers.items():
44-
field, rank = self._split_key(key)
45-
self.get_receive_buffer(recv_buf, field, rank)
46-
## End for
47-
return
48-
4942

5043
class _BoundSpoke(Spoke):
5144
""" A base class for bound spokes

0 commit comments

Comments
 (0)