Skip to content

Commit

Permalink
SDK - Persisting all output values
Browse files Browse the repository at this point in the history
Currently, the parameter output values are not saved to storage and their values are lost as soon as garbage collector removes the workflow object.
This change makes is so the parameter output values are persisted.
  • Loading branch information
Ark-kun committed Sep 17, 2019
1 parent 2ca7d0a commit c5b3c08
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sdk/python/kfp/compiler/_op_to_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def _op_to_template(op: BaseOp):
if isinstance(op, dsl.ContainerOp):
# default output artifacts
output_artifact_paths = OrderedDict(op.output_artifact_paths)
# This should have been as easy as output_artifact_paths.update(op.file_outputs), but the _outputs_to_json function changes the output names and we must do the same here, so that the names are the same
output_artifact_paths.update(sorted(((param.full_name, processed_op.file_outputs[param.name]) for param in processed_op.outputs.values()), key=lambda x: x[0]))

output_artifacts = [
K8sHelper.convert_k8s_obj_to_json(
Expand Down
9 changes: 8 additions & 1 deletion sdk/python/tests/compiler/compiler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def my_pipeline(msg1, json, kind, msg2='value2'):
]},
'name': 'echo',
'outputs': {
'artifacts': [
{
'name': 'echo-merged',
'path': '/tmp/message.txt',
},
],
'parameters': [
{'name': 'echo-merged',
'valueFrom': {'path': '/tmp/message.txt'}
Expand Down Expand Up @@ -571,7 +577,8 @@ def _test_op_to_template_yaml(self, ops, file_base_name):
compiled_template = compiler._op_to_template._op_to_template(ops)

del compiled_template['name'], expected['name']
del compiled_template['outputs']['parameters'][0]['name'], expected['outputs']['parameters'][0]['name']
for output in compiled_template['outputs'].get('parameters', []) + compiled_template['outputs'].get('artifacts', []) + expected['outputs'].get('parameters', []) + expected['outputs'].get('artifacts', []):
del output['name']
assert compiled_template == expected

def test_tolerations(self):
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/tests/compiler/testdata/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ spec:
- name: message
name: get-frequent
outputs:
artifacts:
- name: get-frequent-word
path: /tmp/message.txt
parameters:
- name: get-frequent-word
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/tests/compiler/testdata/basic_no_decorator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ spec:
- name: message
name: get-frequent
outputs:
artifacts:
- name: get-frequent-word
path: /tmp/message.txt
parameters:
- name: get-frequent-word
valueFrom:
Expand Down
6 changes: 6 additions & 0 deletions sdk/python/tests/compiler/testdata/coin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ spec:
image: python:alpine3.6
name: flip
outputs:
artifacts:
- name: flip-output
path: /tmp/output
parameters:
- name: flip-output
valueFrom:
Expand All @@ -105,6 +108,9 @@ spec:
image: python:alpine3.6
name: flip-again
outputs:
artifacts:
- name: flip-again-output
path: /tmp/output
parameters:
- name: flip-again-output
valueFrom:
Expand Down
6 changes: 6 additions & 0 deletions sdk/python/tests/compiler/testdata/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ spec:
- name: url
name: download
outputs:
artifacts:
- name: download-downloaded
path: /tmp/results.txt
parameters:
- name: download-downloaded
valueFrom:
Expand Down Expand Up @@ -85,6 +88,9 @@ spec:
- name: download-downloaded
name: get-frequent
outputs:
artifacts:
- name: get-frequent-word
path: /tmp/message.txt
parameters:
- name: get-frequent-word
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/tests/compiler/testdata/default_value.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ spec:
- name: url
name: download
outputs:
artifacts:
- name: download-downloaded
path: /tmp/results.txt
parameters:
- name: download-downloaded
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/tests/compiler/testdata/imagepullsecrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ spec:
- name: message
name: get-frequent
outputs:
artifacts:
- name: get-frequent-word
path: /tmp/message.txt
parameters:
- name: get-frequent-word
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/tests/compiler/testdata/pipelineparams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ spec:
- sh
- "-c"
outputs:
artifacts:
- name: download-downloaded
path: "/tmp/results.txt"
parameters:
- name: download-downloaded
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/tests/compiler/testdata/preemptible_tpu_gpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ spec:
nodeSelector:
cloud.google.com/gke-preemptible: 'true'
outputs:
artifacts:
- name: flip-output
path: /tmp/output
parameters:
- name: flip-output
valueFrom:
Expand Down
9 changes: 9 additions & 0 deletions sdk/python/tests/compiler/testdata/recursive_do_while.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ spec:
image: python:alpine3.6
name: flip
outputs:
artifacts:
- name: flip-output
path: /tmp/output
parameters:
- name: flip-output
valueFrom:
Expand All @@ -47,6 +50,9 @@ spec:
image: python:alpine3.6
name: flip-2
outputs:
artifacts:
- name: flip-2-output
path: /tmp/output
parameters:
- name: flip-2-output
valueFrom:
Expand All @@ -61,6 +67,9 @@ spec:
image: python:alpine3.6
name: flip-3
outputs:
artifacts:
- name: flip-3-output
path: /tmp/output
parameters:
- name: flip-3-output
valueFrom:
Expand Down
9 changes: 9 additions & 0 deletions sdk/python/tests/compiler/testdata/recursive_while.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ spec:
image: python:alpine3.6
name: flip
outputs:
artifacts:
- name: flip-output
path: /tmp/output
parameters:
- name: flip-output
valueFrom:
Expand All @@ -69,6 +72,9 @@ spec:
image: python:alpine3.6
name: flip-2
outputs:
artifacts:
- name: flip-2-output
path: /tmp/output
parameters:
- name: flip-2-output
valueFrom:
Expand All @@ -83,6 +89,9 @@ spec:
image: python:alpine3.6
name: flip-3
outputs:
artifacts:
- name: flip-3-output
path: /tmp/output
parameters:
- name: flip-3-output
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/tests/compiler/testdata/sidecar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ spec:
parameters: []
templates:
- outputs:
artifacts:
- name: download-downloaded
path: "/tmp/results.txt"
parameters:
- name: download-downloaded
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/tests/compiler/testdata/tolerations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ spec:
parameters: []
templates:
- outputs:
artifacts:
- name: download-downloaded
path: "/tmp/results.txt"
parameters:
- name: download-downloaded
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/tests/compiler/testdata/volume.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ spec:
name: gcp-credentials
name: download
outputs:
artifacts:
- name: download-downloaded
path: /tmp/results.txt
parameters:
- name: download-downloaded
valueFrom:
Expand Down

0 comments on commit c5b3c08

Please sign in to comment.