Skip to content

Commit 037787f

Browse files
committed
adding coverage for coeff rho
1 parent f517440 commit 037787f

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

Diff for: examples/run_all.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,10 @@ def do_one_mmw(dirname, runefstring, npyfile, mmwargstring):
286286
4,
287287
"--instance-name=sslp_15_45_10 --bundles-per-rank=2 "
288288
"--max-iterations=5 --default-rho=1 "
289-
"--subgradient --xhatshuffle --fwph "
289+
"--subgradient --xhatshuffle --fwph --coeff-rho "
290290
"--linearize-proximal-terms "
291291
"--rel-gap=0.0 "
292292
"--solver-name={} --fwph-stop-check-tol 0.01".format(solver_name))
293-
294293
do_one("sslp",
295294
"sslp_cylinders.py",
296295
3,

Diff for: examples/sslp/sslp_cylinders.py

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def _parse_args():
3232
cfg.xhatshuffle_args()
3333
cfg.subgradient_args()
3434
cfg.reduced_costs_args()
35+
cfg.coeff_rho_args()
3536
cfg.parse_command_line("sslp_cylinders")
3637
return cfg
3738

@@ -87,9 +88,15 @@ def main():
8788
if reduced_costs:
8889
vanilla.add_reduced_costs_fixer(hub_dict, cfg)
8990

91+
if cfg.coeff_rho:
92+
vanilla.add_coeff_rho(hub_dict, cfg)
93+
9094
# FWPH spoke
9195
if fwph:
9296
fw_spoke = vanilla.fwph_spoke(*beans, scenario_creator_kwargs=scenario_creator_kwargs)
97+
# Need to fix FWPH to support extensions
98+
# if cfg.coeff_rho:
99+
# vanilla.add_coeff_rho(fw_spoke, cfg)
93100

94101
# Standard Lagrangian bound spoke
95102
if lagrangian:
@@ -100,6 +107,8 @@ def main():
100107
subgradient_spoke = vanilla.subgradient_spoke(*beans,
101108
scenario_creator_kwargs=scenario_creator_kwargs,
102109
rho_setter = None)
110+
if cfg.coeff_rho:
111+
vanilla.add_coeff_rho(subgradient_spoke, cfg)
103112

104113
# xhat looper bound spoke
105114
if xhatlooper:

Diff for: mpisppy/generic_cylinders.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ def _do_decomp(module, cfg, scenario_creator, scenario_creator_kwargs, scenario_
190190
all_nodenames=all_nodenames,
191191
rho_setter=rho_setter,
192192
)
193-
if cfg.sep_rho:
194-
vanilla.add_sep_rho(fw_spoke, cfg)
195-
if cfg.coeff_rho:
196-
vanilla.add_coeff_rho(fw_spoke, cfg)
193+
# Need to fix FWPH to support extensions
194+
# if cfg.sep_rho:
195+
# vanilla.add_sep_rho(fw_spoke, cfg)
196+
# if cfg.coeff_rho:
197+
# vanilla.add_coeff_rho(fw_spoke, cfg)
197198

198199
# Standard Lagrangian bound spoke
199200
if cfg.lagrangian:

Diff for: mpisppy/utils/cfg_vanilla.py

-2
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,10 @@ def add_sep_rho(hub_dict, cfg):
205205
hub_dict = extension_adder(hub_dict,SepRho)
206206
hub_dict["opt_kwargs"]["options"]["sep_rho_options"] = {"multiplier" : cfg.sep_rho_multiplier}
207207

208-
209208
def add_coeff_rho(hub_dict, cfg):
210209
hub_dict = extension_adder(hub_dict,CoeffRho)
211210
hub_dict["opt_kwargs"]["options"]["coeff_rho_options"] = {"multiplier" : cfg.coeff_rho_multiplier}
212211

213-
214212
def add_cross_scenario_cuts(hub_dict,
215213
cfg,
216214
):

Diff for: mpisppy/utils/sputils.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -942,24 +942,36 @@ def reenable_tictoc_output():
942942
tt_timer._ostream.close()
943943
tt_timer._ostream = sys.stdout
944944

945-
945+
946946
def find_active_objective(pyomomodel):
947+
return find_objective(pyomomodel, active=True)
948+
949+
950+
def find_objective(pyomomodel, active=False):
947951
# return the only active objective or raise and error
948952
obj = list(pyomomodel.component_data_objects(
949953
Objective, active=True, descend_into=True))
950-
if len(obj) != 1:
954+
if len(obj) == 1:
955+
return obj[0]
956+
if active or len(obj) > 1:
951957
raise RuntimeError("Could not identify exactly one active "
952958
"Objective for model '%s' (found %d objectives)"
953959
% (pyomomodel.name, len(obj)))
954-
return obj[0]
960+
# search again for a single inactive objective
961+
obj = list(pyomomodel.component_data_objects(
962+
Objective, descend_into=True))
963+
if len(obj) == 1:
964+
return obj[0]
965+
raise RuntimeError("Could not identify exactly one objective for model "
966+
f"{pyomomodel.name} (found {len(obj)} objectives)")
955967

956968

957969
def nonant_cost_coeffs(s):
958970
"""
959971
return a dictionary from s._mpisppy_data.nonant_indices.keys()
960972
to the objective cost coefficient
961973
"""
962-
objective = find_active_objective(s)
974+
objective = find_objective(s)
963975

964976
# initialize to 0
965977
cost_coefs = {ndn_i: 0 for ndn_i in s._mpisppy_data.nonant_indices}

0 commit comments

Comments
 (0)