Skip to content

Commit

Permalink
Enable to run Experiment without Goal (#1065)
Browse files Browse the repository at this point in the history
* Enable to run experiment without goal

* Remove goal from tfjob example

* Fix e2e test

* fix test

* Add goal to tfjob example
  • Loading branch information
andreyvelich authored Mar 23, 2020
1 parent 3717609 commit d622f4a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
9 changes: 6 additions & 3 deletions pkg/controller.v1alpha3/experiment/util/status_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func updateTrialsSummary(instance *experimentsv1alpha3.Experiment, trials *trial
sts.RunningTrialList, sts.PendingTrialList, sts.FailedTrialList, sts.SucceededTrialList, sts.KilledTrialList = nil, nil, nil, nil, nil
bestTrialIndex := -1
isObjectiveGoalReached := false
objectiveValueGoal := *instance.Spec.Objective.Goal
var objectiveValueGoal float64
if instance.Spec.Objective.Goal != nil {
objectiveValueGoal = *instance.Spec.Objective.Goal
}
objectiveType := instance.Spec.Objective.Type
objectiveMetricName := instance.Spec.Objective.ObjectiveMetricName

Expand Down Expand Up @@ -90,15 +93,15 @@ func updateTrialsSummary(instance *experimentsv1alpha3.Experiment, trials *trial
bestTrialValue = *objectiveMetricValue
bestTrialIndex = index
}
if bestTrialValue <= objectiveValueGoal {
if instance.Spec.Objective.Goal != nil && bestTrialValue <= objectiveValueGoal {
isObjectiveGoalReached = true
}
} else if objectiveType == commonv1alpha3.ObjectiveTypeMaximize {
if *objectiveMetricValue > bestTrialValue {
bestTrialValue = *objectiveMetricValue
bestTrialIndex = index
}
if bestTrialValue >= objectiveValueGoal {
if instance.Spec.Objective.Goal != nil && bestTrialValue >= objectiveValueGoal {
isObjectiveGoalReached = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,16 @@ func (g *General) ConvertExperiment(e *experimentsv1alpha3.Experiment) *suggesti
},
Objective: &suggestionapi.ObjectiveSpec{
Type: convertObjectiveType(e.Spec.Objective.Type),
Goal: *e.Spec.Objective.Goal,
ObjectiveMetricName: e.Spec.Objective.ObjectiveMetricName,
},
ParameterSpecs: &suggestionapi.ExperimentSpec_ParameterSpecs{
Parameters: convertParameters(e.Spec.Parameters),
},
}
// Set Goal if user defines it in Objective
if e.Spec.Objective.Goal != nil {
res.Spec.Objective.Goal = *e.Spec.Objective.Goal
}
// Set NasConfig if the user defines it in Spec.
if e.Spec.NasConfig != nil {
res.Spec.NasConfig = convertNasConfig(e.Spec.NasConfig)
Expand All @@ -184,7 +187,6 @@ func (g *General) ConvertTrials(ts []trialsv1alpha3.Trial) []*suggestionapi.Tria
Spec: &suggestionapi.TrialSpec{
Objective: &suggestionapi.ObjectiveSpec{
Type: convertObjectiveType(t.Spec.Objective.Type),
Goal: *t.Spec.Objective.Goal,
ObjectiveMetricName: t.Spec.Objective.ObjectiveMetricName,
AdditionalMetricNames: t.Spec.Objective.AdditionalMetricNames,
},
Expand All @@ -198,6 +200,9 @@ func (g *General) ConvertTrials(ts []trialsv1alpha3.Trial) []*suggestionapi.Tria
t.Status.Observation),
},
}
if t.Spec.Objective.Goal != nil {
trial.Spec.Objective.Goal = *t.Spec.Objective.Goal
}
if len(t.Status.Conditions) > 0 {
// We send only the latest condition of the Trial!
trial.Status.Condition = convertTrialConditionType(
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/v1alpha3/resume-e2e-experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ func main() {
}

objectiveType := exp.Spec.Objective.Type
goal := *exp.Spec.Objective.Goal
if (objectiveType == commonv1alpha3.ObjectiveTypeMinimize && *metricVal < goal) ||
(objectiveType == commonv1alpha3.ObjectiveTypeMaximize && *metricVal > goal) {
var goal float64
if exp.Spec.Objective.Goal != nil {
goal = *exp.Spec.Objective.Goal
}
if (exp.Spec.Objective.Goal != nil && objectiveType == commonv1alpha3.ObjectiveTypeMinimize && *metricVal < goal) ||
(exp.Spec.Objective.Goal != nil && objectiveType == commonv1alpha3.ObjectiveTypeMaximize && *metricVal > goal) {
log.Print("Objective Goal reached")
} else {

Expand Down
9 changes: 6 additions & 3 deletions test/e2e/v1alpha3/run-e2e-experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ func main() {
}

objectiveType := exp.Spec.Objective.Type
goal := *exp.Spec.Objective.Goal
if (objectiveType == commonv1alpha3.ObjectiveTypeMinimize && *metricVal < goal) ||
(objectiveType == commonv1alpha3.ObjectiveTypeMaximize && *metricVal > goal) {
var goal float64
if exp.Spec.Objective.Goal != nil {
goal = *exp.Spec.Objective.Goal
}
if (exp.Spec.Objective.Goal != nil && objectiveType == commonv1alpha3.ObjectiveTypeMinimize && *metricVal < goal) ||
(exp.Spec.Objective.Goal != nil && objectiveType == commonv1alpha3.ObjectiveTypeMaximize && *metricVal > goal) {
log.Print("Objective Goal reached")
} else {

Expand Down

0 comments on commit d622f4a

Please sign in to comment.