Skip to content

Commit

Permalink
fix: run columns mismatching sort/filter columns for run table (#9479)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmanuelAaron authored Jun 11, 2024
1 parent de03909 commit aa6521b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
12 changes: 12 additions & 0 deletions master/internal/api_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ var defaultRunsTableColumns = []*projectv1.ProjectColumn{
Location: projectv1.LocationType_LOCATION_TYPE_RUN,
Type: projectv1.ColumnType_COLUMN_TYPE_DATE,
},
{
Column: "endTime",
DisplayName: "End Time",
Location: projectv1.LocationType_LOCATION_TYPE_RUN,
Type: projectv1.ColumnType_COLUMN_TYPE_DATE,
},
{
Column: "duration",
DisplayName: "Duration",
Expand Down Expand Up @@ -120,6 +126,12 @@ var defaultRunsTableColumns = []*projectv1.ProjectColumn{
Location: projectv1.LocationType_LOCATION_TYPE_RUN,
Type: projectv1.ColumnType_COLUMN_TYPE_TEXT,
},
{
Column: "projectId",
DisplayName: "Project ID",
Location: projectv1.LocationType_LOCATION_TYPE_RUN,
Type: projectv1.ColumnType_COLUMN_TYPE_NUMBER,
},
{
Column: "externalRunId",
DisplayName: "External Run ID",
Expand Down
2 changes: 1 addition & 1 deletion master/internal/api_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func sortRuns(sortString *string, runQuery *bun.SelectQuery) error {
"checkpointSize": "checkpoint_size",
"checkpointCount": "checkpoint_count",
"duration": "duration",
"searcherMetricsVal": "r.searcher_metric_val",
"searcherMetricsVal": "r.searcher_metric_value",
"externalExperimentId": "e.external_experiment_id",
"externalRunId": "r.external_run_id",
"experimentId": "e.id",
Expand Down
59 changes: 59 additions & 0 deletions master/internal/api_runs_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,65 @@ func TestSearchRunsArchivedExperiment(t *testing.T) {
require.Empty(t, resp.Runs)
}

func TestSearchRunsSortAndFilterAllDefaultColumns(t *testing.T) {
api, curUser, ctx := setupAPITest(t, nil)
_, projectIDInt := createProjectAndWorkspace(ctx, t, api)
projectID := int32(projectIDInt)

req := &apiv1.SearchRunsRequest{
ProjectId: &projectID,
Sort: ptrs.Ptr("id=asc"),
}

hyperparameters := map[string]any{"global_batch_size": 1, "test1": map[string]any{"test2": 1}}

exp := createTestExpWithProjectID(t, api, curUser, projectIDInt)

task := &model.Task{TaskType: model.TaskTypeTrial, TaskID: model.NewTaskID()}
require.NoError(t, db.AddTask(ctx, task))
require.NoError(t, db.AddTrial(ctx, &model.Trial{
State: model.PausedState,
ExperimentID: exp.ID,
StartTime: time.Now(),
HParams: hyperparameters,
}, task.TaskID))

resp, err := api.SearchRuns(ctx, req)
require.NoError(t, err)
require.Len(t, resp.Runs, 1)

hyperparameters2 := map[string]any{"global_batch_size": 2, "test1": map[string]any{"test2": 5}}

// Add second experiment
exp2 := createTestExpWithProjectID(t, api, curUser, projectIDInt)

task2 := &model.Task{TaskType: model.TaskTypeTrial, TaskID: model.NewTaskID()}
require.NoError(t, db.AddTask(ctx, task2))
require.NoError(t, db.AddTrial(ctx, &model.Trial{
State: model.PausedState,
ExperimentID: exp2.ID,
StartTime: time.Now(),
HParams: hyperparameters2,
}, task2.TaskID))

for _, c := range defaultRunsTableColumns {
if c.Column == "tags" {
continue
}

filter := fmt.Sprintf(`{"filterGroup":{"children":[{"columnName":"%s","kind":"field",`+
`"location":"%s","operator":"=","type":"%s","value":null}],`+
`"conjunction":"and","kind":"group"},"showArchived":false}`, c.Column, c.Location.String(), c.Type.String())
_, err = api.SearchRuns(ctx, &apiv1.SearchRunsRequest{
ProjectId: req.ProjectId,
Sort: ptrs.Ptr(c.Column + "=asc"),
Filter: ptrs.Ptr(filter),
})

require.NoError(t, err)
}
}

func TestSearchRunsSort(t *testing.T) {
api, curUser, ctx := setupAPITest(t, nil)
_, projectIDInt := createProjectAndWorkspace(ctx, t, api)
Expand Down
4 changes: 3 additions & 1 deletion master/internal/experiment_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ func runColumnNameToSQL(columnName string) (string, error) {
"checkpointCount": "e.checkpoint_count",
"searcherMetricsVal": "r.searcher_metric_value",
"externalExperimentId": "e.external_experiment_id",
"externalTrialId": "r.external_run_id",
"externalRunId": "r.external_run_id",
"experimentId": "e.id",
"isExpMultitrial": "e.config->'searcher'->>'name' != 'single'",
"parentArchived": "(w.archived OR p.archived)",
}
var exists bool
col, exists := filterExperimentColMap[columnName]
Expand Down

0 comments on commit aa6521b

Please sign in to comment.