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

Register Trial in DB #530

Merged
merged 12 commits into from
May 16, 2019
2 changes: 1 addition & 1 deletion cmd/manager/v1alpha2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"log"
"net"

api_pb "github.com/kubeflow/katib/pkg/api/v1alpha2"
health_pb "github.com/kubeflow/katib/pkg/api/health"
api_pb "github.com/kubeflow/katib/pkg/api/v1alpha2"
kdb "github.com/kubeflow/katib/pkg/db/v1alpha2"

"google.golang.org/grpc"
Expand Down
24 changes: 12 additions & 12 deletions cmd/manager/v1alpha2/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ func TestRegisterExperiment(t *testing.T) {
req := &api_pb.RegisterExperimentRequest{
Experiment: &api_pb.Experiment{
Name: "testExp",
ExperimentSpec: &api_pb.ExperimentSpec{
Spec: &api_pb.ExperimentSpec{
ParameterSpecs: &api_pb.ExperimentSpec_ParameterSpecs{
Parameters: []*api_pb.ParameterSpec{},
},
Objective: &api_pb.ObjectiveSpec{
Type: api_pb.ObjectiveType_UNKNOWN,
Goal: 0.99,
ObjectiveMetricName: "f1_score",
AdditionalMetricNames: []string{"loss", "precision", "recall"},
Type: api_pb.ObjectiveType_UNKNOWN,
Goal: 0.99,
ObjectiveMetricName: "f1_score",
AdditionalMetricNames: []string{"loss", "precision", "recall"},
},
Algorithm: &api_pb.AlgorithmSpec{},
TrialTemplate: "",
ParallelTrialCount: 10,
MaxTrialCount: 100,
},
ExperimentStatus: &api_pb.ExperimentStatus{
Status: &api_pb.ExperimentStatus{
Condition: api_pb.ExperimentStatus_CREATED,
StartTime: "2019-02-03T04:05:06+09:00",
CompletionTime: "",
Expand Down Expand Up @@ -78,22 +78,22 @@ func TestGetExperiment(t *testing.T) {

testExp := api_pb.Experiment{
Name: "testExp",
ExperimentSpec: &api_pb.ExperimentSpec{
Spec: &api_pb.ExperimentSpec{
ParameterSpecs: &api_pb.ExperimentSpec_ParameterSpecs{
Parameters: []*api_pb.ParameterSpec{},
},
Objective: &api_pb.ObjectiveSpec{
Type: api_pb.ObjectiveType_UNKNOWN,
Goal: 0.99,
ObjectiveMetricName: "f1_score",
AdditionalMetricNames: []string{"loss", "precision", "recall"},
Type: api_pb.ObjectiveType_UNKNOWN,
Goal: 0.99,
ObjectiveMetricName: "f1_score",
AdditionalMetricNames: []string{"loss", "precision", "recall"},
},
Algorithm: &api_pb.AlgorithmSpec{},
TrialTemplate: "",
ParallelTrialCount: 10,
MaxTrialCount: 100,
},
ExperimentStatus: &api_pb.ExperimentStatus{
Status: &api_pb.ExperimentStatus{
Condition: api_pb.ExperimentStatus_CREATED,
StartTime: "2019-02-03T04:05:06+09:00",
CompletionTime: "",
Expand Down
320 changes: 160 additions & 160 deletions pkg/api/v1alpha2/api.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/api/v1alpha2/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ message ExperimentStatus {

message Experiment {
string name = 1; /// Name of Experiment. This is unique in DB.
ExperimentSpec experiment_spec = 2;
ExperimentStatus experiment_status = 3;
ExperimentSpec spec = 2;
ExperimentStatus status = 3;
}

message ParameterAssignment {
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1alpha2/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,10 @@
"name": {
"type": "string"
},
"experiment_spec": {
"spec": {
"$ref": "#/definitions/alpha2ExperimentSpec"
},
"experiment_status": {
"status": {
"$ref": "#/definitions/alpha2ExperimentStatus"
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1alpha2/gen-doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ TODO
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | Name of Experiment. This is unique in DB. |
| experiment_spec | [ExperimentSpec](#api.v1.alpha2.ExperimentSpec) | | |
| experiment_status | [ExperimentStatus](#api.v1.alpha2.ExperimentStatus) | | |
| spec | [ExperimentSpec](#api.v1.alpha2.ExperimentSpec) | | |
| status | [ExperimentStatus](#api.v1.alpha2.ExperimentStatus) | | |



Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1alpha2/gen-doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,14 @@ <h3 id="api.v1.alpha2.Experiment">Experiment</h3>
</tr>

<tr>
<td>experiment_spec</td>
<td>spec</td>
<td><a href="#api.v1.alpha2.ExperimentSpec">ExperimentSpec</a></td>
<td></td>
<td><p> </p></td>
</tr>

<tr>
<td>experiment_status</td>
<td>status</td>
<td><a href="#api.v1.alpha2.ExperimentStatus">ExperimentStatus</a></td>
<td></td>
<td><p> </p></td>
Expand Down
206 changes: 103 additions & 103 deletions pkg/api/v1alpha2/python/api_pb2.py

Large diffs are not rendered by default.

29 changes: 22 additions & 7 deletions pkg/common/v1alpha2/katib_manager_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ limitations under the License.
package v1alpha2

import (
"os"
"context"
"os"

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

type katibManagerClientAndConn struct {
Conn *grpc.ClientConn
Conn *grpc.ClientConn
KatibManagerClient api_pb.ManagerClient
}

Expand All @@ -59,20 +59,24 @@ func getKatibManagerClientAndConn() (*katibManagerClientAndConn, error) {
if err != nil {
return nil, err
}
kcc := &katibManagerClientAndConn {
Conn: conn,
kcc := &katibManagerClientAndConn{
Conn: conn,
KatibManagerClient: api_pb.NewManagerClient(conn),
}
return kcc, nil
}

func closeKatibManagerConnection(kcc *katibManagerClientAndConn) {
kcc.Conn.Close()
}

func RegisterExperiment(request *api_pb.RegisterExperimentRequest) (*api_pb.RegisterExperimentReply, error) {
ctx := context.Background()
kcc, err := getKatibManagerClientAndConn()
if err != nil {
return nil, err
}
defer kcc.Conn.Close()
defer closeKatibManagerConnection(kcc)
kc := kcc.KatibManagerClient
return kc.RegisterExperiment(ctx, request)
}
Expand All @@ -83,7 +87,7 @@ func DeleteExperiment(request *api_pb.DeleteExperimentRequest) (*api_pb.DeleteEx
if err != nil {
return nil, err
}
defer kcc.Conn.Close()
defer closeKatibManagerConnection(kcc)
kc := kcc.KatibManagerClient
return kc.DeleteExperiment(ctx, request)
}
Expand All @@ -94,7 +98,18 @@ func UpdateExperimentStatus(request *api_pb.UpdateExperimentStatusRequest) (*api
if err != nil {
return nil, err
}
defer kcc.Conn.Close()
defer closeKatibManagerConnection(kcc)
kc := kcc.KatibManagerClient
return kc.UpdateExperimentStatus(ctx, request)
}

func RegisterTrial(request *api_pb.RegisterTrialRequest) (*api_pb.RegisterTrialReply, error) {
ctx := context.Background()
kcc, err := getKatibManagerClientAndConn()
if err != nil {
return nil, err
}
defer closeKatibManagerConnection(kcc)
kc := kcc.KatibManagerClient
return kc.RegisterTrial(ctx, request)
}
26 changes: 13 additions & 13 deletions pkg/controller/v1alpha2/experiment/util/api_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ func GetExperimentFromDB(instance *experimentsv1alpha2.Experiment) (*api_pb.GetE

func GetExperimentConf(instance *experimentsv1alpha2.Experiment) *api_pb.Experiment {
experiment := &api_pb.Experiment{
ExperimentSpec: &api_pb.ExperimentSpec{
Spec: &api_pb.ExperimentSpec{
Objective: &api_pb.ObjectiveSpec{
AdditionalMetricNames: []string{},
},
Algorithm: &api_pb.AlgorithmSpec{
AlgorithmSetting: []*api_pb.AlgorithmSetting{},
},
},
ExperimentStatus: &api_pb.ExperimentStatus{
Status: &api_pb.ExperimentStatus{
StartTime: convertTime2RFC3339(instance.Status.StartTime),
CompletionTime: convertTime2RFC3339(instance.Status.CompletionTime),
Condition: getCondition(instance),
Expand All @@ -89,25 +89,25 @@ func GetExperimentConf(instance *experimentsv1alpha2.Experiment) *api_pb.Experim
//Populate Objective
switch instance.Spec.Objective.Type {
case commonv1alpha2.ObjectiveTypeMaximize:
experiment.ExperimentSpec.Objective.Type = api_pb.ObjectiveType_MAXIMIZE
experiment.Spec.Objective.Type = api_pb.ObjectiveType_MAXIMIZE
case commonv1alpha2.ObjectiveTypeMinimize:
experiment.ExperimentSpec.Objective.Type = api_pb.ObjectiveType_MINIMIZE
experiment.Spec.Objective.Type = api_pb.ObjectiveType_MINIMIZE
default:
experiment.ExperimentSpec.Objective.Type = api_pb.ObjectiveType_UNKNOWN
experiment.Spec.Objective.Type = api_pb.ObjectiveType_UNKNOWN

}
experiment.ExperimentSpec.Objective.Goal = float32(*instance.Spec.Objective.Goal)
experiment.ExperimentSpec.Objective.ObjectiveMetricName = instance.Spec.Objective.ObjectiveMetricName
experiment.Spec.Objective.Goal = float32(*instance.Spec.Objective.Goal)
experiment.Spec.Objective.ObjectiveMetricName = instance.Spec.Objective.ObjectiveMetricName
for _, m := range instance.Spec.Objective.AdditionalMetricNames {
experiment.ExperimentSpec.Objective.AdditionalMetricNames = append(experiment.ExperimentSpec.Objective.AdditionalMetricNames, m)
experiment.Spec.Objective.AdditionalMetricNames = append(experiment.Spec.Objective.AdditionalMetricNames, m)
}

//Populate Algorithm Spec
experiment.ExperimentSpec.Algorithm.AlgorithmName = instance.Spec.Algorithm.AlgorithmName
experiment.Spec.Algorithm.AlgorithmName = instance.Spec.Algorithm.AlgorithmName

for _, as := range instance.Spec.Algorithm.AlgorithmSettings {
experiment.ExperimentSpec.Algorithm.AlgorithmSetting = append(
experiment.ExperimentSpec.Algorithm.AlgorithmSetting,
experiment.Spec.Algorithm.AlgorithmSetting = append(
experiment.Spec.Algorithm.AlgorithmSetting,
&api_pb.AlgorithmSetting{
Name: as.Name,
Value: as.Value,
Expand Down Expand Up @@ -143,7 +143,7 @@ func GetExperimentConf(instance *experimentsv1alpha2.Experiment) *api_pb.Experim
}
parameterSpecs.Parameters = append(parameterSpecs.Parameters, parameter)
}
experiment.ExperimentSpec.ParameterSpecs = parameterSpecs
experiment.Spec.ParameterSpecs = parameterSpecs
}

//Populate NAS Experiment
Expand Down Expand Up @@ -202,7 +202,7 @@ func GetExperimentConf(instance *experimentsv1alpha2.Experiment) *api_pb.Experim
nasConfig.Operations.Operation = append(nasConfig.Operations.Operation, operation)
}

experiment.ExperimentSpec.NasConfig = nasConfig
experiment.Spec.NasConfig = nasConfig
}

return experiment
Expand Down
61 changes: 58 additions & 3 deletions pkg/controller/v1alpha2/trial/util/api_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ limitations under the License.
package util

import (
//v1 "k8s.io/api/core/v1"

commonv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/common/v1alpha2"
trialsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/trial/v1alpha2"
api_pb "github.com/kubeflow/katib/pkg/api/v1alpha2"
common "github.com/kubeflow/katib/pkg/common/v1alpha2"
)

func CreateTrialInDB(instance *trialsv1alpha2.Trial) error {

trial := GetTrialConf(instance)
request := &api_pb.RegisterTrialRequest{
Trial: trial,
}
if _, err := common.RegisterTrial(request); err != nil {
return err
}
return nil
}

Expand All @@ -35,3 +42,51 @@ func GetTrialObservation(instance *trialsv1alpha2.Trial) error {

return nil
}

func GetTrialConf(instance *trialsv1alpha2.Trial) *api_pb.Trial {
trial := &api_pb.Trial{
Spec: &api_pb.TrialSpec{
Objective: &api_pb.ObjectiveSpec{
AdditionalMetricNames: []string{},
},
ParameterAssignments: &api_pb.TrialSpec_ParameterAssignments{
Assignments: []*api_pb.ParameterAssignment{},
},
},
}
trial.Name = instance.Name

trial.Spec.ExperimentName = instance.Labels["experiment"]

//Populate Objective
switch instance.Spec.Objective.Type {
case commonv1alpha2.ObjectiveTypeMaximize:
trial.Spec.Objective.Type = api_pb.ObjectiveType_MAXIMIZE
case commonv1alpha2.ObjectiveTypeMinimize:
trial.Spec.Objective.Type = api_pb.ObjectiveType_MINIMIZE
default:
trial.Spec.Objective.Type = api_pb.ObjectiveType_UNKNOWN

}
trial.Spec.Objective.Goal = float32(*instance.Spec.Objective.Goal)
trial.Spec.Objective.ObjectiveMetricName = instance.Spec.Objective.ObjectiveMetricName
for _, m := range instance.Spec.Objective.AdditionalMetricNames {
trial.Spec.Objective.AdditionalMetricNames = append(trial.Spec.Objective.AdditionalMetricNames, m)
}

//Populate Parameter Assignments
for _, p := range instance.Spec.ParameterAssignments {
trial.Spec.ParameterAssignments.Assignments = append(
trial.Spec.ParameterAssignments.Assignments,
&api_pb.ParameterAssignment{
Name: p.Name,
Value: p.Value,
})
}

trial.Spec.RunSpec = instance.Spec.RunSpec

trial.Spec.MetricsCollectorSpec = instance.Spec.MetricsCollectorSpec

Copy link
Member

Choose a reason for hiding this comment

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

miss trial.Status?

return trial
}
Loading