Core API Reference¶
creator
¶
Manages dynamic creation of agents and components based on configuration.
Creator
¶
Central factory for creating agents and components from configuration.
This class dynamically instantiates all necessary objects for an experiment based on a configuration file, following a convention-over-configuration approach.
Key Responsibilities:
- Creates the main Agent for the experiment.
- Provides a ComponentCreator to the agent, enabling it to build
other components like models, optimizers, and data loaders.
Usage Example
cfg = Config("config.yaml") create = Creator(cfg) agent = create.agent() # Agent can now use create.* to build its parts.
Source code in cvlabkit/core/creator.py
__init__
¶
Initializes the Creator with the main configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Config
|
The configuration object driving the creation process. |
required |
__getattr__
¶
Provides access to the appropriate loader for a given component category.
This method is the entry point for creating any component:
- create.agent() is handled by _AgentLoader.
- create.model(), create.optimizer(), etc., are delegated to ComponentCreator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str
|
The component category name (e.g., 'agent', 'model'). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A loader object capable of creating instances for that category. |
Source code in cvlabkit/core/creator.py
ComponentCreator
¶
Creator Implementation for creating non-agent specific components (e.g., model, optimizer, dataset, etc.).
This class discovers and instantiates components from the cvlabkit.component
package based on the provided configuration.
Source code in cvlabkit/core/creator.py
__init__
¶
Initializes the ComponentCreator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Config
|
The main configuration object. |
required |
__getattr__
¶
Returns a specialized loader for a specific component category.
This method is called when create.model or create.optimizer is accessed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str
|
The component category name (e.g., 'model', 'optimizer'). |
required |
Returns:
| Type | Description |
|---|---|
_ComponentCategoryLoader
|
A loader instance for the specified category. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the category name is 'agent', or if no base class is found for the category. |
Source code in cvlabkit/core/creator.py
config
¶
This module defines the Config class, a central component for managing
experiment configurations within the cvlab-kit framework.
It provides functionalities for loading configurations from YAML files or
dictionaries, accessing parameters using both dictionary-style and attribute-style
syntax, merging configurations, and expanding configurations for grid search
experiments. The Config class also integrates with ConfigProxy for
config validation during dry runs.
Config
¶
A configuration class that handles loading, accessing, and manipulating parameters.
This class provides a unified interface for managing experiment configurations. It can load settings from a YAML file or a dictionary, provides attribute-style access to parameters, and supports advanced features like grid search expansion and special syntax parsing for component-specific parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
_data |
dict[str, Any]
|
The internal dictionary storing the configuration parameters. |
proxy |
ConfigProxy
|
An object that tracks missing configuration keys
during a dry run to help generate a template. It is primarily used
by the |
Source code in cvlabkit/core/config.py
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 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 | |
__init__
¶
Initializes the Config object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | dict[str, Any]
|
A file path to a YAML file (str) or a dictionary containing the configuration parameters (Dict[str, Any]). |
required |
proxy
|
ConfigProxy
|
An optional |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the source is not a file path (str) or a dictionary. |
Source code in cvlabkit/core/config.py
__getitem__
¶
Enables dictionary-style access to configuration parameters.
Allows accessing configuration values using bracket notation, e.g., config["model.name"].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The dot-separated string representing the nested key (e.g., "model.params.lr"). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The configuration value associated with the key. |
Source code in cvlabkit/core/config.py
get
¶
Retrieves a value using a dot-separated key.
This method allows accessing nested configuration values using a single
dot-separated string. For example, config.get("model.params.lr").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A dot-separated string representing the nested key (e.g., "model.params.lr"). |
required |
default
|
Any | None
|
The value to return if the key is not found.
Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The configuration value associated with the key, or the
specified |
Source code in cvlabkit/core/config.py
__getattr__
¶
Enables attribute-style access to configuration parameters.
Allows accessing configuration values using dot notation, e.g., config.model.name.
If the accessed attribute is a dictionary, it is wrapped in a new
Config object to allow for nested attribute access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The name of the attribute to access. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The configuration value, or a new |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the attribute is not a configuration key and not a standard Python attribute. |
Source code in cvlabkit/core/config.py
__contains__
¶
Checks if a key exists in the configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the key exists, False otherwise. |
to_dict
¶
Returns a deep copy of the internal configuration data as a dictionary.
This is useful for obtaining a mutable copy of the configuration that
can be modified without affecting the original Config object.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict[str, Any]: A deep copy of the configuration data. |
Source code in cvlabkit/core/config.py
merge
¶
Merges a dictionary of new parameters into the current configuration.
This method creates a new Config object by combining the current
configuration with the provided new_params. Parameters in new_params
will overwrite existing ones at the top level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_params
|
dict[str, Any]
|
A dictionary of parameters to merge. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Config |
Config
|
A new |
Source code in cvlabkit/core/config.py
expand
¶
Expands the configuration into multiple Config objects for a grid search.
This method identifies all parameters in the configuration that are lists
and creates a Cartesian product of their values. Each combination results
in a new Config object, effectively generating all configurations for
a grid search experiment.
Returns:
| Type | Description |
|---|---|
list[Config]
|
List[Config]: A list of |
Source code in cvlabkit/core/config.py
dump_template
¶
Dumps the current configuration, including inferred missing keys, to a YAML file.
This method is primarily used during dry runs to generate a template configuration file that includes all parameters accessed by the system, even those not explicitly defined in the initial config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The path to the YAML file where the template will be saved. |
required |