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

Remove type definitions from standalone_app #876

Merged
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
1 change: 1 addition & 0 deletions standalone_app/src/components/StorageProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { JournalFileStorage } from "@optuna/storage"
import { SQLite3Storage } from "@optuna/storage"
import type { OptunaStorage } from "@optuna/storage"
import React, { FC, createContext, useState } from "react"

export const StorageContext = createContext<{
Expand Down
2 changes: 1 addition & 1 deletion standalone_app/src/components/StudyDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const StudyDetail: FC<{
const idxNumber = parseInt(idx || "", 10)

const { storage } = useContext(StorageContext)
const [study, setStudy] = useState<Study | null>(null)
const [study, setStudy] = useState<Optuna.Study | null>(null)
useEffect(() => {
const fetchStudy = async () => {
if (storage === null) {
Expand Down
9 changes: 6 additions & 3 deletions standalone_app/src/components/StudyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
useTheme,
} from "@mui/material"
import { styled } from "@mui/system"
import * as Optuna from "@optuna/types"
import React, {
FC,
useEffect,
Expand All @@ -36,7 +37,7 @@ export const StudyList: FC<{
}> = ({ toggleColorMode }) => {
const theme = useTheme()
const { storage } = useContext(StorageContext)
const [studies, setStudies] = useState<StudySummary[]>([])
const [studies, setStudies] = useState<Optuna.StudySummary[]>([])

const [_studyFilterText, setStudyFilterText] = useState<string>("")
const [sortBy, setSortBy] = useState<"id-asc" | "id-desc">("id-asc")
Expand All @@ -52,7 +53,7 @@ export const StudyList: FC<{
fetchStudies()
}, [storage])
const filteredStudies = useMemo(() => {
const studyFilter = (row: StudySummary): boolean => {
const studyFilter = (row: Optuna.StudySummary): boolean => {
const keywords = studyFilterText.split(" ")
return !keywords.every((k) => {
if (k === "") {
Expand All @@ -61,7 +62,9 @@ export const StudyList: FC<{
return row.study_name.indexOf(k) >= 0
})
}
let filteredStudies: StudySummary[] = studies.filter((s) => !studyFilter(s))
let filteredStudies: Optuna.StudySummary[] = studies.filter(
(s) => !studyFilter(s)
)
if (sortBy === "id-desc") {
filteredStudies = filteredStudies.reverse()
}
Expand Down
98 changes: 0 additions & 98 deletions standalone_app/src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,99 +1 @@
declare const IS_VSCODE: boolean

type TrialState = "Running" | "Complete" | "Pruned" | "Fail" | "Waiting"
type TrialStateFinished = "Complete" | "Fail" | "Pruned"
type StudyDirection = "maximize" | "minimize"

type OptunaStorage = {
getStudies: () => Promise<StudySummary[]>
getStudy: (idx: number) => Promise<Study | null>
}

type FloatDistribution = {
type: "FloatDistribution"
low: number
high: number
step: number | null
log: boolean
}

type IntDistribution = {
type: "IntDistribution"
low: number
high: number
step: number | null
log: boolean
}

type CategoricalChoiceType = null | boolean | number | string
type CategoricalDistribution = {
type: "CategoricalDistribution"
choices: CategoricalChoiceType[]
}

type TrialIntermediateValue = {
step: number
value: number
}

type Distribution =
| FloatDistribution
| IntDistribution
| CategoricalDistribution

type Attribute = {
key: string
value: string
}

type AttributeSpec = {
key: string
sortable: boolean
}

type StudySummary = {
study_id: number
study_name: string
directions: StudyDirection[]
}

type Study = {
study_id: number
study_name: string
directions: StudyDirection[]
union_search_space: SearchSpaceItem[]
intersection_search_space: SearchSpaceItem[]
union_user_attrs: AttributeSpec[]
datetime_start?: Date
trials: Trial[]
}

type Trial = {
trial_id: number
number: number
study_id: number
state: TrialState
values?: number[]
params: TrialParam[]
intermediate_values: TrialIntermediateValue[]
user_attrs: Attribute[]
datetime_start?: Date
datetime_complete?: Date
}

type TrialParam = {
name: string
param_internal_value: number
param_external_value: CategoricalChoiceType
param_external_type: string
distribution: Distribution
}

type SearchSpaceItem = {
name: string
}

type ParamImportance = {
name: string
importance: number
}
1 change: 1 addition & 0 deletions tslib/storage/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { JournalFileStorage } from "./journal"
export { SQLite3Storage } from "./sqlite"
export type { OptunaStorage } from "./storage"
Loading