forked from kubeflow/katib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nas.go
109 lines (95 loc) · 3.03 KB
/
nas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
Copyright 2022 The Kubeflow Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1beta1
import (
"context"
"encoding/json"
"log"
"net/http"
"strconv"
trialsv1beta1 "github.com/kubeflow/katib/pkg/apis/controller/trials/v1beta1"
api_pb_v1beta1 "github.com/kubeflow/katib/pkg/apis/manager/v1beta1"
)
func (k *KatibUIHandler) FetchNASJobInfo(w http.ResponseWriter, r *http.Request) {
//enableCors(&w)
experimentName := r.URL.Query()["experimentName"][0]
namespace := r.URL.Query()["namespace"][0]
responseRaw := make([]NNView, 0)
var architecture string
var decoder string
conn, c := k.connectManager()
defer conn.Close()
trials, err := k.katibClient.GetTrialList(experimentName, namespace)
if err != nil {
log.Printf("GetTrialList from NAS job failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
log.Printf("Got Trial List")
for i, t := range trials.Items {
succeeded := false
for _, condition := range t.Status.Conditions {
if condition.Type == trialsv1beta1.TrialSucceeded {
succeeded = true
}
}
if succeeded {
obsLogResp, err := c.GetObservationLog(
context.Background(),
&api_pb_v1beta1.GetObservationLogRequest{
TrialName: t.Name,
StartTime: "",
EndTime: "",
},
)
if err != nil {
log.Printf("GetObservationLog from NAS job failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
metricsName := make([]string, 0)
metricsValue := make([]string, 0)
for _, m := range obsLogResp.ObservationLog.MetricLogs {
metricsName = append(metricsName, m.Metric.Name)
metricsValue = append(metricsValue, m.Metric.Value)
}
for _, trialParam := range t.Spec.ParameterAssignments {
if trialParam.Name == "architecture" {
architecture = trialParam.Value
}
if trialParam.Name == "nn_config" {
decoder = trialParam.Value
}
}
responseRaw = append(responseRaw, NNView{
Name: "Generation " + strconv.Itoa(i),
TrialName: t.Name,
Architecture: generateNNImage(architecture, decoder),
MetricsName: metricsName,
MetricsValue: metricsValue,
})
}
}
log.Printf("Logs parsed, result: %v", responseRaw)
response, err := json.Marshal(responseRaw)
if err != nil {
log.Printf("Marshal result in NAS job failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if _, err = w.Write(response); err != nil {
log.Printf("Write result in NAS job failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}