Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK/CLI] Add version param to run_pipeline #3339

Merged
merged 3 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion sdk/python/kfp/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def list_pipelines(self, page_token='', page_size=10, sort_by=''):
return self._pipelines_api.list_pipelines(page_token=page_token, page_size=page_size, sort_by=sort_by)

# TODO: provide default namespace, similar to kubectl default namespaces.
def run_pipeline(self, experiment_id, job_name, pipeline_package_path=None, params={}, pipeline_id=None, namespace=None):
def run_pipeline(self, experiment_id, job_name, pipeline_package_path=None, params={}, pipeline_id=None, namespace=None, version_id=None):
Copy link
Contributor

@jingzhang36 jingzhang36 Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment on this to indicate that if pipeline id and pipeline version are specified at the same time, pipeline id will prevail and we recommend them to use pipeline version approach? Thanks! (BTW, later on, I'll change backend code to make pipeline version takes priority over pipeline id if both specified though. And then I'll update the comment here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment about it but can you verify the wording to make sure it's accurate?

"""Run a specified pipeline.

Args:
Expand All @@ -313,6 +313,7 @@ def run_pipeline(self, experiment_id, job_name, pipeline_package_path=None, para
namespace: kubernetes namespace where the pipeline runs are created.
For single user deployment, leave it as None;
For multi user, input a namespace where the user is authorized
version_id: the string ID of a pipeline version

Returns:
A run object. Most important field is id.
Expand All @@ -339,6 +340,14 @@ def run_pipeline(self, experiment_id, job_name, pipeline_package_path=None, para
name=namespace,
relationship=kfp_server_api.models.ApiRelationship.OWNER)
resource_references.append(reference)

if version_id is not None:
key = kfp_server_api.models.ApiResourceKey(id=version_id,
type=kfp_server_api.models.ApiResourceType.PIPELINE_VERSION)
reference = kfp_server_api.models.ApiResourceReference(key=key,
relationship=kfp_server_api.models.ApiRelationship.OWNER)
resource_references.append(reference)

spec = kfp_server_api.models.ApiPipelineSpec(
pipeline_id=pipeline_id,
workflow_manifest=pipeline_json_string,
Expand Down
7 changes: 4 additions & 3 deletions sdk/python/kfp/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def list(ctx, experiment_id, max_size):
@click.option('-f', '--package-file', type=click.Path(exists=True, dir_okay=False), help='Path of the pipeline package file.')
@click.option('-p', '--pipeline-id', help='ID of the pipeline template.')
@click.option('-w', '--watch', is_flag=True, default=False, help='Watch the run status until it finishes.')
@click.option('-v', '--version', help='ID of the pipeline version.')
@click.argument('args', nargs=-1)
@click.pass_context
def submit(ctx, experiment_name, run_name, package_file, pipeline_id, watch, args):
def submit(ctx, experiment_name, run_name, package_file, pipeline_id, watch, version, args):
"""submit a KFP run"""
client = ctx.obj['client']
namespace = ctx.obj['namespace']
Expand All @@ -61,7 +62,7 @@ def submit(ctx, experiment_name, run_name, package_file, pipeline_id, watch, arg

arg_dict = dict(arg.split('=') for arg in args)
experiment = client.create_experiment(experiment_name)
run = client.run_pipeline(experiment.id, run_name, package_file, arg_dict, pipeline_id)
run = client.run_pipeline(experiment.id, run_name, package_file, arg_dict, pipeline_id, version_id=version)
print('Run {} is submitted'.format(run.id))
_display_run(client, namespace, run.id, watch)

Expand Down Expand Up @@ -100,4 +101,4 @@ def _display_run(client, namespace, run_id, watch):
def _print_runs(runs):
headers = ['run id', 'name', 'status', 'created at']
data = [[run.id, run.name, run.status, run.created_at.isoformat()] for run in runs]
print(tabulate(data, headers=headers, tablefmt='grid'))
print(tabulate(data, headers=headers, tablefmt='grid'))