Bencher
Continuous Integration Status
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:
- Getting Started guide — sweep types, result types, the
benchmark()pattern, run configuration, and common mistakes - Examples index — every hand-written example, one line each
- Caching guide and Tracking results over time
- Live documentation: https://bencher.readthedocs.io/
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 trackinggenerated/plot_types/— All supported plot types (scatter, line, heatmap, surface, etc.)generated/result_types/— Result types: images, videos, strings, booleans, paths, datasetsgenerated/composable_containers/— Combining results with different composition strategiesgenerated/sampling/— Custom values, levels, uniform, int vs floatgenerated/optimization/— Single and multi-objective optimization with Optunagenerated/advanced/— Time events, caching, aggregation over timegenerated/regression/— Performance regression detectiongenerated/statistics/— Error bands, distributions, repeats comparison
A few hand-written examples remain for unique functionality:
example_simple_float.py— Minimal getting-started exampleexample_image.py/example_video.py— Image and video result typesexample_self_benchmark.py— Bencher self-introspectionexample_workflow.py— Multi-stage optimization workflow
docs/examples_index.md describes every one of them, plus the generated galleries by category.
Documentation
- Getting Started — the practical quick-start reference
- Feature Guide — dimensions, repeats, over-time tracking, optimisation
- Concepts — architecture and the grammar of benchmarking
- Caching — the sample cache, the result cache, and the flags that drive them
- Tracking results over time — history, sliders, and regression detection
- Examples index — every hand-written example with a one-line description
- Examples Documentation
- API documentation
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file holobench-1.122.0.tar.gz.
File metadata
- Download URL: holobench-1.122.0.tar.gz
- Upload date:
- Size: 534.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
436475107512b5a0e42046ca4a06151f5b67248d2a4f0171d29484d9d5334ce9
|
|
| MD5 |
154aacda24a9a12460ce279dadb9cd3f
|
|
| BLAKE2b-256 |
4808f3c6af5214d5e01639b854daa36772b3701bd4647b90b03740303ac97f46
|
File details
Details for the file holobench-1.122.0-py3-none-any.whl.
File metadata
- Download URL: holobench-1.122.0-py3-none-any.whl
- Upload date:
- Size: 788.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6321f0590bbea212ff367e5080a8dfe7c22a8f942f0a36bac3144702b34ca96
|
|
| MD5 |
e570394286b81e99f63913b720a71f45
|
|
| BLAKE2b-256 |
f3131b9cfca9f31b9d13f6d66845538c9f3d8ab3142daa7568cdb945747c02d6
|