Skip to content

Commit

Permalink
only compute cost coeffs once
Browse files Browse the repository at this point in the history
  • Loading branch information
bknueven committed Oct 14, 2024
1 parent 29944ee commit 14f92fa
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions mpisppy/extensions/sep_rho.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self, ph, comm=None):
self.multiplier = ph.options["sep_rho_options"]["multiplier"]
self.cfg = ph.options["sep_rho_options"]["cfg"]

self._nonant_cost_coeffs = None

def _compute_primal_residual_norm(self, ph):
local_nodenames = []
local_primal_residuals = {}
Expand Down Expand Up @@ -136,14 +138,20 @@ def _compute_xmax(ph):
def _compute_xmin(ph):
return SepRho._compute_min_max(ph, np.minimum, MPI.MIN, np.inf)

def nonant_cost_coeffs(self, s):
if self._nonant_cost_coeffs is None:
# Should be the same in every scenario...
self._nonant_cost_coeffs = nonant_cost_coeffs(s)
return self._nonant_cost_coeffs

def _compute_and_update_rho(self):
ph = self.ph
primal_resid = self._compute_primal_residual_norm(ph)
xmax = self._compute_xmax(ph)
xmin = self._compute_xmin(ph)

for s in ph.local_scenarios.values():
cc = nonant_cost_coeffs(s)
cc = self.nonant_cost_coeffs(s)
for ndn_i, rho in s._mpisppy_model.rho.items():
if cc[ndn_i] != 0:
nv = s._mpisppy_data.nonant_indices[ndn_i] # var_data object
Expand All @@ -154,15 +162,7 @@ def _compute_and_update_rho(self):
rho._value *= self.multiplier

def compute_and_update_rho(self):
reenable_prox = False
if not self.ph.prox_disabled:
self.ph._disable_prox()
reenable_prox = True
# this will ask for objective function coefficients,
# so we don't want the prox term (TODO: and maybe W?)
self._compute_and_update_rho()
if reenable_prox:
self.ph._reenable_prox()
sum_rho = 0.0
num_rhos = 0 # could be computed...
for sname, s in self.opt.local_scenarios.items():
Expand Down

0 comments on commit 14f92fa

Please sign in to comment.