From a84d8e9927ac87690a595b90ca2861e7570b1284 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 5 Aug 2023 16:05:30 +0900 Subject: [PATCH 1/7] Fix action.ts and DataGrid.tsx --- optuna_dashboard/ts/action.ts | 10 ++++++++-- optuna_dashboard/ts/components/DataGrid.tsx | 11 +++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/optuna_dashboard/ts/action.ts b/optuna_dashboard/ts/action.ts index 67210906..96fde064 100644 --- a/optuna_dashboard/ts/action.ts +++ b/optuna_dashboard/ts/action.ts @@ -34,6 +34,7 @@ type LocalStorageReloadInterval = { reloadInterval?: number } +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export const actionCreator = () => { const { enqueueSnackbar } = useSnackbar() const [studySummaries, setStudySummaries] = @@ -432,8 +433,13 @@ export const actionCreator = () => { const reader = new FileReader() setUploading(true) reader.readAsDataURL(file) - reader.onload = (upload: any) => { - uploadArtifactAPI(studyId, trialId, file.name, upload.target.result) + reader.onload = (upload: ProgressEvent) => { + uploadArtifactAPI( + studyId, + trialId, + file.name, + upload.target?.result as string + ) .then((res) => { setUploading(false) const index = studyDetails[studyId].trials.findIndex( diff --git a/optuna_dashboard/ts/components/DataGrid.tsx b/optuna_dashboard/ts/components/DataGrid.tsx index 22b63e53..2d6a5670 100644 --- a/optuna_dashboard/ts/components/DataGrid.tsx +++ b/optuna_dashboard/ts/components/DataGrid.tsx @@ -19,6 +19,9 @@ import { Clear } from "@mui/icons-material" type Order = "asc" | "desc" +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type Value = any + const defaultRowsPerPageOption = [10, 50, 100, { label: "All", value: -1 }] interface DataGridColumn { @@ -33,7 +36,7 @@ interface DataGridColumn { interface RowFilter { columnIdx: number - value: any + value: Value } function DataGrid(props: { @@ -45,7 +48,7 @@ function DataGrid(props: { initialRowsPerPage?: number rowsPerPageOption?: Array defaultFilter?: (row: T) => boolean -}) { +}): React.ReactElement { const { columns, rows, keyField, dense, collapseBody, defaultFilter } = props let { initialRowsPerPage, rowsPerPageOption } = props const [order, setOrder] = React.useState("asc") @@ -81,7 +84,7 @@ function DataGrid(props: { const fieldAlreadyFiltered = (columnIdx: number): boolean => filters.some((f) => f.columnIdx === columnIdx) - const handleClickFilterCell = (columnIdx: number, value: any) => { + const handleClickFilterCell = (columnIdx: number, value: Value) => { if (fieldAlreadyFiltered(columnIdx)) { return } @@ -242,7 +245,7 @@ function DataGridRow(props: { row: T keyField: keyof T collapseBody?: (rowIndex: number) => React.ReactNode - handleClickFilterCell: (columnIdx: number, value: any) => void + handleClickFilterCell: (columnIdx: number, value: Value) => void }) { const { columns, From ac242020294ba98a1125f513706c9bd20fd02260 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 5 Aug 2023 16:12:44 +0900 Subject: [PATCH 2/7] Fix GraphHistory.tsx --- optuna_dashboard/ts/components/GraphHistory.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/optuna_dashboard/ts/components/GraphHistory.tsx b/optuna_dashboard/ts/components/GraphHistory.tsx index 3093d82b..0b77e563 100644 --- a/optuna_dashboard/ts/components/GraphHistory.tsx +++ b/optuna_dashboard/ts/components/GraphHistory.tsx @@ -17,10 +17,8 @@ import { } from "@mui/material" import { plotlyDarkTemplate } from "./PlotlyDarkMode" import { - useFilteredTrials, useFilteredTrialsFromStudies, Target, - useObjectiveAndUserAttrTargets, useObjectiveAndUserAttrTargetsFromStudies, } from "../trialFilter" @@ -216,8 +214,8 @@ const plotHistory = ( return xAxis === "number" ? trial.number : xAxis === "datetime_start" - ? trial.datetime_start! - : trial.datetime_complete! + ? trial.datetime_start ?? new Date() + : trial.datetime_complete ?? new Date() } const plotData: Partial[] = [] From a0c3ba01e8706c670e608b72eb86599641610fde Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 5 Aug 2023 16:16:49 +0900 Subject: [PATCH 3/7] Fix GraphParetoFront.tsx --- optuna_dashboard/ts/components/GraphParetoFront.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/optuna_dashboard/ts/components/GraphParetoFront.tsx b/optuna_dashboard/ts/components/GraphParetoFront.tsx index 457ab875..abcf667d 100644 --- a/optuna_dashboard/ts/components/GraphParetoFront.tsx +++ b/optuna_dashboard/ts/components/GraphParetoFront.tsx @@ -114,8 +114,12 @@ const makeScatterObject = ( ): Partial => { const marker = makeMarker(trials, dominated, feasible, mode) return { - x: trials.map((t) => t.values![objectiveXId] as number), - y: trials.map((t) => t.values![objectiveYId] as number), + x: trials.map((t) => + t.values ? (t.values[objectiveXId] as number) : null + ), + y: trials.map((t) => + t.values ? (t.values[objectiveYId] as number) : null + ), text: trials.map((t) => makeHovertext(t)), mode: "markers", hovertemplate: hovertemplate, From 17bdb2025750f65f4cd869d436eae5bf6bd1302f Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 5 Aug 2023 16:21:10 +0900 Subject: [PATCH 4/7] DataGrid.tsx --- standalone_app/src/components/DataGrid.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/standalone_app/src/components/DataGrid.tsx b/standalone_app/src/components/DataGrid.tsx index 22b63e53..2d6a5670 100644 --- a/standalone_app/src/components/DataGrid.tsx +++ b/standalone_app/src/components/DataGrid.tsx @@ -19,6 +19,9 @@ import { Clear } from "@mui/icons-material" type Order = "asc" | "desc" +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type Value = any + const defaultRowsPerPageOption = [10, 50, 100, { label: "All", value: -1 }] interface DataGridColumn { @@ -33,7 +36,7 @@ interface DataGridColumn { interface RowFilter { columnIdx: number - value: any + value: Value } function DataGrid(props: { @@ -45,7 +48,7 @@ function DataGrid(props: { initialRowsPerPage?: number rowsPerPageOption?: Array defaultFilter?: (row: T) => boolean -}) { +}): React.ReactElement { const { columns, rows, keyField, dense, collapseBody, defaultFilter } = props let { initialRowsPerPage, rowsPerPageOption } = props const [order, setOrder] = React.useState("asc") @@ -81,7 +84,7 @@ function DataGrid(props: { const fieldAlreadyFiltered = (columnIdx: number): boolean => filters.some((f) => f.columnIdx === columnIdx) - const handleClickFilterCell = (columnIdx: number, value: any) => { + const handleClickFilterCell = (columnIdx: number, value: Value) => { if (fieldAlreadyFiltered(columnIdx)) { return } @@ -242,7 +245,7 @@ function DataGridRow(props: { row: T keyField: keyof T collapseBody?: (rowIndex: number) => React.ReactNode - handleClickFilterCell: (columnIdx: number, value: any) => void + handleClickFilterCell: (columnIdx: number, value: Value) => void }) { const { columns, From 581eb7676437e48ec75d8f4b9de74d496c82d016 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 5 Aug 2023 16:36:56 +0900 Subject: [PATCH 5/7] Fix PlotHistory.tsx --- standalone_app/src/components/PlotHistory.tsx | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/standalone_app/src/components/PlotHistory.tsx b/standalone_app/src/components/PlotHistory.tsx index adc1443a..0b421e5a 100644 --- a/standalone_app/src/components/PlotHistory.tsx +++ b/standalone_app/src/components/PlotHistory.tsx @@ -231,8 +231,23 @@ const plotHistory = ( return xAxis === "number" ? trial.number : xAxis === "datetime_start" - ? trial.datetime_start! - : trial.datetime_complete! + ? trial.datetime_start ?? new Date() + : trial.datetime_complete ?? new Date() + } + + const getValue = (trial: Trial, objectiveId: number): number | null => { + if ( + objectiveId === null || + trial.values === undefined || + trial.values.length <= objectiveId + ) { + return null + } + const value = trial.values[objectiveId] + if (value === "inf" || value === "-inf") { + return null + } + return value } const xForLinePlot: (number | Date)[] = [] @@ -240,34 +255,35 @@ const plotHistory = ( let currentBest: number | null = null for (let i = 0; i < filteredTrials.length; i++) { const t = filteredTrials[i] + const v = getValue(t, objectiveId) as number if (currentBest === null) { - currentBest = t.values![objectiveId] as number + currentBest = v xForLinePlot.push(getAxisX(t)) - yForLinePlot.push(t.values![objectiveId] as number) + yForLinePlot.push(v) } else if ( study.directions[objectiveId] === "maximize" && - t.values![objectiveId] > currentBest + v > currentBest ) { const p = filteredTrials[i - 1] if (!xForLinePlot.includes(getAxisX(p))) { xForLinePlot.push(getAxisX(p)) yForLinePlot.push(currentBest) } - currentBest = t.values![objectiveId] as number + currentBest = v xForLinePlot.push(getAxisX(t)) - yForLinePlot.push(t.values![objectiveId] as number) + yForLinePlot.push(v) } else if ( study.directions[objectiveId] === "minimize" && - t.values![objectiveId] < currentBest + v < currentBest ) { const p = filteredTrials[i - 1] if (!xForLinePlot.includes(getAxisX(p))) { xForLinePlot.push(getAxisX(p)) yForLinePlot.push(currentBest) } - currentBest = t.values![objectiveId] as number + currentBest = v xForLinePlot.push(getAxisX(t)) - yForLinePlot.push(t.values![objectiveId] as number) + yForLinePlot.push(v) } } xForLinePlot.push(getAxisX(filteredTrials[filteredTrials.length - 1])) @@ -277,7 +293,7 @@ const plotHistory = ( { x: filteredTrials.map(getAxisX), y: filteredTrials.map( - (t: Trial): number => t.values![objectiveId] as number + (t: Trial): number => getValue(t, objectiveId) as number ), name: "Objective Value", mode: "markers", From 87da075fb403764bade4e30160cdd0355109ec4c Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 5 Aug 2023 16:39:39 +0900 Subject: [PATCH 6/7] Fix sqlite3.ts --- standalone_app/src/sqlite3.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/standalone_app/src/sqlite3.ts b/standalone_app/src/sqlite3.ts index 4cabd91f..4f65a65a 100644 --- a/standalone_app/src/sqlite3.ts +++ b/standalone_app/src/sqlite3.ts @@ -7,9 +7,11 @@ export const loadStorage = ( setter: SetterOrUpdater ): void => { sqlite3InitModule({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any print: (...args: any): void => { console.log(args) }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any printErr: (...args: any): void => { console.log(args) }, @@ -32,6 +34,7 @@ export const loadStorage = ( let supported = true db.exec({ sql: "SELECT schema_version FROM version_info LIMIT 1", + // eslint-disable-next-line @typescript-eslint/no-explicit-any callback: (vals: any[]) => { if (vals[0] != 12) { supported = false @@ -49,6 +52,7 @@ export const loadStorage = ( "SELECT s.study_id, s.study_name, sd.direction, sd.objective" + " FROM studies AS s INNER JOIN study_directions AS sd" + " ON s.study_id = sd.study_id ORDER BY sd.study_direction_id", + // eslint-disable-next-line @typescript-eslint/no-explicit-any callback: (vals: any[]) => { const study_id = vals[0] const study_name = vals[1] @@ -82,6 +86,7 @@ export const loadStorage = ( " FROM trials AS t LEFT JOIN trial_values AS tv ON tv.trial_id = t.trial_id" + ` WHERE t.study_id = ${s.study_id}` + " ORDER BY t.number", + // eslint-disable-next-line @typescript-eslint/no-explicit-any callback: (vals: any[]) => { const state: TrialState = vals[3] === "COMPLETE" @@ -115,6 +120,7 @@ export const loadStorage = ( sql: "SELECT param_name, param_value" + ` FROM trial_params WHERE trial_id = ${trial.trial_id}`, + // eslint-disable-next-line @typescript-eslint/no-explicit-any callback: (vals: any[]) => { const param_name = vals[0] params.push({ @@ -151,6 +157,7 @@ export const loadStorage = ( "SELECT value, value_type" + ` FROM trial_values WHERE trial_id = ${trial.trial_id}` + " ORDER BY objective", + // eslint-disable-next-line @typescript-eslint/no-explicit-any callback: (vals: any[]) => { values.push( vals[1] === "INF_NEG" From 3b85942b0750f73d4b004da2934bc78f9e07d447 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sat, 5 Aug 2023 16:49:59 +0900 Subject: [PATCH 7/7] Set maximum warnings as 0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f00b41e9..a319c4d7 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "fmt": "prettier --write \"{optuna_dashboard/ts,typescript_tests,standalone_app/src,vscode/src}/**/*.{ts,tsx}\"", "lint": "npm run lint:eslint && npm run lint:fmt", - "lint:eslint": "eslint . --ext .ts,.tsx", + "lint:eslint": "eslint . --ext .ts,.tsx --max-warnings 0", "lint:fmt": "prettier --list-different \"{optuna_dashboard/ts,typescript_tests,standalone_app/src,vscode/src}/**/*.{ts,tsx}\"", "watch": "NODE_ENV=development TYPESCRIPT_LOADER=esbuild-loader webpack --watch", "build": "webpack",