mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-11 12:30:25 +08:00
Rename @optuna/storage-loader to @optuna/storage
This commit is contained in:
Generated
+16
-5
@@ -13,7 +13,7 @@
|
||||
"@mui/icons-material": "^5.15.12",
|
||||
"@mui/lab": "^5.0.0-alpha.167",
|
||||
"@mui/material": "^5.15.12",
|
||||
"@optuna/storage-loader": "../tslib/storage-loader",
|
||||
"@optuna/storage": "../tslib/storage",
|
||||
"module-workers-polyfill": "^0.3.2",
|
||||
"notistack": "^3.0.1",
|
||||
"optuna": "../rustlib/pkg",
|
||||
@@ -39,9 +39,20 @@
|
||||
"name": "optuna-wasm",
|
||||
"version": "0.1.0"
|
||||
},
|
||||
"../tslib/storage": {
|
||||
"version": "0.0.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@sqlite.org/sqlite-wasm": "^3.45.1-build1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@optuna/types": "../types/"
|
||||
}
|
||||
},
|
||||
"../tslib/storage-loader": {
|
||||
"name": "@optuna/storage-loader",
|
||||
"version": "0.0.1",
|
||||
"extraneous": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@sqlite.org/sqlite-wasm": "^3.45.1-build1"
|
||||
@@ -1325,8 +1336,8 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@optuna/storage-loader": {
|
||||
"resolved": "../tslib/storage-loader",
|
||||
"node_modules/@optuna/storage": {
|
||||
"resolved": "../tslib/storage",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@popperjs/core": {
|
||||
@@ -4614,8 +4625,8 @@
|
||||
"react-is": "^18.2.0"
|
||||
}
|
||||
},
|
||||
"@optuna/storage-loader": {
|
||||
"version": "file:../tslib/storage-loader",
|
||||
"@optuna/storage": {
|
||||
"version": "file:../tslib/storage",
|
||||
"requires": {
|
||||
"@optuna/types": "../types/",
|
||||
"@sqlite.org/sqlite-wasm": "^3.45.1-build1"
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"@mui/icons-material": "^5.15.12",
|
||||
"@mui/lab": "^5.0.0-alpha.167",
|
||||
"@mui/material": "^5.15.12",
|
||||
"@optuna/storage-loader": "../tslib/storage-loader",
|
||||
"@optuna/storage": "../tslib/storage",
|
||||
"module-workers-polyfill": "^0.3.2",
|
||||
"notistack": "^3.0.1",
|
||||
"optuna": "../rustlib/pkg",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { FC, createContext, useState } from "react"
|
||||
import { JournalFileStorage } from "@optuna/storage-loader"
|
||||
import { SQLite3Storage } from "@optuna/storage-loader"
|
||||
import { JournalFileStorage } from "@optuna/storage"
|
||||
import { SQLite3Storage } from "@optuna/storage"
|
||||
|
||||
export const StorageContext = createContext<{
|
||||
storage: OptunaStorage | null
|
||||
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "tslib",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "@optuna/storage-loader",
|
||||
"name": "@optuna/storage",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@optuna/storage-loader",
|
||||
"name": "@optuna/storage",
|
||||
"version": "0.0.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@optuna/storage-loader",
|
||||
"name": "@optuna/storage",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "Loaders for Optuna storages",
|
||||
@@ -34,9 +34,12 @@ interface JournalOpCreateTrial extends JournalOpBase {
|
||||
datetime_start?: string
|
||||
datetime_complete?: string
|
||||
distributions?: { [key: string]: string }
|
||||
params?: { [key: string]: any } // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
user_attrs?: { [key: string]: any } // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
system_attrs?: { [key: string]: any } // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
params?: { [key: string]: any }
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
user_attrs?: { [key: string]: any }
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
system_attrs?: { [key: string]: any }
|
||||
state?: number
|
||||
intermediate_values?: { [key: string]: number }
|
||||
value?: number
|
||||
@@ -66,10 +69,11 @@ interface JournalOpSetTrialIntermediateValue extends JournalOpBase {
|
||||
|
||||
interface JournalOpSetTrialUserAttr extends JournalOpBase {
|
||||
trial_id: number
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
user_attr: { [key: string]: any } // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
}
|
||||
|
||||
const trialStateNumToTrialState = (state: number): Optuna.TrialState => {
|
||||
const trialStateNumToTrialState = (state: number): TrialState => {
|
||||
switch (state) {
|
||||
case 0:
|
||||
return "Running"
|
||||
@@ -86,34 +90,37 @@ const trialStateNumToTrialState = (state: number): Optuna.TrialState => {
|
||||
}
|
||||
}
|
||||
|
||||
const parseDistribution = (distribution: string): Optuna.Distribution => {
|
||||
const parseDistribution = (distribution: string): Distribution => {
|
||||
const distributionJson = JSON.parse(distribution)
|
||||
if (distributionJson["name"] === "IntDistribution") {
|
||||
if (distributionJson.name === "IntDistribution") {
|
||||
return {
|
||||
...distributionJson["attributes"],
|
||||
...distributionJson.attributes,
|
||||
type: "IntDistribution",
|
||||
}
|
||||
} else if (distributionJson["name"] === "FloatDistribution") {
|
||||
}
|
||||
if (distributionJson.name === "FloatDistribution") {
|
||||
return {
|
||||
...distributionJson["attributes"],
|
||||
...distributionJson.attributes,
|
||||
type: "FloatDistribution",
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if (distributionJson.name === "CategoricalDistribution") {
|
||||
return {
|
||||
type: "CategoricalDistribution",
|
||||
choices: distributionJson["attributes"]["choices"],
|
||||
choices: distributionJson.attributes.choices,
|
||||
}
|
||||
}
|
||||
throw new Error(`Unexpected distribution: ${distribution}`)
|
||||
}
|
||||
|
||||
class JournalStorage {
|
||||
private studies: Optuna.Study[] = []
|
||||
private studies: Study[] = []
|
||||
private nextStudyId = 0
|
||||
private studyIdToTrialIDs: Map<number, number[]> = new Map()
|
||||
private trialIdToStudyId: Map<number, number> = new Map()
|
||||
private trialID = 0
|
||||
|
||||
public getStudies(): Optuna.Study[] {
|
||||
public getStudies(): Study[] {
|
||||
for (const study of this.studies) {
|
||||
const unionUserAttrs: Set<string> = new Set()
|
||||
const unionSearchSpace: Set<string> = new Set()
|
||||
@@ -180,11 +187,13 @@ class JournalStorage {
|
||||
return
|
||||
}
|
||||
|
||||
const params: Optuna.TrialParam[] =
|
||||
const params: TrialParam[] =
|
||||
log.params === undefined || log.distributions === undefined
|
||||
? []
|
||||
: Object.entries(log.params).map(([name, value]) => {
|
||||
const distribution = parseDistribution(log.distributions![name])
|
||||
const distribution = parseDistribution(
|
||||
log.distributions?.[name] || ""
|
||||
)
|
||||
return {
|
||||
name: name,
|
||||
param_internal_value: value,
|
||||
@@ -192,11 +201,11 @@ class JournalStorage {
|
||||
param_external_value: (() => {
|
||||
if (distribution.type === "FloatDistribution") {
|
||||
return value.toString()
|
||||
} else if (distribution.type === "IntDistribution") {
|
||||
return value.toString()
|
||||
} else {
|
||||
return distribution.choices[value]
|
||||
}
|
||||
if (distribution.type === "IntDistribution") {
|
||||
return value.toString()
|
||||
}
|
||||
return distribution.choices[value]
|
||||
})(),
|
||||
distribution: distribution,
|
||||
}
|
||||
@@ -219,11 +228,11 @@ class JournalStorage {
|
||||
values: (() => {
|
||||
if (log.value !== undefined) {
|
||||
return [log.value]
|
||||
} else if (log.values !== undefined) {
|
||||
return log.values
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
if (log.values !== undefined) {
|
||||
return log.values
|
||||
}
|
||||
return undefined
|
||||
})(),
|
||||
params: params,
|
||||
intermediate_values: [],
|
||||
@@ -245,7 +254,7 @@ class JournalStorage {
|
||||
this.trialID++
|
||||
}
|
||||
|
||||
private getStudyAndTrial(trial_id: number): [Optuna.Study?, Optuna.Trial?] {
|
||||
private getStudyAndTrial(trial_id: number): [Study?, Trial?] {
|
||||
const study = this.studies.find(
|
||||
(item) => item.study_id === this.trialIdToStudyId.get(trial_id)
|
||||
)
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as Optuna from "@optuna/types"
|
||||
// @ts-ignore
|
||||
import sqlite3InitModule from "@sqlite.org/sqlite-wasm"
|
||||
import * as Optuna from "@optuna/types"
|
||||
import { OptunaStorage } from "./storage"
|
||||
|
||||
type SQLite3DB = {
|
||||
exec(options: {
|
||||
sql: string
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
callback: (...args: any[]) => void
|
||||
}): void
|
||||
close(): void
|
||||
@@ -258,7 +258,10 @@ const getTrialValues = (
|
||||
return values
|
||||
}
|
||||
|
||||
const getTrialParams = (db: SQLite3DB, trialId: number): Optuna.TrialParam[] => {
|
||||
const getTrialParams = (
|
||||
db: SQLite3DB,
|
||||
trialId: number
|
||||
): Optuna.TrialParam[] => {
|
||||
const params: Optuna.TrialParam[] = []
|
||||
db.exec({
|
||||
sql: `SELECT param_name, param_value, distribution_json FROM trial_params WHERE trial_id = ${trialId}`,
|
||||
Reference in New Issue
Block a user