-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add the 'kfp experiment' commands #3705
Merged
k8s-ci-robot
merged 9 commits into
kubeflow:master
from
shotarok:add-experiment-command
May 20, 2020
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
53f1882
Add the 'kfp experiment list' command
shotarok 53692f4
Add the 'kfp experiment get' command
shotarok a9ae5a6
Add the 'kfp experiment create' command
shotarok ab538d1
Add the 'kfp experiment delete' command
shotarok 9de466d
Add a caution to 'kfp experiment delete'
shotarok 5b16b1a
Use directly the backend api method to list experiments
shotarok 45affc3
Merge branch 'master' into add-experiment-command
shotarok e6b43f1
Update a message based on the suggestion
shotarok c91526b
Merge branch 'master' into add-experiment-command
shotarok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
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.list_experiments( | ||
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""" | ||
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")) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The client.list_experiments() method used here is actually a wrapper around our backend api method client.experimetns.list_experiment(). I personally prefer to use the backend api method directly, since the wrapper method client.list_experments() in _client.py might not get timely updates/maintenance as backend api method.
E.g., in your case, could you try if the following works?
client = ctx.obj['client']
client.experiments.list_experiment(page_size=max_size, sort_by='created_at desc')
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. That makes sense. I'll modify code to use the api methods directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed code in 5b16b1a.