From e047d33d8b5838a1ccb5bb687721f58ad1804791 Mon Sep 17 00:00:00 2001 From: David L Woodruff Date: Wed, 30 Oct 2024 11:04:07 -0700 Subject: [PATCH] change default for cfg add to be complain (#438) * 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 --- mpisppy/utils/amalgamator.py | 2 +- mpisppy/utils/config.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mpisppy/utils/amalgamator.py b/mpisppy/utils/amalgamator.py index b051bbdc..7fc6f6b7 100644 --- a/mpisppy/utils/amalgamator.py +++ b/mpisppy/utils/amalgamator.py @@ -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 diff --git a/mpisppy/utils/config.py b/mpisppy/utils/config.py index e6003424..55bb6892 100644 --- a/mpisppy/utils/config.py +++ b/mpisppy/utils/config.py @@ -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 @@ -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