Skip to content

Commit

Permalink
Merge pull request #300 from dyson-ai/feature/test_meta
Browse files Browse the repository at this point in the history
Feature/test meta
  • Loading branch information
blooop committed Dec 31, 2023
2 parents bf2edf3 + 2af9918 commit 8b8cfc7
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ class BenchMeta(bch.ParametrizedSweep):
"""This class uses bencher to display the multidimensional types bencher can represent"""

float_vars = bch.IntSweep(
default=1, bounds=(0, 3), doc="The number of floating point variables that are swept"
default=1, bounds=(0, 4), doc="The number of floating point variables that are swept"
)
categorical_vars = bch.IntSweep(
default=1, bounds=(0, 3), doc="The number of categorical variables that are swept"
)
sample_with_repeats = bch.IntSweep(default=1, bounds=(1, 2))
sample_with_repeats = bch.IntSweep(default=1, bounds=(1, 10))

sample_over_time = bch.BoolSweep(default=False)

Expand Down Expand Up @@ -143,16 +143,16 @@ def __call__(self, **kwargs: Any) -> Any:
def example_meta(
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
) -> bch.Bench:
bench = bch.Bench("bench_meta", BenchMeta(), report=report, run_cfg=run_cfg)
bench = BenchMeta().to_bench(run_cfg, report)

bench.plot_sweep(
title="Meta Bench",
description="""## All Combinations of Variable Sweeps and Resulting Plots
This uses bencher to display all the combinatios of plots bencher is able to produce""",
input_vars=[
BenchMeta.param.float_vars,
BenchMeta.param.float_vars.with_sample_values([0, 1, 2, 3]),
BenchMeta.param.categorical_vars,
BenchMeta.param.sample_with_repeats,
BenchMeta.param.sample_with_repeats.with_sample_values([1, 2]),
# BenchMeta.param.sample_over_time,
],
const_vars=[
Expand Down
25 changes: 25 additions & 0 deletions bencher/example/meta/example_meta_cat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import bencher as bch
from bencher.example.meta.example_meta import BenchMeta


def example_meta_cat(
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
) -> bch.Bench:
bench = BenchMeta().to_bench(run_cfg, report)

bench.plot_sweep(
title="Sweeping Categorical Variables",
input_vars=[
BenchMeta.param.categorical_vars.with_sample_values([1, 2, 3]),
BenchMeta.param.sample_with_repeats.with_sample_values([1, 2]),
],
const_vars=[
BenchMeta.param.float_vars.with_const(0),
],
)

return bench


if __name__ == "__main__":
example_meta_cat().report.show()
23 changes: 23 additions & 0 deletions bencher/example/meta/example_meta_float.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import bencher as bch
from bencher.example.meta.example_meta import BenchMeta


def example_meta_float(
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
) -> bch.Bench:
bench = BenchMeta().to_bench(run_cfg, report)

bench.plot_sweep(
title="Sweeping Floating Point Variables",
input_vars=[BenchMeta.param.float_vars.with_sample_values([1, 2, 3, 4])],
const_vars=[
BenchMeta.param.categorical_vars.with_const(0),
BenchMeta.param.level.with_const(3),
],
)

return bench


if __name__ == "__main__":
example_meta_float().report.show()
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import bencher as bch
from bencher.example.example_meta import BenchMeta
from bencher.example.meta.example_meta import BenchMeta


def example_meta_levels(
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
) -> bch.Bench:
bench = bch.Bench("bench_meta", BenchMeta(), report=report, run_cfg=run_cfg)
bench = BenchMeta().to_bench(run_cfg, report)

bench.plot_sweep(
title="Using Levels to define sample density",
Expand Down
4 changes: 4 additions & 0 deletions bencher/results/bench_result_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def to_hv_dataset(
Returns:
hv.Dataset: results in the form of a holoviews dataset
"""

if reduce == ReduceType.NONE:
kdims = [i.name for i in self.bench_cfg.all_vars]
return hv.Dataset(self.to_dataset(reduce, result_var), kdims=kdims)
return hv.Dataset(self.to_dataset(reduce, result_var))

def to_dataset(
Expand Down
10 changes: 8 additions & 2 deletions bencher/variables/parametrised_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ResultContainer,
ResultReference,
)

from uuid import uuid4


Expand Down Expand Up @@ -207,7 +208,12 @@ def gen_video_path(self, video_name: str) -> str:
def gen_image_path(self, image_name: str, filetype=".png") -> str:
return self.gen_path(image_name, "img", filetype)

def to_bench(self, run_cfg=None, report=None):
def to_bench(self, run_cfg=None, report=None, name: str = None):
from bencher import Bench

return Bench(self.name, self, run_cfg=run_cfg, report=report)
assert isinstance(self, ParametrizedSweep)

if name is None:
name = self.name

return Bench(name, self, run_cfg=run_cfg, report=report)
11 changes: 6 additions & 5 deletions index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "holobench"
version = "1.2.1"
version = "1.2.2"

authors = [{ name = "Austin Gregg-Smith", email = "blooop@gmail.com" }]
description = "A package for benchmarking the performance of arbitrary functions"
Expand Down
21 changes: 16 additions & 5 deletions test/test_bench_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
from bencher.example.example_strings import example_strings
from bencher.example.example_image import example_image
from bencher.example.example_video import example_video
from bencher.example.example_meta_levels import example_meta_levels
from bencher.example.meta.example_meta_levels import example_meta_levels
from bencher.example.meta.example_meta import example_meta
from bencher.example.meta.example_meta_cat import example_meta_cat
from bencher.example.meta.example_meta_float import example_meta_float


import os
Expand Down Expand Up @@ -62,11 +65,13 @@ def test_publish_docs(self):
# b_run.run(level=4, grouped=True, save=True)
# b_run.shutdown()
report = bch.BenchReport()
example_image(run_cfg=run_cfg, report=report)
example_video(run_cfg=run_cfg, report=report)
example_image(run_cfg, report)
example_video(run_cfg, report)
example_meta_cat(run_cfg, report)
example_meta_float(run_cfg, report)
run_cfg.level = 4
example_meta_levels(run_cfg=run_cfg, report=report)
# example_meta(run_cfg=run_cfg, report=report)
example_meta_levels(run_cfg, report)
# example_meta(run_cfg,report)

report.save_index()

Expand Down Expand Up @@ -127,6 +132,12 @@ def test_example_image(self) -> None:
def test_example_video(self) -> None:
self.examples_asserts(example_video(self.create_run_cfg()))

def test_example_meta(self) -> None:
self.examples_asserts(example_meta(self.create_run_cfg()))

# def test_example_meta_scatter(self) -> None:
# self.examples_asserts(example_meta_scatter(self.create_run_cfg()))

# shelved
# def test_example_cone(self) -> None:
# self.examples_asserts(example_cone(self.create_run_cfg()))
Expand Down
2 changes: 1 addition & 1 deletion test/test_bench_result_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import bencher as bch

from bencher.example.example_meta import BenchableObject
from bencher.example.meta.example_meta import BenchableObject


class TestBenchResultBase(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/test_meta_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
import bencher as bch
from bencher.example.example_meta import BenchableObject
from bencher.example.meta.example_meta import BenchableObject


class TestBenchMeta(unittest.TestCase):
Expand Down

0 comments on commit 8b8cfc7

Please sign in to comment.