Mercurial > repos > public > sbplib_julia
changeset 1362:a6918dfb0cf5 bugfix/lazytensors
Merge with default
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Sun, 21 May 2023 20:51:52 +0200 |
parents | 646027afe74b (current diff) 689978b1ef16 (diff) |
children | bc390a33e0a2 |
files | |
diffstat | 9 files changed, 1143 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sat May 20 14:33:25 2023 +0200 +++ b/.hgignore Sun May 21 20:51:52 2023 +0200 @@ -1,3 +1,5 @@ syntax: glob docs/build/ docs/build-local/ +benchmark/results +benchmark/tune.json
--- a/Makefile Sat May 20 14:33:25 2023 +0200 +++ b/Makefile Sun May 21 20:51:52 2023 +0200 @@ -10,16 +10,24 @@ help: @echo 'Targets:' - @echo ' help - Show this help.' - @echo ' docs - Generate docs for webserver deployment.' - @echo ' localdocs - Generate docs for local viewing.' - @echo ' opendocs - Open documentation in the browser remaking it if necessary.' + @echo ' help - Show this help.' + @echo ' docs - Generate docs for webserver deployment.' + @echo ' localdocs - Generate docs for local viewing.' + @echo ' opendocs - Open documentation in the browser remaking it if necessary.' + @echo ' benchmark - Run benchmark suite.' + @echo ' benchmarkrev - Run benchmark suite for revision REV.' + @echo ' benchmarkcmp - Run benchmark suite comparing TARGET to BASELINE.' @echo '' @echo 'Variables:' @echo ' JULIA - Controls which command is used to run julia' @echo ' Default $(JULIA_DEFAULT)' @echo ' BROWSER - Sets the command for how to open html files' @echo ' Default: xdg-open if it exists otherwise open' + @echo ' REV - Valid Mercurial revision specifier used in benchmarkrev' + @echo ' TARGET - Valid Mercurial revision specifier used in benchmarkcmp' + @echo ' as the target revision' + @echo ' BASELINE - Valid Mercurial revision specifier used in benchmarkcmp' + @echo ' as the baseline revision' @echo '' @echo 'Variables can be set on the commandline using the -e flag for make, e.g.' @echo ' make localdocs -e JULIA=path/to/julia' @@ -32,11 +40,26 @@ opendocs: localdocs $(BROWSER) docs/build-local/index.html -clean: +cleandocs: rm -rf docs/build - rm -rf docs/build-local + rm -rf docs/build-local + +benchmark: + $(JULIA) --project=benchmark benchmark/make.jl + +benchmarkrev: + $(JULIA) --project=benchmark benchmark/make.jl --rev $(REV) -.PHONY: help docs localdocs opendocs clean +benchmarkcmp: + $(JULIA) --project=benchmark benchmark/make.jl --cmp $(TARGET) $(BASELINE) + +cleanbenchmark: + rm -rf benchmark/results + rm -f benchmark/tune.json + +clean: cleandocs cleanbenchmark + +.PHONY: help clean docs localdocs opendocs cleandocs benchmark benchmarkrev benchmarkcmp cleanbenchmark SRC_DIRS = src docs/src SRC_FILES_AND_DIRS = $(foreach dir,$(SRC_DIRS),$(shell find $(dir))) @@ -47,8 +70,3 @@ docs/build-local: $(DOCS_DEPENDENCIES) $(JULIA) --project=docs docs/make.jl --build-dir build-local - - -.PHONY: temp -temp: - @echo $(SRC_FILES_AND_DIRS)
--- a/README.md Sat May 20 14:33:25 2023 +0200 +++ b/README.md Sun May 21 20:51:52 2023 +0200 @@ -28,22 +28,54 @@ ``` will run any file named `lazy_tensor_operations_test.jl` and all the files in the `Grids` folder. +## Running benchmarks +Benchmarks are defined in `benchmark/` and use the tools for benchmark suites in BenchmarkTools.jl. The format is compatible with PkgBenchmark.jl which helps with running the suite, comparing results and presenting the results in a readable way. There are custom functions included for running the benchmarks in this Mercurial repository. + +`benchmark/` contains a julia environment with the necessary packages for working with the benchmarks. + +To run the benchmarks, either use `make` run them manually from the REPL, as explained further below. + +Using `make` there are four targets for benchmarks +```shell +make benchmark # Runs the suite for the current working directory +make benchmarkrev REV=rev # Runs the suite at the specified revision +make benchmarkcmp TARGET=target BASELINE=baseline # Compares two revisions +make cleanbenchmark # Cleans up benchmark tunings and results +``` +Here `rev`, `target` and `baseline` are any valid Mercurial revision specifiers. Note that `make benchmarkrev` and `make benchmarkcmp` will fail if you have pending changes in your repository. + + +Alternatively, the benchmarks can be run from the REPL. To do this, first activate the environment in `benchmark/` then include the file `benchmark_utils.jl`. The suite can then be run using the function `main` in one of the following ways + +```julia +main() # Runs the suite for the current working directory +main(rev) # Runs the suite at the specified revision +main(target, baseline) # Compares two revisions +``` + +Again, `rev`, `target` and `baseline` are any valid Mercurial revision specifiers. Note that `main(rev)` and `main(target, baseline)` will fail if you have pending changes in your repository. + +PkgBenchmark can also be used directly. + +```julia +using PkgBenchmark +import Sbplib +r = benchmarkpkg(Sbplib) + +export_markdown(stdout, r) +``` ## Generating and using the documentation Generating the documentation can be done using either `make` or through activating the `docs` environment and including the script `docs/make.jl` at the REPL. -Using `make` there are three targets +Using `make` there are four targets for documentation ```shell -make docs -make localdocs -make opendocs -make help -``` -The first variant generates files suitable for webserver deployment, i.e with `prettyurls=true`. The second generates files sutible for local viewing in a web browser, i.e `prettyurls=false`. To view the documentation locally simply open `docs/build/index.html` in your web browser. The documentation can be automatically built and opened using -```shell -make opendocs +make docs # generates files suitable for webserver deployment, i.e with `prettyurls=true` +make localdocs # generates files suitable for local viewing in a web browser, i.e `prettyurls=false` +make opendocs # build and view documentation locally +make cleandocs # cleans up generated files ``` -When including the `docs/make.jl` script `prettyurls` is set to `false` by default. +Alternatively, to view the documentation locally simply open `docs/build/index.html` in your web browser. When including the `docs/make.jl` script `prettyurls` is set to `false` by default. -Including `docs/make.jl` from the REPL may be preferable when repeatadely building the documentation since this avoids compilation latency. +Including `docs/make.jl` from the REPL may be preferable when repeatedly building the documentation since this avoids compilation latency.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmark/Manifest.toml Sun May 21 20:51:52 2023 +0200 @@ -0,0 +1,335 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.8.5" +manifest_format = "2.0" +project_hash = "25bba7b4a00465d5a2b00b589eb10e3301c31f2a" + +[[deps.AbstractTrees]] +git-tree-sha1 = "faa260e4cb5aba097a73fab382dd4b5819d8ec8c" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.4.4" + +[[deps.Adapt]] +deps = ["LinearAlgebra"] +git-tree-sha1 = "0310e08cb19f5da31d08341c6120c047598f5b9c" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "3.5.0" + +[[deps.ArgTools]] +uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" +version = "1.1.1" + +[[deps.ArrayInterface]] +deps = ["ArrayInterfaceCore", "Compat", "IfElse", "LinearAlgebra", "Static"] +git-tree-sha1 = "6d0918cb9c0d3db7fe56bea2bc8638fc4014ac35" +uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" +version = "6.0.24" + +[[deps.ArrayInterfaceCore]] +deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse"] +git-tree-sha1 = "14c3f84a763848906ac681f94cf469a851601d92" +uuid = "30b0a656-2188-435a-8636-2ec0e6a096e2" +version = "0.1.28" + +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[deps.BenchmarkTools]] +deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"] +git-tree-sha1 = "d9a9701b899b30332bbcb3e1679c41cce81fb0e8" +uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +version = "1.3.2" + +[[deps.Compat]] +deps = ["Dates", "LinearAlgebra", "UUIDs"] +git-tree-sha1 = "00a2cccc7f098ff3b66806862d275ca3db9e6e5a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "4.5.0" + +[[deps.CompilerSupportLibraries_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" +version = "1.0.1+0" + +[[deps.DataAPI]] +git-tree-sha1 = "e8119c1a33d267e16108be441a287a6981ba1630" +uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +version = "1.14.0" + +[[deps.DataValueInterfaces]] +git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" +uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" +version = "1.0.0" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.Downloads]] +deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] +uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +version = "1.6.0" + +[[deps.FileWatching]] +uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" + +[[deps.IfElse]] +git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1" +uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" +version = "0.1.1" + +[[deps.InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[deps.IteratorInterfaceExtensions]] +git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" +uuid = "82899510-4779-5014-852e-03e436cf321d" +version = "1.0.0" + +[[deps.JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "3c837543ddb02250ef42f4738347454f95079d4e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.3" + +[[deps.LeftChildRightSiblingTrees]] +deps = ["AbstractTrees"] +git-tree-sha1 = "fb6803dafae4a5d62ea5cab204b1e657d9737e7f" +uuid = "1d6d02ad-be62-4b6b-8a6d-2f90e265016e" +version = "0.2.0" + +[[deps.LibCURL]] +deps = ["LibCURL_jll", "MozillaCACerts_jll"] +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" +version = "0.6.3" + +[[deps.LibCURL_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] +uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" +version = "7.84.0+0" + +[[deps.LibGit2]] +deps = ["Base64", "NetworkOptions", "Printf", "SHA"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[deps.LibSSH2_jll]] +deps = ["Artifacts", "Libdl", "MbedTLS_jll"] +uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" +version = "1.10.2+0" + +[[deps.Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[deps.LinearAlgebra]] +deps = ["Libdl", "libblastrampoline_jll"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[deps.Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[deps.Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[deps.MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" +version = "2.28.0+0" + +[[deps.Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[deps.MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" +version = "2022.2.1" + +[[deps.Mustache]] +deps = ["Printf", "Tables"] +git-tree-sha1 = "1e566ae913a57d0062ff1af54d2697b9344b99cd" +uuid = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" +version = "1.0.14" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" +version = "1.2.0" + +[[deps.OffsetArrays]] +deps = ["Adapt"] +git-tree-sha1 = "f71d8950b724e9ff6110fc948dff5a329f901d64" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "1.12.8" + +[[deps.OpenBLAS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] +uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" +version = "0.3.20+0" + +[[deps.OrderedCollections]] +git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.4.1" + +[[deps.Parsers]] +deps = ["Dates", "SnoopPrecompile"] +git-tree-sha1 = "8175fc2b118a3755113c8e68084dc1a9e63c61ee" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "2.5.3" + +[[deps.Pkg]] +deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +version = "1.8.0" + +[[deps.PkgBenchmark]] +deps = ["BenchmarkTools", "Dates", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Pkg", "Printf", "TerminalLoggers", "UUIDs"] +git-tree-sha1 = "e4a10b7cdb7ec836850e43a4cee196f4e7b02756" +uuid = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d" +version = "0.2.12" + +[[deps.Preferences]] +deps = ["TOML"] +git-tree-sha1 = "47e5f437cc0e7ef2ce8406ce1e7e24d44915f88d" +uuid = "21216c6a-2e73-6563-6e65-726566657250" +version = "1.3.0" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[[deps.ProgressLogging]] +deps = ["Logging", "SHA", "UUIDs"] +git-tree-sha1 = "80d919dee55b9c50e8d9e2da5eeafff3fe58b539" +uuid = "33c8b6b6-d38a-422a-b730-caa89a2f386c" +version = "0.1.4" + +[[deps.REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[deps.Random]] +deps = ["SHA", "Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" +version = "0.7.0" + +[[deps.Sbplib]] +deps = ["StaticArrays", "TOML", "TiledIteration"] +path = ".." +uuid = "5a373a26-915f-4769-bcab-bf03835de17b" +version = "0.1.0" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[deps.SnoopPrecompile]] +deps = ["Preferences"] +git-tree-sha1 = "e760a70afdcd461cf01a575947738d359234665c" +uuid = "66db9d55-30c0-4569-8b51-7e840670fc0c" +version = "1.0.3" + +[[deps.Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[deps.SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[deps.Static]] +deps = ["IfElse"] +git-tree-sha1 = "c35b107b61e7f34fa3f124026f2a9be97dea9e1c" +uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" +version = "0.8.3" + +[[deps.StaticArrays]] +deps = ["LinearAlgebra", "Random", "StaticArraysCore", "Statistics"] +git-tree-sha1 = "c262c8e978048c2b095be1672c9bee55b4619521" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "1.5.24" + +[[deps.StaticArraysCore]] +git-tree-sha1 = "6b7ba252635a5eff6a0b0664a41ee140a1c9e72a" +uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" +version = "1.4.0" + +[[deps.Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[deps.SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + +[[deps.TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +version = "1.0.0" + +[[deps.TableTraits]] +deps = ["IteratorInterfaceExtensions"] +git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39" +uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" +version = "1.0.1" + +[[deps.Tables]] +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "OrderedCollections", "TableTraits", "Test"] +git-tree-sha1 = "c79322d36826aa2f4fd8ecfa96ddb47b174ac78d" +uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +version = "1.10.0" + +[[deps.Tar]] +deps = ["ArgTools", "SHA"] +uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" +version = "1.10.1" + +[[deps.TerminalLoggers]] +deps = ["LeftChildRightSiblingTrees", "Logging", "Markdown", "Printf", "ProgressLogging", "UUIDs"] +git-tree-sha1 = "f53e34e784ae771eb9ccde4d72e578aa453d0554" +uuid = "5d786b92-1e48-4d6f-9151-6b4477ca9bed" +version = "0.1.6" + +[[deps.Test]] +deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[deps.TiledIteration]] +deps = ["ArrayInterface", "OffsetArrays"] +git-tree-sha1 = "1bf2bb587a7fc99fefac2ff076b18b500128e9c0" +uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac" +version = "0.4.2" + +[[deps.UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.12+3" + +[[deps.libblastrampoline_jll]] +deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] +uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" +version = "5.1.1+0" + +[[deps.nghttp2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" +version = "1.48.0+0" + +[[deps.p7zip_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" +version = "17.4.0+0"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmark/Project.toml Sun May 21 20:51:52 2023 +0200 @@ -0,0 +1,5 @@ +[deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" +PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d" +Sbplib = "5a373a26-915f-4769-bcab-bf03835de17b"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmark/benchmark_utils.jl Sun May 21 20:51:52 2023 +0200 @@ -0,0 +1,316 @@ +import PkgBenchmark +import Markdown +import Mustache +import Dates + +import Sbplib + +const sbplib_root = splitpath(pathof(Sbplib))[1:end-2] |> joinpath +const results_dir = mkpath(joinpath(sbplib_root, "benchmark/results")) +const template_path = joinpath(sbplib_root, "benchmark/result.tmpl") + +""" + mainmain(;rev=nothing, target=nothing, baseline=nothing , kwargs...) + +Calls `run_benchmark(args...; kwargs...)` and writes the results as an HTML +file in `benchmark/results`. + + * If `rev` is set, the benchmarks are run for the given mercurial revision. + * If only `baseline` is set, the current working directory is compared with + the revision given in `baseline`. + * If both `target` and `baseline` is set those revision are compared. + +For control over what happens to the benchmark result datastructure see the +different methods of [`run_benchmark`](@ref) +""" +function main(;rev=nothing, target=nothing, baseline=nothing , kwargs...) + if !isnothing(rev) + r = run_benchmark(rev; kwargs...) + elseif !isnothing(baseline) + if isnothing(target) + r = compare_benchmarks(baseline; kwargs...) + else + r = compare_benchmarks(target, baseline; kwargs...) + end + else + # Neither rev, or baseline were set => Run on current working directory. + r = run_benchmark(;kwargs...) + end + + file_path = write_result_html(r) + open_in_default_browser(file_path) +end + + +""" + run_benchmark() + +Run the benchmark suite for the current working directory and return a +`PkgBenchmark.BenchmarkResult` +""" +function run_benchmark(;kwargs...) + r = PkgBenchmark.benchmarkpkg(Sbplib; kwargs...) + + rev = hg_rev() # Should be changed to hg_id() when the html can handle it. + + return add_rev_info(r, rev) +end + +""" + run_benchmark(rev) + +Updates the repository to the given revison and runs the benchmark suite. When +done, reverts the repository to the original state. `rev` can be any +identifier compatible with `hg update`. + +Returns a `PkgBenchmark.BenchmarkResult` +""" +function run_benchmark(rev; kwargs...) + return hg_at_revision(rev) do + run_benchmark(; kwargs...) + end +end + +""" + compare_benchmarks(target, baseline, f=minimum; judgekwargs=Dict()) + +Runs the benchmark at revisions `target` and `baseline` and compares them +using `PkgBenchmark.judge`. `f` is the function used to compare. `judgekwargs` +are keyword arguments passed to `judge`. + +`target` and `baseline` can be any identifier compatible with `hg update`. + +Returns a `PkgBenchmark.BenchmarkJudgement` +""" +function compare_benchmarks(target, baseline, f=minimum; judgekwargs=Dict(), kwargs...) + t = run_benchmark(target; kwargs...) + b = run_benchmark(baseline; kwargs...) + + return PkgBenchmark.judge(t,b,f; judgekwargs...) +end + +""" + compare_benchmarks(baseline, ...) + +Compare the results at the current working directory with the revision +specified in `baseline`. + +Accepts the same arguments as the two revision version. +""" +function compare_benchmark(baseline, f=minimum; judgekwargs=Dict(), kwargs...) + t = run_benchmark(;kwargs...) + b = run_benchmark(baseline; kwargs...) + + return PkgBenchmark.judge(t,b,f; judgekwargs...) +end + + +function add_rev_info(benchmarkresult, rev) + if endswith(rev,"+") + revstr = "+$rev" # Workaround for the bad presentation of BenchmarkResults. + else + revstr = rev + end + + return PkgBenchmark.BenchmarkResults( + benchmarkresult.name, + revstr, + benchmarkresult.benchmarkgroup, + benchmarkresult.date, + benchmarkresult.julia_commit, + benchmarkresult.vinfo, + benchmarkresult.benchmarkconfig, + ) +end + + +function write_result_html(io, r) + iobuffer = IOBuffer() + PkgBenchmark.export_markdown(iobuffer, r) + + parsed_md = Markdown.parse(String(take!(iobuffer))) + content = Markdown.html(parsed_md) + + template = Mustache.load(template_path) + + dt = Dates.format(PkgBenchmark.date(r), "yyyy-mm-dd HH:MM:SS") + Mustache.render(io, template, Dict("title"=>dt, "content"=>content)) +end + +function write_result_html(r) + dt = Dates.format(PkgBenchmark.date(r), "yyyy-mm-dd HHMMSS") + file_path = joinpath(results_dir, dt*".html") + + open(file_path, "w") do io + write_result_html(io, r) + end + + return file_path +end + + +PkgBenchmark.date(j::PkgBenchmark.BenchmarkJudgement) = PkgBenchmark.date(PkgBenchmark.target_result(j)) + + +function hg_id() + cmd = Cmd(`hg id`, dir=sbplib_root) + return readchomp(addenv(cmd, "HGPLAIN"=>"")) +end + +function hg_rev() + cmd = Cmd(`hg id -i`, dir=sbplib_root) + return readchomp(addenv(cmd, "HGPLAIN"=>"")) +end + +function hg_update(rev) + cmd = Cmd(`hg update --check -r $rev`, dir=sbplib_root) + run(addenv(cmd, "HGPLAIN"=>"")) + + return nothing +end + +""" + hg_commit(msg; secret=false) + +Make a hg commit with the provided message. If `secret` is true the commit is +in the secret phase stopping it from being pushed. +""" +function hg_commit(msg; secret=false) + if secret + cmd = Cmd(`hg commit --verbose --secret --message $msg`, dir=sbplib_root) + else + cmd = Cmd(`hg commit --verbose --message $msg`, dir=sbplib_root) + end + + out = readchomp(addenv(cmd, "HGPLAIN"=>"")) + + return only(match(r"committed changeset \d+:([0-9a-z]+)", out)) +end + +""" + hg_strip(rev; keep=false) + +Strips the given commit from the repo. If `keep` is true, the changes of the +commit are kept in the working directory. +""" +function hg_strip(rev; keep=false) + if keep + cmd = Cmd(`hg --config extensions.strip= strip --keep -r $rev`, dir=sbplib_root) + else + cmd = Cmd(`hg --config extensions.strip= strip -r $rev`, dir=sbplib_root) + end + + run(addenv(cmd, "HGPLAIN"=>"")) + + return nothing +end + +""" + hg_is_dirty() + +Return true if the repositopry has uncommited changes. +""" +function hg_is_dirty() + cmd = Cmd(`hg identify --id`, dir=sbplib_root) + out = readchomp(addenv(cmd, "HGPLAIN"=>"")) + + return endswith(out, "+") +end + +""" + hg_at_revision(f, rev) + +Update the repository to the given revision and run the function `f`. After +`f` is run the working directory is restored. If there are uncommited changes +a temporary commit will be used to save the state of the working directory. +""" +function hg_at_revision(f, rev) + if hg_is_dirty() + hg_with_temporary_commit() do + return _hg_at_revision(f, rev) + end + else + return _hg_at_revision(f, rev) + end +end + +function _hg_at_revision(f, rev) + @assert !hg_is_dirty() + + origin_rev = hg_rev() + + hg_update(rev) + try + return f() + finally + hg_update(origin_rev) + end +end + +""" + hg_with_temporary_commit(f) + +Run the function `f` after making a temporary commit with the current working +directory. After `f` has finished the working directory is restored to its +original state and the temporary commit stripped. +""" +function hg_with_temporary_commit(f) + @assert hg_is_dirty() + + origin_rev = hg_commit("[Automatic commit by julia]",secret=true) + + try + return f() + finally + hg_update(origin_rev) + hg_strip(origin_rev; keep=true) + end +end + + +# From Pluto.jl/src/webserver/WebServer.jl (2023-01-24) +function open_in_default_browser(url::AbstractString)::Bool + try + if Sys.isapple() + Base.run(`open $url`) + true + elseif Sys.iswindows() || detectwsl() + Base.run(`powershell.exe Start "'$url'"`) + true + elseif Sys.islinux() + Base.run(`xdg-open $url`) + true + else + false + end + catch ex + false + end +end + + +main + +# TODO: Better logging of what is happening +# TODO: Improve the workflow? How? + +# TODO: Clean up the HTML output? + # TODO: Make the codeblocks in the table look nicer + # TODO: Change width of tables and code blocks so everything is visible + # TODO: Fix the commit id, it chops off all the important info + # TODO: Make title less verbose + # TBD: Do we have to replace export_markdown? Could use a template instead. + +# Should be able to run the current benchmark script at a different revision. +# Should have a way to filter the benchmark suite + +# TBD: What parts are PkgBenchmark contributing? Can it be stripped out? + + +## Catching the exit code and errors from a command can be done with code similar to + # proc = open(cmd) + # if success(proc) + + # else + + # end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmark/benchmarks.jl Sun May 21 20:51:52 2023 +0200 @@ -0,0 +1,180 @@ +using BenchmarkTools +using Sbplib +using Sbplib.Grids +using Sbplib.SbpOperators +using Sbplib.RegionIndices +using Sbplib.LazyTensors + +const SUITE = BenchmarkGroup() + + +sz(d) = ntuple(i->100, d) +ll(d) = ntuple(i->0., d) +lu(d) = ntuple(i->1., d) + +g1 = equidistant_grid(sz(1)[1],ll(1)[1],lu(1)[1]) +g2 = equidistant_grid(sz(2),ll(2),lu(2)) +g3 = equidistant_grid(sz(3),ll(3),lu(3)) + +v1 = rand(sz(1)...) +v2 = rand(sz(2)...) +v3 = rand(sz(3)...) + +u1 = rand(sz(1)...) +u2 = rand(sz(2)...) +u3 = rand(sz(3)...) + +stencil_set = read_stencil_set(joinpath(sbp_operators_path(),"standard_diagonal.toml"); order=4) + +SUITE["derivatives"] = BenchmarkGroup() + + +SUITE["derivatives"]["first_derivative"] = BenchmarkGroup() + +D₁ = first_derivative(g1,stencil_set) +SUITE["derivatives"]["first_derivative"]["1D"] = @benchmarkable $u1 .= $D₁*$v1 + +Dx = first_derivative(g2,stencil_set,1) +Dy = first_derivative(g2,stencil_set,2) +SUITE["derivatives"]["first_derivative"]["2D"] = BenchmarkGroup() +SUITE["derivatives"]["first_derivative"]["2D"]["x"] = @benchmarkable $u2 .= $Dx*$v2 +SUITE["derivatives"]["first_derivative"]["2D"]["y"] = @benchmarkable $u2 .= $Dy*$v2 + +Dx = first_derivative(g3,stencil_set,1) +Dy = first_derivative(g3,stencil_set,2) +Dz = first_derivative(g3,stencil_set,3) +SUITE["derivatives"]["first_derivative"]["3D"] = BenchmarkGroup() +SUITE["derivatives"]["first_derivative"]["3D"]["x"] = @benchmarkable $u3 .= $Dx*$v3 +SUITE["derivatives"]["first_derivative"]["3D"]["y"] = @benchmarkable $u3 .= $Dy*$v3 +SUITE["derivatives"]["first_derivative"]["3D"]["z"] = @benchmarkable $u3 .= $Dz*$v3 + + +SUITE["derivatives"]["second_derivative"] = BenchmarkGroup() + +D₂ = second_derivative(g1,stencil_set) +SUITE["derivatives"]["second_derivative"]["1D"] = @benchmarkable $u1 .= $D₂*$v1 + +Dx = second_derivative(g2,stencil_set,1) +Dy = second_derivative(g2,stencil_set,2) +SUITE["derivatives"]["second_derivative"]["2D"] = BenchmarkGroup() +SUITE["derivatives"]["second_derivative"]["2D"]["x"] = @benchmarkable $u2 .= $Dx*$v2 +SUITE["derivatives"]["second_derivative"]["2D"]["y"] = @benchmarkable $u2 .= $Dy*$v2 + +Dx = second_derivative(g3,stencil_set,1) +Dy = second_derivative(g3,stencil_set,2) +Dz = second_derivative(g3,stencil_set,3) +SUITE["derivatives"]["second_derivative"]["3D"] = BenchmarkGroup() +SUITE["derivatives"]["second_derivative"]["3D"]["x"] = @benchmarkable $u3 .= $Dx*$v3 +SUITE["derivatives"]["second_derivative"]["3D"]["y"] = @benchmarkable $u3 .= $Dy*$v3 +SUITE["derivatives"]["second_derivative"]["3D"]["z"] = @benchmarkable $u3 .= $Dz*$v3 + + + +SUITE["derivatives"]["addition"] = BenchmarkGroup() + +D₁ = first_derivative(g1,stencil_set) +D₂ = second_derivative(g1,stencil_set) +SUITE["derivatives"]["addition"]["1D"] = BenchmarkGroup() +SUITE["derivatives"]["addition"]["1D"]["apply,add"] = @benchmarkable $u1 .= $D₁*$v1 + $D₂*$v1 +SUITE["derivatives"]["addition"]["1D"]["add,apply"] = @benchmarkable $u1 .= ($D₁ + $D₂)*$v1 + +Dxx = second_derivative(g2,stencil_set,1) +Dyy = second_derivative(g2,stencil_set,2) +SUITE["derivatives"]["addition"]["2D"] = BenchmarkGroup() +SUITE["derivatives"]["addition"]["2D"]["apply,add"] = @benchmarkable $u2 .= $Dxx*$v2 + $Dyy*$v2 +SUITE["derivatives"]["addition"]["2D"]["add,apply"] = @benchmarkable $u2 .= ($Dxx + $Dyy)*$v2 + +Dxx = second_derivative(g3,stencil_set,1) +Dyy = second_derivative(g3,stencil_set,2) +Dzz = second_derivative(g3,stencil_set,3) +SUITE["derivatives"]["addition"]["3D"] = BenchmarkGroup() +SUITE["derivatives"]["addition"]["3D"]["apply,add"] = @benchmarkable $u3 .= $Dxx*$v3 + $Dyy*$v3 + $Dzz*$v3 +SUITE["derivatives"]["addition"]["3D"]["add,apply"] = @benchmarkable $u3 .= ($Dxx + $Dyy + $Dzz)*$v3 + + +SUITE["derivatives"]["composition"] = BenchmarkGroup() + +Dx = first_derivative(g1,stencil_set) +SUITE["derivatives"]["composition"]["1D"] = BenchmarkGroup() +SUITE["derivatives"]["composition"]["1D"]["apply,apply"] = @benchmarkable $u1 .= $Dx*($Dx*$v1) +SUITE["derivatives"]["composition"]["1D"]["compose,apply"] = @benchmarkable $u1 .= ($Dx∘$Dx)*$v1 + +Dx = first_derivative(g2,stencil_set,1) +Dy = first_derivative(g2,stencil_set,2) +SUITE["derivatives"]["composition"]["2D"] = BenchmarkGroup() +SUITE["derivatives"]["composition"]["2D"]["apply,apply"] = @benchmarkable $u2 .= $Dy*($Dx*$v2) +SUITE["derivatives"]["composition"]["2D"]["compose,apply"] = @benchmarkable $u2 .= ($Dy∘$Dx)*$v2 + +Dx = first_derivative(g3,stencil_set,1) +Dy = first_derivative(g3,stencil_set,2) +Dz = first_derivative(g3,stencil_set,3) +SUITE["derivatives"]["composition"]["3D"] = BenchmarkGroup() +SUITE["derivatives"]["composition"]["3D"]["xy"] = BenchmarkGroup() +SUITE["derivatives"]["composition"]["3D"]["xy"]["apply,apply"] = @benchmarkable $u3 .= $Dx*($Dy*$v3) +SUITE["derivatives"]["composition"]["3D"]["xy"]["compose,apply"] = @benchmarkable $u3 .= ($Dx∘$Dy)*$v3 + +SUITE["derivatives"]["composition"]["3D"]["yz"] = BenchmarkGroup() +SUITE["derivatives"]["composition"]["3D"]["yz"]["apply,apply"] = @benchmarkable $u3 .= $Dy*($Dz*$v3) +SUITE["derivatives"]["composition"]["3D"]["yz"]["compose,apply"] = @benchmarkable $u3 .= ($Dy∘$Dz)*$v3 + +SUITE["derivatives"]["composition"]["3D"]["xz"] = BenchmarkGroup() +SUITE["derivatives"]["composition"]["3D"]["xz"]["apply,apply"] = @benchmarkable $u3 .= $Dx*($Dz*$v3) +SUITE["derivatives"]["composition"]["3D"]["xz"]["compose,apply"] = @benchmarkable $u3 .= ($Dx∘$Dz)*$v3 + +SUITE["derivatives"]["composition"]["3D"]["xx"] = BenchmarkGroup() +SUITE["derivatives"]["composition"]["3D"]["xx"]["apply,apply"] = @benchmarkable $u3 .= $Dx*($Dx*$v3) +SUITE["derivatives"]["composition"]["3D"]["xx"]["compose,apply"] = @benchmarkable $u3 .= ($Dx∘$Dx)*$v3 + +SUITE["derivatives"]["composition"]["3D"]["yy"] = BenchmarkGroup() +SUITE["derivatives"]["composition"]["3D"]["yy"]["apply,apply"] = @benchmarkable $u3 .= $Dy*($Dy*$v3) +SUITE["derivatives"]["composition"]["3D"]["yy"]["compose,apply"] = @benchmarkable $u3 .= ($Dy∘$Dy)*$v3 + +SUITE["derivatives"]["composition"]["3D"]["zz"] = BenchmarkGroup() +SUITE["derivatives"]["composition"]["3D"]["zz"]["apply,apply"] = @benchmarkable $u3 .= $Dz*($Dz*$v3) +SUITE["derivatives"]["composition"]["3D"]["zz"]["compose,apply"] = @benchmarkable $u3 .= ($Dz∘$Dz)*$v3 + + +SUITE["boundary_terms"] = BenchmarkGroup() + +H = inner_product(g2, stencil_set) +H⁻¹ = inverse_inner_product(g2, stencil_set) +Dxx = second_derivative(g2, stencil_set, 1) +Dyy = second_derivative(g2, stencil_set, 2) + +e₁ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,Lower}()) +e₁ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,Upper}()) +e₂ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,Lower}()) +e₂ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,Upper}()) + +d₁ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{1,Lower}()) +d₁ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{1,Upper}()) +d₂ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{2,Lower}()) +d₂ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{2,Upper}()) + +H₁ₗ = inner_product(boundary_grid(g2, CartesianBoundary{1,Lower}()), stencil_set) +H₁ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{1,Upper}()), stencil_set) +H₂ₗ = inner_product(boundary_grid(g2, CartesianBoundary{2,Lower}()), stencil_set) +H₂ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{2,Upper}()), stencil_set) + +SUITE["boundary_terms"]["pre_composition"] = @benchmarkable $u2 .= $(H⁻¹∘e₁ₗ'∘H₁ₗ∘d₁ₗ)*$v2 +SUITE["boundary_terms"]["composition"] = @benchmarkable $u2 .= ($H⁻¹∘$e₁ₗ'∘$H₁ₗ∘$d₁ₗ)*$v2 +SUITE["boundary_terms"]["application"] = @benchmarkable $u2 .= $H⁻¹*$e₁ₗ'*$H₁ₗ* $d₁ₗ*$v2 +# An investigation of these allocations can be found in the branch `allocation_test` + +#TODO: Reorg with dimension as first level? To reduce operator creation? + + + +SUITE["lazy_tensors"] = BenchmarkGroup() + +SUITE["lazy_tensors"]["compositions"] = BenchmarkGroup() +s = ScalingTensor(1.,(10,)) +u = rand(10) +v = similar(u) +s3 = s∘s∘s +s4 = s∘s∘s∘s +SUITE["lazy_tensors"]["compositions"]["s∘s∘s"] = @benchmarkable $v .= $s3*$u +SUITE["lazy_tensors"]["compositions"]["s∘s∘s∘s"] = @benchmarkable $v .= $s4*$u + + +SUITE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmark/make.jl Sun May 21 20:51:52 2023 +0200 @@ -0,0 +1,21 @@ +rev = nothing +baseline = nothing +target = nothing + +if "--rev" ∈ ARGS + i = findlast(==("--rev"), ARGS) + rev = ARGS[i+1] +end + +if "--target" ∈ ARGS + i = findlast(==("--target"), ARGS) + target = ARGS[i+1] +end + +if "--baseline" ∈ ARGS + i = findlast(==("--baseline"), ARGS) + baseline = ARGS[i+1] +end + +include("benchmark_utils.jl") +main(;rev, target, baseline)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmark/result.tmpl Sun May 21 20:51:52 2023 +0200 @@ -0,0 +1,211 @@ +<html> +<head> + <title>Benchmark result {{title}}</title> + <meta charset="UTF-8"> + + <style> + @charset "UTF-8"; + body { + font-family: system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; + line-height: 1.4; + max-width: 800px; + margin: 20px auto; + padding: 0 10px; + color: #363636; + background: #fff; + text-rendering:optimizeLegibility + } + + button, input, textarea { + transition:background-color .1s linear, border-color .1s linear, color .1s linear, box-shadow .1s linear, transform .1s ease + } + + h1 { + font-size: 2.2em; + margin-top:0 + } + + h1, h2, h3, h4, h5, h6 { + margin-bottom:12px + } + + h1, h2, h3, h4, h5, h6, strong { + color:#000 + } + + b, h1, h2, h3, h4, h5, h6, strong, th { + font-weight:600 + } + + blockquote { + border-left: 4px solid rgba(0, 150, 191, .67); + margin: 1.5em 0; + padding: .5em 1em; + font-style:italic + } + + blockquote > footer { + margin-top: 10px; + font-style:normal + } + + address, blockquote cite { + font-style:normal + } + + a[href^=mailto]:before { + content: "📧 " + } + + a[href^=tel]:before { + content: "📞 " + } + + a[href^=sms]:before { + content: "💬 " + } + + button, input[type=button], input[type=checkbox], input[type=submit] { + cursor:pointer + } + + input:not([type=checkbox]):not([type=radio]), select { + display:block + } + + button, input, select, textarea { + color: #000; + background-color: #efefef; + font-family: inherit; + font-size: inherit; + margin-right: 6px; + margin-bottom: 6px; + padding: 10px; + border: none; + border-radius: 6px; + outline:none + } + + button, input:not([type=checkbox]):not([type=radio]), select, textarea { + -webkit-appearance:none + } + + textarea { + margin-right: 0; + width: 100%; + box-sizing: border-box; + resize:vertical + } + + button, input[type=button], input[type=submit] { + padding-right: 30px; + padding-left:30px + } + + button:hover, input[type=button]:hover, input[type=submit]:hover { + background:#ddd + } + + button:focus, input:focus, select:focus, textarea:focus { + box-shadow:0 0 0 2px rgba(0, 150, 191, .67) + } + + button:active, input[type=button]:active, input[type=checkbox]:active, input[type=radio]:active, input[type=submit]:active { + transform:translateY(2px) + } + + button:disabled, input:disabled, select:disabled, textarea:disabled { + cursor: not-allowed; + opacity:.5 + } + + ::-webkit-input-placeholder { + color:#949494 + } + + :-ms-input-placeholder { + color:#949494 + } + + ::-ms-input-placeholder { + color:#949494 + } + + ::placeholder { + color:#949494 + } + + a { + text-decoration: none; + color:#0076d1 + } + + a:hover { + text-decoration:underline + } + + code, kbd { + background: #efefef; + color: #000; + padding: 5px; + border-radius:6px + } + + pre > code { + padding: 10px; + display: block; + overflow-x:auto + } + + img { + max-width:100% + } + + hr { + border: none; + border-top:1px solid #dbdbdb + } + + table { + border-collapse: collapse; + margin-bottom: 10px; + width:100% + } + + td, th { + padding: 6px; + text-align:left + } + + th { + border-bottom:1px solid #dbdbdb + } + + tbody tr:nth-child(2n) { + background-color:#efefef + } + + ::-webkit-scrollbar { + height: 10px; + width:10px + } + + ::-webkit-scrollbar-track { + background: #efefef; + border-radius:6px + } + + ::-webkit-scrollbar-thumb { + background: #d5d5d5; + border-radius:6px + } + + ::-webkit-scrollbar-thumb:hover { + background: #c4c4c4 + } + </style> +</head> +<body> + {{{content}}} +</body> +</html>