Skip to content

Commit

Permalink
Enhance katib client by adding get_success_trial_details() (#1442)
Browse files Browse the repository at this point in the history
* Add katibClient method to get success trials

* Remove comment

* Replace hyperparams with hyperparameters

* Add status success check
  • Loading branch information
Adarsh2910 committed Feb 23, 2021
1 parent 804bed4 commit fe64c18
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions sdk/python/v1beta1/kubeflow/katib/api/katib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,52 @@ def list_trials(self, name=None, namespace=None):
{2} ".format(name, namespace, e))
return result

def get_success_trial_details(self, name=None, namespace=None):
"""
Get trial details that succeeded for an experiment
:param name: existing experiment name
:param namespace: defaults to current or default namespace
:return: trials name with hyperparameters and metrics
"""
if namespace is None:
namespace = utils.get_default_target_namespace()

thread = self.api_instance.list_namespaced_custom_object(
constants.KUBEFLOW_GROUP,
constants.KATIB_VERSION,
namespace=namespace,
plural=constants.TRIAL_PLURAL,
async_req=True)

katibtrial = None
try:
katibtrial = thread.get(constants.APISERVER_TIMEOUT)
result = []
for i in katibtrial.get("items"):
output = {}
if i.get("metadata", {}).get("ownerReferences")[0].get("name") == name:
status = i.get("status", {}).get("conditions", [])[-1].get("type")
if status == "Succeeded":
output["name"] = i.get("metadata", {}).get("name")
output["hyperparameters"] = i.get("spec", {}).get("parameterAssignments", [])
output["metrics"] = (
i.get("status", {})
.get("observation", {})
.get("metrics", [])
)
result.append(output)
except multiprocessing.TimeoutError:
raise RuntimeError("Timeout trying to getkatib experiment.")
except client.rest.ApiException as e:
raise RuntimeError(
"Exception when calling CustomObjectsApi->get_namespaced_custom_object:\
%s\n" % e)
except Exception as e:
raise RuntimeError(
"There was a problem to get experiment {0} in namespace {1}. Exception: \
{2} ".format(name, namespace, e))
return result

def get_optimal_hyperparameters(self, name=None, namespace=None):
"""
Get status, currentOptimalTrial with parameterAssignments
Expand Down

0 comments on commit fe64c18

Please sign in to comment.