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

Fix a contour plot visualization issue with categorical parameters #988

Merged
merged 5 commits into from
Nov 6, 2024
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
2 changes: 1 addition & 1 deletion optuna_dashboard/ts/graphUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const getAxisInfoForCategoricalParams = (
)

const indices = distribution.choices
.map((c) => c?.toString() ?? "null")
.map((c) => c?.value ?? "null")
.sort((a, b) =>
a.toLowerCase() < b.toLowerCase()
? -1
Expand Down
2 changes: 1 addition & 1 deletion tslib/react/src/components/PlotTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Card, CardContent, Grid, Typography, useTheme } from "@mui/material"
import * as Optuna from "@optuna/types"
import * as plotly from "plotly.js-dist-min"
import { FC, useEffect } from "react"
import { makeHovertext } from "../utils/graphUtil"
import { makeHovertext } from "../utils/graph"
import { plotlyDarkTemplate } from "./PlotlyDarkMode"

const plotDomId = "graph-timeline"
Expand Down
15 changes: 6 additions & 9 deletions tslib/react/src/utils/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ export const makeHovertext = (trial: Optuna.Trial): string => {
{
number: trial.number,
values: trial.values,
params: trial.params
.map((p) => [p.name, p.param_external_value])
.reduce(
(obj, [key, value]) => {
obj[key as string] = value
return obj
},
{} as Record<string, Optuna.CategoricalChoiceType>
),
params: trial.params.reduce<{
[key: string]: string
}>((obj, p) => {
obj[p.name] = p.param_external_value
return obj
}, {}),
},
undefined,
" "
Expand Down
18 changes: 0 additions & 18 deletions tslib/react/src/utils/graphUtil.ts

This file was deleted.

4 changes: 2 additions & 2 deletions tslib/storage/src/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ const getTrialParams = (
const paramInternalValueToExternalValue = (
distribution: Optuna.Distribution,
internalValue: number
): Optuna.CategoricalChoiceType => {
) => {
if (distribution.type === "FloatDistribution") {
return internalValue.toString()
}
if (distribution.type === "IntDistribution") {
return internalValue.toString()
}
return distribution.choices[internalValue]
return distribution.choices[internalValue].value
}

const parseDistributionJSON = (t: string): Optuna.Distribution => {
Expand Down
7 changes: 5 additions & 2 deletions tslib/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export type IntDistribution = {
log: boolean
}

export type CategoricalChoiceType = null | boolean | number | string
export type CategoricalChoiceType = {
pytype: string
value: string
}

export type CategoricalDistribution = {
type: "CategoricalDistribution"
Expand Down Expand Up @@ -80,7 +83,7 @@ export type Trial = {
export type TrialParam = {
name: string
param_internal_value: number
param_external_value: CategoricalChoiceType
param_external_value: string
param_external_type: string
distribution: Distribution
}
Expand Down
Loading