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.1.tar.gz (5.8 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.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for optuna_async_helper-0.7.1.tar.gz
Algorithm Hash digest
SHA256 89fc577b1217f133dbd0f742d5a2363be5d65e93a7906ff6cb942f083e214965
MD5 cb7a52c3f4e1204f1c997bc17fcfe4be
BLAKE2b-256 b2a68d2ffa18170fef22a869d240ca1ae4031ce945808d8300a7c6a5c8c77ee4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for optuna_async_helper-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 217c0bf865673b0a62b267ab9842d3989b796f84a426bb50ff12ab4bbd64d3ac
MD5 7666a459e14d232e6a3b3e465964feb4
BLAKE2b-256 111baf15edbf70855404fd3ca1cd322cc8c3912654f7b66155e53fa47fb5ca86

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