Materializers
zenml.materializers
Initialization of ZenML materializers.
Materializers are used to convert a ZenML artifact into a specific format. They
are most often used to handle the input or output of ZenML steps, and can be
extended by building on the BaseMaterializer
class.
Attributes
__all__ = ['BuiltInContainerMaterializer', 'BuiltInMaterializer', 'BytesMaterializer', 'CloudpickleMaterializer', 'StructuredStringMaterializer', 'PydanticMaterializer', 'ServiceMaterializer', 'UUIDMaterializer']
module-attribute
Classes
BuiltInContainerMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Handle built-in container types (dict, list, set, tuple).
Define self.data_path
and self.metadata_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI where the artifact data is stored. |
required |
artifact_store
|
Optional[BaseArtifactStore]
|
The artifact store where the artifact data is stored. |
None
|
Source code in src/zenml/materializers/built_in_materializer.py
273 274 275 276 277 278 279 280 281 282 283 284 |
|
Functions
extract_metadata(data: Any) -> Dict[str, MetadataType]
Extract metadata from the given built-in container object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The built-in container object to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/materializers/built_in_materializer.py
450 451 452 453 454 455 456 457 458 459 460 461 |
|
load(data_type: Type[Any]) -> Any
Reads a materialized built-in container object.
If the data was serialized to JSON, deserialize it.
Otherwise, reconstruct all elements according to the metadata file:
1. Resolve the data type using find_type_by_str()
,
2. Get the materializer via the default_materializer_registry
,
3. Initialize the materializer with the desired path,
4. Use load()
of that materializer to load the element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
Any
|
The data read. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the data was not found. |
Source code in src/zenml/materializers/built_in_materializer.py
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 |
|
save(data: Any) -> None
Materialize a built-in container object.
If the object can be serialized to JSON, serialize it.
Otherwise, use the default_materializer_registry
to find the correct
materializer for each element and materialize each element into a
subdirectory.
Tuples and sets are cast to list before materialization.
For non-serializable dicts, materialize keys/values as separate lists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The built-in container object to materialize. |
required |
Raises:
Type | Description |
---|---|
Exception
|
If any exception occurs, it is raised after cleanup. |
Source code in src/zenml/materializers/built_in_materializer.py
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 |
|
save_visualizations(data: Any) -> Dict[str, VisualizationType]
Save visualizations for the given data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to save visualizations for. |
required |
Returns:
Type | Description |
---|---|
Dict[str, VisualizationType]
|
A dictionary of visualization URIs and their types. |
Source code in src/zenml/materializers/built_in_materializer.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
BuiltInMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Handle JSON-serializable basic types (bool
, float
, int
, str
).
Define self.data_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI where the artifact data is stored. |
required |
artifact_store
|
Optional[BaseArtifactStore]
|
The artifact store where the artifact data is stored. |
None
|
Source code in src/zenml/materializers/built_in_materializer.py
66 67 68 69 70 71 72 73 74 75 76 |
|
Functions
extract_metadata(data: Union[bool, float, int, str]) -> Dict[str, MetadataType]
Extract metadata from the given built-in container object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Union[bool, float, int, str]
|
The built-in container object to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/materializers/built_in_materializer.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
load(data_type: Union[Type[bool], Type[float], Type[int], Type[str]]) -> Any
Reads basic primitive types from JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Union[Type[bool], Type[float], Type[int], Type[str]]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
Any
|
The data read. |
Source code in src/zenml/materializers/built_in_materializer.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
save(data: Union[bool, float, int, str]) -> None
Serialize a basic type to JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Union[bool, float, int, str]
|
The data to store. |
required |
Source code in src/zenml/materializers/built_in_materializer.py
98 99 100 101 102 103 104 105 106 107 108 |
|
BytesMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Handle bytes
data type, which is not JSON serializable.
Define self.data_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI where the artifact data is stored. |
required |
artifact_store
|
Optional[BaseArtifactStore]
|
The artifact store where the artifact data is stored. |
None
|
Source code in src/zenml/materializers/built_in_materializer.py
135 136 137 138 139 140 141 142 143 144 145 |
|
Functions
load(data_type: Type[Any]) -> Any
Reads a bytes object from file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
Any
|
The data read. |
Source code in src/zenml/materializers/built_in_materializer.py
147 148 149 150 151 152 153 154 155 156 157 |
|
save(data: Any) -> None
Save a bytes object to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to store. |
required |
Source code in src/zenml/materializers/built_in_materializer.py
159 160 161 162 163 164 165 166 |
|
CloudpickleMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer using cloudpickle.
This materializer can materialize (almost) any object, but does so in a non-reproducble way since artifacts cannot be loaded from other Python versions. It is recommended to use this materializer only as a last resort.
That is also why it has SKIP_REGISTRATION
set to True and is currently
only used as a fallback materializer inside the materializer registry.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
Functions
load(data_type: Type[Any]) -> Any
Reads an artifact from a cloudpickle file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The data type of the artifact. |
required |
Returns:
Type | Description |
---|---|
Any
|
The loaded artifact data. |
Source code in src/zenml/materializers/cloudpickle_materializer.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 |
|
save(data: Any) -> None
Saves an artifact to a cloudpickle file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to save. |
required |
Source code in src/zenml/materializers/cloudpickle_materializer.py
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 |
|
PydanticMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Handle Pydantic BaseModel objects.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
Functions
extract_metadata(data: BaseModel) -> Dict[str, MetadataType]
Extract metadata from the given BaseModel object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
BaseModel
|
The BaseModel object to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/materializers/pydantic_materializer.py
59 60 61 62 63 64 65 66 67 68 |
|
load(data_type: Type[BaseModel]) -> Any
Reads BaseModel from JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[BaseModel]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
Any
|
The data read. |
Source code in src/zenml/materializers/pydantic_materializer.py
37 38 39 40 41 42 43 44 45 46 47 48 |
|
save(data: BaseModel) -> None
Serialize a BaseModel to JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
BaseModel
|
The data to store. |
required |
Source code in src/zenml/materializers/pydantic_materializer.py
50 51 52 53 54 55 56 57 |
|
ServiceMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer to read/write service instances.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
Functions
extract_metadata(service: BaseService) -> Dict[str, MetadataType]
Extract metadata from the given service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
The service to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/materializers/service_materializer.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
load(data_type: Type[Any]) -> BaseService
Creates and returns a service.
This service is instantiated from the serialized service configuration and last known status information saved as artifact.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
BaseService
|
A ZenML service instance. |
Source code in src/zenml/materializers/service_materializer.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
save(service: BaseService) -> None
Writes a ZenML service.
The configuration and last known status of the input service instance are serialized and saved as an artifact.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
A ZenML service instance. |
required |
Source code in src/zenml/materializers/service_materializer.py
56 57 58 59 60 61 62 63 64 65 66 67 |
|
StructuredStringMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer for HTML or Markdown strings.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
Functions
load(data_type: Type[STRUCTURED_STRINGS]) -> STRUCTURED_STRINGS
Loads the data from the HTML or Markdown file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[STRUCTURED_STRINGS]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
STRUCTURED_STRINGS
|
The loaded data. |
Source code in src/zenml/materializers/structured_string_materializer.py
41 42 43 44 45 46 47 48 49 50 51 |
|
save(data: STRUCTURED_STRINGS) -> None
Save data as an HTML or Markdown file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
STRUCTURED_STRINGS
|
The data to save as an HTML or Markdown file. |
required |
Source code in src/zenml/materializers/structured_string_materializer.py
53 54 55 56 57 58 59 60 61 62 |
|
save_visualizations(data: STRUCTURED_STRINGS) -> Dict[str, VisualizationType]
Save visualizations for the given data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
STRUCTURED_STRINGS
|
The data to save visualizations for. |
required |
Returns:
Type | Description |
---|---|
Dict[str, VisualizationType]
|
A dictionary of visualization URIs and their types. |
Source code in src/zenml/materializers/structured_string_materializer.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
UUIDMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer to handle UUID objects.
Define self.data_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI where the artifact data is stored. |
required |
artifact_store
|
Optional[BaseArtifactStore]
|
The artifact store where the artifact data is stored. |
None
|
Source code in src/zenml/materializers/uuid_materializer.py
34 35 36 37 38 39 40 41 42 43 44 |
|
Functions
extract_metadata(data: uuid.UUID) -> Dict[str, MetadataType]
Extract metadata from the UUID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
UUID
|
The UUID to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
A dictionary of metadata extracted from the UUID. |
Source code in src/zenml/materializers/uuid_materializer.py
68 69 70 71 72 73 74 75 76 77 78 79 |
|
load(_: Type[uuid.UUID]) -> uuid.UUID
Read UUID from artifact store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_
|
Type[UUID]
|
The type of the data to be loaded. |
required |
Returns:
Type | Description |
---|---|
UUID
|
The loaded UUID. |
Source code in src/zenml/materializers/uuid_materializer.py
46 47 48 49 50 51 52 53 54 55 56 57 |
|
save(data: uuid.UUID) -> None
Write UUID to artifact store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
UUID
|
The UUID to be saved. |
required |
Source code in src/zenml/materializers/uuid_materializer.py
59 60 61 62 63 64 65 66 |
|
Modules
base_materializer
Metaclass implementation for registering ZenML BaseMaterializer subclasses.
Classes
BaseMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Base Materializer to realize artifact data.
Initializes a materializer with the given URI.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI where the artifact data will be stored. |
required |
artifact_store
|
Optional[BaseArtifactStore]
|
The artifact store used to store this artifact. |
None
|
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
artifact_store: BaseArtifactStore
property
Returns the artifact store used to store this artifact.
It either comes from the configuration of the materializer or from the active stack.
Returns:
Type | Description |
---|---|
BaseArtifactStore
|
The artifact store used to store this artifact. |
can_load_type(data_type: Type[Any]) -> bool
classmethod
Whether the materializer can load an artifact as the given type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the materializer can load an artifact as the given type. |
Source code in src/zenml/materializers/base_materializer.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
can_save_type(data_type: Type[Any]) -> bool
classmethod
Whether the materializer can save a certain type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the materializer can save the given type. |
Source code in src/zenml/materializers/base_materializer.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
extract_full_metadata(data: Any) -> Dict[str, MetadataType]
Extract both base and custom metadata from the given data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
A dictionary of metadata. |
Source code in src/zenml/materializers/base_materializer.py
301 302 303 304 305 306 307 308 309 310 311 312 |
|
extract_metadata(data: Any) -> Dict[str, MetadataType]
Extract metadata from the given data.
This metadata will be tracked and displayed alongside the artifact.
Example:
return {
"some_attribute_i_want_to_track": self.some_attribute,
"pi": 3.14,
}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
A dictionary of metadata. |
Source code in src/zenml/materializers/base_materializer.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
get_temporary_directory(delete_at_exit: bool, delete_after_step_execution: bool = True) -> Iterator[str]
Context manager to get a temporary directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
delete_at_exit
|
bool
|
If set to True, the temporary directory will be deleted after the context manager exits. |
required |
delete_after_step_execution
|
bool
|
If |
True
|
Yields:
Type | Description |
---|---|
str
|
Path to the temporary directory. |
Source code in src/zenml/materializers/base_materializer.py
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 |
|
load(data_type: Type[Any]) -> Any
Write logic here to load the data of an artifact.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
What type the artifact data should be loaded as. |
required |
Returns:
Type | Description |
---|---|
Any
|
The data of the artifact. |
Source code in src/zenml/materializers/base_materializer.py
158 159 160 161 162 163 164 165 166 167 168 |
|
save(data: Any) -> None
Write logic here to save the data of an artifact.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data of the artifact to save. |
required |
Source code in src/zenml/materializers/base_materializer.py
170 171 172 173 174 175 |
|
save_visualizations(data: Any) -> Dict[str, VisualizationType]
Save visualizations of the given data.
If this method is not overridden, no visualizations will be saved.
When overriding this method, make sure to save all visualizations to
files within self.uri
.
Example:
visualization_uri = os.path.join(self.uri, "visualization.html")
with self.artifact_store.open(visualization_uri, "w") as f:
f.write("<html><body>data</body></html>")
visualization_uri_2 = os.path.join(self.uri, "visualization.png")
data.save_as_png(visualization_uri_2)
return {
visualization_uri: ArtifactVisualizationType.HTML,
visualization_uri_2: ArtifactVisualizationType.IMAGE
}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data of the artifact to visualize. |
required |
Returns:
Type | Description |
---|---|
Dict[str, VisualizationType]
|
A dictionary of visualization URIs and their types. |
Source code in src/zenml/materializers/base_materializer.py
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 |
|
validate_load_type_compatibility(data_type: Type[Any]) -> None
Checks whether the materializer can load the given type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type to check. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
If the materializer cannot load the given type. |
Source code in src/zenml/materializers/base_materializer.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
validate_save_type_compatibility(data_type: Type[Any]) -> None
Checks whether the materializer can save the given type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type to check. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
If the materializer cannot save the given type. |
Source code in src/zenml/materializers/base_materializer.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
BaseMaterializerMeta
Bases: type
Metaclass responsible for registering different BaseMaterializer subclasses.
Materializers are used for reading/writing artifacts.
__new__(mcs, name: str, bases: Tuple[Type[Any], ...], dct: Dict[str, Any]) -> BaseMaterializerMeta
Creates a Materializer class and registers it at the MaterializerRegistry
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the class. |
required |
bases
|
Tuple[Type[Any], ...]
|
The base classes of the class. |
required |
dct
|
Dict[str, Any]
|
The dictionary of the class. |
required |
Returns:
Type | Description |
---|---|
BaseMaterializerMeta
|
The BaseMaterializerMeta class. |
Raises:
Type | Description |
---|---|
MaterializerInterfaceError
|
If the class was improperly defined. |
Source code in src/zenml/materializers/base_materializer.py
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 |
|
Functions
Modules
built_in_materializer
Implementation of ZenML's builtin materializer.
Classes
BuiltInContainerMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Handle built-in container types (dict, list, set, tuple).
Define self.data_path
and self.metadata_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI where the artifact data is stored. |
required |
artifact_store
|
Optional[BaseArtifactStore]
|
The artifact store where the artifact data is stored. |
None
|
Source code in src/zenml/materializers/built_in_materializer.py
273 274 275 276 277 278 279 280 281 282 283 284 |
|
extract_metadata(data: Any) -> Dict[str, MetadataType]
Extract metadata from the given built-in container object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The built-in container object to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/materializers/built_in_materializer.py
450 451 452 453 454 455 456 457 458 459 460 461 |
|
load(data_type: Type[Any]) -> Any
Reads a materialized built-in container object.
If the data was serialized to JSON, deserialize it.
Otherwise, reconstruct all elements according to the metadata file:
1. Resolve the data type using find_type_by_str()
,
2. Get the materializer via the default_materializer_registry
,
3. Initialize the materializer with the desired path,
4. Use load()
of that materializer to load the element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
Any
|
The data read. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the data was not found. |
Source code in src/zenml/materializers/built_in_materializer.py
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 |
|
save(data: Any) -> None
Materialize a built-in container object.
If the object can be serialized to JSON, serialize it.
Otherwise, use the default_materializer_registry
to find the correct
materializer for each element and materialize each element into a
subdirectory.
Tuples and sets are cast to list before materialization.
For non-serializable dicts, materialize keys/values as separate lists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The built-in container object to materialize. |
required |
Raises:
Type | Description |
---|---|
Exception
|
If any exception occurs, it is raised after cleanup. |
Source code in src/zenml/materializers/built_in_materializer.py
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 |
|
save_visualizations(data: Any) -> Dict[str, VisualizationType]
Save visualizations for the given data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to save visualizations for. |
required |
Returns:
Type | Description |
---|---|
Dict[str, VisualizationType]
|
A dictionary of visualization URIs and their types. |
Source code in src/zenml/materializers/built_in_materializer.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
BuiltInMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Handle JSON-serializable basic types (bool
, float
, int
, str
).
Define self.data_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI where the artifact data is stored. |
required |
artifact_store
|
Optional[BaseArtifactStore]
|
The artifact store where the artifact data is stored. |
None
|
Source code in src/zenml/materializers/built_in_materializer.py
66 67 68 69 70 71 72 73 74 75 76 |
|
extract_metadata(data: Union[bool, float, int, str]) -> Dict[str, MetadataType]
Extract metadata from the given built-in container object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Union[bool, float, int, str]
|
The built-in container object to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/materializers/built_in_materializer.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
load(data_type: Union[Type[bool], Type[float], Type[int], Type[str]]) -> Any
Reads basic primitive types from JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Union[Type[bool], Type[float], Type[int], Type[str]]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
Any
|
The data read. |
Source code in src/zenml/materializers/built_in_materializer.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
save(data: Union[bool, float, int, str]) -> None
Serialize a basic type to JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Union[bool, float, int, str]
|
The data to store. |
required |
Source code in src/zenml/materializers/built_in_materializer.py
98 99 100 101 102 103 104 105 106 107 108 |
|
BytesMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Handle bytes
data type, which is not JSON serializable.
Define self.data_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI where the artifact data is stored. |
required |
artifact_store
|
Optional[BaseArtifactStore]
|
The artifact store where the artifact data is stored. |
None
|
Source code in src/zenml/materializers/built_in_materializer.py
135 136 137 138 139 140 141 142 143 144 145 |
|
load(data_type: Type[Any]) -> Any
Reads a bytes object from file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
Any
|
The data read. |
Source code in src/zenml/materializers/built_in_materializer.py
147 148 149 150 151 152 153 154 155 156 157 |
|
save(data: Any) -> None
Save a bytes object to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to store. |
required |
Source code in src/zenml/materializers/built_in_materializer.py
159 160 161 162 163 164 165 166 |
|
Functions
find_materializer_registry_type(type_: Type[Any]) -> Type[Any]
For a given type, find the type registered in the registry.
This can be either the type itself, or a superclass of the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_
|
Type[Any]
|
The type to find. |
required |
Returns:
Type | Description |
---|---|
Type[Any]
|
The type registered in the registry. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the type could not be resolved. |
Source code in src/zenml/materializers/built_in_materializer.py
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 |
|
find_type_by_str(type_str: str) -> Type[Any]
Get a Python type, given its string representation.
E.g., "int
.
Currently this is implemented by checking all artifact types registered in
the default_materializer_registry
. This means, only types in the registry
can be found. Any other types will cause a RunTimeError
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_str
|
str
|
The string representation of a type. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the type could not be resolved. |
Returns:
Type | Description |
---|---|
Type[Any]
|
The type whose string representation is |
Source code in src/zenml/materializers/built_in_materializer.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
Modules
cloudpickle_materializer
Implementation of ZenML's cloudpickle materializer.
Classes
CloudpickleMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer using cloudpickle.
This materializer can materialize (almost) any object, but does so in a non-reproducble way since artifacts cannot be loaded from other Python versions. It is recommended to use this materializer only as a last resort.
That is also why it has SKIP_REGISTRATION
set to True and is currently
only used as a fallback materializer inside the materializer registry.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
load(data_type: Type[Any]) -> Any
Reads an artifact from a cloudpickle file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The data type of the artifact. |
required |
Returns:
Type | Description |
---|---|
Any
|
The loaded artifact data. |
Source code in src/zenml/materializers/cloudpickle_materializer.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 |
|
save(data: Any) -> None
Saves an artifact to a cloudpickle file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to save. |
required |
Source code in src/zenml/materializers/cloudpickle_materializer.py
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 |
|
Functions
materializer_registry
Implementation of a default materializer registry.
Classes
MaterializerRegistry()
Matches a Python type to a default materializer.
Initialize the materializer registry.
Source code in src/zenml/materializers/materializer_registry.py
29 30 31 32 |
|
get_default_materializer() -> Type[BaseMaterializer]
Get the default materializer that is used if no other is found.
Returns:
Type | Description |
---|---|
Type[BaseMaterializer]
|
The default materializer. |
Source code in src/zenml/materializers/materializer_registry.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
get_materializer_types() -> Dict[Type[Any], Type[BaseMaterializer]]
Get all registered materializer types.
Returns:
Type | Description |
---|---|
Dict[Type[Any], Type[BaseMaterializer]]
|
A dictionary of registered materializer types. |
Source code in src/zenml/materializers/materializer_registry.py
95 96 97 98 99 100 101 102 103 |
|
is_registered(key: Type[Any]) -> bool
Returns if a materializer class is registered for the given type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Type[Any]
|
Indicates the type of object. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if a materializer is registered for the given type, False |
bool
|
otherwise. |
Source code in src/zenml/materializers/materializer_registry.py
105 106 107 108 109 110 111 112 113 114 115 |
|
register_and_overwrite_type(key: Type[Any], type_: Type[BaseMaterializer]) -> None
Registers a new materializer and also overwrites a default if set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Type[Any]
|
Indicates the type of object. |
required |
type_
|
Type[BaseMaterializer]
|
A BaseMaterializer subclass. |
required |
Source code in src/zenml/materializers/materializer_registry.py
53 54 55 56 57 58 59 60 61 62 63 |
|
register_materializer_type(key: Type[Any], type_: Type[BaseMaterializer]) -> None
Registers a new materializer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Type[Any]
|
Indicates the type of object. |
required |
type_
|
Type[BaseMaterializer]
|
A BaseMaterializer subclass. |
required |
Source code in src/zenml/materializers/materializer_registry.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
Functions
numpy_materializer
Placeholder for importing the Numpy Materializer from its former path.
Classes
pandas_materializer
Placeholder for importing the Pandas Materializer from its former path.
Classes
pydantic_materializer
Implementation of ZenML's pydantic materializer.
Classes
PydanticMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Handle Pydantic BaseModel objects.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
extract_metadata(data: BaseModel) -> Dict[str, MetadataType]
Extract metadata from the given BaseModel object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
BaseModel
|
The BaseModel object to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/materializers/pydantic_materializer.py
59 60 61 62 63 64 65 66 67 68 |
|
load(data_type: Type[BaseModel]) -> Any
Reads BaseModel from JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[BaseModel]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
Any
|
The data read. |
Source code in src/zenml/materializers/pydantic_materializer.py
37 38 39 40 41 42 43 44 45 46 47 48 |
|
save(data: BaseModel) -> None
Serialize a BaseModel to JSON.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
BaseModel
|
The data to store. |
required |
Source code in src/zenml/materializers/pydantic_materializer.py
50 51 52 53 54 55 56 57 |
|
Modules
service_materializer
Implementation of a materializer to read and write ZenML service instances.
Classes
ServiceMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer to read/write service instances.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
extract_metadata(service: BaseService) -> Dict[str, MetadataType]
Extract metadata from the given service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
The service to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/materializers/service_materializer.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
load(data_type: Type[Any]) -> BaseService
Creates and returns a service.
This service is instantiated from the serialized service configuration and last known status information saved as artifact.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
BaseService
|
A ZenML service instance. |
Source code in src/zenml/materializers/service_materializer.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
save(service: BaseService) -> None
Writes a ZenML service.
The configuration and last known status of the input service instance are serialized and saved as an artifact.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
A ZenML service instance. |
required |
Source code in src/zenml/materializers/service_materializer.py
56 57 58 59 60 61 62 63 64 65 66 67 |
|
structured_string_materializer
Implementation of HTMLString materializer.
Classes
StructuredStringMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer for HTML or Markdown strings.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
load(data_type: Type[STRUCTURED_STRINGS]) -> STRUCTURED_STRINGS
Loads the data from the HTML or Markdown file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[STRUCTURED_STRINGS]
|
The type of the data to read. |
required |
Returns:
Type | Description |
---|---|
STRUCTURED_STRINGS
|
The loaded data. |
Source code in src/zenml/materializers/structured_string_materializer.py
41 42 43 44 45 46 47 48 49 50 51 |
|
save(data: STRUCTURED_STRINGS) -> None
Save data as an HTML or Markdown file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
STRUCTURED_STRINGS
|
The data to save as an HTML or Markdown file. |
required |
Source code in src/zenml/materializers/structured_string_materializer.py
53 54 55 56 57 58 59 60 61 62 |
|
save_visualizations(data: STRUCTURED_STRINGS) -> Dict[str, VisualizationType]
Save visualizations for the given data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
STRUCTURED_STRINGS
|
The data to save visualizations for. |
required |
Returns:
Type | Description |
---|---|
Dict[str, VisualizationType]
|
A dictionary of visualization URIs and their types. |
Source code in src/zenml/materializers/structured_string_materializer.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
Functions
uuid_materializer
Implementation of ZenML's UUID materializer.
Classes
UUIDMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer to handle UUID objects.
Define self.data_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The URI where the artifact data is stored. |
required |
artifact_store
|
Optional[BaseArtifactStore]
|
The artifact store where the artifact data is stored. |
None
|
Source code in src/zenml/materializers/uuid_materializer.py
34 35 36 37 38 39 40 41 42 43 44 |
|
extract_metadata(data: uuid.UUID) -> Dict[str, MetadataType]
Extract metadata from the UUID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
UUID
|
The UUID to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
A dictionary of metadata extracted from the UUID. |
Source code in src/zenml/materializers/uuid_materializer.py
68 69 70 71 72 73 74 75 76 77 78 79 |
|
load(_: Type[uuid.UUID]) -> uuid.UUID
Read UUID from artifact store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_
|
Type[UUID]
|
The type of the data to be loaded. |
required |
Returns:
Type | Description |
---|---|
UUID
|
The loaded UUID. |
Source code in src/zenml/materializers/uuid_materializer.py
46 47 48 49 50 51 52 53 54 55 56 57 |
|
save(data: uuid.UUID) -> None
Write UUID to artifact store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
UUID
|
The UUID to be saved. |
required |
Source code in src/zenml/materializers/uuid_materializer.py
59 60 61 62 63 64 65 66 |
|