Configuration
Configuration Management
Centralized configuration management is employed to ensure that experimental conditions are explicitly defined and reproducible. PAYN utilizes a hierarchical configuration file (YAML or JSON) ensure all experimental conditions—from data paths to hyperparameter search spaces—are explicitly defined and version-controllable.
Loading Configuration (payn.ConfigLoader.ConfigLoader)
The ConfigLoader module serves as the primary interface for state initialization.
- File Parsing: It handles the ingestion of static configuration files, supporting both YAML and JSON formats with automatic type inference.
- Type Safety: The loader parses the raw input into structured Python dictionaries, acting as the single source for experimental parameters.
- Instantiation Factory: Key classes (e.g.,
Featurisation,Optimisation) implement afrom_configclass method. This "Config-as-Code" pattern decouples the class logic from the configuration structure, allowing classes to be instantiated programmatically during testing while remaining easily properly configured by the globalconfigduring production runs.
Handles the loading of YAML or JSON configuration files.
Attributes:
| Name | Type | Description |
|---|---|---|
config_path |
str
|
Path to the configuration file. |
file_type |
str
|
Detected file type ('yaml' or 'json'). |
Source code in payn\ConfigLoader\configloader.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 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 | |
__init__(config_path)
Initialize the ConfigLoader class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str
|
Path to the input file. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file extension is not supported (.yaml, .yml, .json). |
Source code in payn\ConfigLoader\configloader.py
15 16 17 18 19 20 21 22 23 24 25 26 27 | |
get(section, key, default=None)
Retrieve a specific configuration value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section
|
str
|
The top-level section in the configuration (e.g., 'dataset'). |
required |
key
|
str
|
The specific key within that section. |
required |
default
|
Any
|
Value to return if the key is missing. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The value associated with the specified section and key, or the default. |
Source code in payn\ConfigLoader\configloader.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
get_all()
Retrieve the entire configuration data.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary with all configuration data. |
Source code in payn\ConfigLoader\configloader.py
116 117 118 119 120 121 122 123 | |
load_config()
Load configuration from the specified file type.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict[str, Any]: A Dictionary containing the configuration data. |
Source code in payn\ConfigLoader\configloader.py
49 50 51 52 53 54 55 56 57 58 59 60 61 | |
ArgParser for CLI / Slurm (payn.ConfigLoader.ConfigArgParser)
To facilitate high-throughput computing (HTC) and integration with workload managers (e.g., Slurm), the ConfigArgParser module enables dynamic runtime modification of the configuration.
- Dynamic Argument Generation: The module recursively traverses the loaded configuration dictionary and automatically generates a corresponding command-line interface (CLI) argument for every parameter (e.g., nested keys like
spy_model.eval_metricare mapped to flags like--spy_model_eval_metric). - Runtime Overrides: This allows specific parameters to be modified for individual jobs within a batch array without altering the source configuration file, ensuring that the base experimental structure remains constant while variables (e.g., hyperparameters) can be altered.
- Provenance: All CLI overrides are logged explicitly at the start of the run to ensure the exact set of parameters used for a specific job can be reconstructed.
Dynamically generates an argparse CLI based on a hierarchical YAML/JSON configuration.
This class allows every parameter in the config file to be overridden via command-line flags.
It flattens nested structures (e.g., section.key becomes --section_key) and handles
type inference automatically.
Attributes:
| Name | Type | Description |
|---|---|---|
config_path |
str
|
Path to the source configuration file. |
config |
Dict[str, Any]
|
The loaded configuration dictionary. |
parser |
ArgumentParser
|
The generated argument parser. |
Source code in payn\ConfigLoader\configArgParser.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 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 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 | |
__init__(config_path)
Initialize the parser and generate arguments from the config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str
|
Path to the YAML or JSON config file. |
required |
Source code in payn\ConfigLoader\configArgParser.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
override_config(args)
Apply CLI overrides to the configuration dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
The parsed CLI arguments. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: The updated configuration dictionary. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a CLI argument cannot be mapped back to the config structure. |
Source code in payn\ConfigLoader\configArgParser.py
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 | |
parse_args()
Parse the command-line arguments.
Source code in payn\ConfigLoader\configArgParser.py
149 150 151 | |
save_config(output_path=None)
Save the current configuration state to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
str
|
Path to save the file. Defaults to original path. |
None
|
Source code in payn\ConfigLoader\configArgParser.py
248 249 250 251 252 253 254 255 256 257 258 259 260 | |