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

Resume experiment with extra trials from last checkpoint #952

Merged
merged 6 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 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,14 @@ func (exp *Experiment) IsCompleted() bool {
return exp.IsSucceeded() || exp.IsFailed()
}

func (exp *Experiment) IsCompletedReason(reason string) bool {
cond := getCondition(exp, ExperimentSucceeded)
if cond != nil && cond.Status == v1.ConditionTrue && cond.Reason == reason {
return true
}
return false
}

func (exp *Experiment) HasRunningTrials() bool {
return exp.Status.TrialsRunning != 0
}
Expand Down Expand Up @@ -131,6 +139,12 @@ func (exp *Experiment) MarkExperimentStatusRunning(reason, message string) {
exp.setCondition(ExperimentRunning, v1.ConditionTrue, reason, message)
}

func (exp *Experiment) MarkExperimentStatusRestarting(reason, message string) {
exp.removeCondition(ExperimentSucceeded)
exp.removeCondition(ExperimentFailed)
exp.setCondition(ExperimentRestarting, v1.ConditionTrue, reason, message)
}

func (exp *Experiment) MarkExperimentStatusSucceeded(reason, message string) {
currentCond := getCondition(exp, ExperimentRunning)
if currentCond != nil {
Expand Down
18 changes: 16 additions & 2 deletions pkg/controller.v1alpha3/experiment/experiment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,22 @@ func (r *ReconcileExperiment) Reconcile(request reconcile.Request) (reconcile.Re
return r.updateFinalizers(instance, finalizers)
}

if instance.IsCompleted() && !instance.HasRunningTrials() {
return reconcile.Result{}, nil
if instance.IsCompleted() {
// Check if completed instance is restartable
// Experiment is restartable only if it is in succeeded state by reaching max trials
if util.IsCompletedExperimentRestartable(instance) {
// Check if max trials is reconfigured
if (instance.Spec.MaxTrialCount != nil) &&
Copy link
Member

Choose a reason for hiding this comment

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

I think if a user changes MaxTrialCount to nil (infinity), here we should also allow to restart it

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

(*instance.Spec.MaxTrialCount != instance.Status.Trials) {
msg := "Experiment is restarted"
instance.MarkExperimentStatusRestarting(util.ExperimentRestartingReason, msg)
}
} else {
// If experiment is completed with no running trials, stop reconcile
if !instance.HasRunningTrials() {
return reconcile.Result{}, nil
}
}
}
if !instance.IsCreated() {
if instance.Status.StartTime == nil {
Expand Down
26 changes: 18 additions & 8 deletions pkg/controller.v1alpha3/experiment/util/status_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import (
var log = logf.Log.WithName("experiment-status-util")

const (
ExperimentCreatedReason = "ExperimentCreated"
ExperimentRunningReason = "ExperimentRunning"
ExperimentSucceededReason = "ExperimentSucceeded"
ExperimentFailedReason = "ExperimentFailed"
ExperimentKilledReason = "ExperimentKilled"
ExperimentCreatedReason = "ExperimentCreated"
ExperimentRunningReason = "ExperimentRunning"
ExperimentRestartingReason = "ExperimentRestarting"
ExperimentGoalReachedReason = "ExperimentGoalReached"
ExperimentMaxTrialsReachedReason = "ExperimentMaxTrialsReached"
ExperimentSuggestionEndReachedReason = "ExperimentSuggestionEndReached"
ExperimentFailedReason = "ExperimentFailed"
ExperimentKilledReason = "ExperimentKilled"
)

func UpdateExperimentStatus(instance *experimentsv1alpha3.Experiment, trials *trialsv1alpha3.TrialList) error {
Expand Down Expand Up @@ -143,23 +146,23 @@ func UpdateExperimentStatusCondition(instance *experimentsv1alpha3.Experiment, i

if isObjectiveGoalReached {
msg := "Experiment has succeeded because Objective goal has reached"
instance.MarkExperimentStatusSucceeded(ExperimentSucceededReason, msg)
instance.MarkExperimentStatusSucceeded(ExperimentGoalReachedReason, msg)
instance.Status.CompletionTime = &now
IncreaseExperimentsSucceededCount()
return
}

if (instance.Spec.MaxTrialCount != nil) && (completedTrialsCount >= *instance.Spec.MaxTrialCount) {
msg := "Experiment has succeeded because max trial count has reached"
instance.MarkExperimentStatusSucceeded(ExperimentSucceededReason, msg)
instance.MarkExperimentStatusSucceeded(ExperimentMaxTrialsReachedReason, msg)
instance.Status.CompletionTime = &now
IncreaseExperimentsSucceededCount()
return
}

if getSuggestionDone && (instance.Status.TrialsPending+instance.Status.TrialsRunning) == 0 {
msg := "Experiment has succeeded because suggestion service has reached the end"
instance.MarkExperimentStatusSucceeded(ExperimentSucceededReason, msg)
instance.MarkExperimentStatusSucceeded(ExperimentSuggestionEndReachedReason, msg)
instance.Status.CompletionTime = &now
IncreaseExperimentsSucceededCount()
return
Expand All @@ -176,3 +179,10 @@ func UpdateExperimentStatusCondition(instance *experimentsv1alpha3.Experiment, i
msg := "Experiment is running"
instance.MarkExperimentStatusRunning(ExperimentRunningReason, msg)
}

func IsCompletedExperimentRestartable(instance *experimentsv1alpha3.Experiment) bool {
if instance.IsSucceeded() && instance.IsCompletedReason(ExperimentMaxTrialsReachedReason) {
return true
}
return false
}