Parameters¶
Parameters¶
-
class
Parameters
(fixed_params={'model': {}, 'training': {}}, variable_params={'model': {}, 'training': {}})[source]¶ Bases:
delira.utils.config.LookupConfig
Class Containing all variable and fixed parameters for training and model instantiation
See also
trixi.util.Config
-
clear
() → None. Remove all items from D.¶
-
contains
(dict_like)¶ Check whether all items in a dictionary-like object match the ones in this Config.
Parameters: dict_like (dict or derivative thereof) – Returns True if this is contained in this Config. Returns: True if dict_like is contained in self, otherwise False. Return type: bool
-
copy
() → a shallow copy of D¶
-
deepcopy
()¶ Get a deep copy of this Config.
Returns: A deep copy of self. Return type: Config
-
deepupdate
(dict_like, ignore=None, allow_dict_overwrite=True)¶ Identical to
update()
with deep=True.Parameters: - dict_like (dict or derivative thereof) – Update source.
- ignore (iterable) – Iterable of keys to ignore in update.
- allow_dict_overwrite (bool) – Allow overwriting with dict. Regular dicts only update on the highest level while we recurse and merge Configs. This flag decides whether it is possible to overwrite a ‘regular’ value with a dict/Config at lower levels. See examples for an illustration of the difference
-
difference_config
(*other_configs)¶ Get the difference of this and any number of other configs. See
difference_config_static()
for more information.Parameters: *other_configs (Config) – Compare these configs and self. Returns: Difference of self and the other configs. Return type: Config
-
static
difference_config_static
(*configs, only_set=False)¶ Make a Config of all elements that differ between N configs.
The resulting Config looks like this:
{ key: (config1[key], config2[key], ...) }
If the key is missing, None will be inserted. The inputs will not be modified.
Parameters: - configs (Config) – Any number of Configs
- only_set (bool) – If only the set of different values hould be returned or for each config the
- one (corresponding) –
Returns: Possibly empty Config
Return type: Config
-
dump
(file_, indent=4, separators=(', ', ': '), **kwargs)¶ Write config to file using
json.dump()
.Parameters:
-
dumps
(indent=4, separators=(', ', ': '), **kwargs)¶ Get string representation using
json.dumps()
.Parameters: - indent (int) – Formatting option.
- separators (iterable) – Formatting option.
- **kwargs – Will be passed to
json.dumps()
.
-
flat
(keep_lists=True, max_split_size=10)¶ Returns a flattened version of the Config as dict.
Nested Configs and lists will be replaced by concatenated keys like so:
{ "a": 1, "b": [2, 3], "c": { "x": 4, "y": { "z": 5 } }, "d": (6, 7) }
Becomes:
{ "a": 1, "b": [2, 3], # if keep_lists is True "b.0": 2, "b.1": 3, "c.x": 4, "c.y.z": 5, "d": (6, 7) }
We return a dict because dots are disallowed within Config keys.
Parameters: - keep_lists – Keeps list along with unpacked values
- max_split_size – List longer than this will not be unpacked
Returns: A flattened version of self
Return type:
-
fromkeys
()¶ Returns a new dict with keys from iterable and values equal to value.
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
hasattr_not_none
(key)¶
-
static
init_objects
(config)¶ Returns a new Config with types converted to instances.
Any value that is a Config and contains a type key will be converted to an instance of that type:
{ "stuff": "also_stuff", "convert_me": { type: { "param": 1, "other_param": 2 }, "something_else": "hopefully_useless" } }
becomes:
{ "stuff": "also_stuff", "convert_me": type(param=1, other_param=2) }
Note that additional entries can be lost as shown above.
Parameters: config (Config) – New Config will be built from this one Returns: A new config with instances made from type entries. Return type: Config
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
load
(file_, raise_=True, decoder_cls_=<class 'trixi.util.util.ModuleMultiTypeDecoder'>, **kwargs)¶ Load config from file using
json.load()
.Parameters:
-
loads
(json_str, decoder_cls_=<class 'trixi.util.util.ModuleMultiTypeDecoder'>, **kwargs)¶ Load config from JSON string using
json.loads()
.Parameters:
-
nested_get
(key, *args, **kwargs)¶ Returns all occurances of
key
inself
and subdictsParameters: - key (str) – the key to search for
- *args – positional arguments to provide default value
- **kwargs – keyword arguments to provide default value
Raises: KeyError
– Multiple Values are found for key (unclear which value should be returned) OR No Value was found for key and no default value was givenReturns: value corresponding to key (or default if value was not found)
Return type: Any
-
permute_hierarchy
()[source]¶ switches hierarchy
Returns: the class with a permuted hierarchy Return type: Parameters Raises: AttributeError
– if no valid hierarchy is found
-
permute_to_hierarchy
(hierarchy: str)[source]¶ Permute hierarchy to match the specified hierarchy
Parameters: hierarchy (str) – target hierarchy Raises: ValueError
– Specified hierarchy is invalidReturns: parameters with proper hierarchy Return type: Parameters
-
permute_training_on_top
()[source]¶ permutes hierarchy in a way that the training-model hierarchy is on top
Returns: Parameters with permuted hierarchy Return type: Parameters
-
permute_variability_on_top
()[source]¶ permutes hierarchy in a way that the training-model hierarchy is on top
Returns: Parameters with permuted hierarchy Return type: Parameters
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised
-
popitem
() → (k, v), remove and return some (key, value) pair as a¶ 2-tuple; but raise KeyError if D is empty.
-
save
(filepath: str)[source]¶ Saves class to given filepath (YAML + Pickle)
Parameters: filepath (str) – file to save data to
-
set_from_string
(str_, stringify_value=False)¶ Set a value from a single string, separated with “=”. Uses :meth:´set_with_decode´.
Parameters: str (str) – String that looks like “key=value”.
-
set_with_decode
(key, value, stringify_value=False)¶ Set single value, using
ModuleMultiTypeDecoder
to interpret key and value strings by creating a temporary JSON string.Parameters: Examples
Example for when you need to set stringify_value=True:
config.set_with_decode("key", "__type__(trixi.util.config.Config)", stringify_value=True)
Example for when you need to set stringify_value=False:
config.set_with_decode("key", "[1, 2, 3]")
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
to_cmd_args_str
()¶ Create a string representing what one would need to pass to the command line. Does not yet use JSON encoding!
Returns: Command line string Return type: str
-
training_on_top
¶ Return whether the training hierarchy is on top
Returns: whether training is on top Return type: bool
-
update
(dict_like, deep=False, ignore=None, allow_dict_overwrite=True)¶ Update entries in the Config.
Parameters: - dict_like (dict or derivative thereof) – Update source.
- deep (bool) – Make deep copies of all references in the source.
- ignore (iterable) – Iterable of keys to ignore in update.
- allow_dict_overwrite (bool) – Allow overwriting with dict. Regular dicts only update on the highest level while we recurse and merge Configs. This flag decides whether it is possible to overwrite a ‘regular’ value with a dict/Config at lower levels. See examples for an illustration of the difference
Examples
The following illustrates the update behaviour if :obj:allow_dict_overwrite is active. If it isn’t, an AttributeError would be raised, originating from trying to update “string”:
config1 = Config(config={ "lvl0": { "lvl1": "string", "something": "else" } }) config2 = Config(config={ "lvl0": { "lvl1": { "lvl2": "string" } } }) config1.update(config2, allow_dict_overwrite=True) >>>config1 { "lvl0": { "lvl1": { "lvl2": "string" }, "something": "else" } }
-
update_missing
(dict_like, deep=False, ignore=None)¶ Recursively insert values that do not yet exist.
Parameters:
-
values
() → an object providing a view on D's values¶
-