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) |
RunGroupsPolicyLoader
Bases: SafeLoader
Source code in lute/io/config.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
_RUN_GROUP_DIRECTIVES = ('@db:run:', '@db:current', '@literal')
class-attribute
The set of prefixes used by the RUN_GROUPS policy adapters.
check_plain()
Allow presence of unquoted directives used by RUN_GROUPS.
Must include support for: - @db:run:NNN - @db:current - @literal
Source code in lute/io/config.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
_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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
_get_nested(data, path)
Return the value a path for nested dicts, or the _MISSING sentinel.
Source code in lute/io/config.py
104 105 106 107 108 109 110 111 | |
_run_group_specificity(current_run, applies_to)
Determine whether, and how specifically, a run matches a group's rule.
Lower values are more specific. A match via an explicit runs list always
beats a match via a range.
NOTE: Within definitions of each type (i.e., a range or list of runs), the more specific definition wins. I.e., a shorter list of runs, or narrower range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_run
|
int
|
The run to check. |
required |
applies_to
|
Dict[str, Any]
|
The group's |
required |
Returns:
| Name | Type | Description |
|---|---|---|
specificity |
Optional[Tuple[int, int]]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in lute/io/config.py
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 | |
_set_nested(data, path, value)
Set the value at path in a set of nested dicts.
NOTE: Any intermediate dictionaries are created as necessary.
Source code in lute/io/config.py
114 115 116 117 118 119 120 121 122 123 124 | |
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
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
resolve_run_group_directives(task_name, task_config, global_groups, work_dir, current_run)
Resolves @ directives to look up parameters based on matching RUN_GROUPS rules.
Possible directives include the following three options:
1. @db:current: Use the parameter value from the last valid database entry
for the experiment run of the current execution.
2. @db:run:NNNN: Use the last valid database entry for the specified run NNNN.
3. @literal: Use the literal value included in the YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_name
|
str
|
The current Task to process configuration for. |
required |
task_config
|
Dict[str, Any]
|
The configuration YAML data. |
required |
global_groups
|
Dict[str, Any]
|
Globally defined RUN GROUPS from the YAML. |
required |
work_dir
|
str
|
The LUTE working directory. |
required |
current_run
|
Optional[Union[int, str]]
|
The current run. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
updated_config |
Dict[str, Any]
|
Parameter configuration after directive resolution. |
Source code in lute/io/config.py
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 156 157 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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
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
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |