Skip to content
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
8 changes: 5 additions & 3 deletions .github/workflows/checks_js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ jobs:
node-version: '24'
- name: Installing biome.js
working-directory: rustuna_js
run: npm i -g biome
run: npm i -g @biomejs/biome@2.6.8
- name: Install TypeScript
run: npm i -g typescript@7.0.2
- name: Lint
working-directory: rustuna_js
run: biome ci examples/*.ts test/*.mjs
Expand All @@ -44,10 +46,10 @@ jobs:
run: |
WASM_BINDGEN_VERSION=$(cargo metadata --format-version 1 --locked | jq -r '.packages[] | select(.name == "wasm-bindgen") | .version')
if ! command -v wasm-bindgen &> /dev/null || [ "$(wasm-bindgen --version | awk '{print $2}')" != "$WASM_BINDGEN_VERSION" ]; then
cargo install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION" --force
cargo install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION" --locked --force
fi
if ! command -v wasm-opt &> /dev/null; then
cargo install wasm-opt
cargo install wasm-opt --version 0.116.1 --locked
fi
- name: Build JS binding
working-directory: rustuna_js
Expand Down
10 changes: 5 additions & 5 deletions rustuna_js/test/distribution.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "node:test";
import assert from "node:assert";
import test from "node:test";

import * as rustuna from "../pkg/node/rustuna.js";

Expand All @@ -8,24 +8,24 @@ test("optimize simple quadratic function", () => {
study.optimize((trial) => {
const x = trial.suggest_float("x", -10.0, 10.0);
const y = trial.suggest_int("y", -10, 10);
const z = trial.suggest_categorical("z", ["foo", "bar"]);
trial.suggest_categorical("z", ["foo", "bar"]);
const value = (x - 5) ** 2 + (y + 2) ** 2;
return value;
}, 30);
const best_trial = study.best_trial;
assert.equal(best_trial.params.length, 3);

let x_param = best_trial.params.find((param) => param.name === "x");
const x_param = best_trial.params.find((param) => param.name === "x");
assert.equal(x_param.name, "x");
assert.equal(
x_param.internal_value >= -10 && x_param.internal_value <= 10,
true,
);

let z_param = best_trial.params.find((param) => param.name === "z");
const z_param = best_trial.params.find((param) => param.name === "z");
assert.equal(z_param.name, "z");
assert.equal(
z_param.external_value == "foo" || z_param.external_value == "bar",
z_param.external_value === "foo" || z_param.external_value === "bar",
true,
);
});
7 changes: 3 additions & 4 deletions rustuna_js/test/study_optimize.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import test from "node:test";
import assert from "node:assert";
import test from "node:test";

import * as rustuna from "../pkg/node/rustuna.js";
import { type } from "node:os";

test("optimize simple quadratic function", () => {
const study = rustuna.create_study("test");
study.optimize((trial) => {
const x = trial.suggest_float("x", -10.0, 10.0);
const y = trial.suggest_int("y", -10, 10);
const z = trial.suggest_categorical("z", ["foo", "bar"]);
trial.suggest_categorical("z", ["foo", "bar"]);
const value = (x - 5) ** 2 + (y + 2) ** 2;
return value;
}, 30);
Expand All @@ -20,7 +19,7 @@ test("optimize simple quadratic function", () => {
test("sample categorical values", () => {
const study = rustuna.create_study("test");
study.optimize((trial) => {
const z = trial.suggest_categorical("z", ["foo", 1, true, false, null]);
trial.suggest_categorical("z", ["foo", 1, true, false, null]);
// console.log(z);
// console.log(typeof z);
return 1.0;
Expand Down
2 changes: 1 addition & 1 deletion rustuna_js/test/user_attr.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "node:test";
import assert from "node:assert";
import test from "node:test";

import * as rustuna from "../pkg/node/rustuna.js";

Expand Down