diff --git a/.github/ISSUE_TEMPLATE/sweep-bugfix.yml b/.github/ISSUE_TEMPLATE/sweep-bugfix.yml deleted file mode 100644 index 25f43c35..00000000 --- a/.github/ISSUE_TEMPLATE/sweep-bugfix.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Bugfix -title: 'Sweep: ' -description: Write something like "We notice ... behavior when ... happens instead of ..."" -labels: sweep -body: - - type: textarea - id: description - attributes: - label: Details - description: More details about the bug - placeholder: The bug might be in ... file \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/sweep-feature.yml b/.github/ISSUE_TEMPLATE/sweep-feature.yml deleted file mode 100644 index 6b985bc8..00000000 --- a/.github/ISSUE_TEMPLATE/sweep-feature.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Feature Request -title: 'Sweep: ' -description: Write something like "Write an api endpoint that does "..." in the "..." file" -labels: sweep -body: - - type: textarea - id: description - attributes: - label: Details - description: More details for Sweep - placeholder: The new endpoint should use the ... class from ... file because it contains ... logic \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/sweep-refactor.yml b/.github/ISSUE_TEMPLATE/sweep-refactor.yml deleted file mode 100644 index ed0f8a66..00000000 --- a/.github/ISSUE_TEMPLATE/sweep-refactor.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Refactor -title: 'Sweep: ' -description: Write something like "Modify the ... api endpoint to use ... version and ... framework" -labels: sweep -body: - - type: textarea - id: description - attributes: - label: Details - description: More details for Sweep - placeholder: We are migrating this function to ... version because ... \ No newline at end of file diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 00000000..667659d7 --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,10 @@ +name: pre-commit + +on: [pull_request] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6e745b75..ce03a161 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,4 +15,4 @@ jobs: with: pypi-token: ${{ secrets.PYPI_API_TOKEN }} gh-token: ${{ secrets.GITHUB_TOKEN }} - parse-changelog: true \ No newline at end of file + parse-changelog: true diff --git a/.pre-commit-config-unused.yaml b/.pre-commit-config-unused.yaml deleted file mode 100644 index 7fb6d12b..00000000 --- a/.pre-commit-config-unused.yaml +++ /dev/null @@ -1,18 +0,0 @@ -repos: - # - repo: ... - - - repo: https://github.com/compilerla/conventional-pre-commit - rev: v3.0.0 - hooks: - - id: conventional-pre-commit - stages: [commit-msg] - args: [] - - repo: https://github.com/psf/black - rev: 23.3.0 - hooks: - - id: black - # It is recommended to specify the latest version of Python - # supported by your project here, or alternatively use - # pre-commit's default_language_version, see - # https://pre-commit.com/#top_level-default_language_version - language_version: python3.10 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..9a2ba27f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,67 @@ +# To use: +# +# pre-commit run -a +# +# Or: +# +# pre-commit install # (runs every time you commit in git) +# +# To update this file: +# +# pre-commit autoupdate +# +# See https://github.com/pre-commit/pre-commit + +repos: + # Standard hooks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-added-large-files + - id: check-ast + - id: check-case-conflict + - id: check-docstring-first + - id: check-merge-conflict + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + - id: name-tests-test + - id: detect-private-key + - id: check-symlinks + - id: check-toml + - id: check-xml + - id: check-yaml + args: ['--unsafe'] # Fixes errors parsing custom jinja templates + # - id: check-json + # - id: pretty-format-json + # args: ['--autofix'] + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + # - id: trailing-whitespace + - id: fix-byte-order-marker + + # Formatter for python + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.4 + hooks: + # Run the linter. + - id: ruff + types_or: [ python, pyi ] + args: [ --fix ] + # Run the formatter. + - id: ruff-format + types_or: [ python, pyi ] + # Checks for spelling mistakes + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 #TODO latest version 2.3.0 finds a lot of spelling mistakes but fails on "assertIn" + hooks: + - id: codespell + args: ['--write-changes','--skip=index.html',"--ignore-words=./codespell-ignore.txt"] + exclude: \.(svg|pyc|lock|json)$ + + # - repo: https://github.com/compilerla/conventional-pre-commit + # rev: v3.0.0 + # hooks: + # - id: conventional-pre-commit + # stages: [commit-msg] + # args: [] diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml deleted file mode 100644 index 81e206b0..00000000 --- a/.pre-commit-hooks.yaml +++ /dev/null @@ -1,8 +0,0 @@ -- id: black - name: black - description: "Black: The uncompromising Python code formatter" - entry: black - language: python - minimum_pre_commit_version: 2.9.2 - require_serial: true - types_or: [python, pyi] \ No newline at end of file diff --git a/.readthedocs.yaml b/.readthedocs.yaml index eb3cd92b..20ea40af 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -29,4 +29,4 @@ sphinx: # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html python: install: - - requirements: docs/requirements.txt \ No newline at end of file + - requirements: docs/requirements.txt diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 4cf65aad..5b53e165 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,17 +1,17 @@ { - "recommendations": [ - "ms-python.python", - "ms-python.vscode-pylance", - "ms-python.pylint", - "ms-python.black-formatter", - "njpwerner.autodocstring", - "charliermarsh.ruff", - "mhutchie.git-graph", - "eamodio.gitlens", - "tamasfe.even-better-toml", - "Codium.codium", - "ms-azuretools.vscode-docker", - "ryanluker.vscode-coverage-gutters", - "jjjermiah.pixi-vscode" - ] -} \ No newline at end of file + "recommendations": [ + "ms-python.python", + "ms-python.vscode-pylance", + "ms-python.pylint", + "ms-python.black-formatter", + "njpwerner.autodocstring", + "charliermarsh.ruff", + "mhutchie.git-graph", + "eamodio.gitlens", + "tamasfe.even-better-toml", + "Codium.codium", + "ms-azuretools.vscode-docker", + "ryanluker.vscode-coverage-gutters", + "jjjermiah.pixi-vscode" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 95c8adf4..aeba9d69 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,4 +21,4 @@ "python.analysis.autoImportCompletions": false, "python.analysis.typeCheckingMode": "off", "python.defaultInterpreterPath": "/workspaces/bencher/.pixi/envs/default/bin/python" //vscode gets it wrong more than right and mostly gets in the way -} \ No newline at end of file +} diff --git a/CODEOWNERS b/CODEOWNERS index f00a73d1..f7af1ca2 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @blooop \ No newline at end of file +* @blooop diff --git a/MANIFEST.in b/MANIFEST.in index 073baf15..a873f4b8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -recursive-include bencher/ *.py \ No newline at end of file +recursive-include bencher/ *.py diff --git a/README.md b/README.md index 8d2f6b49..f0c83c90 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Bencher is a tool to make it easy to benchmark the interactions between the inpu Parameters for bencher are defined using the [param](https://param.holoviz.org/) library as a config class with extra metadata that describes the bounds of the search space you want to measure. You must define a benchmarking function that accepts an instance of the config class and return a dictionary with string metric names and float values. -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, continous, discrete), but you can also pass in a callback to customize plotting. +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. @@ -87,4 +87,3 @@ Start with example_simple_float.py and explore other examples based on your data API documentation can be found at https://bencher.readthedocs.io/en/latest/ More documentation is needed for the examples and general workflow. - diff --git a/bencher.deps.yaml b/bencher.deps.yaml index 548d0fd7..63e6e6bf 100644 --- a/bencher.deps.yaml +++ b/bencher.deps.yaml @@ -7,3 +7,4 @@ apt_tools: pip_language-toolchain: - uv #use uv instead of pip - pip #update to the latest pip + - pre-commit diff --git a/bencher/bench_cfg.py b/bencher/bench_cfg.py index 62e23a59..9923576b 100644 --- a/bencher/bench_cfg.py +++ b/bencher/bench_cfg.py @@ -69,7 +69,7 @@ class BenchRunCfg(BenchPlotSrvCfg): serve_pandas_flat: bool = param.Boolean( True, - doc="Serve a flattend pandas summary on the results webpage. If you have a large dataset consider setting this to false if the page loading is slow", + doc="Serve a flattened pandas summary on the results webpage. If you have a large dataset consider setting this to false if the page loading is slow", ) serve_xarray: bool = param.Boolean( @@ -78,7 +78,7 @@ class BenchRunCfg(BenchPlotSrvCfg): ) auto_plot: bool = param.Boolean( - True, doc=" Automaticlly dedeuce the best type of plot for the results." + True, doc=" Automatically dedeuce the best type of plot for the results." ) raise_duplicate_exception: bool = param.Boolean(False, doc=" Used to debug unique plot names.") @@ -131,13 +131,13 @@ class BenchRunCfg(BenchPlotSrvCfg): render_plotly = param.Boolean( True, - doc="Plotly and Bokeh don't play nicely together, so by default pre-render plotly figures to a non dynamic version so that bokeh plots correctly. If you want interactive 3D graphs, set this to true but be aware that your 2D interactive graphs will probalby stop working.", + doc="Plotly and Bokeh don't play nicely together, so by default pre-render plotly figures to a non dynamic version so that bokeh plots correctly. If you want interactive 3D graphs, set this to true but be aware that your 2D interactive graphs will probably stop working.", ) level = param.Integer( default=0, bounds=[0, 12], - doc="The level parameter is a method of defining the number samples to sweep over in a variable agnostic way, i.e you don't need to specficy the number of samples for each variable as they are calculated dynamically from the sampling level. See example_level.py for more information.", + doc="The level parameter is a method of defining the number samples to sweep over in a variable agnostic way, i.e you don't need to specify the number of samples for each variable as they are calculated dynamically from the sampling level. See example_level.py for more information.", ) run_tag = param.String( @@ -163,10 +163,10 @@ class BenchRunCfg(BenchPlotSrvCfg): plot_size = param.Integer(default=None, doc="Sets the width and height of the plot") plot_width = param.Integer( default=None, - doc="Sets with width of the plots, this will ovverride the plot_size parameter", + doc="Sets with width of the plots, this will override the plot_size parameter", ) plot_height = param.Integer( - default=None, doc="Sets the height of the plot, this will ovverride the plot_size parameter" + default=None, doc="Sets the height of the plot, this will override the plot_size parameter" ) @staticmethod @@ -291,7 +291,7 @@ class BenchCfg(BenchRunCfg): tag: str = param.String( "", - doc="Use tags to group different benchmarks together. By default benchmarks are considered distinct from eachother and are identified by the hash of their name and inputs, constants and results and tag, but you can optionally change the hash value to only depend on the tag. This way you can have multiple unrelated benchmarks share values with eachother based only on the tag value.", + doc="Use tags to group different benchmarks together. By default benchmarks are considered distinct from each other and are identified by the hash of their name and inputs, constants and results and tag, but you can optionally change the hash value to only depend on the tag. This way you can have multiple unrelated benchmarks share values with each other based only on the tag value.", ) hash_value: str = param.String( @@ -311,10 +311,10 @@ def __init__(self, **params): self.iv_repeat = None def hash_persistent(self, include_repeats) -> str: - """override the default hash function becuase the default hash function does not return the same value for the same inputs. It references internal variables that are unique per instance of BenchCfg + """override the default hash function because the default hash function does not return the same value for the same inputs. It references internal variables that are unique per instance of BenchCfg Args: - include_repeats (bool) : by default include repeats as part of the hash execpt with using the sample cache + include_repeats (bool) : by default include repeats as part of the hash except with using the sample cache """ if include_repeats: diff --git a/bencher/bench_plot_server.py b/bencher/bench_plot_server.py index 55b63e05..6e48afb3 100644 --- a/bencher/bench_plot_server.py +++ b/bencher/bench_plot_server.py @@ -84,7 +84,7 @@ def serve( Args: bench_cfg (BenchCfg): benchmark results plots_instance (List[pn.panel]): list of panel objects to display - port (int): use a fixed port to lauch the server + port (int): use a fixed port to launch the server """ # suppress verbose tornado and bokeh output diff --git a/bencher/bench_runner.py b/bencher/bench_runner.py index 6b50737a..87691a08 100644 --- a/bencher/bench_runner.py +++ b/bencher/bench_runner.py @@ -85,7 +85,7 @@ def run( run_cfg (BenchRunCfg, optional): benchmark run configuration. Defaults to None. publish (bool, optional): Publish the results to git, requires a publish url to be set up. Defaults to False. debug (bool, optional): _description_. Defaults to False. - show (bool, optional): show the results in the local web browswer. Defaults to False. + show (bool, optional): show the results in the local web browser. Defaults to False. save (bool, optional): save the results to disk in index.html. Defaults to False. grouped (bool, optional): Produce a single html page with all the benchmarks included. Defaults to True. use_cache (bool, optional): Use the sample cache to reused previous results. Defaults to True. diff --git a/bencher/bencher.py b/bencher/bencher.py index 6cabf897..33491277 100644 --- a/bencher/bencher.py +++ b/bencher/bencher.py @@ -178,7 +178,7 @@ def __init__( self.plot = True def add_plot_callback(self, callback: Callable[[BenchResult], pn.panel], **kwargs) -> None: - """Add a plotting callback that will be called on any result produced when calling a sweep funciton. You can pass additional arguments to the plotting function with kwargs. e.g. add_plot_callback(bch.BenchResult.to_video_grid,) + """Add a plotting callback that will be called on any result produced when calling a sweep function. You can pass additional arguments to the plotting function with kwargs. e.g. add_plot_callback(bch.BenchResult.to_video_grid,) Args: callback (Callable[[BenchResult], pn.panel]): _description_ @@ -498,7 +498,7 @@ def convert_vars_to_params( """check that a variable is a subclass of param Args: - variable (param.Parameter): the varible to check + variable (param.Parameter): the variable to check var_type (str): a string representation of the variable type for better error messages Raises: @@ -560,7 +560,7 @@ def load_history_cache( """Load historical data from a cache if over_time=true Args: - ds (xr.Dataset): Freshly calcuated data + ds (xr.Dataset): Freshly calculated data bench_cfg_hash (int): Hash of the input variables used to generate the data clear_history (bool): Optionally clear the history @@ -593,7 +593,7 @@ def setup_dataset( time_src (datetime | str): a representation of the sample time Returns: - tuple[BenchResult, List, List]: bench_result, function intputs, dimension names + tuple[BenchResult, List, List]: bench_result, function inputs, dimension names """ if time_src is None: @@ -611,7 +611,7 @@ def setup_dataset( function_inputs = list( zip(product(*dims_cfg.dim_ranges_index), product(*dims_cfg.dim_ranges)) ) - # xarray stores K N-dimensional arrays of data. Each array is named and in this case we have a nd array for each result variable + # xarray stores K N-dimensional arrays of data. Each array is named and in this case we have an ND array for each result variable data_vars = {} dataset_list = [] @@ -830,7 +830,7 @@ def add_metadata_to_dataset(self, bench_res: BenchResult, input_var: Parametrize Args: bench_cfg (BenchCfg): - input_var (ParametrizedSweep): The varible to extract metadata from + input_var (ParametrizedSweep): The variable to extract metadata from """ for rv in bench_res.bench_cfg.result_vars: @@ -852,7 +852,7 @@ def add_metadata_to_dataset(self, bench_res: BenchResult, input_var: Parametrize dsvar.attrs["description"] = input_var.__doc__ def report_results(self, bench_cfg: BenchCfg, print_xarray: bool, print_pandas: bool): - """Optionally display the caculated benchmark data as either as pandas, xarray or plot + """Optionally display the calculated benchmark data as either as pandas, xarray or plot Args: bench_cfg (BenchCfg): diff --git a/bencher/example/benchmark_data.py b/bencher/example/benchmark_data.py index f0cc53a0..3ec601c8 100644 --- a/bencher/example/benchmark_data.py +++ b/bencher/example/benchmark_data.py @@ -1,6 +1,6 @@ """This file contains an example of how to define benchmarking parameters sweeps. Categorical values are defined as enums and passed to EnumSweep classes, other types of sweeps are defined by their respective classes. -You can define a subclass which contains an input configuration which can be passed to a function in a type safe way. You can combine the subclass with a higher level class which contains more configuation parameters. This is to help manage the complexity of large configuration/parameter spaces. +You can define a subclass which contains an input configuration which can be passed to a function in a type safe way. You can combine the subclass with a higher level class which contains more configuration parameters. This is to help manage the complexity of large configuration/parameter spaces. """ import math diff --git a/bencher/example/example_categorical.py b/bencher/example/example_categorical.py index 108d2855..21b3273e 100644 --- a/bencher/example/example_categorical.py +++ b/bencher/example/example_categorical.py @@ -86,7 +86,7 @@ def bench_function(cfg: ExampleBenchCfgIn) -> ExampleBenchCfgOut: ], title="Categorical 3D Example Over Time", result_vars=[ExampleBenchCfgOut.param.out_sin], - description="""Lastly, what if you want to track these distributions over time? Set over_time=True and bencher will cache and display historical resuts alongside the latest result. Use clear_history=True to clear that cache.""", + description="""Lastly, what if you want to track these distributions over time? Set over_time=True and bencher will cache and display historical results alongside the latest result. Use clear_history=True to clear that cache.""", post_description="The output shows faceted line plot with confidence intervals for the mean value over time.", run_cfg=run_cfg, ) diff --git a/bencher/example/example_custom_sweep.py b/bencher/example/example_custom_sweep.py index 01c8038a..14525245 100644 --- a/bencher/example/example_custom_sweep.py +++ b/bencher/example/example_custom_sweep.py @@ -23,7 +23,7 @@ def __call__(self, **kwargs) -> dict: def example_custom_sweep( run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport() ) -> bch.Bench: - """This example shows how to define a custom set of value to sample from intead of a uniform sweep + """This example shows how to define a custom set of value to sample from instead of a uniform sweep Args: run_cfg (BenchRunCfg): configuration of how to perform the param sweep diff --git a/bencher/example/example_custom_sweep2.py b/bencher/example/example_custom_sweep2.py index 80b87a8e..09d726d5 100644 --- a/bencher/example/example_custom_sweep2.py +++ b/bencher/example/example_custom_sweep2.py @@ -17,7 +17,7 @@ def __call__(self, **kwargs) -> 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 + """This example shows how to define a custom set of value to sample from instead of a uniform sweep Args: run_cfg (BenchRunCfg): configuration of how to perform the param sweep diff --git a/bencher/example/example_dataframe.py b/bencher/example/example_dataframe.py index ec17c0c6..2d4f8db5 100644 --- a/bencher/example/example_dataframe.py +++ b/bencher/example/example_dataframe.py @@ -6,7 +6,6 @@ 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]) diff --git a/bencher/example/example_image1.py b/bencher/example/example_image1.py index 1ab553ba..4ae3d5ca 100644 --- a/bencher/example/example_image1.py +++ b/bencher/example/example_image1.py @@ -72,7 +72,6 @@ def example_image_vid_sequential1( if __name__ == "__main__": - ex_run_cfg = bch.BenchRunCfg() ex_run_cfg.use_sample_cache = True ex_run_cfg.overwrite_sample_cache = True diff --git a/bencher/example/example_levels.py b/bencher/example/example_levels.py index 38c50d40..c1040b1b 100644 --- a/bencher/example/example_levels.py +++ b/bencher/example/example_levels.py @@ -81,7 +81,7 @@ def run_levels_1D(bench: bch.Bench) -> bch.Bench: bench.report.append(row) bench.report.append_markdown( - "Level 1 returns a single point at the lower bound of the parameter. Level 2 uses the uppper and lower bounds of the parameter. All subsequent levels are created by adding a sample between each previously calculated sample to ensure that all previous values can be reused while retaining an equal sample spacing. The following plots show the sample points as circles and the corresponding plot of a sin function sampled at that level.", + "Level 1 returns a single point at the lower bound of the parameter. Level 2 uses the upper and lower bounds of the parameter. All subsequent levels are created by adding a sample between each previously calculated sample to ensure that all previous values can be reused while retaining an equal sample spacing. The following plots show the sample points as circles and the corresponding plot of a sin function sampled at that level.", width=600, ) diff --git a/bencher/example/example_levels2.py b/bencher/example/example_levels2.py index 3d9d8f59..f07dd52d 100644 --- a/bencher/example/example_levels2.py +++ b/bencher/example/example_levels2.py @@ -15,7 +15,7 @@ def __call__(self, **kwargs) -> dict: def example_levels2(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 + """This example shows how to define a custom set of value to sample from instead of a uniform sweep Args: run_cfg (BenchRunCfg): configuration of how to perform the param sweep diff --git a/bencher/example/example_pareto.py b/bencher/example/example_pareto.py index b1f52fc8..ac87c13b 100644 --- a/bencher/example/example_pareto.py +++ b/bencher/example/example_pareto.py @@ -29,7 +29,7 @@ def example_pareto( res = bench.plot_sweep( title="Pareto Optimisation with Optuna", - description="This example shows how to plot the pareto front of the tradeoff between multiple criteria. When multiple result variable are defined, and use_optuna=True a pareto plot and the relative importance of each input variable on the output criteria is plotted. A summary of the points on the pareto front is printed as well. You can use the pareto plot to decide the how to trade off one objective for another. Pareto plots are suppored for 2D and 3D. If you have more than 3 result variables the first 3 are selected for the pareto plot. Plotting 4D surfaces is left as an exercise to the reader", + description="This example shows how to plot the pareto front of the tradeoff between multiple criteria. When multiple result variable are defined, and use_optuna=True a pareto plot and the relative importance of each input variable on the output criteria is plotted. A summary of the points on the pareto front is printed as well. You can use the pareto plot to decide the how to trade off one objective for another. Pareto plots are supported for 2D and 3D. If you have more than 3 result variables the first 3 are selected for the pareto plot. Plotting 4D surfaces is left as an exercise to the reader", input_vars=[ ExampleBenchCfgIn.param.theta, ExampleBenchCfgIn.param.offset, diff --git a/bencher/example/example_sample_cache_context.py b/bencher/example/example_sample_cache_context.py index 79bd7b51..473acefb 100644 --- a/bencher/example/example_sample_cache_context.py +++ b/bencher/example/example_sample_cache_context.py @@ -82,7 +82,7 @@ def example_cache_context() -> bch.Bench: tag="example_tag1", ) - # these values have not been calcuated before so there should be 1 fn call + # these values have not been calculated before so there should be 1 fn call assert_call_counts(bencher, run_cfg, wrapper_calls=1, fn_calls=1, cache_calls=0) # now create a new benchmark that calculates the values of the previous two benchmarks. The tag is the same so those values will be loaded from the cache instead of getting calculated again @@ -106,7 +106,7 @@ def example_cache_context() -> bch.Bench: tag="example_tag2", ) - # Both calls are calcuated becuase the tag is different so they don't hit the cache + # Both calls are calculated because the tag is different so they don't hit the cache assert_call_counts(bencher, run_cfg, wrapper_calls=2, fn_calls=2, cache_calls=0) return bencher diff --git a/bencher/example/example_simple.py b/bencher/example/example_simple.py index a66158ee..5069d0ce 100644 --- a/bencher/example/example_simple.py +++ b/bencher/example/example_simple.py @@ -12,7 +12,7 @@ import bencher as bch -# define a class with the output variables you want to benchmark. It must inherit from ParametrizedSweep (which inherits from param.Parametrized). Param is a python library that allows you to track metadata about parameters. I would recommend reading at least the intro: https://param.holoviz.org/. I have extended param with some extra metadata such is the units of the variable so that it can automaticaly be plotted. +# define a class with the output variables you want to benchmark. It must inherit from ParametrizedSweep (which inherits from param.Parametrized). Param is a python library that allows you to track metadata about parameters. I would recommend reading at least the intro: https://param.holoviz.org/. I have extended param with some extra metadata such is the units of the variable so that it can automatically be plotted. class OutputCfg(bch.ParametrizedSweep): """A class for defining what variables the benchmark function returns and metadata on those variables""" @@ -41,7 +41,7 @@ class InputCfg(bch.ParametrizedSweep): # The variables must be defined as one of the Sweep types, i.e, FloatSweep, IntSweep, EnumSweep from bencher.bench_vars # theta = FloatSweep(default=0, bounds=[0, math.pi], doc="Input angle", units="rad", samples=30) - # Define sweep variables by passing in an enum class name. The first element of the enum is the default by convention, but you can overrride the default in the constructor + # Define sweep variables by passing in an enum class name. The first element of the enum is the default by convention, but you can override the default in the constructor algo_setting_enum = bch.EnumSweep(AlgoSetting, default=AlgoSetting.poor) # In this case there are no units so its marked as unitless or ul. You can define how many evenly distributed samples to sample the parameter with @@ -66,7 +66,7 @@ def bench_function(cfg: InputCfg) -> OutputCfg: match cfg.algo_setting_enum: case AlgoSetting.noisy: - # add some random noise to the output. When your algorith has noisy output it often is an indication that something is not quite right. The graphs should show that you want to avoid the "noisy" setting in your algorithm + # add some random noise to the output. When your algorithm has noisy output it often is an indication that something is not quite right. The graphs should show that you want to avoid the "noisy" setting in your algorithm output.accuracy += random.uniform(-10, 10) case AlgoSetting.optimum: output.accuracy += 30 # This is the setting with the best performance, and characterising that is is the goal of the benchmarking @@ -122,9 +122,9 @@ def bench_function(cfg: InputCfg) -> OutputCfg: result_vars=[OutputCfg.param.accuracy], const_vars=[(InputCfg.param.algo_setting_float, 1.33)], title="Simple example 1D sweep over time", - description="""Once you have found the optimal settings for your algorithm you want to make sure that the performance is not lost over time. You can set variables to a constant value and in this case the float value is set to its optimum value. The first time this function is run only the results from sweeping the categorical value is plotted (the same as example 1), but the second time it is run a graph the values over time is shown. [Run the code again if you don't see a graph over time]. If the graphs over time shows long term changes (not just noise), it indicate there is another external factor that is affecting your performace over time, i.e. dependencies changing, physical degradation of equipment, an unnoticed bug from a pull request etc... + description="""Once you have found the optimal settings for your algorithm you want to make sure that the performance is not lost over time. You can set variables to a constant value and in this case the float value is set to its optimum value. The first time this function is run only the results from sweeping the categorical value is plotted (the same as example 1), but the second time it is run a graph the values over time is shown. [Run the code again if you don't see a graph over time]. If the graphs over time shows long term changes (not just noise), it indicate there is another external factor that is affecting your performance over time, i.e. dependencies changing, physical degradation of equipment, an unnoticed bug from a pull request etc... - This shows the basic features of bencher. These examples are purposefully simplified to demonstrate its features in isolation and don't reeally show the real advantages of bencher. If you only have a few inputs and outputs its not that complicated to throw together some plots of performance. The power of bencher is that when you have a system with many moving parts that all interact with eachother, teasing apart those influences becomes much harder because the parameter spaces combine quite quickly into a high dimensional mess. Bencher makes it easier to experiment with different combination of inputs to gain an intuition of the system performance. Bencher can plot up to 6D input natively and you can add custom plots if you have exotic data types or state spaces [WIP]. + This shows the basic features of bencher. These examples are purposefully simplified to demonstrate its features in isolation and don't reeally show the real advantages of bencher. If you only have a few inputs and outputs its not that complicated to throw together some plots of performance. The power of bencher is that when you have a system with many moving parts that all interact with each other, teasing apart those influences becomes much harder because the parameter spaces combine quite quickly into a high dimensional mess. Bencher makes it easier to experiment with different combination of inputs to gain an intuition of the system performance. Bencher can plot up to 6D input natively and you can add custom plots if you have exotic data types or state spaces [WIP]. """, post_description="", run_cfg=bch.BenchRunCfg(repeats=10, over_time=True, clear_history=False), diff --git a/bencher/example/meta/example_meta.py b/bencher/example/meta/example_meta.py index 6e9a41fa..261eb761 100644 --- a/bencher/example/meta/example_meta.py +++ b/bencher/example/meta/example_meta.py @@ -149,7 +149,7 @@ def example_meta( 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""", +This uses bencher to display all the combinations of plots bencher is able to produce""", input_vars=[ bch.p("float_vars", [0, 1, 2, 3]), BenchMeta.param.categorical_vars, diff --git a/bencher/example/shelved/example_kwargs.py b/bencher/example/shelved/example_kwargs.py index 546b347c..152bf109 100644 --- a/bencher/example/shelved/example_kwargs.py +++ b/bencher/example/shelved/example_kwargs.py @@ -10,7 +10,7 @@ # trig_func: str = "sin", # **kwargs, # pylint: disable=unused-argument # ) -> dict: -# """All the other examples use classes and parameters to define the inputs and outputs to the function. However it makes the code less flexible when integrating with other systems, so this example shows a more basic interface that accepts and returns dictionaries. The classes still need to be defined however because that is how the sweep and plotting settings are calcuated""" +# """All the other examples use classes and parameters to define the inputs and outputs to the function. However it makes the code less flexible when integrating with other systems, so this example shows a more basic interface that accepts and returns dictionaries. The classes still need to be defined however because that is how the sweep and plotting settings are calculated""" # output = {} # if trig_func == "sin": diff --git a/bencher/plotting/plot_filter.py b/bencher/plotting/plot_filter.py index c82d78f0..1b18104f 100644 --- a/bencher/plotting/plot_filter.py +++ b/bencher/plotting/plot_filter.py @@ -6,7 +6,7 @@ class VarRange: - """A VarRange represents the bounded and unbounded ranges of integers. This class is used to define filters for various variable types. For example by defining cat_var = VarRange(0,0), calling matches(0) will return true, but any other integer will not match. You can also have unbounded ranges for example VarRange(2,None) will match to 2,3,4... up to infinity. for By default the lower and upper bounds are set to -1 so so that no matter what value is passsed to matches() will return false. Matches only takes 0 and positive integers.""" + """A VarRange represents the bounded and unbounded ranges of integers. This class is used to define filters for various variable types. For example by defining cat_var = VarRange(0,0), calling matches(0) will return true, but any other integer will not match. You can also have unbounded ranges for example VarRange(2,None) will match to 2,3,4... up to infinity. for By default the lower and upper bounds are set to -1 so so that no matter what value is passed to matches() will return false. Matches only takes 0 and positive integers.""" def __init__(self, lower_bound: int = 0, upper_bound: int = -1) -> None: """ @@ -71,7 +71,7 @@ def matches_result(self, plt_cnt_cfg: PltCntCfg, plot_name: str) -> PlotMatchesR # @dataclass class PlotMatchesResult: - """Stores information about which properites match the requirements of a particular plotter""" + """Stores information about which properties match the requirements of a particular plotter""" def __init__(self, plot_filter: PlotFilter, plt_cnt_cfg: PltCntCfg, plot_name: str): match_info = [] diff --git a/bencher/plotting/plt_cnt_cfg.py b/bencher/plotting/plt_cnt_cfg.py index 9d59a45c..74a48903 100644 --- a/bencher/plotting/plt_cnt_cfg.py +++ b/bencher/plotting/plt_cnt_cfg.py @@ -3,7 +3,13 @@ from bencher.bench_cfg import BenchCfg from bencher.variables.results import PANEL_TYPES -from bencher.variables.inputs import IntSweep, FloatSweep, BoolSweep, EnumSweep, StringSweep +from bencher.variables.inputs import ( + IntSweep, + FloatSweep, + BoolSweep, + EnumSweep, + StringSweep, +) from bencher.variables.time import TimeSnapshot @@ -17,12 +23,13 @@ class PltCntCfg(param.Parameterized): vector_len = param.Integer(1, doc="The vector length of the return variable , scalars = len 1") result_vars = param.Integer(1, doc="The number result variables to plot") # todo remove panel_vars = param.List(doc="A list of panel results") - panel_cnt = param.Integer(0, doc="Number of results reprented as panel panes") + panel_cnt = param.Integer(0, doc="Number of results represent as panel panes") repeats = param.Integer(0, doc="The number of repeat samples") inputs_cnt = param.Integer(0, doc="The number of repeat samples") print_debug = param.Boolean( - True, doc="Print debug information about why a filter matches this config or not" + True, + doc="Print debug information about why a filter matches this config or not", ) @staticmethod diff --git a/bencher/results/bench_result_base.py b/bencher/results/bench_result_base.py index 009eea9e..8bbf691d 100644 --- a/bencher/results/bench_result_base.py +++ b/bencher/results/bench_result_base.py @@ -60,7 +60,7 @@ def to_hv_dataset( """Generate a holoviews dataset from the xarray dataset. Args: - reduce (ReduceType, optional): Optionally perform reduce options on the dataset. By default the returned dataset will calculate the mean and standard devation over the "repeat" dimension so that the dataset plays nicely with most of the holoviews plot types. Reduce.Sqeeze is used if there is only 1 repeat and you want the "reduce" variable removed from the dataset. ReduceType.None returns an unaltered dataset. Defaults to ReduceType.AUTO. + reduce (ReduceType, optional): Optionally perform reduce options on the dataset. By default the returned dataset will calculate the mean and standard deviation over the "repeat" dimension so that the dataset plays nicely with most of the holoviews plot types. Reduce.Sqeeze is used if there is only 1 repeat and you want the "reduce" variable removed from the dataset. ReduceType.None returns an unaltered dataset. Defaults to ReduceType.AUTO. Returns: hv.Dataset: results in the form of a holoviews dataset @@ -77,7 +77,7 @@ def to_dataset( """Generate a summarised xarray dataset. Args: - reduce (ReduceType, optional): Optionally perform reduce options on the dataset. By default the returned dataset will calculate the mean and standard devation over the "repeat" dimension so that the dataset plays nicely with most of the holoviews plot types. Reduce.Sqeeze is used if there is only 1 repeat and you want the "reduce" variable removed from the dataset. ReduceType.None returns an unaltered dataset. Defaults to ReduceType.AUTO. + reduce (ReduceType, optional): Optionally perform reduce options on the dataset. By default the returned dataset will calculate the mean and standard deviation over the "repeat" dimension so that the dataset plays nicely with most of the holoviews plot types. Reduce.Sqeeze is used if there is only 1 repeat and you want the "reduce" variable removed from the dataset. ReduceType.None returns an unaltered dataset. Defaults to ReduceType.AUTO. Returns: xr.Dataset: results in the form of an xarray dataset @@ -87,7 +87,7 @@ def to_dataset( ds_out = self.ds if result_var is None else self.ds[result_var.name] - match (reduce): + match reduce: case ReduceType.REDUCE: ds_reduce_mean = ds_out.mean(dim="repeat", keep_attrs=True) ds_reduce_std = ds_out.std(dim="repeat", keep_attrs=True) @@ -147,9 +147,9 @@ def get_optimal_value_indices(self, result_var: ParametrizedSweep) -> xr.DataArr opt_val = result_da.max() else: opt_val = result_da.min() - indicies = result_da.where(result_da == opt_val, drop=True).squeeze() + indices = result_da.where(result_da == opt_val, drop=True).squeeze() logging.info(f"optimal value of {result_var.name}: {opt_val.values}") - return indicies + return indices def get_optimal_inputs( self, diff --git a/bencher/results/composable_container/composable_container_base.py b/bencher/results/composable_container/composable_container_base.py index 5ecb4c52..e18a78dc 100644 --- a/bencher/results/composable_container/composable_container_base.py +++ b/bencher/results/composable_container/composable_container_base.py @@ -65,7 +65,7 @@ def append(self, obj: Any) -> None: self.container.append(obj) def render(self): - """Return a representation of the container that can be composed with other render() results. This function can also be used to defer layout and rending options until all the information about the container content is known. You may need to ovverride this method depending on the container. See composable_container_video as an example. + """Return a representation of the container that can be composed with other render() results. This function can also be used to defer layout and rending options until all the information about the container content is known. You may need to override this method depending on the container. See composable_container_video as an example. Returns: Any: Visual representation of the container that can be combined with other containers diff --git a/bencher/results/optuna_result.py b/bencher/results/optuna_result.py index ed1af3f9..1d24ea50 100644 --- a/bencher/results/optuna_result.py +++ b/bencher/results/optuna_result.py @@ -34,7 +34,7 @@ def convert_dataset_bool_dims_to_str(dataset: xr.Dataset) -> xr.Dataset: - """Given a dataarray that contains boolean coordinates, conver them to strings so that holoviews loads the data properly + """Given a dataarray that contains boolean coordinates, convert them to strings so that holoviews loads the data properly Args: dataarray (xr.DataArray): dataarray with boolean coordinates @@ -342,14 +342,14 @@ def set_plot_size(self, **kwargs) -> dict: if "width" not in kwargs: if self.bench_cfg.plot_size is not None: kwargs["width"] = self.bench_cfg.plot_size - # specific width overrrides general size + # specific width overrides general size if self.bench_cfg.plot_width is not None: kwargs["width"] = self.bench_cfg.plot_width if "height" not in kwargs: if self.bench_cfg.plot_size is not None: kwargs["height"] = self.bench_cfg.plot_size - # specific height overrrides general size + # specific height overrides general size if self.bench_cfg.plot_height is not None: kwargs["height"] = self.bench_cfg.plot_height return kwargs diff --git a/bencher/variables/inputs.py b/bencher/variables/inputs.py index aa9de887..ba59dd1a 100644 --- a/bencher/variables/inputs.py +++ b/bencher/variables/inputs.py @@ -7,7 +7,7 @@ class SweepSelector(Selector, SweepBase): - """A class to reprsent a parameter sweep of bools""" + """A class to represent a parameter sweep of bools""" __slots__ = shared_slots @@ -27,7 +27,7 @@ def values(self) -> List[Any]: class BoolSweep(SweepSelector): - """A class to reprsent a parameter sweep of bools""" + """A class to represent a parameter sweep of bools""" def __init__(self, units: str = "ul", samples: int = None, default=True, **params): SweepSelector.__init__( @@ -41,7 +41,7 @@ def __init__(self, units: str = "ul", samples: int = None, default=True, **param class StringSweep(SweepSelector): - """A class to reprsent a parameter sweep of strings""" + """A class to represent a parameter sweep of strings""" def __init__( self, @@ -61,7 +61,7 @@ def __init__( class EnumSweep(SweepSelector): - """A class to reprsent a parameter sweep of enums""" + """A class to represent a parameter sweep of enums""" __slots__ = shared_slots @@ -82,7 +82,7 @@ def __init__(self, enum_type: Enum | List[Enum], units="ul", samples=None, **par class IntSweep(Integer, SweepBase): - """A class to reprsent a parameter sweep of ints""" + """A class to represent a parameter sweep of ints""" __slots__ = shared_slots + ["sample_values"] diff --git a/bencher/variables/sweep_base.py b/bencher/variables/sweep_base.py index 33f95eac..e11e8661 100644 --- a/bencher/variables/sweep_base.py +++ b/bencher/variables/sweep_base.py @@ -77,7 +77,7 @@ def as_slider(self) -> pn.widgets.slider.DiscreteSlider: """given a sweep variable (self), return the range of values as a panel slider Args: - debug (bool, optional): pass to the sweepvar to produce a full set of varaibles, or when debug=True, a reduces number of sweep vars. Defaults to False. + debug (bool, optional): pass to the sweepvar to produce a full set of variables, or when debug=True, a reduces number of sweep vars. Defaults to False. Returns: pn.widgets.slider.DiscreteSlider: A panel slider with the values() of the sweep variable diff --git a/bencher/variables/time.py b/bencher/variables/time.py index a855ac8f..daf87a5d 100644 --- a/bencher/variables/time.py +++ b/bencher/variables/time.py @@ -7,7 +7,7 @@ class TimeBase(SweepBase, Selector): - """A class to capture a time snapshot of benchmark values. Time is reprented as a continous value i.e a datetime which is converted into a np.datetime64. To represent time as a discrete value use the TimeEvent class. The distinction is because holoview and plotly code makes different assumptions about discrete vs continous variables""" + """A class to capture a time snapshot of benchmark values. Time is represent as a continuous value i.e a datetime which is converted into a np.datetime64. To represent time as a discrete value use the TimeEvent class. The distinction is because holoview and plotly code makes different assumptions about discrete vs continuous variables""" def __init__( self, @@ -40,7 +40,7 @@ def values(self) -> List[str]: class TimeSnapshot(TimeBase): - """A class to capture a time snapshot of benchmark values. Time is reprented as a continous value i.e a datetime which is converted into a np.datetime64. To represent time as a discrete value use the TimeEvent class. The distinction is because holoview and plotly code makes different assumptions about discrete vs continous variables""" + """A class to capture a time snapshot of benchmark values. Time is represent as a continuous value i.e a datetime which is converted into a np.datetime64. To represent time as a discrete value use the TimeEvent class. The distinction is because holoview and plotly code makes different assumptions about discrete vs continuous variables""" __slots__ = shared_slots @@ -68,7 +68,7 @@ def __init__( class TimeEvent(TimeBase): - """A class to represent a discrete event in time where the data was captured i.e a series of pull requests. Here time is discrete and can't be interpolated, to represent time as a continous value use the TimeSnapshot class. The distinction is because holoview and plotly code makes different assumptions about discrete vs continous variables""" + """A class to represent a discrete event in time where the data was captured i.e a series of pull requests. Here time is discrete and can't be interpolated, to represent time as a continuous value use the TimeSnapshot class. The distinction is because holoview and plotly code makes different assumptions about discrete vs continuous variables""" __slots__ = shared_slots diff --git a/bencher/video_writer.py b/bencher/video_writer.py index 48438814..7e65af0b 100644 --- a/bencher/video_writer.py +++ b/bencher/video_writer.py @@ -30,7 +30,7 @@ def create_label(label, width=None, height=16, color=(255, 255, 255)): if width is None: width = len(label) * 10 new_img = Image.new("RGB", (width, height), color=color) - # ImageDraw.Draw(new_img).text((width/2, 0), label, (0, 0, 0),align="center",achor="ms") + # ImageDraw.Draw(new_img).text((width/2, 0), label, (0, 0, 0),align="center",anchor="ms") ImageDraw.Draw(new_img).text( (width / 2.0, 0), label, (0, 0, 0), anchor="mt", font_size=height ) diff --git a/codespell-ignore.txt b/codespell-ignore.txt new file mode 100644 index 00000000..faead4f2 --- /dev/null +++ b/codespell-ignore.txt @@ -0,0 +1,2 @@ +assertIn +ND diff --git a/docs/intro.rst b/docs/intro.rst index 81d08fac..100e6e00 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -5,7 +5,7 @@ Bencher is a tool to make it easy to benchmark the interactions between the inpu Parameters for bencher are defined using the param library https://param.holoviz.org/ as a config class with extra metadata that describes the bounds of the search space you want to measure. You must define a benchmarking function that accepts an instance of the config class and return a dictionary with string metric names and float values. -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, continous, discrete), but you can also pass in a callback to customize plotting. +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. diff --git a/docs/requirements.txt b/docs/requirements.txt index 5d39e65c..810533ab 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,4 @@ holobench sphinxcontrib-napoleon sphinx-rtd-theme -sphinx-autoapi \ No newline at end of file +sphinx-autoapi diff --git a/index.html b/index.html index ff81e38c..70f1ed5a 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,7 @@