Skip to content

Commit 0cfa254

Browse files
committed
use duck typing for Hub/Spoke
1 parent 3cf7534 commit 0cfa254

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

Diff for: mpisppy/opt/fwph.py

+8-14
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
from pyomo.core.expr.visitor import replace_expressions
3232
from pyomo.core.expr.numeric_expr import LinearExpression
3333

34-
from mpisppy.cylinders.spoke import Spoke
35-
from mpisppy.cylinders.hub import FWPHHub
3634
from mpisppy.cylinders.xhatshufflelooper_bounder import ScenarioCycler
3735
from mpisppy.extensions.xhatbase import XhatBase
3836

@@ -72,7 +70,6 @@ def __init__(
7270

7371
def _init(self, FW_options):
7472
self.FW_options = FW_options
75-
self.FW_options["save_file"] = "fwph_bench.out"
7673
self._options_checks_fw()
7774
self.vb = True
7875
if ('FW_verbose' in self.FW_options):
@@ -146,7 +143,7 @@ def fwph_main(self, finalize=True):
146143
if (self.extensions):
147144
self.extobject.miditer()
148145

149-
if isinstance(self.spcomm, FWPHHub):
146+
if hasattr(self.spcomm, "sync_Ws"):
150147
self.spcomm.sync_Ws()
151148
if (self._is_timed_out()):
152149
# TODO: replace the convergence messages with global_toc
@@ -212,20 +209,19 @@ def fwph_main(self, finalize=True):
212209
self._reenable_W()
213210

214211
## Hubs/spokes take precedence over convergers
215-
if self.spcomm:
216-
if isinstance(self.spcomm, FWPHHub):
217-
self.spcomm.sync_nonants()
218-
self.spcomm.sync_bounds()
219-
self.spcomm.sync_extensions()
212+
if hasattr(self.spcomm, "sync_nonants"):
213+
self.spcomm.sync_nonants()
214+
self.spcomm.sync_bounds()
215+
self.spcomm.sync_extensions()
220216
if self.spcomm.is_converged():
221217
secs = time.time() - self.t0
222218
self._output(self._local_bound,
223219
best_bound, np.nan, secs)
224220
if (self.cylinder_rank == 0 and self.vb):
225221
print('FWPH converged to user-specified criteria')
226222
break
227-
if isinstance(self.spcomm, Spoke):
228-
self.spcomm.sync()
223+
elif hasattr(self.spcomm, "sync"):
224+
self.spcomm.sync()
229225

230226
if (self.extensions):
231227
self.extobject.enditer_after_sync()
@@ -509,9 +505,7 @@ def _attach_nonant_objective(self, mip, _print_warning=[True]):
509505
obj = find_active_objective(mip)
510506
repn = generate_standard_repn(obj.expr, compute_values=False, quadratic=False)
511507
nonant_var_ids = mip._mpisppy_data.varid_to_nonant_index
512-
if len(repn.nonlinear_vars) > 0:
513-
# hopefull a small number
514-
nonlinear_vars = {id(v) for v in repn.nonlinear_vars}
508+
if repn.nonlinear_vars:
515509
for v in repn.nonlinear_vars:
516510
if id(v) in nonant_var_ids:
517511
raise RuntimeError("FWPH does not support models where the nonants "

0 commit comments

Comments
 (0)