Skip to main content

A Helper Library for Optuna Async Optimization

Project description

Optuna Async Helper

A Helper Library for Optuna Async Optimization

Install

pip install optuna-async-helper

Usage

import tempfile

from optuna_async_helper import (
    SearchSpace,
    SearchSpec,
    optimize,
    create_journal_storage,
    create_study,
)


def rosenbrock(x: float, y: float, z: float) -> float:
    return (z - x) ** 2 + 100 * (y - x**2) ** 2


def test_optimizer():
    search_space: SearchSpace = [
        SearchSpec(var_name="x", domain_type="float", low=-5, high=5),
        SearchSpec(var_name="y", domain_type="float", low=-5, high=5),
    ]
    z = 0.5
    initial_params = [
        {"x": 0, "y": 0},
        {"x": 1.0, "y": 0},
        {"x": 0, "y": 1.0},
    ]

    with tempfile.TemporaryDirectory() as tempdir:
        storage = create_journal_storage(f"{tempdir}/example.db")
        study = create_study(
            study_name="rosenbrock",
            storage=storage,
        )
        study = optimize(
            study,
            objective_func=rosenbrock,
            search_space=search_space,
            initial_params=initial_params,
            n_trials=10,
            batch_size=32,
            z=z,
        )

        assert study.best_value < 1.0
        assert abs(study.best_params["x"] - z) < 1.0
        assert abs(study.best_params["y"] - z) < 1.0

For more detail, please check optimize and SearchSpec definitions.

Development

The project is managed by uv

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optuna_async_helper-0.6.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

optuna_async_helper-0.6.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file optuna_async_helper-0.6.0.tar.gz.

File metadata

  • Download URL: optuna_async_helper-0.6.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.29

File hashes

Hashes for optuna_async_helper-0.6.0.tar.gz
Algorithm Hash digest
SHA256 965c20b0e5e221807013fee1c8cf327430279579ffa5f01e32d8eb28294cebe3
MD5 6626c4cd860612fecf1c10fb3a6f6a18
BLAKE2b-256 60a9aedf9ef6d8c621bf82fca1f62b23c206d4528eb817f1f84310800665b9ed

See more details on using hashes here.

File details

Details for the file optuna_async_helper-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for optuna_async_helper-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b6c473914a0ee4060d7e1b3734576a3e5520490a339a82418522a98fe405536
MD5 5040e6c33e93c3ebda412ddcf5ec1c57
BLAKE2b-256 73465f9c1afdd97ca8b902eda031c917b8d573c6a1dd6ed9f5de1af6dcdc3be0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page