Skip to content

Commit

Permalink
Merge pull request #490 from bknueven/raw_strings
Browse files Browse the repository at this point in the history
  • Loading branch information
bknueven authored Feb 11, 2025
2 parents dd6ff63 + caa4980 commit df6c651
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions mpisppy/fwph/fwph.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def _gather_weight_dict(self, strip_bundle_names=False):
if (self.bundling and strip_bundle_names):
scenario_weights = dict()
for ndn_ix, var in scenario._mpisppy_data.nonant_indices.items():
rexp = '^' + scenario.name + '\.'
rexp = r'^' + scenario.name + r'\.'
var_name = re.sub(rexp, '', var.name)
scenario_weights[var_name] = \
scenario._mpisppy_model.W[ndn_ix].value
Expand Down Expand Up @@ -663,7 +663,7 @@ def _get_xbars(self, strip_bundle_names=False):
for (ix, var) in enumerate(node.nonant_vardata_list):
var_name = var.name
if (self.bundling and strip_bundle_names):
rexp = '^' + random_scenario_name + '\.'
rexp = r'^' + random_scenario_name + r'\.'
var_name = re.sub(rexp, '', var_name)
xbar_dict[var_name] = scenario._mpisppy_model.xbars[node.name, ix].value
return xbar_dict
Expand Down
8 changes: 4 additions & 4 deletions mpisppy/utils/sputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def parent_ndn(nodename):
if nodename == 'ROOT':
return None
else:
return re.search('(.+)_(\d+)',nodename).group(1)
return re.search(r'(.+)_(\d+)',nodename).group(1)


def option_string_to_dict(ostr):
Expand Down Expand Up @@ -759,7 +759,7 @@ def __init__(self, Parent, scenfirst, scenlast, desc_leaf_dict, name):
# make children
first = scenfirst
self.kids = list()
child_regex = re.compile(name+'_\d*\Z')
child_regex = re.compile(name+r'_\d*\Z')
child_list = [x for x in desc_leaf_dict if child_regex.match(x) ]
for i in range(len(desc_leaf_dict)):
childname = name+f"_{i}"
Expand All @@ -768,7 +768,7 @@ def __init__(self, Parent, scenfirst, scenlast, desc_leaf_dict, name):
raise RuntimeError("The all_nodenames argument is giving an inconsistent tree."
f"The node {name} has {len(child_list)} children, but {childname} is not one of them.")
break
childdesc_regex = re.compile(childname+'(_\d*)*\Z')
childdesc_regex = re.compile(childname+r'(_\d*)*\Z')
child_leaf_dict = {ndn:desc_leaf_dict[ndn] for ndn in desc_leaf_dict \
if childdesc_regex.match(ndn)}
#We determine the number of children of this node
Expand Down Expand Up @@ -1079,7 +1079,7 @@ def get_branching_factors_from_nodenames(all_nodenames):
staget_node = "ROOT"
branching_factors = []
while staget_node+"_0" in all_nodenames:
child_regex = re.compile(staget_node+'_\d*\Z')
child_regex = re.compile(staget_node+r'_\d*\Z')
child_list = [x for x in all_nodenames if child_regex.match(x) ]

branching_factors.append(len(child_list))
Expand Down
4 changes: 2 additions & 2 deletions mpisppy/utils/wxbarutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def write_W_to_file(PHB, fname, sep_files=False):


def set_W_from_file(fname, PHB, rank, sep_files=False, disable_check=False):
'''
r'''
Args:
fname (str) -- if sep_files=False, file containing the dual weights.
Otherwise, path of the directory containing the dual weight files
Expand Down Expand Up @@ -269,7 +269,7 @@ def _check_W(w_val_dict, PHB, rank):
dual = sum(c[vname] for c in checks)
if (abs(dual) > 1e-7):
raise RuntimeError('Provided weights do not satisfy '
'dual feasibility: \sum_{scenarios} prob(s) * w(s) != 0. '
r'dual feasibility: \sum_{scenarios} prob(s) * w(s) != 0. '
'Error on variable ' + vname)

''' X-bar utilities '''
Expand Down

0 comments on commit df6c651

Please sign in to comment.