Skip to content

Commit

Permalink
Create experiment only if it's not exist. (#892)
Browse files Browse the repository at this point in the history
* Create experiment only if it's not exist.

* Skip error if experiment is not found.

* Use try catch to bypass the not found error.
  • Loading branch information
hongye-sun authored and k8s-ci-robot committed Mar 2, 2019
1 parent b00081d commit f9cea6d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions sdk/python/kfp/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,25 @@ def create_experiment(self, name):
"""
import kfp_experiment

exp = kfp_experiment.models.ApiExperiment(name=name)
response = self._experiment_api.create_experiment(body=exp)
experiment = None
try:
experiment = self.get_experiment(experiment_name=name)
except:
# Ignore error if the experiment does not exist.
pass

if not experiment:
logging.info('Creating experiment {}.'.format(name))
experiment = kfp_experiment.models.ApiExperiment(name=name)
experiment = self._experiment_api.create_experiment(body=experiment)

if self._is_ipython():
import IPython
html = \
('Experiment link <a href="%s/#/experiments/details/%s" target="_blank" >here</a>'
% (self._get_url_prefix(), response.id))
% (self._get_url_prefix(), experiment.id))
IPython.display.display(IPython.display.HTML(html))
return response
return experiment

def list_experiments(self, page_token='', page_size=10, sort_by=''):
"""List experiments.
Expand Down

0 comments on commit f9cea6d

Please sign in to comment.