Move some types from input.d.ts -> optuna.ts

This commit is contained in:
porink0424
2024-04-17 12:22:23 +09:00
parent e531f1ec4c
commit cf591d0b63
44 changed files with 237 additions and 236 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ import {
StudyDetails,
StudySummary,
Trial,
} from "./types"
} from "./types/optuna"
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const actionCreator = () => {
+1 -2
View File
@@ -2,7 +2,6 @@ import * as plotly from "plotly.js-dist-min"
import axios from "axios"
import * as Optuna from "@optuna/types"
import {
API_ENDPOINT,
Artifact,
FeedbackComponentType,
FormWidgets,
@@ -16,7 +15,7 @@ import {
StudySummary,
Trial,
TrialParam,
} from "./types"
} from "./types/optuna"
const axiosInstance = axios.create({ baseURL: API_ENDPOINT })
-1
View File
@@ -16,7 +16,6 @@ import { CompareStudies } from "./CompareStudies"
import { StudyDetail } from "./StudyDetail"
import { StudyList } from "./StudyList"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import { URL_PREFIX } from "ts/types"
const queryClient = new QueryClient({
defaultOptions: {
@@ -41,7 +41,6 @@ import HistoryIcon from "@mui/icons-material/History"
import LanIcon from "@mui/icons-material/Lan"
import { Switch } from "@mui/material"
import { actionCreator } from "../action"
import { URL_PREFIX } from "ts/types"
const drawerWidth = 240
@@ -6,7 +6,7 @@ import {
import { WaveSurferArtifactViewer } from "./WaveSurferArtifactViewer"
import InsertDriveFileIcon from "@mui/icons-material/InsertDriveFile"
import { CardMedia, Box } from "@mui/material"
import { Artifact } from "ts/types"
import { Artifact } from "ts/types/optuna"
export const ArtifactCardMedia: FC<{
artifact: Artifact
@@ -8,7 +8,7 @@ import {
DialogActions,
} from "@mui/material"
import { actionCreator } from "../../action"
import { Artifact } from "ts/types"
import { Artifact } from "ts/types/optuna"
export const useDeleteTrialArtifactDialog = (): [
(studyId: number, trialId: number, artifact: Artifact) => void,
@@ -27,7 +27,7 @@ import {
isThreejsArtifact,
} from "./ThreejsArtifactViewer"
import { ArtifactCardMedia } from "./ArtifactCardMedia"
import { StudyDetail } from "ts/types"
import { StudyDetail } from "ts/types/optuna"
export const StudyArtifactCards: FC<{ study: StudyDetail }> = ({ study }) => {
const theme = useTheme()
@@ -9,7 +9,7 @@ import { PerspectiveCamera } from "three"
import { Modal, Box, useTheme } from "@mui/material"
import ClearIcon from "@mui/icons-material/Clear"
import IconButton from "@mui/material/IconButton"
import { Artifact } from "ts/types"
import { Artifact } from "ts/types/optuna"
export const isThreejsArtifact = (artifact: Artifact): boolean => {
return (
@@ -27,7 +27,7 @@ import {
isThreejsArtifact,
} from "./ThreejsArtifactViewer"
import { ArtifactCardMedia } from "./ArtifactCardMedia"
import { Trial } from "ts/types"
import { Trial } from "ts/types/optuna"
export const TrialArtifactCards: FC<{ trial: Trial }> = ({ trial }) => {
const theme = useTheme()
@@ -14,7 +14,7 @@ import {
} from "@mui/material"
import { Link } from "react-router-dom"
import LinkIcon from "@mui/icons-material/Link"
import { StudyDetail, Trial, URL_PREFIX } from "ts/types"
import { StudyDetail, Trial } from "ts/types/optuna"
const useBestTrials = (studyDetail: StudyDetail | null): Trial[] => {
return useMemo(() => studyDetail?.best_trials || [], [studyDetail])
@@ -32,7 +32,7 @@ import { GraphEdf } from "./GraphEdf"
import { GraphHistory } from "./GraphHistory"
import { useNavigate } from "react-router-dom"
import { useQuery } from "../urlQuery"
import { StudyDetails, StudySummary, URL_PREFIX } from "ts/types"
import { StudyDetails, StudySummary } from "ts/types/optuna"
const useQueriedStudies = (
studies: StudySummary[],
@@ -19,7 +19,7 @@ import { studySummariesState } from "../state"
import RemoveIcon from "@mui/icons-material/Remove"
import AddIcon from "@mui/icons-material/Add"
import * as Optuna from "@optuna/types"
import { StudySummary } from "ts/types"
import { StudySummary } from "ts/types/optuna"
export const useCreateStudyDialog = (): [() => void, () => ReactNode] => {
const theme = useTheme()
@@ -20,7 +20,7 @@ import { getAxisInfo } from "../graphUtil"
import { PlotType } from "../apiClient"
import { useBackendRender } from "../state"
import { usePlot } from "../hooks/usePlot"
import { SearchSpaceItem, StudyDetail, Trial } from "ts/types"
import { SearchSpaceItem, StudyDetail, Trial } from "ts/types/optuna"
const plotDomId = "graph-contour"
const CONTOUR_DISABLED_THRESHOLD = 100
+1 -1
View File
@@ -4,7 +4,7 @@ import { Typography, useTheme, Box } from "@mui/material"
import { Target, useFilteredTrialsFromStudies } from "../trialFilter"
import { getCompareStudiesPlotAPI, CompareStudiesPlotType } from "../apiClient"
import { usePlotlyColorTheme, useBackendRender } from "../state"
import { StudyDetail, Trial } from "ts/types"
import { StudyDetail, Trial } from "ts/types/optuna"
const getPlotDomId = (objectiveId: number) => `graph-edf-${objectiveId}`
@@ -23,7 +23,7 @@ import {
import { usePlotlyColorTheme } from "../state"
import { useNavigate } from "react-router-dom"
import * as Optuna from "@optuna/types"
import { StudyDetail, Trial, URL_PREFIX } from "ts/types"
import { StudyDetail, Trial } from "ts/types/optuna"
const plotDomId = "graph-history"
@@ -10,7 +10,7 @@ import {
} from "../state"
import { PlotType } from "../apiClient"
import { usePlot } from "../hooks/usePlot"
import { ParamImportance, StudyDetail } from "ts/types"
import { ParamImportance, StudyDetail } from "ts/types/optuna"
const plotDomId = "graph-hyperparameter-importances"
@@ -2,7 +2,7 @@ import * as plotly from "plotly.js-dist-min"
import React, { FC, useEffect } from "react"
import { Box, Typography, useTheme, CardContent, Card } from "@mui/material"
import { usePlotlyColorTheme } from "../state"
import { Trial } from "ts/types"
import { Trial } from "ts/types/optuna"
const plotDomId = "graph-intermediate-values"
@@ -20,7 +20,7 @@ import { useMergedUnionSearchSpace } from "../searchSpace"
import { PlotType } from "../apiClient"
import { useBackendRender } from "../state"
import { usePlot } from "../hooks/usePlot"
import { SearchSpaceItem, StudyDetail, Trial } from "ts/types"
import { SearchSpaceItem, StudyDetail, Trial } from "ts/types/optuna"
const plotDomId = "graph-parallel-coordinate"
@@ -18,7 +18,7 @@ import { PlotType } from "../apiClient"
import { useBackendRender } from "../state"
import { usePlot } from "../hooks/usePlot"
import * as Optuna from "@optuna/types"
import { StudyDetail, Trial, URL_PREFIX } from "ts/types"
import { StudyDetail, Trial } from "ts/types/optuna"
const plotDomId = "graph-pareto-front"
+1 -1
View File
@@ -16,7 +16,7 @@ import { useMergedUnionSearchSpace } from "../searchSpace"
import { PlotType } from "../apiClient"
import { usePlotlyColorTheme, useBackendRender } from "../state"
import { usePlot } from "../hooks/usePlot"
import { SearchSpaceItem, StudyDetail, Trial } from "ts/types"
import { SearchSpaceItem, StudyDetail, Trial } from "ts/types/optuna"
const plotDomId = "graph-rank"
@@ -22,7 +22,7 @@ import { useMergedUnionSearchSpace } from "../searchSpace"
import { PlotType } from "../apiClient"
import { usePlotlyColorTheme, useBackendRender } from "../state"
import { usePlot } from "../hooks/usePlot"
import { SearchSpaceItem, StudyDetail, Trial } from "ts/types"
import { SearchSpaceItem, StudyDetail, Trial } from "ts/types/optuna"
const plotDomId = "graph-slice"
@@ -7,7 +7,7 @@ import { PlotType } from "../apiClient"
import { useBackendRender } from "../state"
import { usePlot } from "../hooks/usePlot"
import * as Optuna from "@optuna/types"
import { StudyDetail, Trial } from "ts/types"
import { StudyDetail, Trial } from "ts/types/optuna"
const plotDomId = "graph-timeline"
const maxBars = 100
+1 -1
View File
@@ -53,7 +53,7 @@ import { darcula } from "react-syntax-highlighter/dist/esm/styles/prism"
import { actionCreator } from "../action"
import { useRecoilValue } from "recoil"
import { artifactIsAvailable, isFileUploading, useArtifacts } from "../state"
import { Note } from "ts/types"
import { Note } from "ts/types/optuna"
const placeholder = `## What is this feature for?
@@ -26,7 +26,7 @@ import { ElkNode } from "elkjs/lib/elk-api.js"
import { useStudyDetailValue } from "../../state"
import { getArtifactUrlPath } from "./PreferentialTrials"
import { PreferentialOutputComponent } from "./PreferentialOutputComponent"
import { StudyDetail, Trial } from "ts/types"
import { StudyDetail, Trial } from "ts/types/optuna"
const elk = new ELK()
const nodeWidth = 400
@@ -21,7 +21,7 @@ import { formatDate } from "../../dateUtil"
import { actionCreator } from "../../action"
import { useStudyDetailValue } from "../../state"
import { PreferentialOutputComponent } from "./PreferentialOutputComponent"
import { PreferenceHistory, StudyDetail, Trial } from "ts/types"
import { PreferenceHistory, StudyDetail, Trial } from "ts/types/optuna"
type TrialType = "worst" | "none"
@@ -1,7 +1,7 @@
import React, { FC, useMemo } from "react"
import { ArtifactCardMedia } from "../Artifact/ArtifactCardMedia"
import { MarkdownRenderer } from "../Note"
import { Artifact, FeedbackComponentType, Trial } from "ts/types"
import { Artifact, FeedbackComponentType, Trial } from "ts/types/optuna"
export const PreferentialOutputComponent: FC<{
trial: Trial
@@ -41,7 +41,7 @@ import {
FeedbackComponentType,
StudyDetail,
Trial,
} from "ts/types"
} from "ts/types/optuna"
const SettingsPage: FC<{
studyDetail: StudyDetail
@@ -10,7 +10,7 @@ import {
} from "@mui/material"
import { actionCreator } from "../action"
import { DebouncedInputTextField } from "./Debounce"
import { StudySummary } from "ts/types"
import { StudySummary } from "ts/types/optuna"
export const useRenameStudyDialog = (
studies: StudySummary[]
+1 -1
View File
@@ -12,7 +12,7 @@ import {
} from "@mui/material"
import ClearIcon from "@mui/icons-material/Clear"
import { usePlotBackendRendering, usePlotlyColorThemeState } from "../state"
import { PlotlyColorThemeDark, PlotlyColorThemeLight } from "ts/types"
import { PlotlyColorThemeDark, PlotlyColorThemeLight } from "ts/types/optuna"
interface SettingsProps {
handleClose: () => void
@@ -34,7 +34,6 @@ import { PreferentialTrials } from "./Preferential/PreferentialTrials"
import { PreferentialHistory } from "./Preferential/PreferentialHistory"
import { PreferentialAnalytics } from "./Preferential/PreferentialAnalytics"
import { PreferentialGraph } from "./Preferential/PreferentialGraph"
import { URL_PREFIX } from "ts/types"
type ParamTypes = {
studyId: string
@@ -27,7 +27,7 @@ import {
import FormControlLabel from "@mui/material/FormControlLabel"
import { artifactIsAvailable } from "../state"
import * as Optuna from "@optuna/types"
import { Trial } from "ts/types"
import { Trial } from "ts/types/optuna"
export const StudyHistory: FC<{ studyId: number }> = ({ studyId }) => {
const theme = useTheme()
+1 -1
View File
@@ -39,7 +39,7 @@ import { useCreateStudyDialog } from "./CreateStudyDialog"
import { useDeleteStudyDialog } from "./DeleteStudyDialog"
import { useRenameStudyDialog } from "./RenameStudyDialog"
import { useQuery } from "../urlQuery"
import { StudySummary, URL_PREFIX } from "ts/types"
import { StudySummary } from "ts/types/optuna"
export const StudyList: FC<{
toggleColorMode: () => void
@@ -25,7 +25,7 @@ import {
ObjectiveUserAttrRef,
Trial,
UserAttrFormWidget,
} from "ts/types"
} from "ts/types/optuna"
type WidgetState = {
isValid: boolean
+1 -1
View File
@@ -31,7 +31,7 @@ import { TrialFormWidgets } from "./TrialFormWidgets"
import { TrialArtifactCards } from "./Artifact/TrialArtifactCards"
import { useQuery } from "../urlQuery"
import { useVirtualizer } from "@tanstack/react-virtual"
import { FormWidgets, StudyDetail, Trial, URL_PREFIX } from "ts/types"
import { FormWidgets, StudyDetail, Trial } from "ts/types/optuna"
const states: Optuna.TrialState[] = [
"Complete",
@@ -5,7 +5,7 @@ import DownloadIcon from "@mui/icons-material/Download"
import { DataGridColumn, DataGrid } from "./DataGrid"
import { Link } from "react-router-dom"
import { StudyDetail, Trial, URL_PREFIX } from "ts/types"
import { StudyDetail, Trial } from "ts/types/optuna"
export const TrialTable: FC<{
studyDetail: StudyDetail | null
@@ -1,7 +1,7 @@
import * as plotly from "plotly.js-dist-min"
import React, { FC, useEffect } from "react"
import { Box } from "@mui/material"
import { PlotlyGraphObject } from "ts/types"
import { PlotlyGraphObject } from "ts/types/optuna"
export const UserDefinedPlot: FC<{
graphObject: PlotlyGraphObject
+1 -1
View File
@@ -1,5 +1,5 @@
import * as Optuna from "@optuna/types"
import { Trial } from "./types"
import { Trial } from "./types/optuna"
const filterFunc = (
trial: Trial,
+1 -1
View File
@@ -1,4 +1,4 @@
import { SearchSpaceItem, Trial } from "./types"
import { SearchSpaceItem, Trial } from "./types/optuna"
import * as Optuna from "@optuna/types"
const PADDING_RATIO = 0.05
@@ -3,7 +3,7 @@ import { useSnackbar } from "notistack"
import { getParamImportances } from "../apiClient"
import { useQuery } from "@tanstack/react-query"
import { AxiosError } from "axios"
import { ParamImportance } from "ts/types"
import { ParamImportance } from "ts/types/optuna"
export const useParamImportance = ({
numCompletedTrials,
+1 -1
View File
@@ -1,5 +1,5 @@
import { useMemo } from "react"
import { SearchSpaceItem } from "./types"
import { SearchSpaceItem } from "./types/optuna"
import * as Optuna from "@optuna/types"
export const mergeUnionSearchSpace = (
+1 -1
View File
@@ -11,7 +11,7 @@ import {
StudyDetail,
StudyDetails,
StudySummary,
} from "./types"
} from "./types/optuna"
export const studySummariesState = atom<StudySummary[]>({
key: "studySummaries",
+1 -1
View File
@@ -1,6 +1,6 @@
import { useMemo, useState } from "react"
import * as Optuna from "@optuna/types"
import { SearchSpaceItem, StudyDetail, Trial } from "./types"
import { SearchSpaceItem, StudyDetail, Trial } from "./types/optuna"
type TargetKind = "objective" | "user_attr" | "params"
-193
View File
@@ -6,196 +6,3 @@ declare module "*.svg"
declare const APP_BAR_TITLE: string
declare const API_ENDPOINT: string
declare const URL_PREFIX: string
import * as Optuna from "@optuna/types"
type PreferenceFeedbackMode = "ChooseWorst"
type GraphVisibility = {
history: boolean
paretoFront: boolean
parallelCoordinate: boolean
intermediateValues: boolean
edf: boolean
contour: boolean
importances: boolean
slice: boolean
}
type TrialParam = {
name: string
param_internal_value: number
param_external_value: string
param_external_type: string
distribution: Optuna.Distribution
}
type ParamImportance = {
name: string
importance: number
distribution: Optuna.Distribution
}
type SearchSpaceItem = {
name: string
distribution: Optuna.Distribution
}
type Note = {
version: number
body: string
}
type Artifact = {
artifact_id: string
filename: string
mimetype: string
encoding: string
}
type Trial = {
trial_id: number
study_id: number
number: number
state: Optuna.TrialState
values?: number[]
intermediate_values: Optuna.TrialIntermediateValue[]
datetime_start?: Date
datetime_complete?: Date
params: TrialParam[]
fixed_params: {
name: string
param_external_value: string
}[]
user_attrs: Optuna.Attribute[]
constraints: number[]
note: Note
artifacts: Artifact[]
}
type StudySummary = {
study_id: number
study_name: string
directions: Optuna.StudyDirection[]
user_attrs: Optuna.Attribute[]
is_preferential: boolean
datetime_start?: Date
}
type ObjectiveChoiceWidget = {
type: "choice"
description: string
user_attr_key?: string
choices: string[]
values: number[]
}
type ObjectiveSliderWidget = {
type: "slider"
description: string
user_attr_key?: string
min: number
max: number
step: number | null
labels:
| {
value: number
label: string
}[]
| null
}
type ObjectiveTextInputWidget = {
type: "text"
description: string
optional: boolean
user_attr_key?: string
}
type ObjectiveUserAttrRef = {
type: "user_attr"
key: string
}
type ObjectiveFormWidget =
| ObjectiveChoiceWidget
| ObjectiveSliderWidget
| ObjectiveTextInputWidget
| ObjectiveUserAttrRef
type UserAttrFormWidget =
| ObjectiveChoiceWidget
| ObjectiveSliderWidget
| ObjectiveTextInputWidget
type FormWidgets =
| {
output_type: "objective"
widgets: ObjectiveFormWidget[]
}
| {
output_type: "user_attr"
widgets: UserAttrFormWidget[]
}
type PlotlyGraphObject = {
id: string
graph_object: string
}
type FeedbackComponentNote = {
output_type: "note"
}
type FeedbackComponentArtifact = {
output_type: "artifact"
artifact_key: string
}
type FeedbackComponentType = FeedbackComponentArtifact | FeedbackComponentNote
type StudyDetail = {
id: number
name: string
directions: Optuna.StudyDirection[]
user_attrs: Optuna.Attribute[]
datetime_start: Date
best_trials: Trial[]
trials: Trial[]
intersection_search_space: SearchSpaceItem[]
union_search_space: SearchSpaceItem[]
union_user_attrs: Optuna.AttributeSpec[]
has_intermediate_values: boolean
note: Note
is_preferential: boolean
objective_names?: string[]
form_widgets?: FormWidgets
feedback_component_type: FeedbackComponentType
preferences?: [number, number][]
preference_history?: PreferenceHistory[]
plotly_graph_objects: PlotlyGraphObject[]
artifacts: Artifact[]
skipped_trial_numbers: number[]
}
type StudyDetails = {
[study_id: string]: StudyDetail
}
type PreferenceHistory = {
id: string
candidates: number[]
clicked: number
feedback_mode: PreferenceFeedbackMode
timestamp: Date
preferences: [number, number][]
is_removed: boolean
}
type PlotlyColorThemeDark = "default"
type PlotlyColorThemeLight = "default" | "seaborn" | "presentation" | "ggplot2"
type PlotlyColorTheme = {
dark: PlotlyColorThemeDark
light: PlotlyColorThemeLight
}
+198
View File
@@ -0,0 +1,198 @@
import * as Optuna from "@optuna/types"
export type PreferenceFeedbackMode = "ChooseWorst"
export type GraphVisibility = {
history: boolean
paretoFront: boolean
parallelCoordinate: boolean
intermediateValues: boolean
edf: boolean
contour: boolean
importances: boolean
slice: boolean
}
export type TrialParam = {
name: string
param_internal_value: number
param_external_value: string
param_external_type: string
distribution: Optuna.Distribution
}
export type ParamImportance = {
name: string
importance: number
distribution: Optuna.Distribution
}
export type SearchSpaceItem = {
name: string
distribution: Optuna.Distribution
}
export type Note = {
version: number
body: string
}
export type Artifact = {
artifact_id: string
filename: string
mimetype: string
encoding: string
}
export type Trial = {
trial_id: number
study_id: number
number: number
state: Optuna.TrialState
values?: number[]
intermediate_values: Optuna.TrialIntermediateValue[]
datetime_start?: Date
datetime_complete?: Date
params: TrialParam[]
fixed_params: {
name: string
param_external_value: string
}[]
user_attrs: Optuna.Attribute[]
constraints: number[]
note: Note
artifacts: Artifact[]
}
export type StudySummary = {
study_id: number
study_name: string
directions: Optuna.StudyDirection[]
user_attrs: Optuna.Attribute[]
is_preferential: boolean
datetime_start?: Date
}
export type ObjectiveChoiceWidget = {
type: "choice"
description: string
user_attr_key?: string
choices: string[]
values: number[]
}
export type ObjectiveSliderWidget = {
type: "slider"
description: string
user_attr_key?: string
min: number
max: number
step: number | null
labels:
| {
value: number
label: string
}[]
| null
}
export type ObjectiveTextInputWidget = {
type: "text"
description: string
optional: boolean
user_attr_key?: string
}
export type ObjectiveUserAttrRef = {
type: "user_attr"
key: string
}
export type ObjectiveFormWidget =
| ObjectiveChoiceWidget
| ObjectiveSliderWidget
| ObjectiveTextInputWidget
| ObjectiveUserAttrRef
export type UserAttrFormWidget =
| ObjectiveChoiceWidget
| ObjectiveSliderWidget
| ObjectiveTextInputWidget
export type FormWidgets =
| {
output_type: "objective"
widgets: ObjectiveFormWidget[]
}
| {
output_type: "user_attr"
widgets: UserAttrFormWidget[]
}
export type PlotlyGraphObject = {
id: string
graph_object: string
}
export type FeedbackComponentNote = {
output_type: "note"
}
export type FeedbackComponentArtifact = {
output_type: "artifact"
artifact_key: string
}
export type FeedbackComponentType =
| FeedbackComponentArtifact
| FeedbackComponentNote
export type StudyDetail = {
id: number
name: string
directions: Optuna.StudyDirection[]
user_attrs: Optuna.Attribute[]
datetime_start: Date
best_trials: Trial[]
trials: Trial[]
intersection_search_space: SearchSpaceItem[]
union_search_space: SearchSpaceItem[]
union_user_attrs: Optuna.AttributeSpec[]
has_intermediate_values: boolean
note: Note
is_preferential: boolean
objective_names?: string[]
form_widgets?: FormWidgets
feedback_component_type: FeedbackComponentType
preferences?: [number, number][]
preference_history?: PreferenceHistory[]
plotly_graph_objects: PlotlyGraphObject[]
artifacts: Artifact[]
skipped_trial_numbers: number[]
}
export type StudyDetails = {
[study_id: string]: StudyDetail
}
export type PreferenceHistory = {
id: string
candidates: number[]
clicked: number
feedback_mode: PreferenceFeedbackMode
timestamp: Date
preferences: [number, number][]
is_removed: boolean
}
export type PlotlyColorThemeDark = "default"
export type PlotlyColorThemeLight =
| "default"
| "seaborn"
| "presentation"
| "ggplot2"
export type PlotlyColorTheme = {
dark: PlotlyColorThemeDark
light: PlotlyColorThemeLight
}