def all_defaults(nengo_cls=None): """Look up all of the default values in the current context. Parameters ---------- nengo_cls : class, optional If specified, only the defaults for a particular class will be returned. If not specified, the defaults for all configured classes will be returned. Returns ------- str """ lines = [] if nengo_cls is None: all_configured = set() for config in Config.context: all_configured.update(key for key in config.params if inspect.isclass(key)) lines.extend([Config.all_defaults(key) for key in all_configured]) else: lines.append(f"Current defaults for {nengo_cls.__name__}:") for attr in dir(nengo_cls): desc = getattr(nengo_cls, attr) if is_param(desc) and desc.configurable: val = Config.default(nengo_cls, attr) lines.append(f" {attr}: {val}") return "\n".join(lines)
def __init__(self, configures): assert inspect.isclass(configures) self._configures = configures self._extraparams = {} self._default_params = tuple( attr for attr in dir(self._configures) if is_param(getattr(self._configures, attr)))
def __init__(self, configures): assert inspect.isclass(configures) self._configures = configures self._extra_params = {} self._default_params = tuple( attr for attr in dir(self._configures) if is_param(getattr(self._configures, attr)))
def all_defaults(nengo_cls=None): """Look up all of the default values in the current context. Parameters ---------- nengo_cls : class, optional If specified, only the defaults for a particular class will be returned. If not specified, the defaults for all configured classes will be returned. Returns ------- str """ lines = [] if nengo_cls is None: all_configured = set() for config in Config.context: all_configured.update(key for key in config.params if inspect.isclass(key)) lines.extend([Config.all_defaults(key) for key in all_configured]) else: lines.append("Current defaults for %s:" % nengo_cls.__name__) for attr in dir(nengo_cls): desc = getattr(nengo_cls, attr) if is_param(desc) and desc.configurable: val = Config.default(nengo_cls, attr) lines.append(" %s: %s" % (attr, val)) return "\n".join(lines)
def set_param(self, key, value): if not is_param(value): raise ConfigError(f"'{key}' is not a parameter") elif key in dir(self._configures): raise ConfigError( f"'{key}' is already a parameter in {self._configures.__name__}. " "Please choose a different name.") self._extra_params[key] = value
def set_param(self, key, value): if not is_param(value): raise ConfigError("'%s' is not a parameter" % key) elif key in dir(self._configures): raise ConfigError("'%s' is already a parameter in %s. " "Please choose a different name." % (key, self._configures.__name__)) self._extra_params[key] = value
def set_param(self, key, value): if not is_param(value): raise TypeError("%s is not a parameter" % key) elif key in dir(self._configures): raise ValueError("%s is already a parameter in %s. " "Please choose a different name." % (key, self._configures.__name__)) self._extraparams[key] = value
def param_list(cls): """Returns a list of parameter names that can be set.""" return (attr for attr in dir(cls) if is_param(getattr(cls, attr)))
def default_params(self): return (attr for attr in dir(self._configures) if is_param(getattr(self._configures, attr)))