-
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 #398 from dyson-ai/feature/with_sample_values
Feature/with sample values
- Loading branch information
Showing
5 changed files
with
86 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import bencher as bch | ||
|
||
|
||
class Square(bch.ParametrizedSweep): | ||
"""An example of a datatype with an integer and float parameter""" | ||
|
||
x = bch.FloatSweep(default=0, bounds=[0, 6]) | ||
|
||
result = bch.ResultVar("ul", doc="Square of x") | ||
|
||
def __call__(self, **kwargs) -> dict: | ||
self.update_params_from_kwargs(**kwargs) | ||
self.result = self.x * self.x | ||
return self.get_results_values_as_dict() | ||
|
||
|
||
def example_custom_sweep2( | ||
run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None | ||
) -> bch.Bench: | ||
"""This example shows how to define a custom set of value to sample from intead of a uniform sweep | ||
Args: | ||
run_cfg (BenchRunCfg): configuration of how to perform the param sweep | ||
Returns: | ||
Bench: results of the parameter sweep | ||
""" | ||
|
||
bench = Square().to_bench(run_cfg=run_cfg, report=report) | ||
|
||
# These are all equivalent | ||
bench.plot_sweep(input_vars=[Square.param.x.with_sample_values([0, 1, 2])]) | ||
bench.plot_sweep(input_vars=dict(x=[2, 3, 4])) | ||
bench.plot_sweep(input_vars=[("x", [3, 4, 5])]) | ||
|
||
return bench | ||
|
||
|
||
if __name__ == "__main__": | ||
example_custom_sweep2().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