Skip to content

Commit

Permalink
change default for cfg add to be complain (#438)
Browse files Browse the repository at this point in the history
* change default for add to be complain

* runtime error if you attempt to a duplicate to cfg is not default

* change amalgamator call that duplicates cfg entries
  • Loading branch information
DLWoodruff authored Oct 30, 2024
1 parent c8895f2 commit e047d33
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mpisppy/utils/amalgamator.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def from_module(mname, cfg, extraargs_fct=None, use_command_line=True):
cfg = Amalgamator_parser(cfg, m.inparser_adder,
extraargs_fct=extraargs_fct,
use_command_line=use_command_line)
cfg.add_and_assign('_mpisppy_probability', description="Uniform prob.", domain=float, default=None, value= 1/cfg['num_scens'])
cfg.add_and_assign('_mpisppy_probability', description="Uniform prob.", domain=float, default=None, value= 1/cfg['num_scens'], complain=False)
start = cfg['start'] if 'start' in cfg else 0
sn = m.scenario_names_creator(cfg['num_scens'], start=start)
dn = m.scenario_denouement if hasattr(m, "scenario_denouement") else None
Expand Down
5 changes: 2 additions & 3 deletions mpisppy/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def add_to_config(self, name, description, domain, default,


#===============
def add_and_assign(self, name, description, domain, default, value, complain=False):
def add_and_assign(self, name, description, domain, default, value, complain=True):
""" Add an arg to the self dict and assign it a value
Args:
name (str): the argument name, underscore separated
Expand All @@ -98,8 +98,7 @@ def add_and_assign(self, name, description, domain, default, value, complain=Fal
"""
if name in self:
if complain:
print(f"Duplicate {name} will not be added to self by add_and_assign {value}.")
# raise RuntimeError(f"Trying to add duplicate {name} to self.")
raise RuntimeError(f"Trying to add duplicate {name=} to cfg {value=}")
else:
self.add_to_config(name, description, domain, default, argparse=False)
self[name] = value
Expand Down

0 comments on commit e047d33

Please sign in to comment.