Entrypoints
zenml.entrypoints
Initializations for ZenML entrypoints module.
Attributes
__all__ = ['StepEntrypointConfiguration', 'PipelineEntrypointConfiguration']
module-attribute
Classes
PipelineEntrypointConfiguration(arguments: List[str])
Bases: BaseEntrypointConfiguration
Base class for entrypoint configurations that run an entire pipeline.
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
61 62 63 64 65 66 67 68 | |
Functions
run() -> None
Prepares the environment and runs the configured pipeline.
Source code in src/zenml/entrypoints/pipeline_entrypoint_configuration.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
StepEntrypointConfiguration(arguments: List[str])
Bases: BaseEntrypointConfiguration
Base class for entrypoint configurations that run a single step.
If an orchestrator needs to run steps in a separate process or environment (e.g. a docker container), this class can either be used directly or subclassed if custom behavior is necessary.
How to subclass:
Passing additional arguments to the entrypoint:
If you need to pass additional arguments to the entrypoint, there are
two methods that you need to implement:
* get_entrypoint_options(): This method should return all
the options that are required in the entrypoint. Make sure to
include the result from the superclass method so the options
are complete.
* `get_entrypoint_arguments(...)`: This method should return
a list of arguments that should be passed to the entrypoint.
Make sure to include the result from the superclass method so
the arguments are complete.
You'll be able to access the argument values from `self.entrypoint_args`
inside your `StepEntrypointConfiguration` subclass.
How to use:
After you created your StepEntrypointConfiguration subclass, you only
have to run the entrypoint somewhere. To do this, you should execute the
command returned by the get_entrypoint_command() method with the
arguments returned by the get_entrypoint_arguments(...) method.
Example:
class MyStepEntrypointConfiguration(StepEntrypointConfiguration):
...
class MyOrchestrator(BaseOrchestrator):
def submit_pipeline(
self,
snapshot: "PipelineSnapshotResponse",
stack: "Stack",
environment: Dict[str, str],
placeholder_run: Optional["PipelineRunResponse"] = None,
) -> Optional[SubmissionResult]:
...
cmd = MyStepEntrypointConfiguration.get_entrypoint_command()
for step_name, step in pipeline.steps.items():
...
args = MyStepEntrypointConfiguration.get_entrypoint_arguments(
step_name=step_name, snapshot_id=snapshot.id
)
# Run the command and pass it the arguments. Our example
# orchestrator here executes the entrypoint in a separate
# process, but in a real-world scenario you would probably run
# it inside a docker container or a different environment.
import subprocess
subprocess.check_call(cmd + args)
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
61 62 63 64 65 66 67 68 | |
Attributes
docker_settings: DockerSettings
property
The Docker settings configured for this entrypoint configuration.
Returns:
| Type | Description |
|---|---|
DockerSettings
|
The Docker settings. |
step: Step
property
Functions
get_entrypoint_arguments(**kwargs: Any) -> List[str]
classmethod
Gets all arguments that the entrypoint command should be called with.
The argument list should be something that
argparse.ArgumentParser.parse_args(...) can handle (e.g.
["--some_option", "some_value"] or ["--some_option=some_value"]).
It needs to provide values for all options returned by the
get_entrypoint_options() method of this class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Kwargs, must include the step name. |
{}
|
Returns:
| Type | Description |
|---|---|
List[str]
|
The superclass arguments as well as arguments for the name of the |
List[str]
|
step to run. |
Source code in src/zenml/entrypoints/step_entrypoint_configuration.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
get_entrypoint_options() -> Dict[str, bool]
classmethod
Gets all options required for running with this configuration.
Returns:
| Type | Description |
|---|---|
Dict[str, bool]
|
The superclass options as well as an option for the name of the |
Dict[str, bool]
|
step to run. |
Source code in src/zenml/entrypoints/step_entrypoint_configuration.py
118 119 120 121 122 123 124 125 126 | |
post_run(pipeline_name: str, step_name: str) -> None
Does cleanup or post-processing after the step finished running.
Subclasses should overwrite this method if they need to run any additional code after the step execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline_name
|
str
|
Name of the parent pipeline of the step that was executed. |
required |
step_name
|
str
|
Name of the step that was executed. |
required |
Source code in src/zenml/entrypoints/step_entrypoint_configuration.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
run() -> None
Prepares the environment and runs the configured step.
Source code in src/zenml/entrypoints/step_entrypoint_configuration.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
Modules
base_entrypoint_configuration
Abstract base class for entrypoint configurations.
Classes
BaseEntrypointConfiguration(arguments: List[str])
Bases: ABC
Abstract base class for entrypoint configurations.
An entrypoint configuration specifies the arguments that should be passed to the entrypoint and what is running inside the entrypoint.
Attributes:
| Name | Type | Description |
|---|---|---|
entrypoint_args |
The parsed arguments passed to the entrypoint. |
Initializes the entrypoint configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
List[str]
|
Command line arguments to configure this object. |
required |
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
61 62 63 64 65 66 67 68 | |
docker_settings: DockerSettings
property
The Docker settings configured for this entrypoint configuration.
Returns:
| Type | Description |
|---|---|
DockerSettings
|
The Docker settings. |
should_download_code: bool
property
Whether code should be downloaded.
Returns:
| Type | Description |
|---|---|
bool
|
Whether code should be downloaded. |
snapshot: PipelineSnapshotResponse
property
The snapshot configured for this entrypoint configuration.
Returns:
| Type | Description |
|---|---|
PipelineSnapshotResponse
|
The snapshot. |
download_code_from_code_repository(code_reference: CodeReferenceResponse) -> None
Download code from a code repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code_reference
|
CodeReferenceResponse
|
The reference to the code. |
required |
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
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 | |
download_code_if_necessary() -> None
Downloads user code if necessary.
Raises:
| Type | Description |
|---|---|
CustomFlavorImportError
|
If the artifact store flavor can't be imported. |
RuntimeError
|
If the current environment requires code download but the snapshot does not have a reference to any code. |
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
get_entrypoint_arguments(**kwargs: Any) -> List[str]
classmethod
Gets all arguments that the entrypoint command should be called with.
The argument list should be something that
argparse.ArgumentParser.parse_args(...) can handle (e.g.
["--some_option", "some_value"] or ["--some_option=some_value"]).
It needs to provide values for all options returned by the
get_entrypoint_options() method of this class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Keyword args. |
{}
|
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of strings with the arguments. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no valid snapshot ID is passed. |
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
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 | |
get_entrypoint_command() -> List[str]
classmethod
Returns a command that runs the entrypoint module.
This entrypoint module is responsible for running the entrypoint
configuration when called. Defaults to running the
zenml.entrypoints.entrypoint module.
Note: This command won't work on its own but needs to be called with
the arguments returned by the get_entrypoint_arguments(...)
method of this class.
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of strings with the command. |
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
get_entrypoint_options() -> Dict[str, bool]
classmethod
Gets all options required for running with this configuration.
Returns:
| Type | Description |
|---|---|
Dict[str, bool]
|
A dictionary of options and whether they are required. |
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
run() -> None
abstractmethod
Runs the entrypoint configuration.
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
341 342 343 | |
Functions
Modules
entrypoint
Functionality to run ZenML steps or pipelines.
Classes
Functions
main() -> None
Runs the entrypoint configuration given by the command line arguments.
Source code in src/zenml/entrypoints/entrypoint.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Modules
pipeline_entrypoint_configuration
Abstract base class for entrypoint configurations that run a pipeline.
Classes
PipelineEntrypointConfiguration(arguments: List[str])
Bases: BaseEntrypointConfiguration
Base class for entrypoint configurations that run an entire pipeline.
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
61 62 63 64 65 66 67 68 | |
run() -> None
Prepares the environment and runs the configured pipeline.
Source code in src/zenml/entrypoints/pipeline_entrypoint_configuration.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
step_entrypoint_configuration
Base class for entrypoint configurations that run a single step.
Classes
StepEntrypointConfiguration(arguments: List[str])
Bases: BaseEntrypointConfiguration
Base class for entrypoint configurations that run a single step.
If an orchestrator needs to run steps in a separate process or environment (e.g. a docker container), this class can either be used directly or subclassed if custom behavior is necessary.
How to subclass:
Passing additional arguments to the entrypoint:
If you need to pass additional arguments to the entrypoint, there are
two methods that you need to implement:
* get_entrypoint_options(): This method should return all
the options that are required in the entrypoint. Make sure to
include the result from the superclass method so the options
are complete.
* `get_entrypoint_arguments(...)`: This method should return
a list of arguments that should be passed to the entrypoint.
Make sure to include the result from the superclass method so
the arguments are complete.
You'll be able to access the argument values from `self.entrypoint_args`
inside your `StepEntrypointConfiguration` subclass.
How to use:
After you created your StepEntrypointConfiguration subclass, you only
have to run the entrypoint somewhere. To do this, you should execute the
command returned by the get_entrypoint_command() method with the
arguments returned by the get_entrypoint_arguments(...) method.
Example:
class MyStepEntrypointConfiguration(StepEntrypointConfiguration):
...
class MyOrchestrator(BaseOrchestrator):
def submit_pipeline(
self,
snapshot: "PipelineSnapshotResponse",
stack: "Stack",
environment: Dict[str, str],
placeholder_run: Optional["PipelineRunResponse"] = None,
) -> Optional[SubmissionResult]:
...
cmd = MyStepEntrypointConfiguration.get_entrypoint_command()
for step_name, step in pipeline.steps.items():
...
args = MyStepEntrypointConfiguration.get_entrypoint_arguments(
step_name=step_name, snapshot_id=snapshot.id
)
# Run the command and pass it the arguments. Our example
# orchestrator here executes the entrypoint in a separate
# process, but in a real-world scenario you would probably run
# it inside a docker container or a different environment.
import subprocess
subprocess.check_call(cmd + args)
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
61 62 63 64 65 66 67 68 | |
docker_settings: DockerSettings
property
The Docker settings configured for this entrypoint configuration.
Returns:
| Type | Description |
|---|---|
DockerSettings
|
The Docker settings. |
step: Step
property
get_entrypoint_arguments(**kwargs: Any) -> List[str]
classmethod
Gets all arguments that the entrypoint command should be called with.
The argument list should be something that
argparse.ArgumentParser.parse_args(...) can handle (e.g.
["--some_option", "some_value"] or ["--some_option=some_value"]).
It needs to provide values for all options returned by the
get_entrypoint_options() method of this class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Kwargs, must include the step name. |
{}
|
Returns:
| Type | Description |
|---|---|
List[str]
|
The superclass arguments as well as arguments for the name of the |
List[str]
|
step to run. |
Source code in src/zenml/entrypoints/step_entrypoint_configuration.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
get_entrypoint_options() -> Dict[str, bool]
classmethod
Gets all options required for running with this configuration.
Returns:
| Type | Description |
|---|---|
Dict[str, bool]
|
The superclass options as well as an option for the name of the |
Dict[str, bool]
|
step to run. |
Source code in src/zenml/entrypoints/step_entrypoint_configuration.py
118 119 120 121 122 123 124 125 126 | |
post_run(pipeline_name: str, step_name: str) -> None
Does cleanup or post-processing after the step finished running.
Subclasses should overwrite this method if they need to run any additional code after the step execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline_name
|
str
|
Name of the parent pipeline of the step that was executed. |
required |
step_name
|
str
|
Name of the step that was executed. |
required |
Source code in src/zenml/entrypoints/step_entrypoint_configuration.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
run() -> None
Prepares the environment and runs the configured step.
Source code in src/zenml/entrypoints/step_entrypoint_configuration.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |