mirror of
https://github.com/clearml/clearml
synced 2025-06-26 18:16:07 +00:00
Add support for decorated pipeline steps (#1154)
This commit is contained in:
24
examples/pipeline/decorated_pipeline_step_decorators.py
Normal file
24
examples/pipeline/decorated_pipeline_step_decorators.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from clearml import PipelineDecorator
|
||||
|
||||
|
||||
def our_decorator(func):
|
||||
def function_wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs) + 1
|
||||
return function_wrapper
|
||||
|
||||
|
||||
@PipelineDecorator.component()
|
||||
@our_decorator
|
||||
def step():
|
||||
return 1
|
||||
|
||||
|
||||
@PipelineDecorator.pipeline(name="test_decorated", project="test_decorated")
|
||||
def pipeline():
|
||||
result = step()
|
||||
assert result == 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
PipelineDecorator.run_locally()
|
||||
pipeline()
|
||||
27
examples/pipeline/decorated_pipeline_step_functions.py
Normal file
27
examples/pipeline/decorated_pipeline_step_functions.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from clearml import PipelineController
|
||||
|
||||
|
||||
def our_decorator(func):
|
||||
def function_wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs) + 1
|
||||
return function_wrapper
|
||||
|
||||
|
||||
@our_decorator
|
||||
def step():
|
||||
return 1
|
||||
|
||||
|
||||
def evaluate(step_return):
|
||||
assert step_return == 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pipeline = PipelineController(name="test_decorated", project="test_decorated")
|
||||
pipeline.add_function_step(name="step", function=step, function_return=["step_return"])
|
||||
pipeline.add_function_step(
|
||||
name="evaluate",
|
||||
function=evaluate,
|
||||
function_kwargs=dict(step_return='${step.step_return}')
|
||||
)
|
||||
pipeline.start_locally(run_pipeline_steps_locally=True)
|
||||
Reference in New Issue
Block a user