mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-08-20 12:40:54 +08:00
Add a test case for JournalFileStorage
This commit is contained in:
@@ -32,6 +32,8 @@ rustlib/pkg/
|
||||
.coverage
|
||||
.coverage.*
|
||||
coverage.xml
|
||||
tslib/storage/test/asset/*.log
|
||||
tslib/storage/test/asset/*.db
|
||||
|
||||
# Others
|
||||
.envrc
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "@optuna/storage",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "Loaders for Optuna storages",
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import os.path
|
||||
import optuna
|
||||
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def objective(trial):
|
||||
x = trial.suggest_uniform('x', -10, 10)
|
||||
return (x - 2) ** 2
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
journal_backend = optuna.storages.JournalFileStorage(os.path.join(BASE_DIR, "journal.log"))
|
||||
storage = optuna.storages.JournalStorage(journal_backend)
|
||||
study = optuna.create_study(storage=storage)
|
||||
study.optimize(objective, n_trials=100)
|
||||
@@ -0,0 +1,15 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert";
|
||||
import path from "node:path";
|
||||
import { openAsBlob } from "node:fs";
|
||||
|
||||
import * as mut from "../pkg/journal.js";
|
||||
|
||||
test("Test Journal File Storage", async () => {
|
||||
const blob = await openAsBlob(path.resolve(".", "test", "asset", "journal.log"));
|
||||
const buf = await blob.arrayBuffer();
|
||||
const storage = new mut.JournalFileStorage(buf);
|
||||
const studies = await storage.getStudies();
|
||||
|
||||
assert.strictEqual(studies.length, 1);
|
||||
});
|
||||
@@ -14,7 +14,7 @@
|
||||
"rootDir": "./src",
|
||||
"outDir": "./pkg",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es5",
|
||||
"target": "es2021",
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"strict": true
|
||||
|
||||
Reference in New Issue
Block a user