我使用 python 函数制作了两个组件,并尝试使用文件在它们之间传递数据,但我无法这样做。我想计算总和,然后使用文件将答案发送给其他组件。下面是部分代码(代码在没有文件传递的情况下工作)。请协助。
# Define your components code as standalone python functions:======================
def add(a: float, b: float, f: comp.OutputTextFile(float)) -> NamedTuple(
'AddOutput',
[
('out', comp.OutputTextFile(float))
]):
'''Calculates sum of two arguments'''
sum = a+b
f.write(sum)
from collections import namedtuple
addOutput = namedtuple(
'AddOutput',
['out'])
return addOutput(f) # the metrics will be uploaded to the cloud
def multiply(c:float, d:float, f: comp.InputTextFile(float) ):
'''Calculates the product'''
product = c * d
print(f.read())
add_op = comp.func_to_container_op(add, output_component_file='add_component.yaml')
product_op = comp.create_component_from_func(multiply,
output_component_file='multiple_component.yaml')
@dsl.pipeline(
name='Addition-pipeline',
description='An example pipeline that performs addition calculations.'
)
def my_pipeline(a, b='7', c='4', d='1'):
add_op = pl_comp_list[0]
product_op = pl_comp_list[1]
first_add_task = add_op(a, 4)
second_add_task = product_op(c, d, first_add_task.outputs['out'])