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
28 changes: 14 additions & 14 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 Expand Up @@ -376,7 +376,7 @@ func TestGetTrialList(t *testing.T) {
},
},
Status: &api_pb.TrialStatus{
Condition: api_pb.TrialStatus_PENDING,
Condition: api_pb.TrialStatus_CREATED,
StartTime: "",
CompletionTime: "",
Observation: &api_pb.Observation{
Expand Down Expand Up @@ -470,7 +470,7 @@ func TestUpdateTrialStatus(t *testing.T) {
req := &api_pb.UpdateTrialStatusRequest{
TrialName: "test1-trial1",
NewStatus: &api_pb.TrialStatus{
Condition: api_pb.TrialStatus_COMPLETED,
Condition: api_pb.TrialStatus_SUCCEEDED,
StartTime: "2019-02-03T04:05:06+09:00",
CompletionTime: "2019-02-03T05:05:06+09:00",
Observation: &api_pb.Observation{
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/operators/apis/trial/v1alpha2/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.
package v1alpha2

import (
"errors"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -85,6 +87,13 @@ func (trial *Trial) IsCompleted() bool {
return trial.IsSucceeded() || trial.IsFailed() || trial.IsKilled()
}

func (trial *Trial) GetLastConditionType() (TrialConditionType, error) {
if len(trial.Status.Conditions) > 0 {
return trial.Status.Conditions[len(trial.Status.Conditions)-1].Type, nil
}
return "", errors.New("Trial doesn't have any condition")
}

func (trial *Trial) setCondition(conditionType TrialConditionType, status v1.ConditionStatus, reason, message string) {

newCond := newCondition(conditionType, status, reason, message)
Expand Down
333 changes: 166 additions & 167 deletions pkg/api/v1alpha2/api.pb.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 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 Expand Up @@ -364,9 +364,9 @@ message TrialSpec {

message TrialStatus {
enum TrialConditionType {
PENDING = 0;
CREATED = 0;
RUNNING = 1;
COMPLETED = 2;
SUCCEEDED = 2;
KILLED = 3;
FAILED = 4;
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/v1alpha2/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,13 @@
"TrialStatusTrialConditionType": {
"type": "string",
"enum": [
"PENDING",
"CREATED",
"RUNNING",
"COMPLETED",
"SUCCEEDED",
"KILLED",
"FAILED"
],
"default": "PENDING"
"default": "CREATED"
},
"alpha2AlgorithmSetting": {
"type": "object",
Expand Down Expand Up @@ -543,10 +543,10 @@
"name": {
"type": "string"
},
"experiment_spec": {
"spec": {
"$ref": "#/definitions/alpha2ExperimentSpec"
},
"experiment_status": {
"status": {
"$ref": "#/definitions/alpha2ExperimentStatus"
}
}
Expand Down
8 changes: 4 additions & 4 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 Expand Up @@ -990,9 +990,9 @@ Types of value for HyperParameter.

| Name | Number | Description |
| ---- | ------ | ----------- |
| PENDING | 0 | |
| CREATED | 0 | |
| RUNNING | 1 | |
| COMPLETED | 2 | |
| SUCCEEDED | 2 | |
| KILLED | 3 | |
| FAILED | 4 | |

Expand Down
8 changes: 4 additions & 4 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 Expand Up @@ -2098,7 +2098,7 @@ <h3 id="api.v1.alpha2.TrialStatus.TrialConditionType">TrialStatus.TrialCondition
<tbody>

<tr>
<td>PENDING</td>
<td>CREATED</td>
<td>0</td>
<td><p></p></td>
</tr>
Expand All @@ -2110,7 +2110,7 @@ <h3 id="api.v1.alpha2.TrialStatus.TrialConditionType">TrialStatus.TrialCondition
</tr>

<tr>
<td>COMPLETED</td>
<td>SUCCEEDED</td>
<td>2</td>
<td><p></p></td>
</tr>
Expand Down
210 changes: 105 additions & 105 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
Loading