Config
zenml.config
special
The config
module contains classes and functions that manage user-specific
configuration. ZenML's configuration is stored in a file called
.zenglobal.json
, located on the user's directory for configuration files.
(The exact location differs from operating system to operating system.)
The GlobalConfig
class is the main class in this module. It provides a
Pydantic configuration object that is used to store and retrieve configuration.
This GlobalConfig
object handles the serialization and deserialization of
the configuration options that are stored in the file in order to persist the
configuration across sessions.
config_keys
ConfigKeys
Class to validate dictionary configurations.
Source code in zenml/config/config_keys.py
class ConfigKeys:
"""Class to validate dictionary configurations."""
@classmethod
def get_keys(cls) -> Tuple[List[str], List[str]]:
"""Gets all the required and optional config keys for this class.
Returns:
A tuple (required, optional) which are lists of the
required/optional keys for this class.
"""
keys = {
key: value
for key, value in cls.__dict__.items()
if not isinstance(value, classmethod)
and not isinstance(value, staticmethod)
and not callable(value)
and not key.startswith("__")
}
required = [v for k, v in keys.items() if not k.endswith("_")]
optional = [v for k, v in keys.items() if k.endswith("_")]
return required, optional
@classmethod
def key_check(cls, config: Dict[str, Any]) -> None:
"""Checks whether a configuration dict contains all required keys
and no unknown keys.
Args:
config: The configuration dict to verify.
Raises:
AssertionError: If the dictionary contains unknown keys or
is missing any required key.
"""
assert isinstance(config, dict), "Please specify a dict for {}".format(
cls.__name__
)
# Required and optional keys for the config dict
required, optional = cls.get_keys()
# Check for missing keys
missing_keys = [k for k in required if k not in config.keys()]
assert len(missing_keys) == 0, "Missing key(s) {} in {}".format(
missing_keys, cls.__name__
)
# Check for unknown keys
unknown_keys = [
k for k in config.keys() if k not in required and k not in optional
]
assert (
len(unknown_keys) == 0
), "Unknown key(s) {} in {}. Required keys : {} " "Optional Keys: {}".format(
unknown_keys,
cls.__name__,
required,
optional,
)
get_keys()
classmethod
Gets all the required and optional config keys for this class.
Returns:
Type | Description |
---|---|
Tuple[List[str], List[str]] |
A tuple (required, optional) which are lists of the required/optional keys for this class. |
Source code in zenml/config/config_keys.py
@classmethod
def get_keys(cls) -> Tuple[List[str], List[str]]:
"""Gets all the required and optional config keys for this class.
Returns:
A tuple (required, optional) which are lists of the
required/optional keys for this class.
"""
keys = {
key: value
for key, value in cls.__dict__.items()
if not isinstance(value, classmethod)
and not isinstance(value, staticmethod)
and not callable(value)
and not key.startswith("__")
}
required = [v for k, v in keys.items() if not k.endswith("_")]
optional = [v for k, v in keys.items() if k.endswith("_")]
return required, optional
key_check(config)
classmethod
Checks whether a configuration dict contains all required keys and no unknown keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Dict[str, Any] |
The configuration dict to verify. |
required |
Exceptions:
Type | Description |
---|---|
AssertionError |
If the dictionary contains unknown keys or is missing any required key. |
Source code in zenml/config/config_keys.py
@classmethod
def key_check(cls, config: Dict[str, Any]) -> None:
"""Checks whether a configuration dict contains all required keys
and no unknown keys.
Args:
config: The configuration dict to verify.
Raises:
AssertionError: If the dictionary contains unknown keys or
is missing any required key.
"""
assert isinstance(config, dict), "Please specify a dict for {}".format(
cls.__name__
)
# Required and optional keys for the config dict
required, optional = cls.get_keys()
# Check for missing keys
missing_keys = [k for k in required if k not in config.keys()]
assert len(missing_keys) == 0, "Missing key(s) {} in {}".format(
missing_keys, cls.__name__
)
# Check for unknown keys
unknown_keys = [
k for k in config.keys() if k not in required and k not in optional
]
assert (
len(unknown_keys) == 0
), "Unknown key(s) {} in {}. Required keys : {} " "Optional Keys: {}".format(
unknown_keys,
cls.__name__,
required,
optional,
)
PipelineConfigurationKeys (ConfigKeys)
Keys for a pipeline configuration dict.
Source code in zenml/config/config_keys.py
class PipelineConfigurationKeys(ConfigKeys):
"""Keys for a pipeline configuration dict."""
NAME = "name"
STEPS = "steps"
StepConfigurationKeys (ConfigKeys)
Keys for a step configuration dict.
Source code in zenml/config/config_keys.py
class StepConfigurationKeys(ConfigKeys):
"""Keys for a step configuration dict."""
SOURCE_ = "source"
PARAMETERS_ = "parameters"
MATERIALIZERS_ = "materializers"
global_config
Global config for the ZenML installation.
GlobalConfig (BaseComponent)
pydantic-model
Class definition for the global config.
Defines global data such as unique user ID and whether they opted in for analytics.
Source code in zenml/config/global_config.py
class GlobalConfig(BaseComponent):
"""Class definition for the global config.
Defines global data such as unique user ID and whether they opted in
for analytics.
"""
user_id: UUID = Field(default_factory=uuid4)
analytics_opt_in: bool = True
def __init__(self, **data: Any):
"""We persist the attributes in the config file. For the global
config, we want to persist the data as soon as it is initialized for
the first time."""
super().__init__(
serialization_dir=get_global_config_directory(), **data
)
# At this point, if the serialization file does not exist we should
# create it and dump our data.
f = self.get_serialization_full_path()
if not fileio.file_exists(str(f)):
self._dump()
def get_serialization_file_name(self) -> str:
"""Gets the global config dir for installed package."""
return GLOBAL_CONFIG_NAME
__init__(self, **data)
special
We persist the attributes in the config file. For the global config, we want to persist the data as soon as it is initialized for the first time.
Source code in zenml/config/global_config.py
def __init__(self, **data: Any):
"""We persist the attributes in the config file. For the global
config, we want to persist the data as soon as it is initialized for
the first time."""
super().__init__(
serialization_dir=get_global_config_directory(), **data
)
# At this point, if the serialization file does not exist we should
# create it and dump our data.
f = self.get_serialization_full_path()
if not fileio.file_exists(str(f)):
self._dump()
get_serialization_file_name(self)
Gets the global config dir for installed package.
Source code in zenml/config/global_config.py
def get_serialization_file_name(self) -> str:
"""Gets the global config dir for installed package."""
return GLOBAL_CONFIG_NAME