Steps
zenml.steps
Initializer for ZenML steps.
A step is a single piece or stage of a ZenML pipeline. Think of each step as being one of the nodes of a Directed Acyclic Graph (or DAG). Steps are responsible for one aspect of processing or interacting with the data / artifacts in the pipeline.
Conceptually, a Step is a discrete and independent part of a pipeline that is responsible for one particular aspect of data manipulation inside a ZenML pipeline.
Steps can be subclassed from the BaseStep
class, or used via our @step
decorator.
Attributes
__all__ = ['BaseStep', 'ResourceSettings', 'StepContext', 'step', 'get_step_context']
module-attribute
Classes
BaseStep(name: Optional[str] = None, enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_artifact_visualization: Optional[bool] = None, enable_step_logs: Optional[bool] = None, experiment_tracker: Optional[str] = None, step_operator: Optional[str] = None, parameters: Optional[Dict[str, Any]] = None, output_materializers: Optional[OutputMaterializersSpecification] = None, settings: Optional[Mapping[str, SettingsOrDict]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None)
Abstract base class for all ZenML steps.
Initializes a step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Optional[str]
|
The name of the step. |
None
|
enable_cache
|
Optional[bool]
|
If caching should be enabled for this step. |
None
|
enable_artifact_metadata
|
Optional[bool]
|
If artifact metadata should be enabled for this step. |
None
|
enable_artifact_visualization
|
Optional[bool]
|
If artifact visualization should be enabled for this step. |
None
|
enable_step_logs
|
Optional[bool]
|
Enable step logs for this step. |
None
|
experiment_tracker
|
Optional[str]
|
The experiment tracker to use for this step. |
None
|
step_operator
|
Optional[str]
|
The step operator to use for this step. |
None
|
parameters
|
Optional[Dict[str, Any]]
|
Function parameters for this step |
None
|
output_materializers
|
Optional[OutputMaterializersSpecification]
|
Output materializers for this step. If given as a dict, the keys must be a subset of the output names of this step. If a single value (type or string) is given, the materializer will be used for all outputs. |
None
|
settings
|
Optional[Mapping[str, SettingsOrDict]]
|
settings for this step. |
None
|
extra
|
Optional[Dict[str, Any]]
|
Extra configurations for this step. |
None
|
on_failure
|
Optional[HookSpecification]
|
Callback function in event of failure of the step. Can
be a function with a single argument of type |
None
|
on_success
|
Optional[HookSpecification]
|
Callback function in event of success of the step. Can
be a function with no arguments, or a source path to such a
function (e.g. |
None
|
model
|
Optional[Model]
|
configuration of the model version in the Model Control Plane. |
None
|
retry
|
Optional[StepRetryConfig]
|
Configuration for retrying the step in case of failure. |
None
|
substitutions
|
Optional[Dict[str, str]]
|
Extra placeholders to use in the name template. |
None
|
Source code in src/zenml/steps/base_step.py
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 |
|
Attributes
caching_parameters: Dict[str, Any]
property
Caching parameters for this step.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary containing the caching parameters |
configuration: PartialStepConfiguration
property
The configuration of the step.
Returns:
Type | Description |
---|---|
PartialStepConfiguration
|
The configuration of the step. |
docstring: Optional[str]
property
The docstring of this step.
Returns:
Type | Description |
---|---|
Optional[str]
|
The docstring of this step. |
enable_cache: Optional[bool]
property
If caching is enabled for the step.
Returns:
Type | Description |
---|---|
Optional[bool]
|
If caching is enabled for the step. |
name: str
property
The name of the step.
Returns:
Type | Description |
---|---|
str
|
The name of the step. |
source_code: str
property
The source code of this step.
Returns:
Type | Description |
---|---|
str
|
The source code of this step. |
source_object: Any
property
The source object of this step.
Returns:
Type | Description |
---|---|
Any
|
The source object of this step. |
Functions
call_entrypoint(*args: Any, **kwargs: Any) -> Any
Calls the entrypoint function of the step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Entrypoint function arguments. |
()
|
**kwargs
|
Any
|
Entrypoint function keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The return value of the entrypoint function. |
Raises:
Type | Description |
---|---|
StepInterfaceError
|
If the arguments to the entrypoint function are invalid. |
Source code in src/zenml/steps/base_step.py
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 560 561 562 |
|
configure(enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_artifact_visualization: Optional[bool] = None, enable_step_logs: Optional[bool] = None, experiment_tracker: Optional[str] = None, step_operator: Optional[str] = None, parameters: Optional[Dict[str, Any]] = None, output_materializers: Optional[OutputMaterializersSpecification] = None, settings: Optional[Mapping[str, SettingsOrDict]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None, merge: bool = True) -> T
Configures the step.
Configuration merging example:
* merge==True
:
step.configure(extra={"key1": 1})
step.configure(extra={"key2": 2}, merge=True)
step.configuration.extra # {"key1": 1, "key2": 2}
* merge==False
:
step.configure(extra={"key1": 1})
step.configure(extra={"key2": 2}, merge=False)
step.configuration.extra # {"key2": 2}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enable_cache
|
Optional[bool]
|
If caching should be enabled for this step. |
None
|
enable_artifact_metadata
|
Optional[bool]
|
If artifact metadata should be enabled for this step. |
None
|
enable_artifact_visualization
|
Optional[bool]
|
If artifact visualization should be enabled for this step. |
None
|
enable_step_logs
|
Optional[bool]
|
If step logs should be enabled for this step. |
None
|
experiment_tracker
|
Optional[str]
|
The experiment tracker to use for this step. |
None
|
step_operator
|
Optional[str]
|
The step operator to use for this step. |
None
|
parameters
|
Optional[Dict[str, Any]]
|
Function parameters for this step |
None
|
output_materializers
|
Optional[OutputMaterializersSpecification]
|
Output materializers for this step. If given as a dict, the keys must be a subset of the output names of this step. If a single value (type or string) is given, the materializer will be used for all outputs. |
None
|
settings
|
Optional[Mapping[str, SettingsOrDict]]
|
settings for this step. |
None
|
extra
|
Optional[Dict[str, Any]]
|
Extra configurations for this step. |
None
|
on_failure
|
Optional[HookSpecification]
|
Callback function in event of failure of the step. Can
be a function with a single argument of type |
None
|
on_success
|
Optional[HookSpecification]
|
Callback function in event of success of the step. Can
be a function with no arguments, or a source path to such a
function (e.g. |
None
|
model
|
Optional[Model]
|
Model to use for this step. |
None
|
retry
|
Optional[StepRetryConfig]
|
Configuration for retrying the step in case of failure. |
None
|
substitutions
|
Optional[Dict[str, str]]
|
Extra placeholders to use in the name template. |
None
|
merge
|
bool
|
If |
True
|
Returns:
Type | Description |
---|---|
T
|
The step instance that this method was called on. |
Source code in src/zenml/steps/base_step.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
|
copy() -> BaseStep
Copies the step.
Returns:
Type | Description |
---|---|
BaseStep
|
The step copy. |
Source code in src/zenml/steps/base_step.py
803 804 805 806 807 808 809 |
|
entrypoint(*args: Any, **kwargs: Any) -> Any
abstractmethod
Abstract method for core step logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Positional arguments passed to the step. |
()
|
**kwargs
|
Any
|
Keyword arguments passed to the step. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The output of the step. |
Source code in src/zenml/steps/base_step.py
214 215 216 217 218 219 220 221 222 223 224 |
|
load_from_source(source: Union[Source, str]) -> BaseStep
classmethod
Loads a step from source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Union[Source, str]
|
The path to the step source. |
required |
Returns:
Type | Description |
---|---|
BaseStep
|
The loaded step. |
Raises:
Type | Description |
---|---|
ValueError
|
If the source is not a valid step source. |
Source code in src/zenml/steps/base_step.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
resolve() -> Source
Resolves the step.
Returns:
Type | Description |
---|---|
Source
|
The step source. |
Source code in src/zenml/steps/base_step.py
248 249 250 251 252 253 254 |
|
with_options(enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_artifact_visualization: Optional[bool] = None, enable_step_logs: Optional[bool] = None, experiment_tracker: Optional[str] = None, step_operator: Optional[str] = None, parameters: Optional[Dict[str, Any]] = None, output_materializers: Optional[OutputMaterializersSpecification] = None, settings: Optional[Mapping[str, SettingsOrDict]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None, merge: bool = True) -> BaseStep
Copies the step and applies the given configurations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enable_cache
|
Optional[bool]
|
If caching should be enabled for this step. |
None
|
enable_artifact_metadata
|
Optional[bool]
|
If artifact metadata should be enabled for this step. |
None
|
enable_artifact_visualization
|
Optional[bool]
|
If artifact visualization should be enabled for this step. |
None
|
enable_step_logs
|
Optional[bool]
|
If step logs should be enabled for this step. |
None
|
experiment_tracker
|
Optional[str]
|
The experiment tracker to use for this step. |
None
|
step_operator
|
Optional[str]
|
The step operator to use for this step. |
None
|
parameters
|
Optional[Dict[str, Any]]
|
Function parameters for this step |
None
|
output_materializers
|
Optional[OutputMaterializersSpecification]
|
Output materializers for this step. If given as a dict, the keys must be a subset of the output names of this step. If a single value (type or string) is given, the materializer will be used for all outputs. |
None
|
settings
|
Optional[Mapping[str, SettingsOrDict]]
|
settings for this step. |
None
|
extra
|
Optional[Dict[str, Any]]
|
Extra configurations for this step. |
None
|
on_failure
|
Optional[HookSpecification]
|
Callback function in event of failure of the step. Can
be a function with a single argument of type |
None
|
on_success
|
Optional[HookSpecification]
|
Callback function in event of success of the step. Can
be a function with no arguments, or a source path to such a
function (e.g. |
None
|
model
|
Optional[Model]
|
Model to use for this step. |
None
|
retry
|
Optional[StepRetryConfig]
|
Configuration for retrying the step in case of failure. |
None
|
substitutions
|
Optional[Dict[str, str]]
|
Extra placeholders for the step name. |
None
|
merge
|
bool
|
If |
True
|
Returns:
Type | Description |
---|---|
BaseStep
|
The copied step instance. |
Source code in src/zenml/steps/base_step.py
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
|
ResourceSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSettings
Hardware resource settings.
Attributes:
Name | Type | Description |
---|---|---|
cpu_count |
Optional[PositiveFloat]
|
The amount of CPU cores that should be configured. |
gpu_count |
Optional[NonNegativeInt]
|
The amount of GPUs that should be configured. |
memory |
Optional[str]
|
The amount of memory that should be configured. |
Source code in src/zenml/config/secret_reference_mixin.py
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 |
|
Attributes
empty: bool
property
Returns if this object is "empty" (=no values configured) or not.
Returns:
Type | Description |
---|---|
bool
|
|
Functions
get_memory(unit: Union[str, ByteUnit] = ByteUnit.GB) -> Optional[float]
Gets the memory configuration in a specific unit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit
|
Union[str, ByteUnit]
|
The unit to which the memory should be converted. |
GB
|
Raises:
Type | Description |
---|---|
ValueError
|
If the memory string is invalid. |
Returns:
Type | Description |
---|---|
Optional[float]
|
The memory configuration converted to the requested unit, or None |
Optional[float]
|
if no memory was configured. |
Source code in src/zenml/config/resource_settings.py
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 |
|
StepContext(pipeline_run: PipelineRunResponse, step_run: StepRunResponse, output_materializers: Mapping[str, Sequence[Type[BaseMaterializer]]], output_artifact_uris: Mapping[str, str], output_artifact_configs: Mapping[str, Optional[ArtifactConfig]])
Provides additional context inside a step function.
This singleton class is used to access information about the current run, step run, or its outputs inside a step function.
Usage example:
from zenml.steps import get_step_context
@step
def my_trainer_step() -> Any:
context = get_step_context()
# get info about the current pipeline run
current_pipeline_run = context.pipeline_run
# get info about the current step run
current_step_run = context.step_run
# get info about the future output artifacts of this step
output_artifact_uri = context.get_output_artifact_uri()
...
Initialize the context of the currently running step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pipeline_run
|
PipelineRunResponse
|
The model of the current pipeline run. |
required |
step_run
|
StepRunResponse
|
The model of the current step run. |
required |
output_materializers
|
Mapping[str, Sequence[Type[BaseMaterializer]]]
|
The output materializers of the step that this context is used in. |
required |
output_artifact_uris
|
Mapping[str, str]
|
The output artifacts of the step that this context is used in. |
required |
output_artifact_configs
|
Mapping[str, Optional[ArtifactConfig]]
|
The outputs' ArtifactConfigs of the step that this context is used in. |
required |
Raises:
Type | Description |
---|---|
StepContextError
|
If the keys of the output materializers and output artifacts do not match. |
Source code in src/zenml/steps/step_context.py
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 |
|
Attributes
inputs: Dict[str, StepRunInputResponse]
property
Returns the input artifacts of the current step.
Returns:
Type | Description |
---|---|
Dict[str, StepRunInputResponse]
|
The input artifacts of the current step. |
model: Model
property
Returns configured Model.
Order of resolution to search for Model is
- Model from the step context
- Model from the pipeline context
Returns:
Type | Description |
---|---|
Model
|
The |
Raises:
Type | Description |
---|---|
StepContextError
|
If no |
pipeline: PipelineResponse
property
Returns the current pipeline.
Returns:
Type | Description |
---|---|
PipelineResponse
|
The current pipeline or None. |
Raises:
Type | Description |
---|---|
StepContextError
|
If the pipeline run does not have a pipeline. |
Functions
add_output_metadata(metadata: Dict[str, MetadataType], output_name: Optional[str] = None) -> None
Adds metadata for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
Dict[str, MetadataType]
|
The metadata to add. |
required |
output_name
|
Optional[str]
|
Optional name of the output for which to add the metadata. If no name is given and the step only has a single output, the metadata of this output will be added. If the step has multiple outputs, an exception will be raised. |
None
|
Source code in src/zenml/steps/step_context.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
add_output_tags(tags: List[str], output_name: Optional[str] = None) -> None
Adds tags for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tags
|
List[str]
|
The tags to add. |
required |
output_name
|
Optional[str]
|
Optional name of the output for which to add the tags. If no name is given and the step only has a single output, the tags of this output will be added. If the step has multiple outputs, an exception will be raised. |
None
|
Source code in src/zenml/steps/step_context.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
get_output_artifact_uri(output_name: Optional[str] = None) -> str
Returns the artifact URI for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_name
|
Optional[str]
|
Optional name of the output for which to get the URI. If no name is given and the step only has a single output, the URI of this output will be returned. If the step has multiple outputs, an exception will be raised. |
None
|
Returns:
Type | Description |
---|---|
str
|
Artifact URI for the given output. |
Source code in src/zenml/steps/step_context.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
get_output_materializer(output_name: Optional[str] = None, custom_materializer_class: Optional[Type[BaseMaterializer]] = None, data_type: Optional[Type[Any]] = None) -> BaseMaterializer
Returns a materializer for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_name
|
Optional[str]
|
Optional name of the output for which to get the materializer. If no name is given and the step only has a single output, the materializer of this output will be returned. If the step has multiple outputs, an exception will be raised. |
None
|
custom_materializer_class
|
Optional[Type[BaseMaterializer]]
|
If given, this |
None
|
data_type
|
Optional[Type[Any]]
|
If the output annotation is of type |
None
|
Returns:
Type | Description |
---|---|
BaseMaterializer
|
A materializer initialized with the output artifact for |
BaseMaterializer
|
the given output. |
Source code in src/zenml/steps/step_context.py
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 |
|
get_output_metadata(output_name: Optional[str] = None) -> Dict[str, MetadataType]
Returns the metadata for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_name
|
Optional[str]
|
Optional name of the output for which to get the metadata. If no name is given and the step only has a single output, the metadata of this output will be returned. If the step has multiple outputs, an exception will be raised. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
Metadata for the given output. |
Source code in src/zenml/steps/step_context.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|
get_output_tags(output_name: Optional[str] = None) -> List[str]
Returns the tags for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_name
|
Optional[str]
|
Optional name of the output for which to get the metadata. If no name is given and the step only has a single output, the metadata of this output will be returned. If the step has multiple outputs, an exception will be raised. |
None
|
Returns:
Type | Description |
---|---|
List[str]
|
Tags for the given output. |
Source code in src/zenml/steps/step_context.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
remove_output_tags(tags: List[str], output_name: Optional[str] = None) -> None
Removes tags for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tags
|
List[str]
|
The tags to remove. |
required |
output_name
|
Optional[str]
|
Optional name of the output for which to remove the tags. If no name is given and the step only has a single output, the tags of this output will be removed. If the step has multiple outputs, an exception will be raised. |
None
|
Source code in src/zenml/steps/step_context.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
Functions
get_step_context() -> StepContext
Get the context of the currently running step.
Returns:
Type | Description |
---|---|
StepContext
|
The context of the currently running step. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If no step is currently running. |
Source code in src/zenml/steps/step_context.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
step(_func: Optional[F] = None, *, name: Optional[str] = None, enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_artifact_visualization: Optional[bool] = None, enable_step_logs: Optional[bool] = None, experiment_tracker: Optional[str] = None, step_operator: Optional[str] = None, output_materializers: Optional[OutputMaterializersSpecification] = None, settings: Optional[Dict[str, SettingsOrDict]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None) -> Union[BaseStep, Callable[[F], BaseStep]]
step(_func: F) -> BaseStep
step(
*,
name: Optional[str] = None,
enable_cache: Optional[bool] = None,
enable_artifact_metadata: Optional[bool] = None,
enable_artifact_visualization: Optional[bool] = None,
enable_step_logs: Optional[bool] = None,
experiment_tracker: Optional[str] = None,
step_operator: Optional[str] = None,
output_materializers: Optional[
OutputMaterializersSpecification
] = None,
settings: Optional[Dict[str, SettingsOrDict]] = None,
extra: Optional[Dict[str, Any]] = None,
on_failure: Optional[HookSpecification] = None,
on_success: Optional[HookSpecification] = None,
model: Optional[Model] = None,
retry: Optional[StepRetryConfig] = None,
substitutions: Optional[Dict[str, str]] = None,
) -> Callable[[F], BaseStep]
Decorator to create a ZenML step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_func
|
Optional[F]
|
The decorated function. |
None
|
name
|
Optional[str]
|
The name of the step. If left empty, the name of the decorated function will be used as a fallback. |
None
|
enable_cache
|
Optional[bool]
|
Specify whether caching is enabled for this step. If no value is passed, caching is enabled by default. |
None
|
enable_artifact_metadata
|
Optional[bool]
|
Specify whether metadata is enabled for this step. If no value is passed, metadata is enabled by default. |
None
|
enable_artifact_visualization
|
Optional[bool]
|
Specify whether visualization is enabled for this step. If no value is passed, visualization is enabled by default. |
None
|
enable_step_logs
|
Optional[bool]
|
Specify whether step logs are enabled for this step. |
None
|
experiment_tracker
|
Optional[str]
|
The experiment tracker to use for this step. |
None
|
step_operator
|
Optional[str]
|
The step operator to use for this step. |
None
|
output_materializers
|
Optional[OutputMaterializersSpecification]
|
Output materializers for this step. If given as a dict, the keys must be a subset of the output names of this step. If a single value (type or string) is given, the materializer will be used for all outputs. |
None
|
settings
|
Optional[Dict[str, SettingsOrDict]]
|
Settings for this step. |
None
|
extra
|
Optional[Dict[str, Any]]
|
Extra configurations for this step. |
None
|
on_failure
|
Optional[HookSpecification]
|
Callback function in event of failure of the step. Can be a
function with a single argument of type |
None
|
on_success
|
Optional[HookSpecification]
|
Callback function in event of success of the step. Can be a
function with no arguments, or a source path to such a function
(e.g. |
None
|
model
|
Optional[Model]
|
configuration of the model in the Model Control Plane. |
None
|
retry
|
Optional[StepRetryConfig]
|
configuration of step retry in case of step failure. |
None
|
substitutions
|
Optional[Dict[str, str]]
|
Extra placeholders for the step name. |
None
|
Returns:
Source code in src/zenml/steps/step_decorator.py
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 |
|
Modules
base_step
Base Step for ZenML.
Classes
BaseStep(name: Optional[str] = None, enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_artifact_visualization: Optional[bool] = None, enable_step_logs: Optional[bool] = None, experiment_tracker: Optional[str] = None, step_operator: Optional[str] = None, parameters: Optional[Dict[str, Any]] = None, output_materializers: Optional[OutputMaterializersSpecification] = None, settings: Optional[Mapping[str, SettingsOrDict]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None)
Abstract base class for all ZenML steps.
Initializes a step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Optional[str]
|
The name of the step. |
None
|
enable_cache
|
Optional[bool]
|
If caching should be enabled for this step. |
None
|
enable_artifact_metadata
|
Optional[bool]
|
If artifact metadata should be enabled for this step. |
None
|
enable_artifact_visualization
|
Optional[bool]
|
If artifact visualization should be enabled for this step. |
None
|
enable_step_logs
|
Optional[bool]
|
Enable step logs for this step. |
None
|
experiment_tracker
|
Optional[str]
|
The experiment tracker to use for this step. |
None
|
step_operator
|
Optional[str]
|
The step operator to use for this step. |
None
|
parameters
|
Optional[Dict[str, Any]]
|
Function parameters for this step |
None
|
output_materializers
|
Optional[OutputMaterializersSpecification]
|
Output materializers for this step. If given as a dict, the keys must be a subset of the output names of this step. If a single value (type or string) is given, the materializer will be used for all outputs. |
None
|
settings
|
Optional[Mapping[str, SettingsOrDict]]
|
settings for this step. |
None
|
extra
|
Optional[Dict[str, Any]]
|
Extra configurations for this step. |
None
|
on_failure
|
Optional[HookSpecification]
|
Callback function in event of failure of the step. Can
be a function with a single argument of type |
None
|
on_success
|
Optional[HookSpecification]
|
Callback function in event of success of the step. Can
be a function with no arguments, or a source path to such a
function (e.g. |
None
|
model
|
Optional[Model]
|
configuration of the model version in the Model Control Plane. |
None
|
retry
|
Optional[StepRetryConfig]
|
Configuration for retrying the step in case of failure. |
None
|
substitutions
|
Optional[Dict[str, str]]
|
Extra placeholders to use in the name template. |
None
|
Source code in src/zenml/steps/base_step.py
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 |
|
caching_parameters: Dict[str, Any]
property
Caching parameters for this step.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary containing the caching parameters |
configuration: PartialStepConfiguration
property
The configuration of the step.
Returns:
Type | Description |
---|---|
PartialStepConfiguration
|
The configuration of the step. |
docstring: Optional[str]
property
The docstring of this step.
Returns:
Type | Description |
---|---|
Optional[str]
|
The docstring of this step. |
enable_cache: Optional[bool]
property
If caching is enabled for the step.
Returns:
Type | Description |
---|---|
Optional[bool]
|
If caching is enabled for the step. |
name: str
property
The name of the step.
Returns:
Type | Description |
---|---|
str
|
The name of the step. |
source_code: str
property
The source code of this step.
Returns:
Type | Description |
---|---|
str
|
The source code of this step. |
source_object: Any
property
The source object of this step.
Returns:
Type | Description |
---|---|
Any
|
The source object of this step. |
call_entrypoint(*args: Any, **kwargs: Any) -> Any
Calls the entrypoint function of the step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Entrypoint function arguments. |
()
|
**kwargs
|
Any
|
Entrypoint function keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The return value of the entrypoint function. |
Raises:
Type | Description |
---|---|
StepInterfaceError
|
If the arguments to the entrypoint function are invalid. |
Source code in src/zenml/steps/base_step.py
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 560 561 562 |
|
configure(enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_artifact_visualization: Optional[bool] = None, enable_step_logs: Optional[bool] = None, experiment_tracker: Optional[str] = None, step_operator: Optional[str] = None, parameters: Optional[Dict[str, Any]] = None, output_materializers: Optional[OutputMaterializersSpecification] = None, settings: Optional[Mapping[str, SettingsOrDict]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None, merge: bool = True) -> T
Configures the step.
Configuration merging example:
* merge==True
:
step.configure(extra={"key1": 1})
step.configure(extra={"key2": 2}, merge=True)
step.configuration.extra # {"key1": 1, "key2": 2}
* merge==False
:
step.configure(extra={"key1": 1})
step.configure(extra={"key2": 2}, merge=False)
step.configuration.extra # {"key2": 2}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enable_cache
|
Optional[bool]
|
If caching should be enabled for this step. |
None
|
enable_artifact_metadata
|
Optional[bool]
|
If artifact metadata should be enabled for this step. |
None
|
enable_artifact_visualization
|
Optional[bool]
|
If artifact visualization should be enabled for this step. |
None
|
enable_step_logs
|
Optional[bool]
|
If step logs should be enabled for this step. |
None
|
experiment_tracker
|
Optional[str]
|
The experiment tracker to use for this step. |
None
|
step_operator
|
Optional[str]
|
The step operator to use for this step. |
None
|
parameters
|
Optional[Dict[str, Any]]
|
Function parameters for this step |
None
|
output_materializers
|
Optional[OutputMaterializersSpecification]
|
Output materializers for this step. If given as a dict, the keys must be a subset of the output names of this step. If a single value (type or string) is given, the materializer will be used for all outputs. |
None
|
settings
|
Optional[Mapping[str, SettingsOrDict]]
|
settings for this step. |
None
|
extra
|
Optional[Dict[str, Any]]
|
Extra configurations for this step. |
None
|
on_failure
|
Optional[HookSpecification]
|
Callback function in event of failure of the step. Can
be a function with a single argument of type |
None
|
on_success
|
Optional[HookSpecification]
|
Callback function in event of success of the step. Can
be a function with no arguments, or a source path to such a
function (e.g. |
None
|
model
|
Optional[Model]
|
Model to use for this step. |
None
|
retry
|
Optional[StepRetryConfig]
|
Configuration for retrying the step in case of failure. |
None
|
substitutions
|
Optional[Dict[str, str]]
|
Extra placeholders to use in the name template. |
None
|
merge
|
bool
|
If |
True
|
Returns:
Type | Description |
---|---|
T
|
The step instance that this method was called on. |
Source code in src/zenml/steps/base_step.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
|
copy() -> BaseStep
Copies the step.
Returns:
Type | Description |
---|---|
BaseStep
|
The step copy. |
Source code in src/zenml/steps/base_step.py
803 804 805 806 807 808 809 |
|
entrypoint(*args: Any, **kwargs: Any) -> Any
abstractmethod
Abstract method for core step logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Positional arguments passed to the step. |
()
|
**kwargs
|
Any
|
Keyword arguments passed to the step. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The output of the step. |
Source code in src/zenml/steps/base_step.py
214 215 216 217 218 219 220 221 222 223 224 |
|
load_from_source(source: Union[Source, str]) -> BaseStep
classmethod
Loads a step from source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Union[Source, str]
|
The path to the step source. |
required |
Returns:
Type | Description |
---|---|
BaseStep
|
The loaded step. |
Raises:
Type | Description |
---|---|
ValueError
|
If the source is not a valid step source. |
Source code in src/zenml/steps/base_step.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
resolve() -> Source
Resolves the step.
Returns:
Type | Description |
---|---|
Source
|
The step source. |
Source code in src/zenml/steps/base_step.py
248 249 250 251 252 253 254 |
|
with_options(enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_artifact_visualization: Optional[bool] = None, enable_step_logs: Optional[bool] = None, experiment_tracker: Optional[str] = None, step_operator: Optional[str] = None, parameters: Optional[Dict[str, Any]] = None, output_materializers: Optional[OutputMaterializersSpecification] = None, settings: Optional[Mapping[str, SettingsOrDict]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None, merge: bool = True) -> BaseStep
Copies the step and applies the given configurations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enable_cache
|
Optional[bool]
|
If caching should be enabled for this step. |
None
|
enable_artifact_metadata
|
Optional[bool]
|
If artifact metadata should be enabled for this step. |
None
|
enable_artifact_visualization
|
Optional[bool]
|
If artifact visualization should be enabled for this step. |
None
|
enable_step_logs
|
Optional[bool]
|
If step logs should be enabled for this step. |
None
|
experiment_tracker
|
Optional[str]
|
The experiment tracker to use for this step. |
None
|
step_operator
|
Optional[str]
|
The step operator to use for this step. |
None
|
parameters
|
Optional[Dict[str, Any]]
|
Function parameters for this step |
None
|
output_materializers
|
Optional[OutputMaterializersSpecification]
|
Output materializers for this step. If given as a dict, the keys must be a subset of the output names of this step. If a single value (type or string) is given, the materializer will be used for all outputs. |
None
|
settings
|
Optional[Mapping[str, SettingsOrDict]]
|
settings for this step. |
None
|
extra
|
Optional[Dict[str, Any]]
|
Extra configurations for this step. |
None
|
on_failure
|
Optional[HookSpecification]
|
Callback function in event of failure of the step. Can
be a function with a single argument of type |
None
|
on_success
|
Optional[HookSpecification]
|
Callback function in event of success of the step. Can
be a function with no arguments, or a source path to such a
function (e.g. |
None
|
model
|
Optional[Model]
|
Model to use for this step. |
None
|
retry
|
Optional[StepRetryConfig]
|
Configuration for retrying the step in case of failure. |
None
|
substitutions
|
Optional[Dict[str, str]]
|
Extra placeholders for the step name. |
None
|
merge
|
bool
|
If |
True
|
Returns:
Type | Description |
---|---|
BaseStep
|
The copied step instance. |
Source code in src/zenml/steps/base_step.py
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
|
Functions
Modules
decorated_step
Internal BaseStep subclass used by the step decorator.
Classes
entrypoint_function_utils
Util functions for step and pipeline entrypoint functions.
Classes
EntrypointFunctionDefinition
Bases: NamedTuple
Class representing a step entrypoint function.
Attributes:
Name | Type | Description |
---|---|---|
inputs |
Dict[str, Parameter]
|
The entrypoint function inputs. |
outputs |
Dict[str, OutputSignature]
|
The entrypoint function outputs. This dictionary maps output names to output annotations. |
validate_input(key: str, value: Any) -> None
Validates an input to the step entrypoint function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The key for which the input was passed |
required |
value
|
Any
|
The input value. |
required |
Raises:
Type | Description |
---|---|
KeyError
|
If the function has no input for the given key. |
RuntimeError
|
If a parameter is passed for an input that is
annotated as an |
RuntimeError
|
If the input value is not valid for the type annotation provided for the function parameter. |
StepInterfaceError
|
If the input is a parameter and not JSON serializable. |
Source code in src/zenml/steps/entrypoint_function_utils.py
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 |
|
StepArtifact(invocation_id: str, output_name: str, annotation: Any, pipeline: Pipeline)
Class to represent step output artifacts.
Initialize a step artifact.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
invocation_id
|
str
|
The ID of the invocation that produces this artifact. |
required |
output_name
|
str
|
The name of the output that produces this artifact. |
required |
annotation
|
Any
|
The output type annotation. |
required |
pipeline
|
Pipeline
|
The pipeline which the invocation is part of. |
required |
Source code in src/zenml/steps/entrypoint_function_utils.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
Functions
validate_entrypoint_function(func: Callable[..., Any], reserved_arguments: Sequence[str] = ()) -> EntrypointFunctionDefinition
Validates a step entrypoint function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
The step entrypoint function to validate. |
required |
reserved_arguments
|
Sequence[str]
|
The reserved arguments for the entrypoint function. |
()
|
Raises:
Type | Description |
---|---|
StepInterfaceError
|
If the entrypoint function has variable arguments or keyword arguments. |
RuntimeError
|
If type annotations should be enforced and a type annotation is missing. |
Returns:
Type | Description |
---|---|
EntrypointFunctionDefinition
|
A validated definition of the entrypoint function. |
Source code in src/zenml/steps/entrypoint_function_utils.py
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 |
|
validate_reserved_arguments(signature: inspect.Signature, reserved_arguments: Sequence[str]) -> None
Validates that the signature does not contain any reserved arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signature
|
Signature
|
The signature to validate. |
required |
reserved_arguments
|
Sequence[str]
|
The reserved arguments for the signature. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the signature contains a reserved argument. |
Source code in src/zenml/steps/entrypoint_function_utils.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
Modules
step_context
Step context class.
Classes
StepContext(pipeline_run: PipelineRunResponse, step_run: StepRunResponse, output_materializers: Mapping[str, Sequence[Type[BaseMaterializer]]], output_artifact_uris: Mapping[str, str], output_artifact_configs: Mapping[str, Optional[ArtifactConfig]])
Provides additional context inside a step function.
This singleton class is used to access information about the current run, step run, or its outputs inside a step function.
Usage example:
from zenml.steps import get_step_context
@step
def my_trainer_step() -> Any:
context = get_step_context()
# get info about the current pipeline run
current_pipeline_run = context.pipeline_run
# get info about the current step run
current_step_run = context.step_run
# get info about the future output artifacts of this step
output_artifact_uri = context.get_output_artifact_uri()
...
Initialize the context of the currently running step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pipeline_run
|
PipelineRunResponse
|
The model of the current pipeline run. |
required |
step_run
|
StepRunResponse
|
The model of the current step run. |
required |
output_materializers
|
Mapping[str, Sequence[Type[BaseMaterializer]]]
|
The output materializers of the step that this context is used in. |
required |
output_artifact_uris
|
Mapping[str, str]
|
The output artifacts of the step that this context is used in. |
required |
output_artifact_configs
|
Mapping[str, Optional[ArtifactConfig]]
|
The outputs' ArtifactConfigs of the step that this context is used in. |
required |
Raises:
Type | Description |
---|---|
StepContextError
|
If the keys of the output materializers and output artifacts do not match. |
Source code in src/zenml/steps/step_context.py
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 |
|
inputs: Dict[str, StepRunInputResponse]
property
Returns the input artifacts of the current step.
Returns:
Type | Description |
---|---|
Dict[str, StepRunInputResponse]
|
The input artifacts of the current step. |
model: Model
property
Returns configured Model.
Order of resolution to search for Model is
- Model from the step context
- Model from the pipeline context
Returns:
Type | Description |
---|---|
Model
|
The |
Raises:
Type | Description |
---|---|
StepContextError
|
If no |
pipeline: PipelineResponse
property
Returns the current pipeline.
Returns:
Type | Description |
---|---|
PipelineResponse
|
The current pipeline or None. |
Raises:
Type | Description |
---|---|
StepContextError
|
If the pipeline run does not have a pipeline. |
add_output_metadata(metadata: Dict[str, MetadataType], output_name: Optional[str] = None) -> None
Adds metadata for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
Dict[str, MetadataType]
|
The metadata to add. |
required |
output_name
|
Optional[str]
|
Optional name of the output for which to add the metadata. If no name is given and the step only has a single output, the metadata of this output will be added. If the step has multiple outputs, an exception will be raised. |
None
|
Source code in src/zenml/steps/step_context.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
add_output_tags(tags: List[str], output_name: Optional[str] = None) -> None
Adds tags for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tags
|
List[str]
|
The tags to add. |
required |
output_name
|
Optional[str]
|
Optional name of the output for which to add the tags. If no name is given and the step only has a single output, the tags of this output will be added. If the step has multiple outputs, an exception will be raised. |
None
|
Source code in src/zenml/steps/step_context.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
get_output_artifact_uri(output_name: Optional[str] = None) -> str
Returns the artifact URI for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_name
|
Optional[str]
|
Optional name of the output for which to get the URI. If no name is given and the step only has a single output, the URI of this output will be returned. If the step has multiple outputs, an exception will be raised. |
None
|
Returns:
Type | Description |
---|---|
str
|
Artifact URI for the given output. |
Source code in src/zenml/steps/step_context.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
get_output_materializer(output_name: Optional[str] = None, custom_materializer_class: Optional[Type[BaseMaterializer]] = None, data_type: Optional[Type[Any]] = None) -> BaseMaterializer
Returns a materializer for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_name
|
Optional[str]
|
Optional name of the output for which to get the materializer. If no name is given and the step only has a single output, the materializer of this output will be returned. If the step has multiple outputs, an exception will be raised. |
None
|
custom_materializer_class
|
Optional[Type[BaseMaterializer]]
|
If given, this |
None
|
data_type
|
Optional[Type[Any]]
|
If the output annotation is of type |
None
|
Returns:
Type | Description |
---|---|
BaseMaterializer
|
A materializer initialized with the output artifact for |
BaseMaterializer
|
the given output. |
Source code in src/zenml/steps/step_context.py
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 |
|
get_output_metadata(output_name: Optional[str] = None) -> Dict[str, MetadataType]
Returns the metadata for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_name
|
Optional[str]
|
Optional name of the output for which to get the metadata. If no name is given and the step only has a single output, the metadata of this output will be returned. If the step has multiple outputs, an exception will be raised. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
Metadata for the given output. |
Source code in src/zenml/steps/step_context.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|
get_output_tags(output_name: Optional[str] = None) -> List[str]
Returns the tags for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_name
|
Optional[str]
|
Optional name of the output for which to get the metadata. If no name is given and the step only has a single output, the metadata of this output will be returned. If the step has multiple outputs, an exception will be raised. |
None
|
Returns:
Type | Description |
---|---|
List[str]
|
Tags for the given output. |
Source code in src/zenml/steps/step_context.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
remove_output_tags(tags: List[str], output_name: Optional[str] = None) -> None
Removes tags for a given step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tags
|
List[str]
|
The tags to remove. |
required |
output_name
|
Optional[str]
|
Optional name of the output for which to remove the tags. If no name is given and the step only has a single output, the tags of this output will be removed. If the step has multiple outputs, an exception will be raised. |
None
|
Source code in src/zenml/steps/step_context.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
StepContextOutput(materializer_classes: Sequence[Type[BaseMaterializer]], artifact_uri: str, artifact_config: Optional[ArtifactConfig])
Represents a step output in the step context.
Initialize the step output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
materializer_classes
|
Sequence[Type[BaseMaterializer]]
|
The materializer classes for the output. |
required |
artifact_uri
|
str
|
The artifact URI for the output. |
required |
artifact_config
|
Optional[ArtifactConfig]
|
The ArtifactConfig object of the output. |
required |
Source code in src/zenml/steps/step_context.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|
Functions
get_step_context() -> StepContext
Get the context of the currently running step.
Returns:
Type | Description |
---|---|
StepContext
|
The context of the currently running step. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If no step is currently running. |
Source code in src/zenml/steps/step_context.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
step_decorator
Step decorator function.
Classes
Functions
step(_func: Optional[F] = None, *, name: Optional[str] = None, enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_artifact_visualization: Optional[bool] = None, enable_step_logs: Optional[bool] = None, experiment_tracker: Optional[str] = None, step_operator: Optional[str] = None, output_materializers: Optional[OutputMaterializersSpecification] = None, settings: Optional[Dict[str, SettingsOrDict]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None) -> Union[BaseStep, Callable[[F], BaseStep]]
step(_func: F) -> BaseStep
step(
*,
name: Optional[str] = None,
enable_cache: Optional[bool] = None,
enable_artifact_metadata: Optional[bool] = None,
enable_artifact_visualization: Optional[bool] = None,
enable_step_logs: Optional[bool] = None,
experiment_tracker: Optional[str] = None,
step_operator: Optional[str] = None,
output_materializers: Optional[
OutputMaterializersSpecification
] = None,
settings: Optional[Dict[str, SettingsOrDict]] = None,
extra: Optional[Dict[str, Any]] = None,
on_failure: Optional[HookSpecification] = None,
on_success: Optional[HookSpecification] = None,
model: Optional[Model] = None,
retry: Optional[StepRetryConfig] = None,
substitutions: Optional[Dict[str, str]] = None,
) -> Callable[[F], BaseStep]
Decorator to create a ZenML step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_func
|
Optional[F]
|
The decorated function. |
None
|
name
|
Optional[str]
|
The name of the step. If left empty, the name of the decorated function will be used as a fallback. |
None
|
enable_cache
|
Optional[bool]
|
Specify whether caching is enabled for this step. If no value is passed, caching is enabled by default. |
None
|
enable_artifact_metadata
|
Optional[bool]
|
Specify whether metadata is enabled for this step. If no value is passed, metadata is enabled by default. |
None
|
enable_artifact_visualization
|
Optional[bool]
|
Specify whether visualization is enabled for this step. If no value is passed, visualization is enabled by default. |
None
|
enable_step_logs
|
Optional[bool]
|
Specify whether step logs are enabled for this step. |
None
|
experiment_tracker
|
Optional[str]
|
The experiment tracker to use for this step. |
None
|
step_operator
|
Optional[str]
|
The step operator to use for this step. |
None
|
output_materializers
|
Optional[OutputMaterializersSpecification]
|
Output materializers for this step. If given as a dict, the keys must be a subset of the output names of this step. If a single value (type or string) is given, the materializer will be used for all outputs. |
None
|
settings
|
Optional[Dict[str, SettingsOrDict]]
|
Settings for this step. |
None
|
extra
|
Optional[Dict[str, Any]]
|
Extra configurations for this step. |
None
|
on_failure
|
Optional[HookSpecification]
|
Callback function in event of failure of the step. Can be a
function with a single argument of type |
None
|
on_success
|
Optional[HookSpecification]
|
Callback function in event of success of the step. Can be a
function with no arguments, or a source path to such a function
(e.g. |
None
|
model
|
Optional[Model]
|
configuration of the model in the Model Control Plane. |
None
|
retry
|
Optional[StepRetryConfig]
|
configuration of step retry in case of step failure. |
None
|
substitutions
|
Optional[Dict[str, str]]
|
Extra placeholders for the step name. |
None
|
Returns:
Source code in src/zenml/steps/step_decorator.py
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 |
|
step_invocation
Step invocation class definition.
Classes
StepInvocation(id: str, step: BaseStep, input_artifacts: Dict[str, StepArtifact], external_artifacts: Dict[str, Union[ExternalArtifact, ArtifactVersionResponse]], model_artifacts_or_metadata: Dict[str, ModelVersionDataLazyLoader], client_lazy_loaders: Dict[str, ClientLazyLoader], parameters: Dict[str, Any], default_parameters: Dict[str, Any], upstream_steps: Set[str], pipeline: Pipeline)
Step invocation class.
Initialize a step invocation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The invocation ID. |
required |
step
|
BaseStep
|
The step that is represented by the invocation. |
required |
input_artifacts
|
Dict[str, StepArtifact]
|
The input artifacts for the invocation. |
required |
external_artifacts
|
Dict[str, Union[ExternalArtifact, ArtifactVersionResponse]]
|
The external artifacts for the invocation. |
required |
model_artifacts_or_metadata
|
Dict[str, ModelVersionDataLazyLoader]
|
The model artifacts or metadata for the invocation. |
required |
client_lazy_loaders
|
Dict[str, ClientLazyLoader]
|
The client lazy loaders for the invocation. |
required |
parameters
|
Dict[str, Any]
|
The parameters for the invocation. |
required |
default_parameters
|
Dict[str, Any]
|
The default parameters for the invocation. |
required |
upstream_steps
|
Set[str]
|
The upstream steps for the invocation. |
required |
pipeline
|
Pipeline
|
The parent pipeline of the invocation. |
required |
Source code in src/zenml/steps/step_invocation.py
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 |
|
finalize(parameters_to_ignore: Set[str]) -> StepConfiguration
Finalizes a step invocation.
It will validate the upstream steps and run final configurations on the step that is represented by the invocation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters_to_ignore
|
Set[str]
|
Set of parameters that should not be applied to the step instance. |
required |
Returns:
Type | Description |
---|---|
StepConfiguration
|
The finalized step configuration. |
Source code in src/zenml/steps/step_invocation.py
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 |
|
utils
Utility functions and classes to run ZenML steps.
Classes
OnlyNoneReturnsVisitor()
Bases: ReturnVisitor
Checks whether a function AST contains only None
returns.
Initializes a visitor instance.
Source code in src/zenml/steps/utils.py
321 322 323 324 |
|
visit_Return(node: ast.Return) -> None
Visit a return statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Return
|
The return statement to visit. |
required |
Source code in src/zenml/steps/utils.py
326 327 328 329 330 331 332 333 334 335 336 337 |
|
OutputSignature
Bases: BaseModel
The signature of an output artifact.
get_output_types() -> Tuple[Any, ...]
Get all output types that match the type annotation.
Returns:
Type | Description |
---|---|
Tuple[Any, ...]
|
All output types that match the type annotation. |
Source code in src/zenml/steps/utils.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
ReturnVisitor(ignore_nested_functions: bool = True)
Bases: NodeVisitor
AST visitor class that can be subclassed to visit function returns.
Initializes a return visitor instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ignore_nested_functions
|
bool
|
If |
True
|
Source code in src/zenml/steps/utils.py
288 289 290 291 292 293 294 295 296 |
|
TupleReturnVisitor()
Bases: ReturnVisitor
Checks whether a function AST contains tuple returns.
Initializes a visitor instance.
Source code in src/zenml/steps/utils.py
343 344 345 346 |
|
visit_Return(node: ast.Return) -> None
Visit a return statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Return
|
The return statement to visit. |
required |
Source code in src/zenml/steps/utils.py
348 349 350 351 352 353 354 355 |
|
Functions
get_args(obj: Any) -> Tuple[Any, ...]
Get arguments of a type annotation.
Example
get_args(Union[int, str]) == (int, str)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The annotation. |
required |
Returns:
Type | Description |
---|---|
Tuple[Any, ...]
|
The args of the annotation. |
Source code in src/zenml/steps/utils.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
get_artifact_config_from_annotation_metadata(annotation: Any) -> Optional[ArtifactConfig]
Get the artifact config from the annotation metadata of a step output.
Example:
get_output_name_from_annotation_metadata(int) # None
get_output_name_from_annotation_metadata(Annotated[int, "name"] # ArtifactConfig(name="name")
get_output_name_from_annotation_metadata(Annotated[int, ArtifactConfig(name="name", model_name="foo")] # ArtifactConfig(name="name", model_name="foo")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation
|
Any
|
The type annotation. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the annotation is not following the expected format or if the name was specified multiple times or is an empty string. |
Returns:
Type | Description |
---|---|
Optional[ArtifactConfig]
|
The artifact config. |
Source code in src/zenml/steps/utils.py
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 |
|
has_only_none_returns(func: Callable[..., Any]) -> bool
Checks whether a function contains only None
returns.
A None
return could be either an explicit return None
or an empty
return
statement.
Example:
def f1():
return None
def f2():
return
def f3(condition):
if condition:
return None
else:
return 1
has_only_none_returns(f1) # True
has_only_none_returns(f2) # True
has_only_none_returns(f3) # False
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
The function to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the function contains only |
Source code in src/zenml/steps/utils.py
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 |
|
has_tuple_return(func: Callable[..., Any]) -> bool
Checks whether a function returns multiple values.
Multiple values means that the return
statement is followed by a tuple
(with or without brackets).
Example:
def f1():
return 1, 2
def f2():
return (1, 2)
def f3():
var = (1, 2)
return var
has_tuple_return(f1) # True
has_tuple_return(f2) # True
has_tuple_return(f3) # False
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
The function to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the function returns multiple values. |
Source code in src/zenml/steps/utils.py
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 |
|
log_step_metadata(metadata: Dict[str, MetadataType], step_name: Optional[str] = None, pipeline_name_id_or_prefix: Optional[Union[str, UUID]] = None, run_id: Optional[str] = None) -> None
Logs step metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
Dict[str, MetadataType]
|
The metadata to log. |
required |
step_name
|
Optional[str]
|
The name of the step to log metadata for. Can be omitted when being called inside a step. |
None
|
pipeline_name_id_or_prefix
|
Optional[Union[str, UUID]]
|
The name of the pipeline to log metadata for. Can be omitted when being called inside a step. |
None
|
run_id
|
Optional[str]
|
The ID of the run to log metadata for. Can be omitted when being called inside a step. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If no step name is provided and the function is not called from within a step or if no pipeline name or ID is provided and the function is not called from within a step. |
Source code in src/zenml/steps/utils.py
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 |
|
parse_return_type_annotations(func: Callable[..., Any], enforce_type_annotations: bool = False) -> Dict[str, OutputSignature]
Parse the return type annotation of a step function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
The step function. |
required |
enforce_type_annotations
|
bool
|
If |
False
|
Raises:
Type | Description |
---|---|
RuntimeError
|
If the output annotation has variable length or contains duplicate output names. |
RuntimeError
|
If type annotations should be enforced and a type annotation is missing. |
Returns:
Type | Description |
---|---|
Dict[str, OutputSignature]
|
|
Source code in src/zenml/steps/utils.py
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 |
|
resolve_type_annotation(obj: Any) -> Any
Returns the non-generic class for generic aliases of the typing module.
Example: if the input object is typing.Dict
, this method will return the
concrete class dict
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to resolve. |
required |
Returns:
Type | Description |
---|---|
Any
|
The non-generic class for generic aliases of the typing module. |
Source code in src/zenml/steps/utils.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
run_as_single_step_pipeline(__step: BaseStep, *args: Any, **kwargs: Any) -> Any
Runs the step as a single step pipeline.
- All inputs that are not JSON serializable will be uploaded to the artifact store before the pipeline is being executed.
- All output artifacts of the step will be loaded using the materializer that was used to store them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Entrypoint function arguments. |
()
|
**kwargs
|
Any
|
Entrypoint function keyword arguments. |
{}
|
Raises:
Type | Description |
---|---|
RuntimeError
|
If the step execution failed. |
StepInterfaceError
|
If the arguments to the entrypoint function are invalid. |
Returns:
Type | Description |
---|---|
Any
|
The output of the step entrypoint function. |
Source code in src/zenml/steps/utils.py
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 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
|