Skip to main content

Bencher

Continuous Integration Status

Ci Read the Docs Codecov GitHub issues GitHub pull-requests merged PyPI PyPI - Downloads License Python Pixi Badge

Getting Started

Bencher sweeps a function across the Cartesian product of typed parameters, stores the results in an N-dimensional xarray dataset, and auto-selects interactive plots from the parameter and result types. Opt in to caching and each sample is persisted as it completes, so an interrupted sweep resumes instead of starting over. You declare the inputs, the outputs, and the body of the measurement — no sweep loops, no plotting code, no report scaffolding.

pip install holobench
import math

import bencher as bn


class SimpleFloat(bn.ParametrizedSweep):
    theta = bn.FloatSweep(default=0, bounds=[0, math.pi], doc="Input angle", units="rad", samples=30)
    out_sin = bn.ResultFloat(units="v", doc="sin of theta")

    def benchmark(self):
        self.out_sin = math.sin(self.theta)


def example_simple_float(run_cfg: bn.BenchRunCfg | None = None) -> bn.Bench:
    bench = SimpleFloat().to_bench(run_cfg)
    bench.plot_sweep()
    return bench


if __name__ == "__main__":
    bn.run(example_simple_float)

Running that opens an interactive report containing a line plot of out_sin against theta, picked automatically because the input is a float and the result is a float. The full version of this file is bencher/example/example_simple_float.py.

Next steps:

Intro

Bencher is a tool to make it easy to benchmark the interactions between the input parameters to your algorithm and its resulting performance on a set of metrics. It calculates the cartesian product of a set of variables

Parameters for bencher are defined using the param library as a config class with extra metadata that describes the bounds of the search space you want to measure. That class implements a benchmark() method which reads the swept parameters from self and assigns the measured values to the result variables declared on the same class.

Parameters are benchmarked by passing in a list N parameters, and an N-Dimensional tensor is returned. You can optionally sample each point multiple times to get back a distribution and also track its value over time. By default the data will be plotted automatically based on the types of parameters you are sampling (e.g, continuous, discrete), but you can also pass in a callback to customize plotting.

The data is stored in a persistent database so that past performance is tracked.

Assumptions

The input types should also be of one of the basic datatypes (bool, int, float, str, enum, datetime) so that the data can be easily hashed, cached and stored in the database and processed with seaborn and xarray plotting functions. You can use class inheritance to define hierarchical parameter configuration class types that can be reused in a bigger configuration classes.

Bencher is designed to work with stochastic pure functions with no side effects. It assumes that when the objective function is given the same inputs, it will return the same output +- random noise. This is because the function must be called multiple times to get a good statistical distribution of it and so each call must not be influenced by anything or the results will be corrupted.

Pseudocode of bencher

Enumerate a list of all input parameter combinations
for each set of input parameters:
    pass the inputs to the objective function and store results in the N-D array

    get unique hash for the set of inputs parameters
    look up previous results for that hash
    if it exists:
        load historical data
        combine latest data with historical data
    
    store the results using the input hash as a key
deduce the type of plot based on the input and output types
return data and plot

Resource Management with sampling_context

If your benchmark holds external resources (DB pools, GPU handles, simulators) you may want to release them before the interactive result viewer starts. Wrapping the entire bn.run() call in a with block won't work — the context stays open while the Panel/Bokeh server blocks:

# Anti-pattern: resources held during the entire viewing session
with gpu_context():
    bn.run(my_bench, show=True)

Instead, pass the context manager as sampling_context. It wraps only the sampling phase; its __exit__ runs before the server starts:

bn.run(my_bench, show=True, sampling_context=gpu_context())

save and publish still execute inside the context (during sampling), so results are persisted before the resource is released.

Demo

if you have pixi installed you can run a demo example with:

pixi run demo

An example of the type of output bencher produces can be seen here:

https://blooop.github.io/bencher/

Examples

Most features are demonstrated in the auto-generated examples under bencher/example/generated/.

Run pixi run generate-docs to regenerate the full example gallery. Key sections include:

  • generated/N_float/ — Parameter sweeps with 0–3 float inputs, with/without repeats and over-time tracking
  • generated/plot_types/ — All supported plot types (scatter, line, heatmap, surface, etc.)
  • generated/result_types/ — Result types: images, videos, strings, booleans, paths, datasets
  • generated/composable_containers/ — Combining results with different composition strategies
  • generated/sampling/ — Custom values, levels, uniform, int vs float
  • generated/optimization/ — Single and multi-objective optimization with Optuna
  • generated/advanced/ — Time events, caching, aggregation over time
  • generated/regression/ — Performance regression detection
  • generated/statistics/ — Error bands, distributions, repeats comparison

A few hand-written examples remain for unique functionality:

  • example_simple_float.py — Minimal getting-started example
  • example_image.py / example_video.py — Image and video result types
  • example_self_benchmark.py — Bencher self-introspection
  • example_workflow.py — Multi-stage optimization workflow

docs/examples_index.md describes every one of them, plus the generated galleries by category.

Documentation

Download files

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

Source Distribution

holobench-1.119.0.tar.gz (527.7 kB view details)

Uploaded Source

Built Distribution

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

holobench-1.119.0-py3-none-any.whl (781.4 kB view details)

Uploaded Python 3

File details

Details for the file holobench-1.119.0.tar.gz.

File metadata

  • Download URL: holobench-1.119.0.tar.gz
  • Upload date:
  • Size: 527.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for holobench-1.119.0.tar.gz
Algorithm Hash digest
SHA256 3dc79078e9e867074762351124cf2e8f91949c9450c2adb6cdda6d590e494561
MD5 2570e5e52762bedf06a1bb8b0859b829
BLAKE2b-256 8ca6b737999f666ce1c2b1eda28675cb57b9a99ac53e0663b49580eeac8bc508

See more details on using hashes here.

File details

Details for the file holobench-1.119.0-py3-none-any.whl.

File metadata

  • Download URL: holobench-1.119.0-py3-none-any.whl
  • Upload date:
  • Size: 781.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for holobench-1.119.0-py3-none-any.whl
Algorithm Hash digest
SHA256 976e1783581695bd524281a95e9498a2e016e45df5d3e954f482e29fc7c91f8b
MD5 e1612c6f399e352f7e00e4d1364dd25d
BLAKE2b-256 90a31a32c006632325cd0bda2fdfc0799a0f1f922738522a3de198bc36f59942

See more details on using hashes here.

Release history Release notifications | RSS feed

1.122.0

2 files

1.121.1

2 files

1.121.0

2 files

1.120.0

2 files

1.119.1

2 files

This release

1.119.0 This release

2 files

1.118.0

2 files

1.117.0

2 files

1.116.0

2 files

1.115.0

2 files

1.114.0

2 files

1.113.1

2 files

1.113.0

2 files

1.112.0

2 files

1.111.0

2 files

1.110.0

2 files

1.109.0

2 files

1.108.0

2 files

1.107.0

2 files

1.106.2

2 files

1.106.1

2 files

1.106.0

2 files

1.105.0

2 files

1.104.2

2 files

1.104.1

2 files

1.104.0

2 files

1.103.1

2 files

1.103.0

2 files

1.102.0

2 files

1.101.1

2 files

1.101.0

2 files

1.100.0

2 files

1.99.0

2 files

1.98.0

2 files

1.97.0

2 files

1.96.0

2 files

1.95.0

2 files

1.94.0

2 files

1.93.0

2 files

1.92.0

2 files

1.91.0

2 files

1.90.0

2 files

1.89.0

2 files

1.88.0

2 files

1.87.0

2 files

1.86.0

2 files

1.85.1

2 files

1.85.0

2 files

1.84.0

2 files

1.83.0

2 files

1.82.1

2 files

1.82.0

2 files

1.81.0

2 files

1.80.2

2 files

1.80.1

2 files

1.80.0

2 files

1.79.0

2 files

1.78.0

2 files

1.77.0

2 files

1.76.0

2 files

1.75.2

2 files

1.75.1

2 files

1.75.0

2 files

1.74.0

2 files

1.73.1

2 files

1.73.0

2 files

1.72.5

2 files

1.72.4

2 files

1.72.3

2 files

1.72.2

2 files

1.72.1

2 files

1.72.0

2 files

1.71.0

2 files

1.70.5

2 files

1.70.4

2 files

1.70.3

2 files

1.70.2

2 files

1.70.1

2 files

1.70.0

2 files

1.69.0

2 files

1.68.0

2 files

1.67.0

2 files

1.66.3

2 files

1.66.2

2 files

1.66.1

2 files

1.66.0

2 files

1.65.0

2 files

1.64.0

2 files

1.63.0

2 files

1.62.0

2 files

1.61.0

2 files

1.60.0

2 files

1.59.0

2 files

1.58.1

2 files

1.58.0

2 files

1.57.0

2 files

1.56.1

2 files

1.56.0

2 files

1.55.0

2 files

1.54.2

2 files

1.54.1

2 files

1.54.0

2 files

1.53.1

2 files

1.53.0

2 files

1.52.0

2 files

1.51.3

2 files

1.51.2

2 files

1.51.1

2 files

1.51.0

2 files

1.50.0

2 files

1.49.0

2 files

1.48.0

2 files

1.47.0

2 files

1.46.0

2 files

1.45.0

2 files

1.44.0

2 files

1.43.0

2 files

1.42.0

2 files

1.41.0

2 files

1.40.1

2 files

1.40.0

2 files

1.39.0

2 files

1.38.0

2 files

1.36.2

2 files

1.36.1

2 files

1.36.0

2 files

1.35.0

2 files

1.34.0

2 files

1.33.2

2 files

1.33.1

2 files

1.33.0

2 files

1.32.0

2 files

1.31.1

2 files

1.31.0

2 files

1.30.3

2 files

1.30.2

2 files

1.30.1

2 files

1.30.0

2 files

1.29.0

2 files

1.28.1

2 files

1.28.0

2 files

1.27.0

2 files

1.26.3

2 files

1.25.2

2 files

1.25.1

2 files

1.25.0

2 files

1.24.0

2 files

1.23.0

2 files

1.22.2

2 files

1.19.0

2 files

1.18.0

2 files

1.17.1

2 files

1.17.0

2 files

1.16.0

2 files

1.15.0

2 files

1.13.0

2 files

1.12.0

2 files

1.11.0

2 files

1.10.0

2 files

1.9.0

2 files

1.8.0

2 files

1.7.0

2 files

1.6.0

2 files

1.5.0

2 files

1.4.0

2 files

1.3.6

2 files

1.3.5

2 files

1.3.4

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.6.1

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.16

2 files

0.3.15

2 files

0.3.14

2 files

0.3.13

2 files

0.3.9

2 files

0.3.6

2 files

0.3.3

2 files

0.3.2

2 files

0.3.0

2 files

0.2.5

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.0.8

2 files

0.0.6

2 files

0.0.5

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

0.0.0

2 files

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