1515
1616import contextvars
1717import inspect
18- from concurrent .futures import Future , ThreadPoolExecutor
18+ from concurrent .futures import ThreadPoolExecutor
1919from typing import (
2020 TYPE_CHECKING ,
2121 Any ,
3434from zenml .client import Client
3535from zenml .config .compiler import Compiler
3636from zenml .config .step_configurations import Step
37+ from zenml .execution .pipeline .dynamic .outputs import (
38+ OutputArtifact ,
39+ StepRunOutputs ,
40+ StepRunOutputsFuture ,
41+ )
42+ from zenml .execution .pipeline .dynamic .run_context import (
43+ DynamicPipelineRunContext ,
44+ )
3745from zenml .execution .step .utils import launch_step
3846from zenml .logger import get_logger
3947from zenml .logging .step_logging import setup_pipeline_logging
4755 publish_successful_pipeline_run ,
4856)
4957from zenml .pipelines .dynamic .pipeline_definition import DynamicPipeline
50- from zenml .pipelines .dynamic .run_context import DynamicPipelineRunContext
5158from zenml .pipelines .run_utils import create_placeholder_run
5259from zenml .stack import Stack
5360from zenml .steps .entrypoint_function_utils import StepArtifact
6370logger = get_logger (__name__ )
6471
6572
66- class DynamicStepRunOutput (ArtifactVersionResponse ):
67- """Dynamic step run output artifact."""
68-
69- output_name : str
70- step_name : str
71-
72-
73- StepRunOutputs = Union [
74- None , DynamicStepRunOutput , Tuple [DynamicStepRunOutput , ...]
75- ]
76-
77-
78- # TODO: maybe one future per artifact? But for a step that doesn't return anything, the user wouldn't have a future to wait for.
79- # Or that step returns a future that returns None? Would be similar to a python function.
80- class StepRunOutputsFuture :
81- """Future for a step run output."""
82-
83- def __init__ (
84- self , wrapped : Future [StepRunOutputs ], invocation_id : str
85- ) -> None :
86- """Initialize the future.
87-
88- Args:
89- wrapped: The wrapped future object.
90- invocation_id: The invocation ID of the step run.
91- """
92- self ._wrapped = wrapped
93- self ._invocation_id = invocation_id
94-
95- def wait (self ) -> None :
96- """Wait for the future to complete."""
97- self ._wrapped .result ()
98-
99- def result (self ) -> StepRunOutputs :
100- """Get the step run output artifacts.
101-
102- Returns:
103- The step run output artifacts.
104- """
105- return self ._wrapped .result ()
106-
107- def load (self ) -> Any :
108- """Get the step run output artifact data.
109-
110- Raises:
111- ValueError: If the step run output is invalid.
112-
113- Returns:
114- The step run output artifact data.
115- """
116- result = self .result ()
117-
118- if result is None :
119- return None
120- elif isinstance (result , ArtifactVersionResponse ):
121- return result .load ()
122- elif isinstance (result , tuple ):
123- return tuple (item .load () for item in result )
124- else :
125- raise ValueError (f"Invalid step run output: { result } " )
126-
127-
12873class DynamicPipelineRunner :
12974 """Dynamic pipeline runner."""
13075
@@ -352,14 +297,14 @@ def _await_and_validate_input(input: Any) -> Any:
352297 if (
353298 input
354299 and isinstance (input , tuple )
355- and isinstance (input [0 ], DynamicStepRunOutput )
300+ and isinstance (input [0 ], OutputArtifact )
356301 ):
357302 raise ValueError (
358303 "Passing multiple step run outputs to another step is not "
359304 "allowed."
360305 )
361306
362- if isinstance (input , DynamicStepRunOutput ):
307+ if isinstance (input , OutputArtifact ):
363308 upstream_steps .add (input .step_name )
364309
365310 return input
@@ -383,7 +328,7 @@ def _await_and_validate_input(input: Any) -> Any:
383328 input_artifacts = {}
384329 external_artifacts = {}
385330 for name , value in validated_args .items ():
386- if isinstance (value , DynamicStepRunOutput ):
331+ if isinstance (value , OutputArtifact ):
387332 input_artifacts [name ] = StepArtifact (
388333 invocation_id = value .step_name ,
389334 output_name = value .output_name ,
@@ -434,8 +379,8 @@ def _load_step_run_outputs(step_run_id: UUID) -> StepRunOutputs:
434379
435380 def _convert_output_artifact (
436381 output_name : str , artifact : ArtifactVersionResponse
437- ) -> DynamicStepRunOutput :
438- return DynamicStepRunOutput (
382+ ) -> OutputArtifact :
383+ return OutputArtifact (
439384 output_name = output_name ,
440385 step_name = step_run .name ,
441386 ** artifact .model_dump (),
0 commit comments