Skip to content

Commit

Permalink
Add the 'kfp experiment' commands (#3705)
Browse files Browse the repository at this point in the history
* Add the 'kfp experiment list' command

* Add the 'kfp experiment get' command

* Add the 'kfp experiment create' command

* Add the 'kfp experiment delete' command

* Add a caution to 'kfp experiment delete'

* Use directly the backend api method to list experiments

* Update a message based on the suggestion

#3705 (comment)
  • Loading branch information
shotarok committed May 20, 2020
1 parent f2a860b commit 291f5b3
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdk/python/kfp/cli/cli.py
Expand Up @@ -19,6 +19,7 @@
from .run import run
from .pipeline import pipeline
from .diagnose_me_cli import diagnose_me
from .experiment import experiment

@click.group()
@click.option('--endpoint', help='Endpoint of the KFP API service to connect.')
Expand All @@ -40,6 +41,7 @@ def main():
cli.add_command(run)
cli.add_command(pipeline)
cli.add_command(diagnose_me,'diagnose_me')
cli.add_command(experiment)
try:
cli(obj={}, auto_envvar_prefix='KFP')
except Exception as e:
Expand Down
96 changes: 96 additions & 0 deletions sdk/python/kfp/cli/experiment.py
@@ -0,0 +1,96 @@
import click
import logging
from tabulate import tabulate


@click.group()
def experiment():
"""Manage experiment resources"""
pass


@experiment.command()
@click.option(
'--description',
help="Description of the experiment."
)
@click.argument("name")
@click.pass_context
def create(ctx, description, name):
"""Create an experiment"""
client = ctx.obj["client"]

response = client.create_experiment(name, description=description)
logging.info("Experiment {} has been submitted\n".format(name))
_display_experiment(response)


@experiment.command()
@click.option(
'--max-size',
default=100,
help="Max size of the listed experiments."
)
@click.pass_context
def list(ctx, max_size):
"""List experiments"""
client = ctx.obj['client']

response = client.experiments.list_experiment(
page_size=max_size,
sort_by="created_at desc"
)
if response.experiments:
_display_experiments(response.experiments)
else:
logging.info("No experiments found")


@experiment.command()
@click.argument("experiment-id")
@click.pass_context
def get(ctx, experiment_id):
"""Get detailed information about an experiment"""
client = ctx.obj["client"]

response = client.get_experiment(experiment_id)
_display_experiment(response)


@experiment.command()
@click.argument("experiment-id")
@click.pass_context
def delete(ctx, experiment_id):
"""Delete an experiment"""

confirmation = "Caution. The RunDetails page could have an issue" \
" when it renders a run that has no experiment." \
" Do you want to continue?"
if not click.confirm(confirmation):
return

client = ctx.obj["client"]

client.experiments.delete_experiment(id=experiment_id)
print("{} is deleted.".format(experiment_id))


def _display_experiments(experiments):
headers = ["Experiment ID", "Name", "Created at"]
data = [[
exp.id,
exp.name,
exp.created_at.isoformat()
] for exp in experiments]
print(tabulate(data, headers=headers, tablefmt="grid"))


def _display_experiment(exp):
print(tabulate([], headers=["Experiment Details"]))
table = [
["ID", exp.id],
["Name", exp.name],
["Description", exp.description],
["Created at", exp.created_at.isoformat()],
]
print(tabulate(table, tablefmt="plain"))

0 comments on commit 291f5b3

Please sign in to comment.