-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #416 from dyson-ai/composable/container_dateframe
Composable/container dateframe
- Loading branch information
Showing
17 changed files
with
576 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
ResultReference, | ||
ResultVolume, | ||
OptDir, | ||
ResultDataSet, | ||
curve, | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import bencher as bch | ||
|
||
import xarray as xr | ||
import numpy as np | ||
import holoviews as hv | ||
|
||
|
||
class ExampleMergeDataset(bch.ParametrizedSweep): | ||
|
||
value = bch.FloatSweep(default=0, bounds=[0, 10]) | ||
repeats_x = bch.IntSweep(default=2, bounds=[2, 4]) | ||
# repeats_y = bch.IntSweep(default=2, bounds=[2, 4]) | ||
|
||
result_df = bch.ResultDataSet() | ||
|
||
def __call__(self, **kwargs): | ||
self.update_params_from_kwargs(**kwargs) | ||
# First, create a DataArray from the vector | ||
vector = [v + self.value for v in range(1, self.repeats_x)] | ||
data_array = xr.DataArray(vector, dims=["index"], coords={"index": np.arange(len(vector))}) | ||
# Convert the DataArray to a Dataset | ||
result_df = xr.Dataset({"result_df": data_array}) | ||
self.result_df = bch.ResultDataSet(result_df.to_pandas()) | ||
return super().__call__(**kwargs) | ||
|
||
|
||
def example_dataset(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None): | ||
bench = ExampleMergeDataset().to_bench(run_cfg, report) | ||
res = bench.plot_sweep(input_vars=["value"], const_vars=dict(repeats_x=4)) | ||
# bench.report.append(res.to_panes(target_dimension=1)) | ||
# bench.report.append(res.to_panes(target_dimension=2)) | ||
# bench.reprt.append(res.to_video_grid | ||
# # bch.BenchResult.to_video_grid, | ||
# target_duration=0.06, | ||
# compose_method_list=[ | ||
# bch.ComposeType.right, | ||
# bch.ComposeType.right, | ||
# bch.ComposeType.sequence, | ||
# ], | ||
# ) | ||
# bench.report.append(res.to_panes(container=hv.Bars,target_dimension=1)) | ||
# bench.report.append(res.to_panes(container=hv.Curve)) | ||
bench.report.append(res.to_dataset1(container=hv.Curve)) | ||
return bench | ||
|
||
|
||
if __name__ == "__main__": | ||
example_dataset().report.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import bencher as bch | ||
import numpy as np | ||
import math | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def polygon_points(radius: float, sides: int, start_angle: float): | ||
points = [] | ||
for ang in np.linspace(0, 360, sides + 1): | ||
angle = math.radians(start_angle + ang) | ||
points.append(([math.sin(angle) * radius, math.cos(angle) * radius])) | ||
return points | ||
|
||
|
||
class BenchPolygons(bch.ParametrizedSweep): | ||
sides = bch.IntSweep(default=3, bounds=(3, 7)) | ||
radius = bch.FloatSweep(default=1, bounds=(0.2, 1)) | ||
linewidth = bch.FloatSweep(default=1, bounds=(1, 10)) | ||
linestyle = bch.StringSweep(["solid", "dashed", "dotted"]) | ||
color = bch.StringSweep(["red", "green", "blue"]) | ||
start_angle = bch.FloatSweep(default=0, bounds=[0, 360]) | ||
polygon = bch.ResultImage() | ||
polygon_small = bch.ResultImage() | ||
|
||
area = bch.ResultVar() | ||
side_length = bch.ResultVar() | ||
|
||
def __call__(self, **kwargs): | ||
self.update_params_from_kwargs(**kwargs) | ||
points = polygon_points(self.radius, self.sides, self.start_angle) | ||
# self.hmap = hv.Curve(points) | ||
self.polygon = self.points_to_polygon_png(points, bch.gen_image_path("polygon"), dpi=30) | ||
self.polygon_small = self.points_to_polygon_png( | ||
points, bch.gen_image_path("polygon"), dpi=10 | ||
) | ||
|
||
self.side_length = 2 * self.radius * math.sin(math.pi / self.sides) | ||
self.area = (self.sides * self.side_length**2) / (4 * math.tan(math.pi / self.sides)) | ||
return super().__call__() | ||
|
||
def points_to_polygon_png(self, points: list[float], filename: str, dpi): | ||
"""Draw a closed polygon and save to png""" | ||
fig = plt.figure(frameon=False) | ||
ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0], frameon=False) | ||
ax.set_axis_off() | ||
ax.plot( | ||
[p[0] for p in points], | ||
[p[1] for p in points], | ||
linewidth=self.linewidth, | ||
linestyle=self.linestyle, | ||
color=self.color, | ||
) | ||
ax.set_xlim(-1, 1) | ||
ax.set_ylim(-1, 1) | ||
|
||
ax.set_aspect("equal") | ||
fig.add_axes(ax) | ||
fig.savefig(filename, dpi=dpi) | ||
|
||
return filename | ||
|
||
|
||
def example_image_vid_sequential1( | ||
run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None | ||
) -> bch.Bench: | ||
bench = BenchPolygons().to_bench(run_cfg, report) | ||
res = bench.plot_sweep(input_vars=["sides"]) | ||
|
||
bench.report.append(res.to_panes(zip_results=True)) | ||
|
||
return bench | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
ex_run_cfg = bch.BenchRunCfg() | ||
ex_run_cfg.use_sample_cache = True | ||
ex_run_cfg.overwrite_sample_cache = True | ||
ex_run_cfg.level = 3 | ||
|
||
example_image_vid_sequential1(ex_run_cfg).report.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.