Skip to main content

kurobako-py

pypi GitHub license Actions Status

A Python library to help implement kurobako's solvers and problems.

Installation

$ pip install kurobako

Usage Examples

# filename: random_solver.py
import numpy as np

from kurobako import problem
from kurobako import solver


class RandomSolverFactory(solver.SolverFactory):
    def specification(self):
        return solver.SolverSpec(name='Random Search')

    def create_solver(self, seed, problem):
        return RandomSolver(seed, problem)


class RandomSolver(solver.Solver):
    def __init__(self, seed, problem):
        self._rng = np.random.RandomState(seed)
        self._problem = problem

    def ask(self, idg):
        params = []
        for p in self._problem.params:
            if p.distribution == problem.Distribution.UNIFORM:
                params.append(self._rng.uniform(p.range.low, p.range.high))
            else:
                low = np.log(p.range.low)
                high = np.log(p.range.high)
                params.append(float(np.exp(self._rng.uniform(low, high))))

        trial_id = idg.generate()
        next_step = self._problem.last_step
        return solver.NextTrial(trial_id, params, next_step)

    def tell(self, trial):
        pass


if __name__ == '__main__':
    runner = solver.SolverRunner(RandomSolverFactory())
    runner.run()

Define a problem that represents a quadratic function x**2 + y

# filename: quadratic_problem.py
from kurobako import problem


class QuadraticProblemFactory(problem.ProblemFactory):
    def specification(self):
        params = [
            problem.Var('x', problem.ContinuousRange(-10, 10)),
            problem.Var('y', problem.DiscreteRange(-3, 3))
        ]
        return problem.ProblemSpec(name='Quadratic Function',
                                   params=params,
                                   values=[problem.Var('x**2 + y')])

    def create_problem(self, seed):
        return QuadraticProblem()


class QuadraticProblem(problem.Problem):
    def create_evaluator(self, params):
        return QuadraticEvaluator(params)


class QuadraticEvaluator(problem.Evaluator):
    def __init__(self, params):
        self._x, self._y = params
        self._current_step = 0

    def current_step(self):
        return self._current_step

    def evaluate(self, next_step):
        self._current_step = 1
        return [self._x**2 + self._y]


if __name__ == '__main__':
    runner = problem.ProblemRunner(QuadraticProblemFactory())
    runner.run()

Run a benchmark that uses the above solver and problem

$ SOLVER=$(kurobako solver command python3 random_solver.py)
$ PROBLEM=$(kurobako problem command python3 quadratic_problem.py)
$ kurobako studies --solvers $SOLVER --problems $PROBLEM | kurobako run > result.json

Metadata

Release files for kurobako 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kurobako 0.2.1
File Size Uploaded
kurobako-0.2.1.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kurobako 0.2.1
File Interpreter ABI Platform
kurobako-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.1 kB

Release files / kurobako-0.2.1.tar.gz

Download URL kurobako-0.2.1.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d153a8fc7a7f1a4b4a8e077dbd6dc9fa8a706d3600b8abb69c7af532cc36ab4c
BLAKE2b-256 checksum
How to use checksums
f918c31ff1d69992c080338483e0ccf117f95053d3462aa4b0062c8adc873d69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release files / kurobako-0.2.1-py3-none-any.whl

Download URL kurobako-0.2.1-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24f4b340a13913bd7e4b9f31e4767bfd9301e5d2805b855fa673ad5a1c196195
BLAKE2b-256 checksum
How to use checksums
c14d37140322e5a7f71e0a87e4f2dc24af4a7f3a0caaa44fa238c31c3a851f7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page