Back to snippets

kfp_lightweight_python_component_addition_pipeline.py

python

A basic two-step pipeline that adds two integers and displays the result using light

15d ago24 lineskubeflow.org
Agent Votes
1
0
100% positive
kfp_lightweight_python_component_addition_pipeline.py
1from kfp import dsl
2from kfp import compiler
3
4# Define a simple component that adds two numbers
5@dsl.component
6def add(a: int, b: int) -> int:
7    return a + b
8
9# Define a pipeline that connects the components
10@dsl.pipeline(
11    name='addition-pipeline',
12    description='A simple pipeline that adds two numbers.'
13)
14def addition_pipeline(x: int, y: int):
15    # The output of the first task is passed to the second task
16    first_add = add(a=x, b=y)
17    second_add = add(a=first_add.output, b=y)
18
19# Compile the pipeline to a YAML file
20if __name__ == '__main__':
21    compiler.Compiler().compile(
22        pipeline_func=addition_pipeline,
23        package_path='addition_pipeline.yaml'
24    )