diff --git a/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py b/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py index f74646ee022..99c79bbfe0a 100644 --- a/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py +++ b/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py @@ -268,6 +268,7 @@ def list_experiments(self, namespace=None): async_req=True) katibexp = None + result = [] try: katibexp = thread.get(constants.APISERVER_TIMEOUT) result = [ @@ -339,17 +340,20 @@ def list_trials(self, name=None, namespace=None): async_req=True) katibtrial = None + result = [] try: katibtrial = thread.get(constants.APISERVER_TIMEOUT) - result = [ - self.api_client.deserialize(utils.FakeResponse(item), V1beta1Trial) - for item in katibtrial.get("items") - ] + + for item in katibtrial.get("items"): + if name is not None and item.get("metadata", {}).get("ownerReferences")[0].get("name") != name: + continue + + result.append(self.api_client.deserialize(utils.FakeResponse(item), V1beta1Trial)) except multiprocessing.TimeoutError: - raise RuntimeError("Timeout trying to getkatib experiment.") + raise RuntimeError("Timeout trying to get katib experiment.") except client.rest.ApiException as e: raise RuntimeError( - "Exception when calling CustomObjectsApi->get_namespaced_custom_object:\ + "Exception when calling CustomObjectsApi->list_namespaced_custom_object:\ %s\n" % e) except Exception as e: raise RuntimeError( @@ -378,32 +382,38 @@ def get_success_trial_details(self, name=None, namespace=None): async_req=True) katibtrial = None + result = [] try: katibtrial = thread.get(constants.APISERVER_TIMEOUT) - result = [] - for i in katibtrial.get("items"): + + for item in katibtrial.get("items"): + status = item.get("status", {}).get("conditions", [])[-1].get("type") + if status != "Succeeded": + continue + + if name is not None and item.get("metadata", {}).get("ownerReferences")[0].get("name") != name: + continue + 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) + output["name"] = item.get("metadata", {}).get("name") + output["hyperparameters"] = item.get("spec", {}).get("parameterAssignments", []) + output["metrics"] = ( + item.get("status", {}) + .get("observation", {}) + .get("metrics", []) + ) + result.append(output) except multiprocessing.TimeoutError: - raise RuntimeError("Timeout trying to getkatib experiment.") + raise RuntimeError("Timeout trying to get succeeded trials of the katib experiment.") except client.rest.ApiException as e: raise RuntimeError( - "Exception when calling CustomObjectsApi->get_namespaced_custom_object:\ + "Exception when calling CustomObjectsApi->list_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):