Fix workflows

This commit is contained in:
c-bata
2024-03-27 07:50:22 +09:00
parent 8be15734f8
commit e6107cc275
8 changed files with 107 additions and 33 deletions
+32
View File
@@ -62,3 +62,35 @@ jobs:
run: |
npm install
npm run test
test-tslib:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
architecture: x64
- name: Generate test asset
working-directory: tslib/storage/test/
run: |
python -m pip install --progress-bar off --upgrade pip setuptools
pip install --progress-bar off optuna
python generate_assets.py
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Build test
run: make tslib
- name: Run tslib test
working-directory: tslib/storage
run: |
npm run test
+1 -2
View File
@@ -32,8 +32,7 @@ rustlib/pkg/
.coverage
.coverage.*
coverage.xml
tslib/storage/test/asset/*.log
tslib/storage/test/asset/*.db
tslib/storage/test/asset/
# Others
.envrc
+2 -1
View File
@@ -9,7 +9,8 @@
"vscode/src/**/*.ts",
"vscode/src/**/*.tsx",
"tslib/**/*.ts",
"tslib/**/*.tsx"
"tslib/**/*.tsx",
"tslib/**/*.mjs"
],
"ignore": [
"optuna_dashboard/ts/components/PlotlyColorTemplates.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"scripts": {
"fmt": "biome format --write . && biome check standalone_app vscode --apply",
"fmt": "biome format --write . && biome check standalone_app vscode tslib --apply",
"lint": "npm run lint:eslint && npm run lint:biome",
"lint:eslint": "eslint . --ext .ts,.tsx --max-warnings 0",
"lint:biome": "biome format . && biome ci standalone_app vscode tslib"
+1 -1
View File
@@ -4,4 +4,4 @@ ignore =
W503
max-line-length = 99
statistics = True
exclude = venv,build
exclude = venv,build,node_modules
@@ -1,17 +0,0 @@
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)
+55
View File
@@ -0,0 +1,55 @@
import os.path
import shutil
import optuna
from optuna.storages import BaseStorage, JournalStorage, JournalFileStorage, RDBStorage
optuna.logging.set_verbosity(optuna.logging.WARNING)
BASE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "asset")
def remove_assets() -> None:
if os.path.exists(BASE_DIR):
shutil.rmtree(BASE_DIR)
os.mkdir(BASE_DIR)
def create_optuna_storage(storage: BaseStorage) -> None:
# Single-objective study
study = optuna.create_study(
study_name="single-objective", storage=storage, sampler=optuna.samplers.RandomSampler()
)
print(f"Generating {study.study_name} for {type(storage).__name__}...")
def objective_single(trial: optuna.Trial) -> float:
x1 = trial.suggest_float("x1", 0, 10)
x2 = trial.suggest_float("x2", 0, 10)
trial.suggest_categorical("x3", ["foo", "bar"])
return (x1 - 2) ** 2 + (x2 - 5) ** 2
study.optimize(objective_single, n_trials=50)
# Single-objective study with dynamic search space
study = optuna.create_study(
study_name="single-objective-dynamic", storage=storage, direction="maximize"
)
print(f"Generating {study.study_name} for {type(storage).__name__}...")
def objective_single_dynamic(trial: optuna.Trial) -> float:
category = trial.suggest_categorical("category", ["foo", "bar"])
if category == "foo":
return (trial.suggest_float("x1", 0, 10) - 2) ** 2
else:
return -((trial.suggest_float("x2", -10, 0) + 5) ** 2)
study.optimize(objective_single_dynamic, n_trials=50)
if __name__ == "__main__":
remove_assets()
for storage in [
JournalStorage(JournalFileStorage(os.path.join(BASE_DIR, "journal.log"))),
RDBStorage("sqlite:///" + os.path.join(BASE_DIR, "db.sqlite3")),
]:
create_optuna_storage(storage)
+15 -11
View File
@@ -1,15 +1,19 @@
import test from "node:test";
import assert from "node:assert";
import path from "node:path";
import { openAsBlob } from "node:fs";
import assert from "node:assert"
import { openAsBlob } from "node:fs"
import path from "node:path"
import test from "node:test"
import * as mut from "../pkg/journal.js";
import * as mut from "../pkg/journal.js"
const n_studies = 2
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();
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);
});
assert.strictEqual(studies.length, n_studies)
})