yaml_data ¶
Utility module for handling YAML configuration files and their validation.
Classes:
-
YamlColumns
–Model for column configuration.
-
YamlColumnsEncoder
–Model for column encoder configuration.
-
YamlConfigDict
–Model for main YAML configuration.
-
YamlGlobalParams
–Model for global parameters in YAML configuration.
-
YamlSchema
–Model for validating YAML schema.
-
YamlSplit
–Model for split configuration.
-
YamlSubConfigDict
–Model for sub-configuration generated from main config.
-
YamlTransform
–Model for transform configuration.
-
YamlTransformColumns
–Model for transform columns configuration.
-
YamlTransformColumnsTransformation
–Model for column transformation configuration.
Functions:
-
check_yaml_schema
–Validate YAML configuration fields have correct types.
-
dump_yaml_list_into_files
–Dumps a list of YAML configurations into separate files with custom formatting.
-
expand_transform_list_combinations
–Expands a list of transforms into all possible parameter combinations.
-
expand_transform_parameter_combinations
–Get all possible transforms by extracting parameters at each valid index.
-
extract_transform_parameters_at_index
–Get a transform with parameters at the specified index.
-
generate_data_configs
–Generates all possible data configurations from a YAML config.
YamlColumns ¶
Bases: BaseModel
Model for column configuration.
YamlColumnsEncoder ¶
Bases: BaseModel
Model for column encoder configuration.
YamlConfigDict ¶
Bases: BaseModel
Model for main YAML configuration.
YamlGlobalParams ¶
Bases: BaseModel
Model for global parameters in YAML configuration.
YamlSchema ¶
Bases: BaseModel
Model for validating YAML schema.
YamlSplit ¶
Bases: BaseModel
Model for split configuration.
YamlSubConfigDict ¶
Bases: BaseModel
Model for sub-configuration generated from main config.
YamlTransform ¶
Bases: BaseModel
Model for transform configuration.
Methods:
-
validate_param_lists_across_columns
–Validate that parameter lists across columns have consistent lengths.
validate_param_lists_across_columns classmethod
¶
validate_param_lists_across_columns(
columns: list[YamlTransformColumns],
) -> list[YamlTransformColumns]
Validate that parameter lists across columns have consistent lengths.
Parameters:
-
columns
(list[YamlTransformColumns]
) –List of transform columns to validate
Returns:
-
list[YamlTransformColumns]
–The validated columns list
Source code in src/stimulus/utils/yaml_data.py
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 |
|
YamlTransformColumns ¶
Bases: BaseModel
Model for transform columns configuration.
YamlTransformColumnsTransformation ¶
Bases: BaseModel
Model for column transformation configuration.
check_yaml_schema ¶
check_yaml_schema(config_yaml: YamlConfigDict) -> str
Validate YAML configuration fields have correct types.
If the children field is specific to a parent, the children fields class is hosted in the parent fields class. If any field in not the right type, the function prints an error message explaining the problem and exits the python code.
Parameters:
-
config_yaml
(YamlConfigDict
) –The YamlConfigDict containing the fields of the yaml configuration file
Returns:
-
str
(str
) –Empty string if validation succeeds
Raises:
-
ValueError
–If validation fails
Source code in src/stimulus/utils/yaml_data.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
dump_yaml_list_into_files ¶
dump_yaml_list_into_files(
yaml_list: list[YamlSubConfigDict],
directory_path: str,
base_name: str,
) -> None
Dumps a list of YAML configurations into separate files with custom formatting.
Source code in src/stimulus/utils/yaml_data.py
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 283 284 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 |
|
expand_transform_list_combinations ¶
expand_transform_list_combinations(
transform_list: list[YamlTransform],
) -> list[YamlTransform]
Expands a list of transforms into all possible parameter combinations.
Takes a list of transforms where each transform may contain parameter lists, and expands them into separate transforms with single parameter values. For example, if a transform has parameters [0.1, 0.2] and [1, 2], this will create two transforms: one with 0.1/1 and another with 0.2/2.
Parameters:
-
transform_list
(list[YamlTransform]
) –A list of YamlTransform objects containing parameter lists that need to be expanded into individual transforms.
Returns:
-
list[YamlTransform]
–list[YamlTransform]: A flattened list of transforms where each transform has single parameter values instead of parameter lists. The length of the returned list will be the sum of the number of parameter combinations for each input transform.
Source code in src/stimulus/utils/yaml_data.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
expand_transform_parameter_combinations ¶
expand_transform_parameter_combinations(
transform: YamlTransform,
) -> list[YamlTransform]
Get all possible transforms by extracting parameters at each valid index.
For a transform with parameter lists, creates multiple new transforms, each containing single parameter values from the corresponding indices of the parameter lists.
Parameters:
-
transform
(YamlTransform
) –The original transform containing parameter lists
Returns:
-
list[YamlTransform]
–A list of transforms, each with single parameter values from sequential indices
Source code in src/stimulus/utils/yaml_data.py
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 |
|
extract_transform_parameters_at_index ¶
extract_transform_parameters_at_index(
transform: YamlTransform, index: int = 0
) -> YamlTransform
Get a transform with parameters at the specified index.
Parameters:
-
transform
(YamlTransform
) –The original transform containing parameter lists
-
index
(int
, default:0
) –Index to extract parameters from (default 0)
Returns:
-
YamlTransform
–A new transform with single parameter values at the specified index
Source code in src/stimulus/utils/yaml_data.py
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 |
|
generate_data_configs ¶
generate_data_configs(
yaml_config: YamlConfigDict,
) -> list[YamlSubConfigDict]
Generates all possible data configurations from a YAML config.
Takes a YAML configuration that may contain parameter lists and splits, and generates all possible combinations of parameters and splits into separate data configurations.
For example, if the config has: - A transform with parameters [0.1, 0.2] - Two splits [0.7/0.3] and [0.8/0.2] This will generate 4 configs, 2 for each split.
Parameters:
-
yaml_config
(YamlConfigDict
) –The source YAML configuration containing transforms with parameter lists and multiple splits.
Returns:
-
list[YamlSubConfigDict]
–list[YamlSubConfigDict]: A list of data configurations, where each config has single parameter values and one split configuration. The length will be the product of the number of parameter combinations and the number of splits.
Source code in src/stimulus/utils/yaml_data.py
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 |
|