hyfi.composer
BaseConfig
Bases: BaseModel
Base class for all config classes.
Source code in hyfi/composer/config.py
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 |
|
__setattr__(key, val)
Overrides the default setattr method to allow for custom property set methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The name of the attribute to set. |
required |
val
|
Any
|
The value to set the attribute to. |
required |
Source code in hyfi/composer/config.py
export_config(exclude=None, exclude_none=True, only_include=None)
Export the configuration to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exclude
|
Optional[Union[str, List[str], Set[str], None]]
|
Keys to exclude from the saved configuration. Defaults to None. |
None
|
exclude_none
|
bool
|
Whether to exclude keys with None values. Defaults to True. |
True
|
only_include
|
Optional[Union[str, List[str], Set[str], None]]
|
Keys to include in the saved configuration. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The configuration dictionary. |
Source code in hyfi/composer/config.py
save_config(filepath, exclude=None, exclude_none=True, only_include=None)
Save the batch configuration to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
[Union[str, Path]
|
The filepath to save the configuration to. |
required |
exclude
|
Optional[Union[str, List[str], Set[str], None]]
|
Keys to exclude from the saved configuration. Defaults to None. |
None
|
exclude_none
|
bool
|
Whether to exclude keys with None values. Defaults to True. |
True
|
only_include
|
Optional[Union[str, List[str], Set[str], None]]
|
Keys to include in the saved configuration. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The filename of the saved configuration. |
Source code in hyfi/composer/config.py
BaseModel
Bases: BaseModel
Base class for all Pydantic models.
Attributes:
Name | Type | Description |
---|---|---|
_config_name_ |
str
|
The name of the model. |
_config_group_ |
str
|
The group of the model. |
_auto_populate_ |
bool
|
Whether to auto-populate the model with defaults from the config. |
_auto_generate_ |
bool
|
Whether to auto-generate the config for the model. |
Source code in hyfi/composer/model.py
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 |
|
auto_generate: bool
property
Returns whether the model should be auto-generated.
auto_populate: bool
property
Returns whether the model should be auto-populated.
config_group: str
property
Returns the group of the model.
config_name: str
property
Returns the name of the model.
kwargs: Dict[str, Any]
property
Returns the model as a dictionary excluding any keys specified in the class's exclude_keys
list.
generate_config(config_name=None, config_path=None, config_root=None, save=True)
classmethod
Saves a HyFI config for itself.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cls
|
BaseModel
|
The class to generate a config for. |
required |
config_name
|
Optional[str]
|
The name of the config. If not provided, the name of the target will be used. |
None
|
config_path
|
Optional[str]
|
The path to save the config to (relative to the config root). Defaults to "run". |
None
|
config_root
|
Optional[str]
|
The root of the config path. If not provided, the global hyfi config directory will be used. |
None
|
**kwargs_for_target
|
Keyword arguments to pass to the target. |
required |
Source code in hyfi/composer/model.py
sanitized_config(config)
staticmethod
Converts a config to Hydra-supported type if necessary and possible.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Dict[str, Any]
|
The config to sanitize. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: The sanitized config. |
Source code in hyfi/composer/model.py
BaseSettings
Bases: BaseSettings
, ENVs
Configuration class for environment variables in HyFI.
!! The variables are read-only and cannot be changed after initialization.
Source code in hyfi/composer/settings.py
os
property
Returns the OS environment variables.
Composer
Bases: UTILs
, GENERATOR
Compose a configuration by applying overrides
Source code in hyfi/composer/composer.py
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 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 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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 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 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
|
generate_alias_for_special_keys(key)
staticmethod
Generate an alias for special keys. with -> run pipe -> pipe_target run -> run
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The special key to generate an alias for. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The alias for the special key. |
Source code in hyfi/composer/composer.py
getsource(obj)
staticmethod
Return the source code of the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to get the source code of. |
required |
Returns:
Type | Description |
---|---|
str
|
The source code of the object as a string. |
Source code in hyfi/composer/composer.py
instantiate(config, *args, **kwargs)
staticmethod
Instantiates an object using the provided config object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Any
|
An config object describing what to call and what params to use. In addition to the parameters, the config must contain: target : target class or callable name (str) And may contain: args: List-like of positional arguments to pass to the target recursive: Construct nested objects as well (bool). False by default. may be overridden via a recursive key in the kwargs convert: Conversion strategy none : Passed objects are DictConfig and ListConfig, default partial : Passed objects are converted to dict and list, with the exception of Structured Configs (and their fields). all : Passed objects are dicts, lists and primitives without a trace of OmegaConf containers partial: If True, return functools.partial wrapped method or object False by default. Configure per target. args: List-like of positional arguments |
required |
args
|
Any
|
Optional positional parameters pass-through |
()
|
kwargs
|
Any
|
Optional named parameters to override parameters in the config object. Parameters not present in the config objects are being passed as is to the target. IMPORTANT: dataclasses instances in kwargs are interpreted as config and cannot be used as passthrough |
{}
|
Returns:
Type | Description |
---|---|
Any
|
if target is a class name: the instantiated object |
Any
|
if target is a callable: the return value of the call |
Source code in hyfi/composer/composer.py
instantiate_config(config_group=None, overrides=None, config_data=None, global_package=False, *args, **kwargs)
staticmethod
Instantiates an object using the provided config group and overrides.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_group
|
Optional[str]
|
Name of the config group to compose ( |
None
|
overrides
|
Optional[List[str]]
|
List of config groups to apply overrides to ( |
None
|
config_data
|
Optional[Union[Dict[str, Any], DictConfig]]
|
Keyword arguments to override config group values (will be converted to overrides of the form |
None
|
global_package
|
bool
|
If True, the config assumed to be a global package |
False
|
args
|
Any
|
Optional positional parameters pass-through |
()
|
kwargs
|
Any
|
Optional named parameters to override parameters in the config object. Parameters not present in the config objects are being passed as is to the target. IMPORTANT: dataclasses instances in kwargs are interpreted as config and cannot be used as passthrough |
{}
|
Returns:
Type | Description |
---|---|
Any
|
if target is a class name: the instantiated object |
Any
|
if target is a callable: the return value of the call |
Source code in hyfi/composer/composer.py
is_composable(config_group, config_module=None)
staticmethod
Determines whether the input configuration object is composable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_group
|
str
|
The name of the configuration group to check. |
required |
config_module
|
Optional[str]
|
The name of the configuration module to check. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the configuration object is composable, False otherwise. |
Source code in hyfi/composer/composer.py
is_instantiatable(cfg)
staticmethod
Determines whether the input configuration object is instantiatable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg
|
Any
|
The configuration object to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the configuration object is instantiatable, False otherwise. |
Source code in hyfi/composer/composer.py
partial(config, *args, **kwargs)
staticmethod
Returns a callable object that is a partial version of the function or class specified in the config object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Union[str, Dict]
|
An config object describing what to call and what params to use. In addition to the parameters, the config must contain: target : target class or callable name (str) And may contain: partial: If True, return functools.partial wrapped method or object False by default. Configure per target. |
required |
args
|
Any
|
Optional positional parameters pass-through |
()
|
kwargs
|
Any
|
Optional named parameters to override parameters in the config object. Parameters not present in the config objects are being passed as is to the target. IMPORTANT: dataclasses instances in kwargs are interpreted as config and cannot be used as passthrough |
{}
|
Returns: A callable object that is a partial version of the function or class specified in the config object.
Source code in hyfi/composer/composer.py
print_config(config_group=None, overrides=None, config_data=None, global_package=False)
staticmethod
Print the configuration
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_group
|
Optional[str]
|
Name of the config group to compose ( |
None
|
overrides
|
Optional[List[str]]
|
List of config groups to apply overrides to ( |
None
|
config_data
|
Optional[Union[Dict[str, Any], DictConfig]]
|
Keyword arguments to override config group values (will be converted to overrides of the form |
None
|
global_package
|
bool
|
If True, the config assumed to be a global package |
False
|
Source code in hyfi/composer/composer.py
replace_special_keys(_dict)
staticmethod
Replace special keys in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_dict
|
Mapping[str, Any]
|
The dictionary to update. |
required |
Returns:
Name | Type | Description |
---|---|---|
Mapping |
Mapping
|
The updated dictionary. |
Source code in hyfi/composer/composer.py
viewsource(obj)
staticmethod
Print the source code of the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to print the source code of. |
required |
DocGenerator
Bases: BaseModel
A class for generating reference documentation and configuration documentation.
This class provides methods for generating reference documentation for modules and configuration documentation for directories.
Attributes:
Name | Type | Description |
---|---|---|
_config_name_ |
str
|
The name of the configuration. |
_config_group_ |
str
|
The group of the configuration. |
config_docs_dirname |
str
|
The name of the directory for configuration documentation. |
reference_docs_dirname |
str
|
The name of the directory for reference documentation. |
exclude_configs |
List[str]
|
A list of configurations to exclude. |
exclude_references |
List[str]
|
A list of references to exclude. |
Properties
root_dir: The root directory. package_dir: The package directory. package_name: The package name. config_dir: The configuration directory. config_docs_dir: The directory for configuration documentation. reference_docs_dir: The directory for reference documentation.
Methods:
Name | Description |
---|---|
generate_reference_docs |
Generates reference documentation for modules. |
write_ref_doc |
Writes reference documentation for a module. |
generate_config_docs |
Generates configuration documentation for directories. |
write_config_doc |
Writes configuration documentation for a directory. |
Example
Source code in hyfi/composer/docs.py
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 |
|
GENERATOR
Generates Hydra configs for functions and classes.
Source code in hyfi/composer/generator.py
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 |
|
generate_callable_config(target, config_name=None, config_path='run', config_root=None, use_first_arg_as_pipe_obj=False, **kwargs_for_target)
staticmethod
Saves a HyFI config to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target
|
Callable
|
The function or class to generate a config for. |
required |
use_first_arg_as_pipe_obj
|
bool
|
Whether to use the first argument as the pipe object. |
False
|
config_name
|
Optional[str]
|
The name of the config. If not provided, the name of the target will be used. |
None
|
config_path
|
Optional[str]
|
The path to save the config to (relative to the config root). Defaults to "run". |
'run'
|
config_root
|
Optional[str]
|
The root of the config path. If not provided, the global hyfi config directory will be used. |
None
|
**kwargs_for_target
|
Keyword arguments to pass to the target. |
{}
|
Source code in hyfi/composer/generator.py
generate_pipe_config(target, pipe_target_type=PipeTargetTypes.GENERAL_EXTERNAL_FUNCS, use_pipe_obj=True, pipe_obj_arg_name=None, return_pipe_obj=False, pipe_prefix=None, config_name=None, config_root=None, **kwargs_for_target)
staticmethod
Generates HyFI pipe config for a given target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target
|
Callable
|
Target function or class. |
required |
pipe_target_type
|
PipeTargetTypes
|
Type of target function or class. |
GENERAL_EXTERNAL_FUNCS
|
use_pipe_obj
|
bool
|
Whether to use pipe object as the first argument. |
True
|
pipe_obj_arg_name
|
Optional[str]
|
Name of the pipe object argument. |
None
|
return_pipe_obj
|
bool
|
Whether to return pipe object. |
False
|
pipe_prefix
|
Optional[str]
|
Prefix for pipe object argument. |
None
|
config_name
|
Optional[str]
|
Name of the config. |
None
|
config_root
|
Optional[str]
|
Root of the config. |
None
|
**kwargs_for_target
|
Keyword arguments for the target. |
{}
|
Source code in hyfi/composer/generator.py
generate_target_config(target, remove_first_arg=False, **kwargs)
staticmethod
Generates a HyFI config for a given target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target
|
Callable
|
The function or class to generate a config for. |
required |
remove_first_arg
|
bool
|
Whether to remove the first argument from the config. |
False
|
**kwargs
|
Keyword arguments to pass to the target. |
{}
|
Source code in hyfi/composer/generator.py
SpecialKeys
Bases: str
, Enum
Special keys in configs used by HyFI.