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.7.0.tar.gz (5.9 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.7.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for optuna_async_helper-0.7.0.tar.gz
Algorithm Hash digest
SHA256 198763cc7d2df06d3744afe2ba5788b2b1a77e01679454ac8a10e61b991a4e80
MD5 04f4853b5be920957eed76e8d95a82d1
BLAKE2b-256 d0446c854df797e57d1fad0329cfde45f12f2be693fefc25707fbe7a1b57e026

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for optuna_async_helper-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b70b31b1d790ade3a8f0992d96cac52c6d2d4df32ff9690c600c2d126d0bc2d
MD5 71b1b6ffeffc813966112d8568436744
BLAKE2b-256 9dadc442a3b048e4c246f4f6c4793cece7c931c300f1e9b3ace07dda17a796ea

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