Skip to content

Commit

Permalink
fix: update experiment hp search param quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
erikwilson committed Dec 27, 2023
1 parent b50a810 commit 53ad6e3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion master/internal/api_experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2495,7 +2495,8 @@ func sortExperiments(sortString *string, experimentQuery *bun.SelectQuery) error
sortDirection := sortByMap[paramDetail[1]]
switch {
case strings.HasPrefix(paramDetail[0], "hp."):
hps := strings.ReplaceAll(strings.TrimPrefix(paramDetail[0], "hp."), ".", "'->'")
param := strings.ReplaceAll(paramDetail[0], "'", "")
hps := strings.ReplaceAll(strings.TrimPrefix(param, "hp."), ".", "'->'")
experimentQuery.OrderExpr(
fmt.Sprintf("e.config->'hyperparameters'->'%s' %s", hps, sortDirection))
case strings.Contains(paramDetail[0], "."):
Expand Down
29 changes: 29 additions & 0 deletions master/internal/api_experiment_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,35 @@ func TestSearchExperiments(t *testing.T) {
require.Equal(t, int32(5), resp.Experiments[2].BestTrial.Restarts)
}

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

// No trial doesn't cause errors.
exp := createTestExpWithProjectID(t, api, curUser, projectIDInt)

req := &apiv1.SearchExperimentsRequest{
ProjectId: &projectID,
Sort: ptrs.Ptr("wow.it's.mean=asc"),
}
resp, err := api.SearchExperiments(ctx, req)
require.NoError(t, err)
require.Len(t, resp.Experiments, 1)
require.Nil(t, resp.Experiments[0].BestTrial)
require.Equal(t, int32(exp.ID), resp.Experiments[0].Experiment.Id)

req = &apiv1.SearchExperimentsRequest{
ProjectId: &projectID,
Sort: ptrs.Ptr("hp.tests'=asc"),
}
resp, err = api.SearchExperiments(ctx, req)
require.NoError(t, err)
require.Len(t, resp.Experiments, 1)
require.Nil(t, resp.Experiments[0].BestTrial)
require.Equal(t, int32(exp.ID), resp.Experiments[0].Experiment.Id)
}

// Test that endpoints don't puke when running against old experiments.
func TestLegacyExperiments(t *testing.T) {
err := etc.SetRootPath("../static/srv")
Expand Down

0 comments on commit 53ad6e3

Please sign in to comment.