Config¶
Configuration and model building utilities.
Build Module¶
build_module(config, hyperpar=None)
¶
Build a module based on the provided configuration. Every (possibly nested) dictionary with a 'class' key will be replaced by an instance initialized with arguments and keywords provided as 'args' and 'kwargs' keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Union[str, Dict, List]
|
The configuration for building the module. |
required |
hyperpar
|
Union[str, Dict, None]
|
The hyperparameters for the module. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Union[List, Dict, Callable]: The built module. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
Source code in aimnet/config.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
Module Lookup¶
get_module(name)
¶
Retrieves a module and function based on the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the module and function in the format 'module.function'. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
function |
Callable[..., Any]
|
The function object. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the module cannot be imported. |
AttributeError
|
If the function does not exist in the module. |
Source code in aimnet/config.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
get_init_module(name, args=None, kwargs=None)
¶
Get the initialized module based on the given name, arguments, and keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the module. |
required |
args
|
List
|
The arguments to pass to the module constructor. Defaults to an empty list. |
None
|
kwargs
|
Dict
|
The keyword arguments to pass to the module constructor. Defaults to an empty dictionary. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The initialized module. |
Source code in aimnet/config.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
YAML Loading¶
load_yaml(config, hyperpar=None, *, basedir=None)
¶
Load a YAML configuration file and apply optional hyperparameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Union[str, List, Dict]
|
The YAML configuration file path or a YAML object. |
required |
hyperpar
|
Optional[Union[Dict, str, None]]
|
Optional hyperparameters to apply to the configuration. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | list
|
Union[List, Dict]: The loaded and processed configuration. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If a file specified in the configuration does not exist. |
Source code in aimnet/config.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
Dotted Dictionaries¶
dict_to_dotted(d, parent='')
¶
Source code in aimnet/config.py
149 150 151 152 153 154 155 156 157 158 159 | |
dotted_to_dict(d)
¶
Source code in aimnet/config.py
162 163 164 165 166 167 168 169 170 171 172 173 174 | |