Skip to content

Commit

Permalink
[hotfix]: filter by name of experiment (#1920)
Browse files Browse the repository at this point in the history
Signed-off-by: Jaeyeon Kim <anencore94@gmail.com>
  • Loading branch information
anencore94 authored Jul 30, 2022
1 parent 3b37d93 commit 42bc6a9
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions sdk/python/v1beta1/kubeflow/katib/api/katib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def list_experiments(self, namespace=None):
async_req=True)

katibexp = None
result = []
try:
katibexp = thread.get(constants.APISERVER_TIMEOUT)
result = [
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 42bc6a9

Please sign in to comment.