Facing type error while building a simple tfx pipeline

Hey, ca someone pls help me through this ,

Facing the error as - TypeError: Expected type <class ‘int’> for parameter ‘num1’ but got OutputChannel(artifact_type=Integer, producer_component_id=Add, output_key=Sum, additional_properties={}, additional_custom_properties={}, _input_trigger=None instead

In the print statement inside the pipeline function it does give output as <class 'int >

Code -.>>>>> ( assume all library are installed )

Component

@component
def Add(num1:Parameter[int], num2:Parameter[int])-> tfx.v1.dsl.components.OutputDict(Sum=int):
Sum= num1 + num2

return {
‘Sum’:Sum
}

@component
def Multi(num1:Parameter[int], num2:Parameter[int])-> tfx.v1.dsl.components.OutputDict(Multi=int):
Multi= num1 + num2

return {
‘Multi’:Multi
}

@component
def Sub(num1:Parameter[int], num2:Parameter[int])-> tfx.v1.dsl.components.OutputDict(Sub=int):
Sub= num1 + num2

return {
‘Sub’:Sub
}

Main pipeline function

def my_arth_pipeline2(
number1:int,
number2:int,
number3:int,
number4:int,
):

pipeline_name = ‘add_numbers_pipeline’
pipeline_root = os.path.join(‘tfx_arth_pipeline_output’, pipeline_name)
metadata_path=os.path.join(‘metadata’, pipeline_name, ‘metadata.db’)

print(type(int(number1)))

creating the pipeline component

Addition=Add(num1=int(number1), num2=number2)
Multiplication=Multi(num1=Addition.outputs[‘Sum’], num2=number3)
Subtraction=Sub(num1=Multiplication.outputs[‘Multi’], num2=number4)

add_numbers_pipeline=pipeline.Pipeline(
pipeline_name=pipeline_name,
pipeline_root=pipeline_root,
metadata_path=metadata_path,
components=[Addition,Multiplication,Subtraction],
metadata_connection_config=tfx.orchestration.metadata.sqlite_metadata_connection_config(metadata_path),
data_path=data_path,
enable_cache=False
)

return add_numbers_pipeline

Main function

if name == ‘main’:
#logging.set_verbosity(logging.INFO)
number1 = 42
number2 = 20
number3 = 11
number4 = 23
LocalDagRunner().run(my_arth_pipeline2(number1 ,number2 ,number3 ,number4) )

What am I doing wrong .?

Hi @Aditya_Soni ,

You were encountering a TypeError because TFX wraps component outputs in OutputChannel objects, which are not directly compatible with the int type expected by your components.

You can follow this Gist for resolving this error you can structured your pipeline this way for results ,

Hope this Helps ,

Thank You .