Skip to content

Commit

Permalink
Adding comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johnugeorge committed Apr 21, 2019
1 parent cde0287 commit 8c48f16
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions pkg/controller/v1alpha2/experiment/util/status_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ limitations under the License.
package util

import (
"errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"

experimentsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/experiment/v1alpha2"
Expand All @@ -37,37 +34,23 @@ const (

func UpdateExperimentStatus(instance *experimentsv1alpha2.Experiment, trials *trialsv1alpha2.TrialList) error {

isObjectiveGoalReached, err := updateTrialsSummary(instance, trials)
if err != nil {
return err
}
isObjectiveGoalReached := updateTrialsSummary(instance, trials)

updateExperimentStatusCondition(instance, isObjectiveGoalReached)
return nil

}

func updateTrialsSummary(instance *experimentsv1alpha2.Experiment, trials *trialsv1alpha2.TrialList) (bool, error) {
func updateTrialsSummary(instance *experimentsv1alpha2.Experiment, trials *trialsv1alpha2.TrialList) bool {

var trialsPending, trialsRunning, trialsSucceeded, trialsFailed, trialsKilled int
var bestTrialIndex int
var bestTrialValue float64
bestTrialIndex := -1
isObjectiveGoalReached := false
objectiveValueGoal := *instance.Spec.Objective.Goal
objectiveType := instance.Spec.Objective.Type
objectiveMetricName := instance.Spec.Objective.ObjectiveMetricName

if objectiveMetricValue := getObjectiveMetricValue(trials.Items[0], objectiveMetricName); objectiveMetricValue != nil {
bestTrialValue = *objectiveMetricValue
if bestTrialValue <= objectiveValueGoal {
isObjectiveGoalReached = true
}
} else {
//may be log
err := errors.New(string(metav1.StatusReasonNotFound))
return isObjectiveGoalReached, err
}

for index, trial := range trials.Items {
if trial.IsKilled() {
trialsKilled++
Expand All @@ -83,9 +66,14 @@ func updateTrialsSummary(instance *experimentsv1alpha2.Experiment, trials *trial

objectiveMetricValue := getObjectiveMetricValue(trial, objectiveMetricName)
if objectiveMetricValue == nil {
//may be log
err := errors.New(string(metav1.StatusReasonNotFound))
return isObjectiveGoalReached, err
log.Info("Objective metric name not found", "trial", trial.GetName())
continue
}

//intialize vars to objective metric value of the first trial
if bestTrialIndex == -1 {
bestTrialValue = *objectiveMetricValue
bestTrialIndex = index
}

if objectiveType == experimentsv1alpha2.ObjectiveTypeMinimize {
Expand Down Expand Up @@ -123,7 +111,7 @@ func updateTrialsSummary(instance *experimentsv1alpha2.Experiment, trials *trial
for _, metric := range bestTrial.Status.Observation.Metrics {
instance.Status.CurrentOptimalTrial.Observation.Metrics = append(instance.Status.CurrentOptimalTrial.Observation.Metrics, metric)
}
return isObjectiveGoalReached, nil
return isObjectiveGoalReached
}

func getObjectiveMetricValue(trial trialsv1alpha2.Trial, objectiveMetricName string) *float64 {
Expand Down

0 comments on commit 8c48f16

Please sign in to comment.