From 582b6cd5915e1251ce6dc34431c83c361f67a559 Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Wed, 28 Aug 2019 15:54:27 -0700 Subject: [PATCH] Renamed InputArtifactArgument to InputArgumentPath Also renamed input_artifact_arguments to artifact_argument_paths in the ContainerOp's constructor --- sdk/python/kfp/dsl/__init__.py | 2 +- sdk/python/kfp/dsl/_container_op.py | 13 +++++++------ .../compiler/testdata/input_artifact_raw_value.py | 10 +++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sdk/python/kfp/dsl/__init__.py b/sdk/python/kfp/dsl/__init__.py index 8baede3ad6ff..fb12902583aa 100644 --- a/sdk/python/kfp/dsl/__init__.py +++ b/sdk/python/kfp/dsl/__init__.py @@ -15,7 +15,7 @@ from ._pipeline_param import PipelineParam, match_serialized_pipelineparam from ._pipeline import Pipeline, pipeline, get_pipeline_conf -from ._container_op import ContainerOp, InputArtifactArgument, UserContainer, Sidecar +from ._container_op import ContainerOp, InputArgumentPath, UserContainer, Sidecar from ._resource_op import ResourceOp from ._volume_op import ( VolumeOp, VOLUME_MODE_RWO, VOLUME_MODE_RWM, VOLUME_MODE_ROM diff --git a/sdk/python/kfp/dsl/_container_op.py b/sdk/python/kfp/dsl/_container_op.py index 5415a8432ec0..6215c817f8fa 100644 --- a/sdk/python/kfp/dsl/_container_op.py +++ b/sdk/python/kfp/dsl/_container_op.py @@ -903,7 +903,7 @@ def __repr__(self): from ._pipeline_volume import PipelineVolume # The import is here to prevent circular reference problems. -class InputArtifactArgument: +class InputArgumentPath: def __init__(self, argument, input=None, path=None): self.argument = argument self.input = input @@ -968,7 +968,7 @@ def __init__( init_containers: List[UserContainer] = None, sidecars: List[Sidecar] = None, container_kwargs: Dict = None, - input_artifact_arguments : List[InputArtifactArgument] = None, + artifact_argument_paths : List[InputArgumentPath] = None, file_outputs: Dict[str, str] = None, output_artifact_paths : Dict[str, str]=None, artifact_location: V1alpha1ArtifactLocation=None, @@ -992,9 +992,10 @@ def __init__( together with the `main` container. container_kwargs: the dict of additional keyword arguments to pass to the op's `Container` definition. - input_artifact_arguments: Maps artifact inputs to the artifact argument values and paths. - Only artifact argument value is required. + artifact_argument_paths: Optional. Maps input artifact arguments (values or references) to the local file paths where they'll be placed. At pipeline run time, the value of the artifact argument is saved to a local file with specified path. + This parameter is only needed when the input file paths are hard-coded in the program. + Otherwise it's better to pass input artifact placement paths by including artifact arguments in the command-line using the InputArgumentPath class instances. file_outputs: Maps output labels to local file paths. At pipeline run time, the value of a PipelineParam is saved to its corresponding local file. It's one way for outside world to receive outputs of the container. @@ -1019,7 +1020,7 @@ def __init__( def resolve_artifact_argument(artarg): from ..components._components import _generate_input_file_name - if not isinstance(artarg, InputArtifactArgument): + if not isinstance(artarg, InputArgumentPath): return artarg input_name = getattr(artarg.input, 'name', artarg.input) or ('input-' + str(len(artifact_arguments))) input_path = artarg.path or _generate_input_file_name(input_name) @@ -1030,7 +1031,7 @@ def resolve_artifact_argument(artarg): artifact_arguments[input_name] = artarg.argument return input_path - for artarg in input_artifact_arguments or []: + for artarg in artifact_argument_paths or []: resolve_artifact_argument(artarg) if isinstance(command, Sequence) and not isinstance(command, str): diff --git a/sdk/python/tests/compiler/testdata/input_artifact_raw_value.py b/sdk/python/tests/compiler/testdata/input_artifact_raw_value.py index 8111f6f09e03..b57d3e8253e4 100644 --- a/sdk/python/tests/compiler/testdata/input_artifact_raw_value.py +++ b/sdk/python/tests/compiler/testdata/input_artifact_raw_value.py @@ -27,7 +27,7 @@ def component_with_inline_input_artifact(text: str): return dsl.ContainerOp( name='component_with_inline_input_artifact', image='alpine', - command=['cat', dsl.InputArtifactArgument(text, path='/tmp/inputs/text/data', input='text')], # path and input are optional + command=['cat', dsl.InputArgumentPath(str(text), path='/tmp/inputs/text/data', input='text')], # path and input are optional ) @@ -36,8 +36,8 @@ def component_with_input_artifact(text): return dsl.ContainerOp( name='component_with_input_artifact', - input_artifact_arguments=[ - dsl.InputArtifactArgument(argument=text, path='/tmp/inputs/text/data', input='text'), # path and input are optional + artifact_argument_paths=[ + dsl.InputArgumentPath(argument=str(text), path='/tmp/inputs/text/data', input='text'), # path and input are optional ], image='alpine', command=['cat', '/tmp/inputs/text/data'], @@ -57,7 +57,7 @@ def component_with_input_artifact_value_from_file(file_path): name='Pipeline with artifact input raw argument value.', description='Pipeline shows how to define artifact inputs and pass raw artifacts to them.' ) -def retry_sample_pipeline(): +def input_artifact_pipeline(): component_with_inline_input_artifact('Constant artifact value') component_with_input_artifact('Constant artifact value') component_with_hardcoded_input_artifact_value() @@ -66,4 +66,4 @@ def retry_sample_pipeline(): component_with_input_artifact_value_from_file(file_path) if __name__ == '__main__': - kfp.compiler.Compiler().compile(retry_sample_pipeline, __file__ + '.yaml') + kfp.compiler.Compiler().compile(input_artifact_pipeline, __file__ + '.yaml')