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

Implement GetSuggestions for general suggestion #546

Merged
merged 1 commit into from
May 17, 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions pkg/api/operators/apis/experiment/v1alpha2/experiment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ type ExperimentSpec struct {

// How many trials can be processed in parallel.
// Defaults to 3
ParallelTrialCount *int `json:"parallelTrialCount,omitempty"`
ParallelTrialCount *int32 `json:"parallelTrialCount,omitempty"`

// Max completed trials to mark experiment as succeeded
MaxTrialCount *int `json:"maxTrialCount,omitempty"`
MaxTrialCount *int32 `json:"maxTrialCount,omitempty"`

// Max failed trials to mark experiment as failed.
MaxFailedTrialCount *int `json:"maxFailedTrialCount,omitempty"`
MaxFailedTrialCount *int32 `json:"maxFailedTrialCount,omitempty"`

// Whether to retain historical data in DB after deletion.
RetainHistoricalData bool `json:"retainHistoricalData,omitempty"`
Expand Down Expand Up @@ -80,22 +80,22 @@ type ExperimentStatus struct {
CurrentOptimalTrial OptimalTrial `json:"currentOptimalTrial,omitempty"`

// Trials is the total number of trials owned by the experiment.
Trials int `json:"trials,omitempty"`
Trials int32 `json:"trials,omitempty"`

// How many trials have succeeded.
TrialsSucceeded int `json:"trialsSucceeded,omitempty"`
TrialsSucceeded int32 `json:"trialsSucceeded,omitempty"`

// How many trials have failed.
TrialsFailed int `json:"trialsFailed,omitempty"`
TrialsFailed int32 `json:"trialsFailed,omitempty"`

// How many trials have been killed.
TrialsKilled int `json:"trialsKilled,omitempty"`
TrialsKilled int32 `json:"trialsKilled,omitempty"`

// How many trials are currently pending.
TrialsPending int `json:"trialsPending,omitempty"`
TrialsPending int32 `json:"trialsPending,omitempty"`

// How many trials are currently running.
TrialsRunning int `json:"trialsRunning,omitempty"`
TrialsRunning int32 `json:"trialsRunning,omitempty"`
}

type OptimalTrial struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pkg/common/v1alpha2/katib_manager_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,14 @@ func UpdateTrialStatus(request *api_pb.UpdateTrialStatusRequest) (*api_pb.Update
kc := kcc.KatibManagerClient
return kc.UpdateTrialStatus(ctx, request)
}

func GetSuggestions(request *api_pb.GetSuggestionsRequest) (*api_pb.GetSuggestionsReply, error) {
ctx := context.Background()
kcc, err := getKatibManagerClientAndConn()
if err != nil {
return nil, err
}
defer closeKatibManagerConnection(kcc)
kc := kcc.KatibManagerClient
return kc.GetSuggestions(ctx, request)
}
6 changes: 3 additions & 3 deletions pkg/controller/v1alpha2/experiment/experiment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (r *ReconcileExperiment) ReconcileTrials(instance *experimentsv1alpha2.Expe
}

} else if activeCount < parallelCount {
requiredActiveCount := 0
var requiredActiveCount int32 = 0
Copy link
Member

Choose a reason for hiding this comment

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

var initializes to zero by default

if instance.Spec.MaxTrialCount == nil {
requiredActiveCount = parallelCount
} else {
Expand Down Expand Up @@ -349,7 +349,7 @@ func (r *ReconcileExperiment) ReconcileTrials(instance *experimentsv1alpha2.Expe

}

func (r *ReconcileExperiment) createTrials(instance *experimentsv1alpha2.Experiment, addCount int) error {
func (r *ReconcileExperiment) createTrials(instance *experimentsv1alpha2.Experiment, addCount int32) error {

logger := log.WithValues("Experiment", types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()})
trials, err := r.GetSuggestions(instance, addCount)
Expand All @@ -366,7 +366,7 @@ func (r *ReconcileExperiment) createTrials(instance *experimentsv1alpha2.Experim
return nil
}

func (r *ReconcileExperiment) deleteTrials(instance *experimentsv1alpha2.Experiment, deleteCount int) error {
func (r *ReconcileExperiment) deleteTrials(instance *experimentsv1alpha2.Experiment, deleteCount int32) error {

return nil
}
2 changes: 1 addition & 1 deletion pkg/controller/v1alpha2/experiment/suggestion/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ func New() suggestion.Suggestion {
return &Fake{}
}

func (k *Fake) GetSuggestions(instance *experimentsv1alpha2.Experiment, addCount int) ([]*api_pb.Trial, error) {
func (k *Fake) GetSuggestions(instance *experimentsv1alpha2.Experiment, addCount int32) ([]*api_pb.Trial, error) {
return nil, nil
}
18 changes: 13 additions & 5 deletions pkg/controller/v1alpha2/experiment/suggestion/suggestion.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package suggestion

import (
"fmt"

experimentsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/experiment/v1alpha2"
api_pb "github.com/kubeflow/katib/pkg/api/v1alpha2"
common "github.com/kubeflow/katib/pkg/common/v1alpha2"
)

type Suggestion interface {
GetSuggestions(instance *experimentsv1alpha2.Experiment, addCount int) ([]*api_pb.Trial, error)
GetSuggestions(instance *experimentsv1alpha2.Experiment, addCount int32) ([]*api_pb.Trial, error)
}

type General struct {
Expand All @@ -18,6 +17,15 @@ func New() Suggestion {
return &General{}
}

func (g *General) GetSuggestions(instance *experimentsv1alpha2.Experiment, addCount int) ([]*api_pb.Trial, error) {
return nil, fmt.Errorf("Not implemented")
func (g *General) GetSuggestions(instance *experimentsv1alpha2.Experiment, addCount int32) ([]*api_pb.Trial, error) {
request := &api_pb.GetSuggestionsRequest{
ExperimentName: instance.Name,
AlgorithmName: instance.Spec.Algorithm.AlgorithmName,
RequestNumber: *instance.Spec.ParallelTrialCount,
}
if reply, err :=common.GetSuggestions(request); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Format here is not gofmted, since the code is merged, we could format it in another PR about suggestion.

return nil, err
} else {
return reply.Trials, nil
}
}
2 changes: 1 addition & 1 deletion pkg/controller/v1alpha2/experiment/util/status_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func UpdateExperimentStatus(instance *experimentsv1alpha2.Experiment, trials *tr

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

var totalTrials, trialsPending, trialsRunning, trialsSucceeded, trialsFailed, trialsKilled int
var totalTrials, trialsPending, trialsRunning, trialsSucceeded, trialsFailed, trialsKilled int32
var bestTrialValue float64
bestTrialIndex := -1
isObjectiveGoalReached := false
Expand Down