Add a test case for JournalFileStorage

This commit is contained in:
c-bata
2024-03-23 02:41:31 +09:00
parent d2a135d474
commit 8be15734f8
5 changed files with 36 additions and 1 deletions
+2
View File
@@ -32,6 +32,8 @@ rustlib/pkg/
.coverage
.coverage.*
coverage.xml
tslib/storage/test/asset/*.log
tslib/storage/test/asset/*.db
# Others
.envrc
+1
View File
@@ -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)
+15
View File
@@ -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);
});
+1 -1
View File
@@ -14,7 +14,7 @@
"rootDir": "./src",
"outDir": "./pkg",
"allowSyntheticDefaultImports": true,
"target": "es5",
"target": "es2021",
"sourceMap": true,
"declaration": true,
"strict": true