config
Machinary for the IO of configuration YAML files and their validation.
Functions:
Name | Description |
---|---|
parse_config |
str, config_path: str) -> TaskParameters: Parse a configuration file and return a TaskParameters object of validated parameters for a specific Task. Raises an exception if the provided configuration does not match the expected model. |
Raises:
Type | Description |
---|---|
ValidationError
|
Error raised by pydantic during data validation. (From Pydantic) |
_check_str_numeric(string)
Check if a string is an integer or float and return it as such.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
Input string to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
output |
str | int | float
|
Returns an int or float if the string can be converted to one. Otherwise returns the original string. |
Source code in lute/io/config.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
parse_config(task_name='test', config_path='')
Parse a configuration file and validate the contents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_name
|
str
|
Name of the specific task that will be run. |
'test'
|
config_path
|
str
|
Path to the configuration file. |
''
|
Returns:
Name | Type | Description |
---|---|---|
params |
TaskParameters
|
A TaskParameters object of validated
task-specific parameters. Parameters are accessed with "dot"
notation. E.g. |
Raises:
Type | Description |
---|---|
ValidationError
|
Raised if there are problems with the configuration file. Passed through from Pydantic. |
Source code in lute/io/config.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
substitute_variables(header, config, curr_key=None)
Performs variable substitutions on a dictionary read from config YAML file.
Can be used to define input parameters in terms of other input parameters.
This is similar to functionality employed by validators for parameters in
the specific Task models, but is intended to be more accessible to users.
Variable substitutions are defined using a minimal syntax from Jinja:
{{ experiment }}
defines a substitution of the variable experiment
. The characters {{ }}
can be escaped if the literal symbols are needed in place.
For example, a path to a file can be defined in terms of experiment and run values in the config file: MyTask: experiment: myexp run: 2 special_file: /path/to/{{ experiment }}/{{ run }}/file.inp
Acceptable variables for substitutions are values defined elsewhere in the
YAML file. Environment variables can also be used if prefaced with a $
character. E.g. to get the experiment from an environment variable:
MyTask:
run: 2
special_file: /path/to/{{ $EXPERIMENT }}/{{ run }}/file.inp
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
A dictionary of parsed configuration. |
required |
curr_key
|
Optional[str]
|
Used to keep track of recursion level when scanning through iterable items in the config dictionary. |
None
|
Returns:
Name | Type | Description |
---|---|---|
subbed_config |
Dict[str, Any]
|
The config dictionary after substitutions have been made. May be identical to the input if no substitutions are needed. |
Source code in lute/io/config.py
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 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 147 148 149 150 151 152 153 154 155 |
|