From 49ded6045bca6eee5b2341d6a3464e162c5abc02 Mon Sep 17 00:00:00 2001 From: David L Woodruff Date: Tue, 1 Oct 2024 11:17:11 -0700 Subject: [PATCH] getting started on a checker for selected config options (#436) --- mpisppy/generic_cylinders.py | 3 ++- mpisppy/utils/config.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mpisppy/generic_cylinders.py b/mpisppy/generic_cylinders.py index ad18286a7..50649d556 100644 --- a/mpisppy/generic_cylinders.py +++ b/mpisppy/generic_cylinders.py @@ -73,8 +73,9 @@ def _parse_args(m): cfg.sep_rho_args() cfg.coeff_rho_args() cfg.sensi_rho_args() - cfg.parse_command_line(f"mpi-sppy for {cfg.module_name}") + + cfg.checker() # looks for inconsistencies return cfg def _name_lists(module, cfg): diff --git a/mpisppy/utils/config.py b/mpisppy/utils/config.py index a8b334a2a..ac31d36e5 100644 --- a/mpisppy/utils/config.py +++ b/mpisppy/utils/config.py @@ -140,6 +140,20 @@ def get(self, name, ifmissing=None): else: return ifmissing + #=============== + def checker(self): + """Verify that options *selected* make sense with respect to each other + """ + def _bad_rho_setters(msg): + raise ValueError("Rho setter options do not make sense together:\n" + f"{msg}") + + if self.grad_rho_setter and self.sensi_rho: + _bad_rho_setters("Only one rho setter can be active.") + if not self.grad_rho_setter and not self.sensi_rho: + if self.dynamic_rho_primal_crit or self.dynamic_rho_dual_crit: + _bad_rho_setters("dynamic rho only works with grad- and sensi-") + def add_solver_specs(self, prefix=""): sstr = f"{prefix}_solver" if prefix != "" else "solver" self.add_to_config(f"{sstr}_name",