From d76aeb502514d0a030cc0e6a7d5455619c7569d9 Mon Sep 17 00:00:00 2001 From: porink0424 Date: Wed, 6 Nov 2024 14:26:20 +0900 Subject: [PATCH 1/5] Update CategoricalChoiceType to object-like --- tslib/types/src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tslib/types/src/index.ts b/tslib/types/src/index.ts index c37be5b03..4b7d423c8 100644 --- a/tslib/types/src/index.ts +++ b/tslib/types/src/index.ts @@ -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" @@ -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 } From 78886832fee7b353ad50c69c2d81775328a1542d Mon Sep 17 00:00:00 2001 From: porink0424 Date: Wed, 6 Nov 2024 14:34:24 +0900 Subject: [PATCH 2/5] Delete duplicated unnecessary makeHovertext function --- tslib/react/src/utils/graph.ts | 15 ++++++--------- tslib/react/src/utils/graphUtil.ts | 18 ------------------ 2 files changed, 6 insertions(+), 27 deletions(-) delete mode 100644 tslib/react/src/utils/graphUtil.ts diff --git a/tslib/react/src/utils/graph.ts b/tslib/react/src/utils/graph.ts index 9c97acc49..94797435d 100644 --- a/tslib/react/src/utils/graph.ts +++ b/tslib/react/src/utils/graph.ts @@ -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 - ), + params: trial.params.reduce<{ + [key: string]: string + }>((obj, p) => { + obj[p.name] = p.param_external_value + return obj + }, {}), }, undefined, " " diff --git a/tslib/react/src/utils/graphUtil.ts b/tslib/react/src/utils/graphUtil.ts deleted file mode 100644 index 6f788dc5f..000000000 --- a/tslib/react/src/utils/graphUtil.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as Optuna from "@optuna/types" - -export const makeHovertext = (trial: Optuna.Trial): string => { - return JSON.stringify( - { - number: trial.number, - values: trial.values, - params: trial.params.reduce<{ - [key: string]: Optuna.CategoricalChoiceType - }>((obj, p) => { - obj[p.name] = p.param_external_value - return obj - }, {}), - }, - undefined, - " " - ).replace(/\n/g, "
") -} From 8be657d726e1e7319a5ed6ddba7f2a9035b57011 Mon Sep 17 00:00:00 2001 From: porink0424 Date: Wed, 6 Nov 2024 14:36:06 +0900 Subject: [PATCH 3/5] Align CategoricalChoiceType in optuna_dashboard --- optuna_dashboard/ts/graphUtil.ts | 2 +- tslib/react/src/components/PlotTimeline.tsx | 2 +- tslib/storage/src/sqlite.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/optuna_dashboard/ts/graphUtil.ts b/optuna_dashboard/ts/graphUtil.ts index 8f3a1f559..c9829a270 100644 --- a/optuna_dashboard/ts/graphUtil.ts +++ b/optuna_dashboard/ts/graphUtil.ts @@ -45,7 +45,7 @@ const getAxisInfoForCategoricalParams = ( ) const indices = distribution.choices - .map((c) => c?.toString() ?? "null") + .map((c) => c?.value.toString() ?? "null") .sort((a, b) => a.toLowerCase() < b.toLowerCase() ? -1 diff --git a/tslib/react/src/components/PlotTimeline.tsx b/tslib/react/src/components/PlotTimeline.tsx index 6cf8501fa..0d427265d 100644 --- a/tslib/react/src/components/PlotTimeline.tsx +++ b/tslib/react/src/components/PlotTimeline.tsx @@ -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" diff --git a/tslib/storage/src/sqlite.ts b/tslib/storage/src/sqlite.ts index 6702ba652..ee84a8f4c 100644 --- a/tslib/storage/src/sqlite.ts +++ b/tslib/storage/src/sqlite.ts @@ -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 => { From b0b2e419fd6cfe8ec0886e4efab3be4236ce3b93 Mon Sep 17 00:00:00 2001 From: porink0424 Date: Wed, 6 Nov 2024 14:39:14 +0900 Subject: [PATCH 4/5] Apply formatter --- tslib/types/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tslib/types/src/index.ts b/tslib/types/src/index.ts index 4b7d423c8..4500f0298 100644 --- a/tslib/types/src/index.ts +++ b/tslib/types/src/index.ts @@ -19,7 +19,7 @@ export type IntDistribution = { } export type CategoricalChoiceType = { - pytype: string, + pytype: string value: string } From ecf4730a2bc6c95ca882378127c7d2772e5c779f Mon Sep 17 00:00:00 2001 From: Daichi Kato <83964523+porink0424@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:55:25 +0900 Subject: [PATCH 5/5] Remove unnecessary toString() Co-authored-by: c-bata --- optuna_dashboard/ts/graphUtil.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna_dashboard/ts/graphUtil.ts b/optuna_dashboard/ts/graphUtil.ts index c9829a270..7131032f4 100644 --- a/optuna_dashboard/ts/graphUtil.ts +++ b/optuna_dashboard/ts/graphUtil.ts @@ -45,7 +45,7 @@ const getAxisInfoForCategoricalParams = ( ) const indices = distribution.choices - .map((c) => c?.value.toString() ?? "null") + .map((c) => c?.value ?? "null") .sort((a, b) => a.toLowerCase() < b.toLowerCase() ? -1