Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish reconcile only after running trials are complete #861

Merged
merged 3 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/apis/controller/experiments/v1alpha3/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (exp *Experiment) IsCompleted() bool {
return exp.IsSucceeded() || exp.IsFailed()
}

func (exp *Experiment) HasRunningTrials() bool {
return exp.Status.TrialsRunning != 0
}

func (exp *Experiment) GetLastConditionType() (ExperimentConditionType, error) {
if len(exp.Status.Conditions) > 0 {
return exp.Status.Conditions[len(exp.Status.Conditions)-1].Type, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (r *ReconcileExperiment) Reconcile(request reconcile.Request) (reconcile.Re
}
instance := original.DeepCopy()

if instance.IsCompleted() {
if instance.IsCompleted() && !instance.HasRunningTrials() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

willn't this line make new trial never be created?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore my comment, get it now


return reconcile.Result{}, nil

Expand Down
5 changes: 3 additions & 2 deletions pkg/controller.v1alpha3/experiment/util/status_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func UpdateExperimentStatus(instance *experimentsv1alpha3.Experiment, trials *tr

isObjectiveGoalReached := updateTrialsSummary(instance, trials)

UpdateExperimentStatusCondition(instance, isObjectiveGoalReached, false)
if !instance.IsCompleted() {
UpdateExperimentStatusCondition(instance, isObjectiveGoalReached, false)
}
return nil

}
Expand Down Expand Up @@ -69,7 +71,6 @@ func updateTrialsSummary(instance *experimentsv1alpha3.Experiment, trials *trial

objectiveMetricValue := getObjectiveMetricValue(trial, objectiveMetricName)
if objectiveMetricValue == nil {
log.Info("Objective metric name not found", "trial", trial.GetName())
continue
}

Expand Down
38 changes: 25 additions & 13 deletions test/e2e/v1alpha3/run-e2e-experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client"

commonv1alpha3 "github.com/kubeflow/katib/pkg/apis/controller/common/v1alpha3"
experimentsv1alpha3 "github.com/kubeflow/katib/pkg/apis/controller/experiments/v1alpha3"
"github.com/kubeflow/katib/pkg/util/v1alpha3/katibclient"
)
Expand All @@ -20,20 +21,20 @@ const (
timeout = 30 * time.Minute
)

func verifyResult(exp *experimentsv1alpha3.Experiment) error {
func verifyResult(exp *experimentsv1alpha3.Experiment) (*float64, error) {
if len(exp.Status.CurrentOptimalTrial.ParameterAssignments) == 0 {
return fmt.Errorf("Best parameter assignments not updated in status")
return nil, fmt.Errorf("Best parameter assignments not updated in status")
}

if len(exp.Status.CurrentOptimalTrial.Observation.Metrics) == 0 {
return fmt.Errorf("Bst metrics not updated in status")
return nil, fmt.Errorf("Best metrics not updated in status")
}

metric := exp.Status.CurrentOptimalTrial.Observation.Metrics[0]
if metric.Name != exp.Spec.Objective.ObjectiveMetricName {
return fmt.Errorf("Best objective metric not updated in status")
return nil, fmt.Errorf("Best objective metric not updated in status")
}
return nil
return &metric.Value, nil
}

func main() {
Expand Down Expand Up @@ -102,17 +103,28 @@ func main() {
log.Fatal("Experiment run timed out")
}

if exp.Status.Trials != *exp.Spec.MaxTrialCount {
log.Fatal("All trials are not run in the experiment ", exp.Status.Trials, exp.Spec.MaxTrialCount)
}

if exp.Status.TrialsSucceeded != *exp.Spec.MaxTrialCount {
log.Fatal("All trials are not successful ", exp.Status.TrialsSucceeded, *exp.Spec.MaxTrialCount)
}
err = verifyResult(exp)
metricVal, err := verifyResult(exp)
if err != nil {
log.Fatal(err)
}
if metricVal == nil {
log.Fatal("Metric value in CurrentOptimalTrial not populated")
}

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

if exp.Status.Trials != *exp.Spec.MaxTrialCount {
log.Fatal("All trials are not run in the experiment ", exp.Status.Trials, exp.Spec.MaxTrialCount)
}

if exp.Status.TrialsSucceeded != *exp.Spec.MaxTrialCount {
log.Fatal("All trials are not successful ", exp.Status.TrialsSucceeded, *exp.Spec.MaxTrialCount)
}
}
log.Printf("Experiment has recorded best current Optimal Trial %v", exp.Status.CurrentOptimalTrial)
}
4 changes: 2 additions & 2 deletions test/scripts/v1alpha3/check-katib-ready.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ cd ${GO_DIR}

echo "Deploying tf-operator from kubeflow/manifests master"
cd "${MANIFESTS_DIR}/tf-training/tf-job-operator/base"
kustomize build . | kubectl apply -n kubeflow -f -
kustomize build . | kubectl apply -n kubeflow -f - --validate=false

echo "Deploying pytorch-operator from kubeflow/manifests master"
cd "${MANIFESTS_DIR}/pytorch-job/pytorch-operator/base/"
kustomize build . | kubectl apply -n kubeflow -f -
kustomize build . | kubectl apply -n kubeflow -f - --validate=false


TIMEOUT=120
Expand Down