def __init__(self, OptimizerClass: tp.Type[Optimizer], config: tp.Dict[str, tp.Any], as_config: bool = False) -> None: self._OptimizerClass = OptimizerClass config.pop("self", None) # self comes from "locals()" config.pop("__class__", None) # self comes from "locals()" self._as_config = as_config self._config = config # keep all, to avoid weird behavior at mismatch between optim and configoptim diff = ngtools.different_from_defaults(instance=self, instance_dict=config, check_mismatches=True) params = ", ".join(f"{x}={y!r}" for x, y in sorted(diff.items())) self.name = f"{self.__class__.__name__}({params})" if not as_config: # try instantiating for init checks # if as_config: check can be done before setting attributes self(parametrization=4, budget=100)
def __init__(self, OptimizerClass: OptCls, config: tp.Dict[str, tp.Any], as_config: bool = False) -> None: self._OptimizerClass = OptimizerClass config.pop("self", None) # self comes from "locals()" config.pop("__class__", None) # self comes from "locals()" self._as_config = as_config self._config = config # keep all, to avoid weird behavior at mismatch between optim and configoptim diff = ngtools.different_from_defaults(instance=self, instance_dict=config, check_mismatches=True) params = ", ".join(f"{x}={y!r}" for x, y in sorted(diff.items())) self.name = f"{self.__class__.__name__}({params})" if not as_config: # try instantiating for init checks # if as_config: check can be done before setting attributes with warnings.catch_warnings(): warnings.filterwarnings( "ignore", category=errors.InefficientSettingsWarning ) # this check does not need to be efficient self(parametrization=4, budget=100)
def __init__(self) -> None: different = ngtools.different_from_defaults(self, check_mismatches=True) super().__init__(**different)
def __repr__(self) -> str: diff = ",".join(f"{x}={y}" for x, y in sorted( ngtools.different_from_defaults(instance=self, check_mismatches=True).items())) return f"{self.__class__.__name__}({diff})"