From 28dde7fd428e420c117a3533bb3dc1ad755926ae Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sun, 7 Jul 2024 15:40:11 +0900 Subject: [PATCH 01/23] Use tslib PlotImportance in optuna-dashboard --- .../GraphHyperparameterImportances.tsx | 129 +++--------------- standalone_app/src/components/StudyDetail.tsx | 4 +- tslib/react/src/components/PlotImportance.tsx | 19 +-- 3 files changed, 31 insertions(+), 121 deletions(-) diff --git a/optuna_dashboard/ts/components/GraphHyperparameterImportances.tsx b/optuna_dashboard/ts/components/GraphHyperparameterImportances.tsx index 33f6a4ea..6aadbba1 100644 --- a/optuna_dashboard/ts/components/GraphHyperparameterImportances.tsx +++ b/optuna_dashboard/ts/components/GraphHyperparameterImportances.tsx @@ -1,16 +1,13 @@ -import { Box, Card, CardContent, Typography, useTheme } from "@mui/material" +import { Box, Card, CardContent } from "@mui/material" import * as plotly from "plotly.js-dist-min" import React, { FC, useEffect } from "react" -import { ParamImportance, StudyDetail } from "ts/types/optuna" +import { PlotImportance } from "@optuna/react" +import { StudyDetail } from "ts/types/optuna" import { PlotType } from "../apiClient" import { useParamImportance } from "../hooks/useParamImportance" import { usePlot } from "../hooks/usePlot" -import { - useBackendRender, - usePlotlyColorTheme, - useStudyDirections, -} from "../state" +import { useBackendRender } from "../state" const plotDomId = "graph-hyperparameter-importances" @@ -19,6 +16,13 @@ export const GraphHyperparameterImportance: FC<{ study: StudyDetail | null graphHeight: string }> = ({ studyId, study = null, graphHeight }) => { + const numCompletedTrials = + study?.trials.filter((t) => t.state === "Complete").length || 0 + const { importances } = useParamImportance({ + numCompletedTrials, + studyId, + }) + if (useBackendRender()) { return ( + + + + + ) } } @@ -64,100 +72,3 @@ const GraphHyperparameterImportanceBackend: FC<{ return } - -const GraphHyperparameterImportanceFrontend: FC<{ - studyId: number - study: StudyDetail | null - graphHeight: string -}> = ({ studyId, study = null, graphHeight }) => { - const theme = useTheme() - const colorTheme = usePlotlyColorTheme(theme.palette.mode) - - const numCompletedTrials = - study?.trials.filter((t) => t.state === "Complete").length || 0 - const { importances } = useParamImportance({ - numCompletedTrials, - studyId, - }) - const nObjectives = useStudyDirections(studyId)?.length - const objectiveNames: string[] = - study?.objective_names || - study?.directions.map((d, i) => `Objective ${i}`) || - [] - - useEffect(() => { - if (importances !== undefined && nObjectives === importances.length) { - plotParamImportance(importances, objectiveNames, colorTheme) - } - }, [nObjectives, importances, colorTheme]) - - return ( - - - - Hyperparameter Importance - - - - - ) -} - -const plotParamImportance = ( - importances: ParamImportance[][], - objectiveNames: string[], - colorTheme: Partial -) => { - const layout: Partial = { - xaxis: { - title: "Hyperparameter Importance", - }, - yaxis: { - title: "Hyperparameter", - automargin: true, - }, - margin: { - l: 50, - t: 0, - r: 50, - b: 50, - }, - barmode: "group", - bargap: 0.15, - bargroupgap: 0.1, - uirevision: "true", - template: colorTheme, - legend: { - x: 1.0, - y: 0.95, - }, - } - - if (document.getElementById(plotDomId) === null) { - return - } - const traces: Partial[] = importances.map( - (importance, i) => { - const reversed = [...importance].reverse() - const importance_values = reversed.map((p) => p.importance) - const param_names = reversed.map((p) => p.name) - const param_hover_templates = reversed.map( - (p) => `${p.name} (${p.distribution}): ${p.importance} ` - ) - return { - type: "bar", - orientation: "h", - name: objectiveNames[i], - x: importance_values, - y: param_names, - text: importance_values.map((v) => String(v.toFixed(2))), - textposition: "outside", - hovertemplate: param_hover_templates, - } - } - ) - plotly.react(plotDomId, traces, layout) -} diff --git a/standalone_app/src/components/StudyDetail.tsx b/standalone_app/src/components/StudyDetail.tsx index 7d137f5b..e7647a37 100644 --- a/standalone_app/src/components/StudyDetail.tsx +++ b/standalone_app/src/components/StudyDetail.tsx @@ -180,9 +180,7 @@ export const StudyDetail: FC<{ - {!!study && ( - - )} + diff --git a/tslib/react/src/components/PlotImportance.tsx b/tslib/react/src/components/PlotImportance.tsx index f923e78d..9636c816 100644 --- a/tslib/react/src/components/PlotImportance.tsx +++ b/tslib/react/src/components/PlotImportance.tsx @@ -7,19 +7,20 @@ import { plotlyDarkTemplate } from "./PlotlyDarkMode" const plotDomId = "graph-hyperparameter-importances" export const PlotImportance: FC<{ - study: Optuna.Study - importance: Optuna.ParamImportance[][] -}> = ({ study, importance }) => { + study: Optuna.Study | null + importance?: Optuna.ParamImportance[][] + graphHeight?: string +}> = ({ study = null, importance, graphHeight = "450px" }) => { const theme = useTheme() - const objectiveNames: string[] = study.directions.map( - (_d, i) => `Objective ${i}` - ) + const objectiveNames: string[] = study + ? study.directions.map((_d, i) => `Objective ${i}`) + : [] useEffect(() => { - if (importance.length > 0) { + if (study !== null && importance !== undefined && importance.length > 0) { plotParamImportancesBeta(importance, objectiveNames, theme.palette.mode) } - }, [objectiveNames, importance, theme.palette.mode]) + }, [study, objectiveNames, importance, theme.palette.mode]) return ( <> @@ -29,7 +30,7 @@ export const PlotImportance: FC<{ > Hyperparameter Importance - + ) } From eb4a326317725ab1771de4d739637e4c6e0b554c Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Mon, 8 Jul 2024 16:10:09 +0900 Subject: [PATCH 02/23] Use tslib's IntermediateValue in optuna-dashboard --- .../ts/components/GraphIntermediateValues.tsx | 96 ++----------------- 1 file changed, 8 insertions(+), 88 deletions(-) diff --git a/optuna_dashboard/ts/components/GraphIntermediateValues.tsx b/optuna_dashboard/ts/components/GraphIntermediateValues.tsx index 3552f64a..eae2c43e 100644 --- a/optuna_dashboard/ts/components/GraphIntermediateValues.tsx +++ b/optuna_dashboard/ts/components/GraphIntermediateValues.tsx @@ -1,102 +1,22 @@ -import { Box, Card, CardContent, Typography, useTheme } from "@mui/material" -import * as plotly from "plotly.js-dist-min" -import React, { FC, useEffect } from "react" +import { Card, CardContent } from "@mui/material" +import { PlotIntermediateValues } from "@optuna/react" +import React, { FC } from "react" import { Trial } from "ts/types/optuna" -import { usePlotlyColorTheme } from "../state" - -const plotDomId = "graph-intermediate-values" export const GraphIntermediateValues: FC<{ trials: Trial[] includePruned: boolean logScale: boolean }> = ({ trials, includePruned, logScale }) => { - const theme = useTheme() - const colorTheme = usePlotlyColorTheme(theme.palette.mode) - - useEffect(() => { - plotIntermediateValue(trials, colorTheme, false, !includePruned, logScale) - }, [trials, colorTheme, includePruned, logScale]) - return ( - - Intermediate values - - + ) } - -const plotIntermediateValue = ( - trials: Trial[], - colorTheme: Partial, - filterCompleteTrial: boolean, - filterPrunedTrial: boolean, - logScale: boolean -) => { - if (document.getElementById(plotDomId) === null) { - return - } - - const layout: Partial = { - margin: { - l: 50, - t: 0, - r: 50, - b: 0, - }, - yaxis: { - title: "Objective Value", - type: logScale ? "log" : "linear", - }, - xaxis: { - title: "Step", - type: "linear", - }, - uirevision: "true", - template: colorTheme, - legend: { - x: 1.0, - y: 0.95, - }, - } - if (trials.length === 0) { - plotly.react(plotDomId, [], layout) - return - } - - const filteredTrials = trials.filter( - (t) => - (!filterCompleteTrial && t.state === "Complete") || - (!filterPrunedTrial && - t.state === "Pruned" && - t.values && - t.values.length > 0) || - t.state === "Running" - ) - const plotData: Partial[] = filteredTrials.map((trial) => { - const isFeasible = trial.constraints.every((c) => c <= 0) - return { - x: trial.intermediate_values.map((iv) => iv.step), - y: trial.intermediate_values.map((iv) => iv.value), - marker: { maxdisplayed: 10 }, - mode: "lines+markers", - type: "scatter", - name: `trial #${trial.number} ${ - trial.state === "Running" - ? "(running)" - : !isFeasible - ? "(infeasible)" - : "" - }`, - ...(!isFeasible && { line: { color: "#CCCCCC" } }), - } - }) - plotly.react(plotDomId, plotData, layout) -} From 3e353e6ef3059f450301bacd605d91ff423e303a Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Thu, 18 Jul 2024 16:14:04 +0900 Subject: [PATCH 03/23] Follow review comments --- tslib/react/src/components/PlotImportance.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tslib/react/src/components/PlotImportance.tsx b/tslib/react/src/components/PlotImportance.tsx index 9636c816..96807d2c 100644 --- a/tslib/react/src/components/PlotImportance.tsx +++ b/tslib/react/src/components/PlotImportance.tsx @@ -59,6 +59,10 @@ const plotParamImportancesBeta = ( bargroupgap: 0.1, uirevision: "true", template: mode === "dark" ? plotlyDarkTemplate : {}, + legend: { + x: 1.0, + y: 0.95, + }, } if (document.getElementById(plotDomId) === null) { From 5a60e18954868e236c28222a168707d1859ac115 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Thu, 18 Jul 2024 16:56:40 +0900 Subject: [PATCH 04/23] Follow review comments --- .../src/components/PlotIntermediateValues.tsx | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tslib/react/src/components/PlotIntermediateValues.tsx b/tslib/react/src/components/PlotIntermediateValues.tsx index d91c4506..ea339be7 100644 --- a/tslib/react/src/components/PlotIntermediateValues.tsx +++ b/tslib/react/src/components/PlotIntermediateValues.tsx @@ -64,6 +64,10 @@ const plotIntermediateValue = ( }, uirevision: "true", template: mode === "dark" ? plotlyDarkTemplate : {}, + legend: { + x: 1.0, + y: 0.95, + }, } if (trials.length === 0) { plotly.react(plotDomId, [], layout) @@ -79,23 +83,23 @@ const plotIntermediateValue = ( t.values.length > 0) || t.state === "Running" ) + const plotData: Partial[] = filteredTrials.map((trial) => { - const values = trial.intermediate_values.filter( - (iv) => - iv.value !== Infinity && - iv.value !== -Infinity && - !Number.isNaN(iv.value) - ) + const isFeasible = trial.constraints.every((c) => c <= 0) return { - x: values.map((iv) => iv.step), - y: values.map((iv) => iv.value), + x: trial.intermediate_values.map((iv) => iv.step), + y: trial.intermediate_values.map((iv) => iv.value), marker: { maxdisplayed: 10 }, mode: "lines+markers", type: "scatter", - name: - trial.state !== "Running" - ? `trial #${trial.number}` - : `trial #${trial.number} (running)`, + name: `trial #${trial.number} ${ + trial.state === "Running" + ? "(running)" + : !isFeasible + ? "(infeasible)" + : "" + }`, + ...(!isFeasible && { line: { color: "#CCCCCC" } }), } }) plotly.react(plotDomId, plotData, layout) From f10583753423cb0219f33113c1cf3475da927d78 Mon Sep 17 00:00:00 2001 From: pandega Date: Fri, 19 Jul 2024 18:57:44 +0700 Subject: [PATCH 05/23] fix(timeline): remove toISOString to make date axis more consistent --- optuna_dashboard/ts/components/GraphTimeline.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/optuna_dashboard/ts/components/GraphTimeline.tsx b/optuna_dashboard/ts/components/GraphTimeline.tsx index 766d4951..fbaff870 100644 --- a/optuna_dashboard/ts/components/GraphTimeline.tsx +++ b/optuna_dashboard/ts/components/GraphTimeline.tsx @@ -157,7 +157,7 @@ const plotTimeline = ( xaxis: { title: "Datetime", type: "date", - range: [minDatetime.toISOString(), maxDatetime.toISOString()], + range: [minDatetime, maxDatetime], }, yaxis: { title: "Trial", @@ -188,7 +188,7 @@ const plotTimeline = ( x: runDurations, y: bars.map((b) => b.number), // @ts-ignore: To suppress ts(2322) - base: starts.map((s) => s.toISOString()), + base: starts, name: state, text: bars.map((b) => makeHovertext(b)), hovertemplate: "%{text}" + state + "", From 00fc20531c297f81b82bffb82413394c844ec510 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Thu, 18 Jul 2024 17:19:52 +0900 Subject: [PATCH 06/23] Add distribution property in ParamImportance of tslib --- tslib/types/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tslib/types/src/index.ts b/tslib/types/src/index.ts index c37be5b0..60a90838 100644 --- a/tslib/types/src/index.ts +++ b/tslib/types/src/index.ts @@ -93,4 +93,5 @@ export type SearchSpaceItem = { export type ParamImportance = { name: string importance: number + distribution: Distribution } From cd9b714b3c7c3c1dce378e6a9ce59e475421077a Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 20 Jul 2024 14:55:42 +0900 Subject: [PATCH 07/23] Remove distribution property in ParamImportance --- optuna_dashboard/ts/types/optuna.ts | 6 ------ tslib/types/src/index.ts | 1 - 2 files changed, 7 deletions(-) diff --git a/optuna_dashboard/ts/types/optuna.ts b/optuna_dashboard/ts/types/optuna.ts index 01844f72..f69d008a 100644 --- a/optuna_dashboard/ts/types/optuna.ts +++ b/optuna_dashboard/ts/types/optuna.ts @@ -21,12 +21,6 @@ export type TrialParam = { distribution: Optuna.Distribution } -export type ParamImportance = { - name: string - importance: number - distribution: Optuna.Distribution -} - export type SearchSpaceItem = { name: string distribution: Optuna.Distribution diff --git a/tslib/types/src/index.ts b/tslib/types/src/index.ts index 60a90838..c37be5b0 100644 --- a/tslib/types/src/index.ts +++ b/tslib/types/src/index.ts @@ -93,5 +93,4 @@ export type SearchSpaceItem = { export type ParamImportance = { name: string importance: number - distribution: Distribution } From 7366550729eba5e2f0e4402c6992c48ca7f6ce6f Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 20 Jul 2024 15:02:08 +0900 Subject: [PATCH 08/23] Fix code in optuna-dashboard --- optuna_dashboard/ts/apiClient.ts | 7 ++++--- optuna_dashboard/ts/axiosClient.ts | 5 +++-- optuna_dashboard/ts/hooks/useParamImportance.ts | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/optuna_dashboard/ts/apiClient.ts b/optuna_dashboard/ts/apiClient.ts index f1a7ad8c..e618e21f 100644 --- a/optuna_dashboard/ts/apiClient.ts +++ b/optuna_dashboard/ts/apiClient.ts @@ -5,7 +5,6 @@ import { FeedbackComponentType, FormWidgets, Note, - ParamImportance, PlotlyGraphObject, PreferenceFeedbackMode, PreferenceHistory, @@ -113,7 +112,7 @@ export type UploadArtifactAPIResponse = { } export interface ParamImportancesResponse { - param_importances: ParamImportance[][] + param_importances: Optuna.ParamImportance[][] } export type PlotResponse = { @@ -228,7 +227,9 @@ export abstract class APIClient { trialId: number, user_attrs: { [key: string]: number | string } ): Promise - abstract getParamImportances(studyId: number): Promise + abstract getParamImportances( + studyId: number + ): Promise abstract reportPreference( studyId: number, candidates: number[], diff --git a/optuna_dashboard/ts/axiosClient.ts b/optuna_dashboard/ts/axiosClient.ts index bb2b811a..9b29f2db 100644 --- a/optuna_dashboard/ts/axiosClient.ts +++ b/optuna_dashboard/ts/axiosClient.ts @@ -15,7 +15,6 @@ import { } from "./apiClient" import { FeedbackComponentType, - ParamImportance, StudyDetail, StudySummary, Trial, @@ -230,7 +229,9 @@ export class AxiosClient extends APIClient { .then(() => { return }) - getParamImportances = (studyId: number): Promise => + getParamImportances = ( + studyId: number + ): Promise => this.axiosInstance .get( `/api/studies/${studyId}/param_importances` diff --git a/optuna_dashboard/ts/hooks/useParamImportance.ts b/optuna_dashboard/ts/hooks/useParamImportance.ts index 9cddaafa..e5baef6f 100644 --- a/optuna_dashboard/ts/hooks/useParamImportance.ts +++ b/optuna_dashboard/ts/hooks/useParamImportance.ts @@ -1,8 +1,8 @@ +import * as Optuna from "@optuna/types" import { useQuery } from "@tanstack/react-query" import { AxiosError } from "axios" import { useSnackbar } from "notistack" import { useEffect } from "react" -import { ParamImportance } from "ts/types/optuna" import { useAPIClient } from "../apiClientProvider" export const useParamImportance = ({ @@ -13,7 +13,7 @@ export const useParamImportance = ({ const { enqueueSnackbar } = useSnackbar() const { data, isLoading, error } = useQuery< - ParamImportance[][], + Optuna.ParamImportance[][], AxiosError<{ reason: string }> >({ queryKey: ["paramImportance", studyId, numCompletedTrials], From f33d705c1fdedee91d091bada36fa4ee88678d5f Mon Sep 17 00:00:00 2001 From: c-bata Date: Tue, 23 Jul 2024 16:47:00 +0900 Subject: [PATCH 09/23] Update type annotations in artifact module --- optuna_dashboard/artifact/_backend.py | 10 +++++----- optuna_dashboard/artifact/boto3.py | 3 +-- optuna_dashboard/artifact/exceptions.py | 3 +++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/optuna_dashboard/artifact/_backend.py b/optuna_dashboard/artifact/_backend.py index 6ea65987..3be9f4c8 100644 --- a/optuna_dashboard/artifact/_backend.py +++ b/optuna_dashboard/artifact/_backend.py @@ -74,7 +74,7 @@ def get_artifact_path( def register_artifact_route( - app: Bottle, storage: BaseStorage, artifact_store: Optional[ArtifactStore] + app: Bottle, storage: BaseStorage, artifact_store: ArtifactStore | None ) -> None: @app.get("/artifacts//") def proxy_study_artifact(study_id: int, artifact_id: str) -> HTTPResponse | bytes: @@ -243,8 +243,8 @@ def upload_artifact( trial: optuna.Trial, file_path: str, *, - mimetype: Optional[str] = None, - encoding: Optional[str] = None, + mimetype: str | None = None, + encoding: str | None = None, ) -> str: """Upload an artifact (files), which is associated with the trial. @@ -300,7 +300,7 @@ def _dashboard_artifact_prefix(trial_id: int) -> str: def get_study_artifact_meta( storage: BaseStorage, study_id: int, artifact_id: str -) -> Optional[ArtifactMeta]: +) -> ArtifactMeta | None: study_system_attrs = storage.get_study_system_attrs(study_id) attr_key = ARTIFACTS_ATTR_PREFIX + artifact_id artifact_meta = study_system_attrs.get(attr_key) @@ -311,7 +311,7 @@ def get_study_artifact_meta( def get_trial_artifact_meta( storage: BaseStorage, study_id: int, trial_id: int, artifact_id: str -) -> Optional[ArtifactMeta]: +) -> ArtifactMeta | None: # Search study_system_attrs due to backward compatibility. study_system_attrs = storage.get_study_system_attrs(study_id) attr_key = _dashboard_artifact_prefix(trial_id=trial_id) + artifact_id diff --git a/optuna_dashboard/artifact/boto3.py b/optuna_dashboard/artifact/boto3.py index 46edf165..a0dafd3d 100644 --- a/optuna_dashboard/artifact/boto3.py +++ b/optuna_dashboard/artifact/boto3.py @@ -12,7 +12,6 @@ from optuna_dashboard.artifact.exceptions import ArtifactNotFound if TYPE_CHECKING: from typing import BinaryIO - from typing import Optional from mypy_boto3_s3 import S3Client @@ -43,7 +42,7 @@ class Boto3Backend: """ def __init__( - self, bucket_name: str, client: Optional[S3Client] = None, *, avoid_buf_copy: bool = False + self, bucket_name: str, client: S3Client | None = None, *, avoid_buf_copy: bool = False ) -> None: self.bucket = bucket_name self.client = client or boto3.client("s3") diff --git a/optuna_dashboard/artifact/exceptions.py b/optuna_dashboard/artifact/exceptions.py index abc014df..78913f26 100644 --- a/optuna_dashboard/artifact/exceptions.py +++ b/optuna_dashboard/artifact/exceptions.py @@ -1,3 +1,6 @@ +from __future__ import annotations + + class ArtifactNotFound(Exception): """Exception raised when an artifact is not found. From 640f83ecff00de6d6d4280d37b4db33d3df3dd90 Mon Sep 17 00:00:00 2001 From: c-bata Date: Tue, 23 Jul 2024 16:49:37 +0900 Subject: [PATCH 10/23] Update type annotations in python_tests --- python_tests/artifact/test_backend.py | 2 ++ python_tests/artifact/test_backoff.py | 2 ++ python_tests/artifact/test_boto3.py | 2 ++ python_tests/artifact/test_file_system.py | 2 ++ python_tests/artifact/test_prefix.py | 2 ++ python_tests/preferential/samplers/test_gp.py | 2 ++ python_tests/streamlit/test_streamlit_helper.py | 7 ++++--- python_tests/wsgi_client.py | 8 +++----- 8 files changed, 19 insertions(+), 8 deletions(-) diff --git a/python_tests/artifact/test_backend.py b/python_tests/artifact/test_backend.py index 56fdf6f5..38333fe9 100644 --- a/python_tests/artifact/test_backend.py +++ b/python_tests/artifact/test_backend.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import base64 import json import tempfile diff --git a/python_tests/artifact/test_backoff.py b/python_tests/artifact/test_backoff.py index 5d99c1b7..cbcdafad 100644 --- a/python_tests/artifact/test_backoff.py +++ b/python_tests/artifact/test_backoff.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import io import uuid diff --git a/python_tests/artifact/test_boto3.py b/python_tests/artifact/test_boto3.py index 9a48fb3e..be82abfc 100644 --- a/python_tests/artifact/test_boto3.py +++ b/python_tests/artifact/test_boto3.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import io from unittest import TestCase diff --git a/python_tests/artifact/test_file_system.py b/python_tests/artifact/test_file_system.py index ceaaf125..07f1a890 100644 --- a/python_tests/artifact/test_file_system.py +++ b/python_tests/artifact/test_file_system.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import io import tempfile from unittest import TestCase diff --git a/python_tests/artifact/test_prefix.py b/python_tests/artifact/test_prefix.py index 87287d4c..39cdeb7f 100644 --- a/python_tests/artifact/test_prefix.py +++ b/python_tests/artifact/test_prefix.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import io import uuid diff --git a/python_tests/preferential/samplers/test_gp.py b/python_tests/preferential/samplers/test_gp.py index e5df9727..fba0023a 100644 --- a/python_tests/preferential/samplers/test_gp.py +++ b/python_tests/preferential/samplers/test_gp.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import sys from unittest.mock import patch diff --git a/python_tests/streamlit/test_streamlit_helper.py b/python_tests/streamlit/test_streamlit_helper.py index 8f324820..7745634d 100644 --- a/python_tests/streamlit/test_streamlit_helper.py +++ b/python_tests/streamlit/test_streamlit_helper.py @@ -1,6 +1,7 @@ +from __future__ import annotations + import itertools from typing import Sequence -from typing import Union import optuna from optuna_dashboard import ChoiceWidget @@ -60,7 +61,7 @@ for r in range(len(widget_list) + 1): @pytest.mark.parametrize("widgets", widgets_combinations_for_user_attr) def test_render_user_attr_form_widgets( - widgets: Sequence[Union[ChoiceWidget, SliderWidget, TextInputWidget]], + widgets: Sequence[ChoiceWidget | SliderWidget | TextInputWidget], ) -> None: study = optuna.create_study() register_user_attr_form_widgets(study, widgets) # type: ignore @@ -77,7 +78,7 @@ for r in range(1, len(widget_list) + 1): @pytest.mark.parametrize("widgets", widgets_combinations_for_objective) def test_render_objective_form_widgets( - widgets: Sequence[Union[ChoiceWidget, SliderWidget, TextInputWidget]], + widgets: Sequence[ChoiceWidget | SliderWidget | TextInputWidget], ) -> None: study = optuna.create_study(directions=["maximize"] * len(widgets)) register_objective_form_widgets(study, widgets) # type: ignore diff --git a/python_tests/wsgi_client.py b/python_tests/wsgi_client.py index 84fe8aac..0bf527bf 100644 --- a/python_tests/wsgi_client.py +++ b/python_tests/wsgi_client.py @@ -2,8 +2,6 @@ from __future__ import annotations import io import typing -from typing import Optional -from typing import Union from bottle import Bottle from optuna_dashboard._storage import trials_cache @@ -58,9 +56,9 @@ def send_request( app: Bottle, path: str, method: str, - body: Union[str, bytes] = b"", - queries: Optional[dict[str, str]] = None, - headers: Optional[dict[str, str]] = None, + body: str | bytes = b"", + queries: dict[str, str] | None = None, + headers: dict[str, str] | None = None, content_type: str = "text/plain; charset=utf-8", ) -> tuple[int, list[tuple[str, str]], bytes]: status: str = "" From 874829843b7a1da409e06473679520ce02dcbc8c Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 31 Jul 2024 08:33:33 +0200 Subject: [PATCH 11/23] Fix CSV artifact Viewer error --- optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx index 6fc01f02..96dfe222 100644 --- a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx +++ b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx @@ -55,7 +55,7 @@ export const TableArtifactViewer: React.FC = ( }) const keys = Array.from(unionSet) return keys.map((key) => ({ - header: key, + header: key || " ", accessorFn: (info: Data) => typeof info[key] === "object" ? JSON.stringify(info[key]) : info[key], enableSorting: true, From 71f85c01c204bf32154a64a7982772d5f7f49990 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 31 Jul 2024 08:39:56 +0200 Subject: [PATCH 12/23] Add an inline comment --- optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx index 96dfe222..a9a2414c 100644 --- a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx +++ b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx @@ -55,6 +55,7 @@ export const TableArtifactViewer: React.FC = ( }) const keys = Array.from(unionSet) return keys.map((key) => ({ + // ``header`` cannot be a falsy value, so replace key with a string looking like an empty string. header: key || " ", accessorFn: (info: Data) => typeof info[key] === "object" ? JSON.stringify(info[key]) : info[key], From 50171978330cca2ba7a2f6c8b312610ba83a5c28 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 31 Jul 2024 09:11:03 +0200 Subject: [PATCH 13/23] Add table artifact viewer for trial --- .../components/Artifact/TableArtifactViewer.tsx | 2 +- .../components/Artifact/TrialArtifactCards.tsx | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx index 6fc01f02..96dfe222 100644 --- a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx +++ b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx @@ -55,7 +55,7 @@ export const TableArtifactViewer: React.FC = ( }) const keys = Array.from(unionSet) return keys.map((key) => ({ - header: key, + header: key || " ", accessorFn: (info: Data) => typeof info[key] === "object" ? JSON.stringify(info[key]) : info[key], enableSorting: true, diff --git a/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx b/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx index fe7593ce..16171cb5 100644 --- a/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx +++ b/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx @@ -24,6 +24,7 @@ import { Trial } from "ts/types/optuna" import { actionCreator } from "../../action" import { ArtifactCardMedia } from "./ArtifactCardMedia" import { useDeleteTrialArtifactDialog } from "./DeleteArtifactDialog" +import { isTableArtifact, useTableArtifactModal } from "./TableArtifactViewer" import { isThreejsArtifact, useThreejsArtifactModal, @@ -35,6 +36,8 @@ export const TrialArtifactCards: FC<{ trial: Trial }> = ({ trial }) => { useDeleteTrialArtifactDialog() const [openThreejsArtifactModal, renderThreejsArtifactModal] = useThreejsArtifactModal() + const [openTableArtifactModal, renderTableArtifactModal] = + useTableArtifactModal() const isArtifactModifiable = (trial: Trial) => { return trial.state === "Running" || trial.state === "Waiting" } @@ -104,6 +107,19 @@ export const TrialArtifactCards: FC<{ trial: Trial }> = ({ trial }) => { ) : null} + {isTableArtifact(artifact) ? ( + { + openTableArtifactModal(urlPath, artifact) + }} + > + + + ) : null} {isArtifactModifiable(trial) ? ( = ({ trial }) => { {renderDeleteArtifactDialog()} {renderThreejsArtifactModal()} + {renderTableArtifactModal()} ) } From 72e93699881d491c50ab9ec7b3cc1473c3de8dbf Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 31 Jul 2024 09:13:35 +0200 Subject: [PATCH 14/23] Reduce diff --- optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx index 96dfe222..6fc01f02 100644 --- a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx +++ b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx @@ -55,7 +55,7 @@ export const TableArtifactViewer: React.FC = ( }) const keys = Array.from(unionSet) return keys.map((key) => ({ - header: key || " ", + header: key, accessorFn: (info: Data) => typeof info[key] === "object" ? JSON.stringify(info[key]) : info[key], enableSorting: true, From a65011aaeccafaffb319329e21136609143a9c42 Mon Sep 17 00:00:00 2001 From: c-bata Date: Wed, 31 Jul 2024 16:29:02 +0900 Subject: [PATCH 15/23] Fix the style of artifact card media --- .../ts/components/Artifact/ArtifactCardMedia.tsx | 2 +- .../ts/components/Artifact/TrialArtifactCards.tsx | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/optuna_dashboard/ts/components/Artifact/ArtifactCardMedia.tsx b/optuna_dashboard/ts/components/Artifact/ArtifactCardMedia.tsx index 7ea83290..c242fdb3 100644 --- a/optuna_dashboard/ts/components/Artifact/ArtifactCardMedia.tsx +++ b/optuna_dashboard/ts/components/Artifact/ArtifactCardMedia.tsx @@ -67,5 +67,5 @@ export const ArtifactCardMedia: FC<{ /> ) } - return + return } diff --git a/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx b/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx index 16171cb5..861bf122 100644 --- a/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx +++ b/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx @@ -66,6 +66,9 @@ export const TrialArtifactCards: FC<{ trial: Trial }> = ({ trial }) => { marginBottom: theme.spacing(2), width: width, margin: theme.spacing(0, 1, 1, 0), + display: "flex", + flexDirection: "column", + alignItems: "center" }} > = ({ trial }) => { sx={{ p: theme.spacing(0.5, 0), flexGrow: 1, - wordWrap: "break-word", + wordBreak: "break-all", maxWidth: `calc(100% - ${theme.spacing( 4 + (isThreejsArtifact(artifact) ? 4 : 0) + From 1e288ec3ffd929493bfafabb209032a21ec5fab6 Mon Sep 17 00:00:00 2001 From: c-bata Date: Wed, 31 Jul 2024 16:30:31 +0900 Subject: [PATCH 16/23] Fix lint errors --- optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx b/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx index 861bf122..e182988d 100644 --- a/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx +++ b/optuna_dashboard/ts/components/Artifact/TrialArtifactCards.tsx @@ -68,7 +68,7 @@ export const TrialArtifactCards: FC<{ trial: Trial }> = ({ trial }) => { margin: theme.spacing(0, 1, 1, 0), display: "flex", flexDirection: "column", - alignItems: "center" + alignItems: "center", }} > Date: Thu, 1 Aug 2024 14:35:41 +0900 Subject: [PATCH 17/23] Skip empty lines on CSV --- optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx index a9a2414c..644dbff2 100644 --- a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx +++ b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx @@ -143,6 +143,7 @@ const loadCSV = (props: TableArtifactViewerProps): Promise => { Papa.parse(props.src, { header: true, download: true, + skipEmptyLines: true, complete: (results: Papa.ParseResult) => { resolve(results?.data) }, From c5a7bf85bdcfdf7f392c5a80bb59c7b3285cab00 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Sat, 3 Aug 2024 17:33:40 +0200 Subject: [PATCH 18/23] Sort artifact cards by filename --- .../ts/components/Artifact/StudyArtifactCards.tsx | 11 ++++++++++- .../ts/components/Artifact/TrialArtifactCards.tsx | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/optuna_dashboard/ts/components/Artifact/StudyArtifactCards.tsx b/optuna_dashboard/ts/components/Artifact/StudyArtifactCards.tsx index 9fd12cf4..b24995f2 100644 --- a/optuna_dashboard/ts/components/Artifact/StudyArtifactCards.tsx +++ b/optuna_dashboard/ts/components/Artifact/StudyArtifactCards.tsx @@ -41,6 +41,15 @@ export const StudyArtifactCards: FC<{ study: StudyDetail }> = ({ study }) => { const width = "200px" const height = "150px" + const artifacts = [...study.artifacts].sort((a, b) => { + if (a.filename < b.filename) { + return -1 + } else if (a.filename > b.filename) { + return 1 + } else { + return 0 + } + }) return ( <> @@ -48,7 +57,7 @@ export const StudyArtifactCards: FC<{ study: StudyDetail }> = ({ study }) => { component="div" sx={{ display: "flex", flexWrap: "wrap", p: theme.spacing(1, 0) }} > - {study.artifacts.map((artifact) => { + {artifacts.map((artifact) => { const urlPath = `/artifacts/${study.id}/${artifact.artifact_id}` return ( = ({ trial }) => { const width = "200px" const height = "150px" + const artifacts = [...trial.artifacts].sort((a, b) => { + if (a.filename < b.filename) { + return -1 + } else if (a.filename > b.filename) { + return 1 + } else { + return 0 + } + }) return ( <> @@ -57,7 +66,7 @@ export const TrialArtifactCards: FC<{ trial: Trial }> = ({ trial }) => { component="div" sx={{ display: "flex", flexWrap: "wrap", p: theme.spacing(1, 0) }} > - {trial.artifacts.map((artifact) => { + {artifacts.map((artifact) => { const urlPath = `/artifacts/${trial.study_id}/${trial.trial_id}/${artifact.artifact_id}` return ( Date: Sun, 4 Aug 2024 17:52:04 +0900 Subject: [PATCH 19/23] Add plotly color theme to GraphEdf --- optuna_dashboard/ts/components/GraphEdf.tsx | 13 +++++++++++-- tslib/react/src/components/PlotEdf.tsx | 15 +++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/optuna_dashboard/ts/components/GraphEdf.tsx b/optuna_dashboard/ts/components/GraphEdf.tsx index 234b2e6f..d067f8f3 100644 --- a/optuna_dashboard/ts/components/GraphEdf.tsx +++ b/optuna_dashboard/ts/components/GraphEdf.tsx @@ -1,10 +1,11 @@ +import { useTheme } from "@mui/material" import { GraphContainer, PlotEdf, useGraphComponentState } from "@optuna/react" import * as plotly from "plotly.js-dist-min" import React, { FC, useEffect } from "react" import { StudyDetail } from "ts/types/optuna" import { CompareStudiesPlotType } from "../apiClient" import { useAPIClient } from "../apiClientProvider" -import { useBackendRender } from "../state" +import { useBackendRender, usePlotlyColorTheme } from "../state" export const GraphEdf: FC<{ studies: StudyDetail[] @@ -13,7 +14,15 @@ export const GraphEdf: FC<{ if (useBackendRender()) { return } else { - return + const theme = useTheme() + const colorTheme = usePlotlyColorTheme(theme.palette.mode) + return ( + + ) } } diff --git a/tslib/react/src/components/PlotEdf.tsx b/tslib/react/src/components/PlotEdf.tsx index 56dce17e..65281dcf 100644 --- a/tslib/react/src/components/PlotEdf.tsx +++ b/tslib/react/src/components/PlotEdf.tsx @@ -17,10 +17,13 @@ const getPlotDomId = (objectiveId: number) => `plot-edf-${objectiveId}` export const PlotEdf: FC<{ studies: Optuna.Study[] objectiveId: number -}> = ({ studies, objectiveId }) => { + colorTheme?: Partial +}> = ({ studies, objectiveId, colorTheme }) => { const { graphComponentState, notifyGraphDidRender } = useGraphComponentState() const theme = useTheme() + const colorThemeUsed = + colorTheme ?? (theme.palette.mode === "dark" ? plotlyDarkTemplate : {}) const domId = getPlotDomId(objectiveId) const target = useMemo( @@ -39,11 +42,11 @@ export const PlotEdf: FC<{ // biome-ignore lint/correctness/useExhaustiveDependencies: useEffect(() => { if (graphComponentState !== "componentWillMount") { - plotEdf(edfPlotInfos, target, domId, theme.palette.mode)?.then( + plotEdf(edfPlotInfos, target, domId, colorThemeUsed)?.then( notifyGraphDidRender ) } - }, [studies, target, theme.palette.mode, graphComponentState]) + }, [studies, target, colorThemeUsed, graphComponentState]) return ( @@ -65,14 +68,14 @@ const plotEdf = ( edfPlotInfos: EdfPlotInfo[], target: Target, domId: string, - mode: string + colorTheme: Partial ) => { if (document.getElementById(domId) === null) { return } if (edfPlotInfos.length === 0) { return plotly.react(domId, [], { - template: mode === "dark" ? plotlyDarkTemplate : {}, + template: colorTheme, }) } @@ -90,7 +93,7 @@ const plotEdf = ( r: 50, b: 50, }, - template: mode === "dark" ? plotlyDarkTemplate : {}, + template: colorTheme, legend: { x: 1.0, y: 0.95, From abe7c3983931c8dbb7b730a5b77559c9d1c43add Mon Sep 17 00:00:00 2001 From: c-bata Date: Wed, 7 Aug 2024 19:18:43 +0900 Subject: [PATCH 20/23] Remove recoil dependency from @optuna/storage --- optuna_dashboard/package-lock.json | 25 +----------------- standalone_app/package-lock.json | 3 +-- tslib/react/package-lock.json | 27 +------------------- tslib/react/package.json | 3 +-- tslib/react/src/utils/loadStorageFromFile.ts | 3 ++- 5 files changed, 6 insertions(+), 55 deletions(-) diff --git a/optuna_dashboard/package-lock.json b/optuna_dashboard/package-lock.json index 0513b6c2..a26d6e09 100644 --- a/optuna_dashboard/package-lock.json +++ b/optuna_dashboard/package-lock.json @@ -76,8 +76,7 @@ "@tanstack/react-table": "^8.17.3", "plotly.js-dist-min": "^2.30.1", "react": "^18.2.0", - "react-dom": "^18.2.0", - "recoil": "^0.7.7" + "react-dom": "^18.2.0" }, "devDependencies": { "@optuna/types": "file:../types", @@ -7185,10 +7184,6 @@ "gunzip-maybe": "bin.js" } }, - "../tslib/react/node_modules/hamt_plus": { - "version": "1.0.2", - "license": "MIT" - }, "../tslib/react/node_modules/handlebars": { "version": "4.7.8", "dev": true, @@ -9943,24 +9938,6 @@ "dev": true, "license": "0BSD" }, - "../tslib/react/node_modules/recoil": { - "version": "0.7.7", - "license": "MIT", - "dependencies": { - "hamt_plus": "1.0.2" - }, - "peerDependencies": { - "react": ">=16.13.1" - }, - "peerDependenciesMeta": { - "react-dom": { - "optional": true - }, - "react-native": { - "optional": true - } - } - }, "../tslib/react/node_modules/redent": { "version": "3.0.0", "dev": true, diff --git a/standalone_app/package-lock.json b/standalone_app/package-lock.json index 67c7ef31..a90f2302 100644 --- a/standalone_app/package-lock.json +++ b/standalone_app/package-lock.json @@ -60,8 +60,7 @@ "@tanstack/react-table": "^8.17.3", "plotly.js-dist-min": "^2.30.1", "react": "^18.2.0", - "react-dom": "^18.2.0", - "recoil": "^0.7.7" + "react-dom": "^18.2.0" }, "devDependencies": { "@optuna/types": "file:../types", diff --git a/tslib/react/package-lock.json b/tslib/react/package-lock.json index 1ef5fac4..513fca4d 100644 --- a/tslib/react/package-lock.json +++ b/tslib/react/package-lock.json @@ -19,8 +19,7 @@ "@tanstack/react-table": "^8.17.3", "plotly.js-dist-min": "^2.30.1", "react": "^18.2.0", - "react-dom": "^18.2.0", - "recoil": "^0.7.7" + "react-dom": "^18.2.0" }, "devDependencies": { "@optuna/types": "file:../types", @@ -8409,11 +8408,6 @@ "gunzip-maybe": "bin.js" } }, - "node_modules/hamt_plus": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/hamt_plus/-/hamt_plus-1.0.2.tgz", - "integrity": "sha512-t2JXKaehnMb9paaYA7J0BX8QQAY8lwfQ9Gjf4pg/mk4krt+cmwmU652HOoWonf+7+EQV97ARPMhhVgU1ra2GhA==" - }, "node_modules/handlebars": { "version": "4.7.8", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz", @@ -11430,25 +11424,6 @@ "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==", "dev": true }, - "node_modules/recoil": { - "version": "0.7.7", - "resolved": "https://registry.npmjs.org/recoil/-/recoil-0.7.7.tgz", - "integrity": "sha512-8Og5KPQW9LwC577Vc7Ug2P0vQshkv1y3zG3tSSkWMqkWSwHmE+by06L8JtnGocjW6gcCvfwB3YtrJG6/tWivNQ==", - "dependencies": { - "hamt_plus": "1.0.2" - }, - "peerDependencies": { - "react": ">=16.13.1" - }, - "peerDependenciesMeta": { - "react-dom": { - "optional": true - }, - "react-native": { - "optional": true - } - } - }, "node_modules/redent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", diff --git a/tslib/react/package.json b/tslib/react/package.json index cbb072c8..df193489 100644 --- a/tslib/react/package.json +++ b/tslib/react/package.json @@ -36,8 +36,7 @@ "@tanstack/react-table": "^8.17.3", "plotly.js-dist-min": "^2.30.1", "react": "^18.2.0", - "react-dom": "^18.2.0", - "recoil": "^0.7.7" + "react-dom": "^18.2.0" }, "devDependencies": { "@optuna/types": "file:../types", diff --git a/tslib/react/src/utils/loadStorageFromFile.ts b/tslib/react/src/utils/loadStorageFromFile.ts index eac68ac4..abc298b9 100644 --- a/tslib/react/src/utils/loadStorageFromFile.ts +++ b/tslib/react/src/utils/loadStorageFromFile.ts @@ -1,6 +1,7 @@ import { JournalFileStorage, SQLite3Storage } from "@optuna/storage" import * as Optuna from "@optuna/types" -import { SetterOrUpdater } from "recoil" + +type SetterOrUpdater = (valOrUpdater: ((currVal: T) => T) | T) => void const readFile = async (file: File) => { return new Promise((resolve, reject) => { From 91faf1b33df5f120de849830054179a86a8f8dda Mon Sep 17 00:00:00 2001 From: c-bata Date: Wed, 7 Aug 2024 19:40:12 +0900 Subject: [PATCH 21/23] Remoev @optuna/storage dependency from @optuna/react --- optuna_dashboard/package-lock.json | 4 +++- standalone_app/package-lock.json | 2 +- tslib/react/package-lock.json | 3 ++- tslib/react/package.json | 2 +- tslib/react/{src/utils => test}/loadStorageFromFile.ts | 0 tslib/react/test/setup_studies.ts | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) rename tslib/react/{src/utils => test}/loadStorageFromFile.ts (100%) diff --git a/optuna_dashboard/package-lock.json b/optuna_dashboard/package-lock.json index a26d6e09..247fb1cf 100644 --- a/optuna_dashboard/package-lock.json +++ b/optuna_dashboard/package-lock.json @@ -72,13 +72,13 @@ "@mui/lab": "^5.0.0-alpha.170", "@mui/material": "^5.15.10", "@mui/system": "^5.15.9", - "@optuna/storage": "file:../storage", "@tanstack/react-table": "^8.17.3", "plotly.js-dist-min": "^2.30.1", "react": "^18.2.0", "react-dom": "^18.2.0" }, "devDependencies": { + "@optuna/storage": "file:../storage", "@optuna/types": "file:../types", "@storybook/addon-essentials": "^8.0.4", "@storybook/addon-interactions": "^8.0.4", @@ -12065,6 +12065,7 @@ "../tslib/storage": { "name": "@optuna/storage", "version": "0.0.1", + "dev": true, "license": "MIT", "dependencies": { "@sqlite.org/sqlite-wasm": "^3.45.1-build1" @@ -12080,6 +12081,7 @@ }, "../tslib/storage/node_modules/@sqlite.org/sqlite-wasm": { "version": "3.45.1-build1", + "dev": true, "license": "Apache-2.0", "bin": { "sqlite-wasm": "bin/index.js" diff --git a/standalone_app/package-lock.json b/standalone_app/package-lock.json index a90f2302..9ee8c8d7 100644 --- a/standalone_app/package-lock.json +++ b/standalone_app/package-lock.json @@ -56,13 +56,13 @@ "@mui/lab": "^5.0.0-alpha.170", "@mui/material": "^5.15.10", "@mui/system": "^5.15.9", - "@optuna/storage": "file:../storage", "@tanstack/react-table": "^8.17.3", "plotly.js-dist-min": "^2.30.1", "react": "^18.2.0", "react-dom": "^18.2.0" }, "devDependencies": { + "@optuna/storage": "file:../storage", "@optuna/types": "file:../types", "@storybook/addon-essentials": "^8.0.4", "@storybook/addon-interactions": "^8.0.4", diff --git a/tslib/react/package-lock.json b/tslib/react/package-lock.json index 513fca4d..a0ef388c 100644 --- a/tslib/react/package-lock.json +++ b/tslib/react/package-lock.json @@ -15,13 +15,13 @@ "@mui/lab": "^5.0.0-alpha.170", "@mui/material": "^5.15.10", "@mui/system": "^5.15.9", - "@optuna/storage": "file:../storage", "@tanstack/react-table": "^8.17.3", "plotly.js-dist-min": "^2.30.1", "react": "^18.2.0", "react-dom": "^18.2.0" }, "devDependencies": { + "@optuna/storage": "file:../storage", "@optuna/types": "file:../types", "@storybook/addon-essentials": "^8.0.4", "@storybook/addon-interactions": "^8.0.4", @@ -46,6 +46,7 @@ "../storage": { "name": "@optuna/storage", "version": "0.0.1", + "dev": true, "license": "MIT", "dependencies": { "@sqlite.org/sqlite-wasm": "^3.45.1-build1" diff --git a/tslib/react/package.json b/tslib/react/package.json index df193489..bb920b8c 100644 --- a/tslib/react/package.json +++ b/tslib/react/package.json @@ -32,7 +32,6 @@ "@mui/lab": "^5.0.0-alpha.170", "@mui/material": "^5.15.10", "@mui/system": "^5.15.9", - "@optuna/storage": "file:../storage", "@tanstack/react-table": "^8.17.3", "plotly.js-dist-min": "^2.30.1", "react": "^18.2.0", @@ -40,6 +39,7 @@ }, "devDependencies": { "@optuna/types": "file:../types", + "@optuna/storage": "file:../storage", "@storybook/addon-essentials": "^8.0.4", "@storybook/addon-interactions": "^8.0.4", "@storybook/addon-links": "^8.0.4", diff --git a/tslib/react/src/utils/loadStorageFromFile.ts b/tslib/react/test/loadStorageFromFile.ts similarity index 100% rename from tslib/react/src/utils/loadStorageFromFile.ts rename to tslib/react/test/loadStorageFromFile.ts diff --git a/tslib/react/test/setup_studies.ts b/tslib/react/test/setup_studies.ts index e3c77059..905d448d 100644 --- a/tslib/react/test/setup_studies.ts +++ b/tslib/react/test/setup_studies.ts @@ -1,6 +1,6 @@ import fs from "node:fs" import * as Optuna from "@optuna/types" -import { loadStorageFromFile } from "../src/utils/loadStorageFromFile" +import { loadStorageFromFile } from "./loadStorageFromFile" declare global { interface Window { From 0fed50681711d8b6cd2693ccff0fe0c34e494361 Mon Sep 17 00:00:00 2001 From: c-bata Date: Wed, 7 Aug 2024 21:50:58 +0900 Subject: [PATCH 22/23] Fix the build of vscode extension --- .github/workflows/typescript-tests.yml | 10 ++++++++++ standalone_app/webpack.config.js | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/.github/workflows/typescript-tests.yml b/.github/workflows/typescript-tests.yml index 26c98501..33c7725d 100644 --- a/.github/workflows/typescript-tests.yml +++ b/.github/workflows/typescript-tests.yml @@ -112,6 +112,16 @@ jobs: - name: Setup tslib run: make tslib + - name: Build standalone_app for vscode extension + working-directory: standalone_app + run: | + npm run build:vscode + + - name: Build standalone_app for GitHub pages + working-directory: standalone_app + run: | + npx vite build --out-dir ./gh-pages + - name: Build bundle.js working-directory: optuna_dashboard run: | diff --git a/standalone_app/webpack.config.js b/standalone_app/webpack.config.js index 4c599a49..ed589617 100644 --- a/standalone_app/webpack.config.js +++ b/standalone_app/webpack.config.js @@ -36,6 +36,12 @@ module.exports = { test: /\.wasm$/, type: "asset/inline", }, + { + test: /\.m?js/, + resolve: { + fullySpecified: false + } + } ] }, resolve: { From 5c995c4bff67d9328d4942630b08d820c0207ac3 Mon Sep 17 00:00:00 2001 From: c-bata Date: Wed, 7 Aug 2024 21:59:37 +0900 Subject: [PATCH 23/23] Fix github workflow --- .github/workflows/typescript-tests.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/typescript-tests.yml b/.github/workflows/typescript-tests.yml index 33c7725d..88f186c5 100644 --- a/.github/workflows/typescript-tests.yml +++ b/.github/workflows/typescript-tests.yml @@ -109,17 +109,25 @@ jobs: with: node-version: '20' + - name: Build rustlib for standalone_app + working-directory: rustlib + run: | + curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + wasm-pack build --target web + - name: Setup tslib run: make tslib - name: Build standalone_app for vscode extension working-directory: standalone_app run: | + npm install npm run build:vscode - name: Build standalone_app for GitHub pages working-directory: standalone_app run: | + npm install npx vite build --out-dir ./gh-pages - name: Build bundle.js