Skip to content

Commit

Permalink
feedback: read metadata from labels and improve label query backend p…
Browse files Browse the repository at this point in the history
…erformance.
  • Loading branch information
a9p committed Jun 19, 2022
1 parent cc32156 commit 5ca9a97
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 74 deletions.
2 changes: 1 addition & 1 deletion cmd/new-ui/v1beta1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {

http.HandleFunc("/katib/fetch_hp_job_info/", kuh.FetchHPJobInfo)
http.HandleFunc("/katib/fetch_hp_job_trial_info/", kuh.FetchHPJobTrialInfo)
http.HandleFunc("/katib/fetch_hp_job_annotation_info/", kuh.FetchHPJobAnnotationInfo)
http.HandleFunc("/katib/fetch_hp_job_label_info/", kuh.FetchHPJobLabelInfo)
http.HandleFunc("/katib/fetch_nas_job_info/", kuh.FetchNASJobInfo)

http.HandleFunc("/katib/fetch_trial_templates/", kuh.FetchTrialTemplates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<mat-tab label="PBT">
<app-experiment-pbt-tab
[experiment]="experimentDetails"
[annotationsCsv]="annotationsCsv"
[labelCsv]="labelCsv"
[experimentTrialsCsv]="experimentTrialsCsv"
></app-experiment-pbt-tab>
</mat-tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ExperimentDetailsComponent implements OnInit, OnDestroy {
columns: string[] = [];
details: string[][] = [];
experimentTrialsCsv: string;
annotationsCsv: string;
labelCsv: string;
hoveredTrial: number;
experimentDetails: ExperimentK8s;
showGraph: boolean;
Expand Down Expand Up @@ -96,9 +96,9 @@ export class ExperimentDetailsComponent implements OnInit, OnDestroy {
this.showGraph = true;
});
this.backendService
.getExperimentAnnotationsInfo(this.name, this.namespace)
.getExperimentLabelInfo(this.name, this.namespace)
.subscribe(response => {
this.annotationsCsv = response;
this.labelCsv = response;
});
this.backendService
.getExperiment(this.name, this.namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@ import { ExperimentK8s } from '../../../models/experiment.k8s.model';
import { Inject } from '@angular/core';
import { DOCUMENT } from '@angular/common';

import { StatusEnum } from 'src/app/enumerations/status.enum';

declare let d3: any;

type PbtPoint = {
uid: string;
parentUid: string;
trialName: string;
parentUid: string;
parameters: Object; // all y-axis possible values (parameters + alternativeMetrics)
generation: number; // generation
metricValue: number; // evaluation metric
};

type PbtAnnotation = {
uid: string;
parentUid: string;
generation: number;
trialName: string;
};

@Component({
selector: 'app-experiment-pbt-tab',
templateUrl: './pbt-tab.component.html',
Expand All @@ -48,8 +42,8 @@ export class PbtTabComponent implements OnChanges, OnInit, AfterViewInit {
selectedName: string; // user selected parameter/metric
displayTrace: boolean;

private annotData: { [uid: string]: PbtAnnotation } = {};
private trialData = {}; // primary key: trialName
private labelData: { [trialName: string]: PbtPoint } = {};
private trialData: { [trialName: string]: Object } = {};
private parameterNames: string[]; // parameter names
private goalName: string = '';
private data: PbtPoint[][] = []; // data sorted by generation and segment
Expand All @@ -59,7 +53,7 @@ export class PbtTabComponent implements OnChanges, OnInit, AfterViewInit {
experiment: ExperimentK8s;

@Input()
annotationsCsv: string[] = [];
labelCsv: string[] = [];

@Input()
experimentTrialsCsv: string[] = [];
Expand Down Expand Up @@ -184,50 +178,54 @@ export class PbtTabComponent implements OnChanges, OnInit, AfterViewInit {

ngOnChanges(changes: SimpleChanges): void {
if (!this.graphHelper || !this.graphHelper.ngInit) {
// Wait for view to properly initialize
return;
console.warn(
'graphHelper not initialized yet, attempting manual call to ngOnInit()',
);
this.ngOnInit();
}
// Recompute formatted plotting points on data input changes
let updatePoints = false;
if (changes.experimentTrialsCsv && this.experimentTrialsCsv) {
let trialArr = d3.csv.parse(this.experimentTrialsCsv);
for (let trial of trialArr) {
let existingEntry = this.trialData[trial['trialName']];
if (existingEntry != trial) {
if (
trial['Status'] == StatusEnum.SUCCEEDED &&
!this.trialData.hasOwnProperty(trial['trialName'])
) {
this.trialData[trial['trialName']] = trial;
updatePoints = true;
}
}
}

if (changes.annotationsCsv && this.annotationsCsv) {
let annotArr = d3.csv.parse(this.annotationsCsv);
for (let annot of annotArr) {
let newEntry: PbtAnnotation = {
trialName: annot['trialName'],
uid: annot['trialName'],
parentUid: annot['pbt.suggestion.katib.kubeflow.org/parent'],
if (changes.labelCsv && this.labelCsv) {
let labelArr = d3.csv.parse(this.labelCsv);
for (let label of labelArr) {
if (this.labelData.hasOwnProperty(label['trialName'])) {
continue;
}
let newEntry: PbtPoint = {
trialName: label['trialName'],
parentUid: label['pbt.suggestion.katib.kubeflow.org/parent'],
generation: parseInt(
annot['pbt.suggestion.katib.kubeflow.org/generation'],
label['pbt.suggestion.katib.kubeflow.org/generation'],
),
parameters: undefined,
metricValue: undefined,
};
let existingEntry = this.annotData[newEntry.uid];
if (existingEntry != newEntry) {
this.annotData[newEntry.uid] = newEntry;
updatePoints = true;
}
this.labelData[newEntry.trialName] = newEntry;
updatePoints = true;
}
}

if (updatePoints) {
// Lazy; reprocess all points
let points: PbtPoint[] = [];
Object.values(this.annotData).forEach(entry => {
Object.values(this.labelData).forEach(entry => {
let point = {} as PbtPoint;
point.uid = entry.uid;
point.trialName = entry.trialName;
point.generation = entry.generation;
point.parentUid = entry.parentUid;
point.trialName = entry.trialName;

// Find corresponding trial data
let trial = this.trialData[point.trialName];
Expand All @@ -247,7 +245,7 @@ export class PbtTabComponent implements OnChanges, OnInit, AfterViewInit {
// Group seeds
let remaining_points = {};
for (let p of points) {
remaining_points[p.uid] = p;
remaining_points[p.trialName] = p;
}

this.data = [];
Expand All @@ -258,9 +256,9 @@ export class PbtTabComponent implements OnChanges, OnInit, AfterViewInit {
let v = seed;
while (v) {
segment.push(v);
let delete_uid = v.uid;
let delete_entry = v.trialName;
v = remaining_points[v.parentUid];
delete remaining_points[delete_uid];
delete remaining_points[delete_entry];
}
this.data.push(segment);
}
Expand Down Expand Up @@ -323,7 +321,7 @@ export class PbtTabComponent implements OnChanges, OnInit, AfterViewInit {
}

private getRangeX() {
const xValues = Object.values(this.annotData).map(entry => {
const xValues = Object.values(this.labelData).map(entry => {
return entry.generation;
});
return d3.scale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ export class KWABackendService extends BackendService {
return this.http.get(url).pipe(catchError(error => this.parseError(error)));
}

getExperimentAnnotationsInfo(
name: string,
namespace: string,
): Observable<any> {
const url = `/katib/fetch_hp_job_annotation_info/?experimentName=${name}&namespace=${namespace}`;
getExperimentLabelInfo(name: string, namespace: string): Observable<any> {
const url = `/katib/fetch_hp_job_label_info/?experimentName=${name}&namespace=${namespace}`;

return this.http.get(url).pipe(catchError(error => this.parseError(error)));
}
Expand Down
53 changes: 27 additions & 26 deletions pkg/new-ui/v1beta1/hp.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func (k *KatibUIHandler) FetchHPJobInfo(w http.ResponseWriter, r *http.Request)
log.Printf("Got Trial List")

// append a column for the Pipeline UID associated with the Trial
if hasAnnotation(trialList.Items, kfpRunIDAnnotation) {
if havePipelineUID(trialList.Items) {
resultText += ",KFP Run"
}

foundPipelineUID := false
for _, t := range trialList.Items {
runUid, ok := t.Spec.Annotations[kfpRunIDAnnotation]
runUid, ok := t.GetAnnotations()[kfpRunIDAnnotation]
if !ok {
log.Printf("Trial %s has no pipeline run.", t.Name)
runUid = ""
Expand Down Expand Up @@ -246,13 +246,11 @@ func (k *KatibUIHandler) FetchHPJobTrialInfo(w http.ResponseWriter, r *http.Requ
}
}

func (k *KatibUIHandler) FetchHPJobAnnotationInfo(w http.ResponseWriter, r *http.Request) {
func (k *KatibUIHandler) FetchHPJobLabelInfo(w http.ResponseWriter, r *http.Request) {
//enableCors(&w)
experimentName := r.URL.Query()["experimentName"][0]
namespace := r.URL.Query()["namespace"][0]

resultText := "trialName"

trialList, err := k.katibClient.GetTrialList(experimentName, namespace)
if err != nil {
log.Printf("GetTrialList from HP job failed: %v", err)
Expand All @@ -261,34 +259,37 @@ func (k *KatibUIHandler) FetchHPJobAnnotationInfo(w http.ResponseWriter, r *http
}
log.Printf("Got Trial List")

// Find set(annotations)
annotations := map[string]int{}
labelList := map[string]int{}
labelList["trialName"] = 0
var trialRes [][]string
for _, t := range trialList.Items {
for a := range t.Spec.Annotations {
annotations[a] = 0
trialResText := make([]string, len(labelList))
trialResText[labelList["trialName"]] = t.Name
for k, v := range t.ObjectMeta.Labels {
i, exists := labelList[k]
if !exists {
i = len(labelList)
labelList[k] = i
trialResText = append(trialResText, "")
}
trialResText[i] = v
}
trialRes = append(trialRes, trialResText)
}

// Set the index of each annotation
a_index := 0
for a := range annotations {
annotations[a] = a_index
resultText += "," + a
a_index++
// Format header output
headerArr := make([]string, len(labelList))
for k, v := range labelList {
headerArr[v] = k
}
log.Printf("Got Annotations List")
resultText := strings.Join(headerArr, ",")

for _, t := range trialList.Items {
trialResText := make([]string, len(annotations))
for a, n := range annotations {
a_value, ok := t.Spec.Annotations[a]
if !ok {
log.Printf("Trial %s has no annotation value for %s", t.Name, a)
a_value = ""
}
trialResText[n] = a_value
// Format entry output
for _, row := range trialRes {
resultText += "\n" + strings.Join(row, ",")
for j := 0; j < len(labelList)-len(row); j++ {
resultText += ","
}
resultText += "\n" + t.Name + "," + strings.Join(trialResText, ",")
}

log.Printf("Logs parsed, results:\n %v", resultText)
Expand Down
4 changes: 2 additions & 2 deletions pkg/new-ui/v1beta1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func (k *KatibUIHandler) getExperiments(namespace []string) ([]ExperimentView, e
return experiments, nil
}

func hasAnnotation(trials []trialv1beta1.Trial, annotation string) bool {
func havePipelineUID(trials []trialv1beta1.Trial) bool {
for _, t := range trials {
_, ok := t.Spec.Annotations[annotation]
_, ok := t.GetAnnotations()[kfpRunIDAnnotation]
if ok {
return true
}
Expand Down

0 comments on commit 5ca9a97

Please sign in to comment.