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

Add create time to Trial API #410

Merged
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
395 changes: 202 additions & 193 deletions pkg/api/api.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pkg/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,15 @@ message StudyOverview {
* A set of Hyperparameter.
* In a study, multiple trials are evaluated by workers.
* Suggestion service will generate next trials.
* Create time will be filled in the server automatically side even user set the value
*/
message Trial {
string trial_id = 1; /// Trial ID.
string study_id = 2; /// Study ID.
repeated Parameter parameter_set = 3; /// Hyperparameter set
string objective_value = 4; /// Objective Value
repeated Tag tags = 5; /// Tags of Trial.
string create_time = 6; /// Trial create timestamp RFC3339 format.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please explain that the create_time will be filled in the server side even user set the value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}

/**
Expand Down
5 changes: 4 additions & 1 deletion pkg/api/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1464,9 +1464,12 @@
"items": {
"$ref": "#/definitions/apiTag"
}
},
"create_time": {
"type": "string"
}
},
"description": "*\nA set of Hyperparameter.\nIn a study, multiple trials are evaluated by workers.\nSuggestion service will generate next trials."
"title": "*\nA set of Hyperparameter.\nIn a study, multiple trials are evaluated by workers.\nSuggestion service will generate next trials.\nCreate time will be filled in the server automatically side even user set the value"
},
"apiUpdateWorkerStateReply": {
"type": "object"
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/gen-doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@ Tag for each resource.
A set of Hyperparameter.
In a study, multiple trials are evaluated by workers.
Suggestion service will generate next trials.
Create time will be filled in the server automatically side even user set the value


| Field | Type | Label | Description |
Expand All @@ -1306,6 +1307,7 @@ Suggestion service will generate next trials.
| parameter_set | [Parameter](#api.Parameter) | repeated | Hyperparameter set |
| objective_value | [string](#string) | | Objective Value |
| tags | [Tag](#api.Tag) | repeated | Tags of Trial. |
| create_time | [string](#string) | | Trial create timestamp RFC3339 format. |



Expand Down
9 changes: 8 additions & 1 deletion pkg/api/gen-doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ <h3 id="api.Tag">Tag</h3>


<h3 id="api.Trial">Trial</h3>
<p>A set of Hyperparameter.</p><p>In a study, multiple trials are evaluated by workers.</p><p>Suggestion service will generate next trials.</p>
<p>A set of Hyperparameter.</p><p>In a study, multiple trials are evaluated by workers.</p><p>Suggestion service will generate next trials.</p><p>Create time will be filled in the server automatically side even user set the value</p>


<table class="field-table">
Expand Down Expand Up @@ -2708,6 +2708,13 @@ <h3 id="api.Trial">Trial</h3>
<td><p>Tags of Trial. </p></td>
</tr>

<tr>
<td>create_time</td>
<td><a href="#string">string</a></td>
<td></td>
<td><p>Trial create timestamp RFC3339 format. </p></td>
</tr>

</tbody>
</table>

Expand Down
311 changes: 159 additions & 152 deletions pkg/api/python/api_pb2.py

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions pkg/db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,13 @@ func (d *dbConn) getTrials(trialID string, studyID string) ([]*api.Trial, error)
trial := new(api.Trial)

var parameters, tags string
var timeStamp string
var createTimeStr string
err := rows.Scan(&trial.TrialId,
&trial.StudyId,
&parameters,
&trial.ObjectiveValue,
&tags,
&timeStamp,
&createTimeStr,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -415,6 +415,14 @@ func (d *dbConn) getTrials(trialID string, studyID string) ([]*api.Trial, error)
}
}
trial.Tags = t

createTimeMysql, errParseTimeMysql := time.Parse(mysqlTimeFmt, createTimeStr)
if errParseTimeMysql != nil {
log.Printf("Error parsing Trial create time %s to mysqlFormat: %v", createTimeStr, errParseTimeMysql)
continue
}
trial.CreateTime = createTimeMysql.UTC().Format(time.RFC3339Nano)

result = append(result, trial)
}

Expand Down Expand Up @@ -478,10 +486,10 @@ func (d *dbConn) CreateTrial(trial *api.Trial) error {
i := 3
for true {
trialID = generateRandid()
timeString := time.Now().UTC().Format(mysqlTimeFmt)
createTimeString := time.Now().UTC().Format(mysqlTimeFmt)
_, err := d.db.Exec("INSERT INTO trials VALUES (?, ?, ?, ?, ?, ?)",
trialID, trial.StudyId, strings.Join(params, ",\n"),
trial.ObjectiveValue, strings.Join(tags, ",\n"), timeString)
trial.ObjectiveValue, strings.Join(tags, ",\n"), createTimeString)
if err == nil {
trial.TrialId = trialID
break
Expand Down
4 changes: 2 additions & 2 deletions pkg/db/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestGetTrial(t *testing.T) {
id, "s1234567890abcde",
"{\"name\": \"1\"},\n{}", "obj_val",
"{\"name\": \"foo\"},\n{}",
""))
"2019-02-26 09:54:32"))
trial, err := dbInterface.GetTrial(id)
if err != nil {
t.Errorf("GetTrial error %v", err)
Expand All @@ -231,7 +231,7 @@ func TestGetTrialList(t *testing.T) {
var ids = []string{"abcdef1234567890", "bcdef1234567890a"}
rows := sqlmock.NewRows(trialColumns)
for _, id := range ids {
rows.AddRow(id, studyID, "", "obj_val", "", "")
rows.AddRow(id, studyID, "", "obj_val", "", "2019-02-26 09:54:32")
}
mock.ExpectQuery(`SELECT \* FROM trials WHERE study_id = \?`).WithArgs(studyID).WillReturnRows(rows)
trials, err := dbInterface.GetTrialList(studyID)
Expand Down