From 645dab6d7aef389abfff9af9c1842844711ec72c Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Sun, 13 Oct 2024 00:46:06 +1100 Subject: [PATCH 01/16] Started exploring benchmarks --- benchmark/Project.toml | 4 ++++ benchmark/benchmarks.jl | 28 ++++++++++++++++++++++++++++ benchmark/drivers.jl | 20 ++++++++++++++++++++ benchmark/run_benchmarks.jl | 15 +++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 benchmark/Project.toml create mode 100644 benchmark/benchmarks.jl create mode 100644 benchmark/drivers.jl create mode 100644 benchmark/run_benchmarks.jl diff --git a/benchmark/Project.toml b/benchmark/Project.toml new file mode 100644 index 000000000..03356cbf5 --- /dev/null +++ b/benchmark/Project.toml @@ -0,0 +1,4 @@ +[deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e" +PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d" diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 000000000..5f47843fd --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,28 @@ +using BenchmarkTools +using Gridap + +include("drivers.jl") + +const SUITE = BenchmarkGroup() + +ncells = 40 +for D in [2,3] + for order in [1,2,3] + basis_cases = [ + ("lagrangian",lagrangian,Float64,order), + ("vector_lagragian",lagrangian,VectorValue{D,Float64},order), + ("raviart_thomas",raviart_thomas,Float64,order-1), + ] + for (basis_name,basis,T,degree) in basis_cases + biform_cases = [ + ("mass",mass,2*order), + ("laplacian",laplacian,2*(order-1)), + ] + for (biform_name,biform,qdegree) in biform_cases + reffe = ReferenceFE(basis, T, degree) + name = "assembly_$(D)D_$(basis_name)_$(biform_name)_$(order)" + SUITE[name] = @benchmarkable bm_matrix_assembly(D,ncells,reffe,qdegree,biform) + end + end + end +end diff --git a/benchmark/drivers.jl b/benchmark/drivers.jl new file mode 100644 index 000000000..e62a14bfb --- /dev/null +++ b/benchmark/drivers.jl @@ -0,0 +1,20 @@ + +mass(u,v,dΩ) = ∫(u⋅v)dΩ +laplacian(u,v,dΩ) = ∫(∇(u)⊙∇(v))dΩ + +function bm_matrix_assembly( + D :: Integer, + n :: Integer, + reffe :: Tuple, + qdegree :: Integer, + biform :: Function +) + domain = Tuple(repeat((0,1), D)...) + partition = Tuple(repeat(n, D)...) + model = UnstructuredDiscreteModel(CartesianDiscreteModel(domain, partition)) + Ω = Triangulation(model) + dΩ = Measure(Ω,qdegree) + V = TestFESpace(model, reffe) + a(u,v) = biform(u,v,dΩ) + A = assemble_matrix(a, V, V) +end diff --git a/benchmark/run_benchmarks.jl b/benchmark/run_benchmarks.jl new file mode 100644 index 000000000..6c85739b3 --- /dev/null +++ b/benchmark/run_benchmarks.jl @@ -0,0 +1,15 @@ + +using Gridap +using PkgBenchmark +using DrWatson + +target = "raviart_thomas" + +results = judge( + Gridap, + BenchmarkConfig(juliacmd = `julia -O3`, id = target), + BenchmarkConfig(juliacmd = `julia -O3`, id = "master") +) + +outfile = projectdir("benchmark/results_$(target).json") +export_markdown(outfile,results) From 6ff1c1db0d0011d720e66ca712acc939cd841bc6 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 15 Oct 2024 11:10:17 +1100 Subject: [PATCH 02/16] Minor fixes --- benchmark/benchmarks.jl | 4 +++- benchmark/drivers.jl | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index 5f47843fd..440d84166 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -21,7 +21,9 @@ for D in [2,3] for (biform_name,biform,qdegree) in biform_cases reffe = ReferenceFE(basis, T, degree) name = "assembly_$(D)D_$(basis_name)_$(biform_name)_$(order)" - SUITE[name] = @benchmarkable bm_matrix_assembly(D,ncells,reffe,qdegree,biform) + SUITE[name] = @benchmarkable bm_matrix_assembly( + $(D),$(ncells),$(reffe),$(qdegree),$(biform) + ) end end end diff --git a/benchmark/drivers.jl b/benchmark/drivers.jl index e62a14bfb..6ac5bf6a5 100644 --- a/benchmark/drivers.jl +++ b/benchmark/drivers.jl @@ -1,4 +1,6 @@ +using Gridap.Geometry + mass(u,v,dΩ) = ∫(u⋅v)dΩ laplacian(u,v,dΩ) = ∫(∇(u)⊙∇(v))dΩ @@ -9,8 +11,8 @@ function bm_matrix_assembly( qdegree :: Integer, biform :: Function ) - domain = Tuple(repeat((0,1), D)...) - partition = Tuple(repeat(n, D)...) + domain = Tuple([repeat([0,1], D)...]) + partition = Tuple(fill(n, D)) model = UnstructuredDiscreteModel(CartesianDiscreteModel(domain, partition)) Ω = Triangulation(model) dΩ = Measure(Ω,qdegree) From 7c1891df01cfb2048c5244a4ed513c52cf371199 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 17 Oct 2024 16:57:16 +1100 Subject: [PATCH 03/16] Minor --- benchmark/run_benchmarks.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/benchmark/run_benchmarks.jl b/benchmark/run_benchmarks.jl index 6c85739b3..05c82c694 100644 --- a/benchmark/run_benchmarks.jl +++ b/benchmark/run_benchmarks.jl @@ -1,3 +1,8 @@ +using Pkg + +Pkg.activate(@__DIR__) +Pkg.develop(PackageSpec(path = dirname(@__DIR__))) +Pkg.instantiate() using Gridap using PkgBenchmark From 7fd75de835c15cea21ecb392f439b9e004df92cc Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 17 Oct 2024 17:26:26 +1100 Subject: [PATCH 04/16] Minor --- benchmark/run_benchmarks.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/run_benchmarks.jl b/benchmark/run_benchmarks.jl index 05c82c694..fec741470 100644 --- a/benchmark/run_benchmarks.jl +++ b/benchmark/run_benchmarks.jl @@ -8,7 +8,7 @@ using Gridap using PkgBenchmark using DrWatson -target = "raviart_thomas" +target = "raviart-thomas" results = judge( Gridap, From 668ef36cef340f3d344da78493c57b98db6b0fad Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 17 Oct 2024 17:34:16 +1100 Subject: [PATCH 05/16] Minor --- benchmark/benchmarks.jl | 3 +-- benchmark/run_benchmarks.jl | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index 440d84166..e14106e0a 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -5,8 +5,7 @@ include("drivers.jl") const SUITE = BenchmarkGroup() -ncells = 40 -for D in [2,3] +for (D,ncells) in [(2,20),(3,8)] for order in [1,2,3] basis_cases = [ ("lagrangian",lagrangian,Float64,order), diff --git a/benchmark/run_benchmarks.jl b/benchmark/run_benchmarks.jl index fec741470..dcd3f1570 100644 --- a/benchmark/run_benchmarks.jl +++ b/benchmark/run_benchmarks.jl @@ -8,13 +8,11 @@ using Gridap using PkgBenchmark using DrWatson -target = "raviart-thomas" - results = judge( Gridap, - BenchmarkConfig(juliacmd = `julia -O3`, id = target), + BenchmarkConfig(juliacmd = `julia -O3`), # target -> current branch BenchmarkConfig(juliacmd = `julia -O3`, id = "master") ) -outfile = projectdir("benchmark/results_$(target).json") +outfile = normpath(@__DIR__,"results_$(target).json") export_markdown(outfile,results) From a3bf057df0272855206ea5978dc3c51815fb32eb Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 17 Oct 2024 18:46:34 +1100 Subject: [PATCH 06/16] Added github workflow --- .github/workflows/benchmark.yml | 56 +++++++++++++++++++++++++++++++++ benchmark/run_benchmarks.jl | 22 +++++++++---- 2 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/benchmark.yml diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 000000000..e7c29485a --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,56 @@ +name: Benchmarks + +on: + workflow_dispatch: + inputs: + target: + description: 'Target branch' + required: true + type: string + base: + description: 'Base branch' + required: true + default: 'master' + type: string + +jobs: + benchmark: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + version: + - '1.10' + arch: + - x64 + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v4 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - uses: julia-actions/julia-buildpkg@v1 + - name: Install Gridap in main environment + run: julia -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' + - name: Install dependencies + run: julia --project=benchmark/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' + - name: Run benchmarks + run: julia --project=benchmark/ --color=yes benchmark/run_benchmarks.jl + env: + BM_BASE: ${{ github.event.inputs.base }} + BM_TARGET: ${{ github.event.inputs.target }} + - uses: actions/upload-artifact@v4 + with: + name: benchmarks + path: benchmark/benchmark_results.md \ No newline at end of file diff --git a/benchmark/run_benchmarks.jl b/benchmark/run_benchmarks.jl index dcd3f1570..5f939cb1a 100644 --- a/benchmark/run_benchmarks.jl +++ b/benchmark/run_benchmarks.jl @@ -6,13 +6,23 @@ Pkg.instantiate() using Gridap using PkgBenchmark -using DrWatson -results = judge( - Gridap, - BenchmarkConfig(juliacmd = `julia -O3`), # target -> current branch - BenchmarkConfig(juliacmd = `julia -O3`, id = "master") +config_kwargs = (; + juliacmd = `julia -O3`, ) -outfile = normpath(@__DIR__,"results_$(target).json") +if haskey(ENV,"BM_TARGET") + target = BenchmarkConfig(config_kwargs..., id = ENV["BM_TARGET"]) +else + target = BenchmarkConfig(config_kwargs...) +end + +if haskey(ENV,"BM_BASE") + base = BenchmarkConfig(config_kwargs..., id = ENV["BM_BASE"]) +else + base = BenchmarkConfig(config_kwargs..., id = "master") +end + +results = judge(Gridap, target, base) +outfile = normpath(@__DIR__,"benchmark_results.md") export_markdown(outfile,results) From 3c00c10c06841763a6006c1781af128772664ad1 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Thu, 17 Oct 2024 18:52:08 +1100 Subject: [PATCH 07/16] Minor --- benchmark/run_benchmarks.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/benchmark/run_benchmarks.jl b/benchmark/run_benchmarks.jl index 5f939cb1a..db3cc5fa3 100644 --- a/benchmark/run_benchmarks.jl +++ b/benchmark/run_benchmarks.jl @@ -11,15 +11,15 @@ config_kwargs = (; juliacmd = `julia -O3`, ) -if haskey(ENV,"BM_TARGET") +if haskey(ENV,"BM_TARGET") # Provided by CI workflow target = BenchmarkConfig(config_kwargs..., id = ENV["BM_TARGET"]) -else +else # Default to the current commit target = BenchmarkConfig(config_kwargs...) end -if haskey(ENV,"BM_BASE") +if haskey(ENV,"BM_BASE") # Provided by CI workflow base = BenchmarkConfig(config_kwargs..., id = ENV["BM_BASE"]) -else +else # Default to master base = BenchmarkConfig(config_kwargs..., id = "master") end From 4b5127c5599ccebb427caa14375d63826ea824c1 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Fri, 18 Oct 2024 16:18:02 +1100 Subject: [PATCH 08/16] Added support for Aqua.jl --- NEWS.md | 1 + Project.toml | 4 +++- test/Aqua.jl | 8 ++++++++ test/runtests.jl | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/Aqua.jl diff --git a/NEWS.md b/NEWS.md index 98d2d211f..d3a2e5c18 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added MacroFElements. These are defined as having the basis/dof-basis of a FESpace created on top of a RefinementRule. Since PR[#1024](https://github.com/gridap/Gridap.jl/pull/1024). - Added Barycentric refinement rule in 2D and 3D. Added Simplexify refinement rule. Since PR[#1024](https://github.com/gridap/Gridap.jl/pull/1024). +- Added support for benchmarking, through PkgBenchmark.jl. Since PR[#1039](https://github.com/gridap/Gridap.jl/pull/1039). ## [0.18.6] - 2024-08-29 diff --git a/Project.toml b/Project.toml index 540d53294..49303019f 100644 --- a/Project.toml +++ b/Project.toml @@ -33,6 +33,7 @@ WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192" [compat] AbstractTrees = "0.3.3, 0.4" +Aqua = "0.8" BSON = "0.2.5, 0.3" BlockArrays = "0.12.12, 0.13, 0.14, 0.15, 0.16" Combinatorics = "1.0.0" @@ -56,7 +57,8 @@ WriteVTK = "1.12.0" julia = "1.3" [extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Aqua","Test"] diff --git a/test/Aqua.jl b/test/Aqua.jl new file mode 100644 index 000000000..38fd18af5 --- /dev/null +++ b/test/Aqua.jl @@ -0,0 +1,8 @@ + +using Gridap +using Aqua + +Aqua.test_all( + Gridap, + ambiguities = false, +) diff --git a/test/runtests.jl b/test/runtests.jl index 98342027a..1963646a7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -34,4 +34,6 @@ using Test @time @testset "Adaptivity" begin include("AdaptivityTests/runtests.jl") end +@time @testset "Aqua" begin include("Aqua.jl") end + end # module From 5a9aa7e488a37814ff71e15af340d6808a2cb50b Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 5 Nov 2024 11:42:56 +1100 Subject: [PATCH 09/16] Deactivated unbound-args tests --- test/Aqua.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/Aqua.jl b/test/Aqua.jl index 38fd18af5..361fa29be 100644 --- a/test/Aqua.jl +++ b/test/Aqua.jl @@ -1,3 +1,4 @@ +module AquaTests using Gridap using Aqua @@ -5,4 +6,28 @@ using Aqua Aqua.test_all( Gridap, ambiguities = false, + unbound_args = false ) + +""" +Comment: Ambiguities + +I think all ambiguities are either false positives or never used in practice... I've seen +other packages set `ambiguities = false` as well, so I think it's fine to do so. +""" + +""" +Comment: Unbound Args + +We do have some unbound type warnings. However, these are calls which are never executed in +the code. + +They mostly involve things like `f(a::T...) where T`, which trigger the warning +in the case were the function `f` is called with no arguments. This can be fixed as described +in https://juliatesting.github.io/Aqua.jl/stable/unbound_args/#test_unbound_args, but it is quite +a pain to do so... + +I guess something to think about in the future. +""" + +end \ No newline at end of file From 0652dc2423984fe742d8706c52f06aeb5d833042 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 5 Nov 2024 11:44:25 +1100 Subject: [PATCH 10/16] Fixed undefined exports --- src/Geometry/Geometry.jl | 2 -- src/ODEs/ODEs.jl | 2 -- src/ReferenceFEs/ReferenceFEs.jl | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/Geometry/Geometry.jl b/src/Geometry/Geometry.jl index 8723502eb..471b420ff 100644 --- a/src/Geometry/Geometry.jl +++ b/src/Geometry/Geometry.jl @@ -97,8 +97,6 @@ export is_oriented export is_regular export expand_cell_data export compress_cell_data -export compress_contributions -export compress_ids export UnstructuredGridTopology diff --git a/src/ODEs/ODEs.jl b/src/ODEs/ODEs.jl index daec78a48..30f294d5d 100644 --- a/src/ODEs/ODEs.jl +++ b/src/ODEs/ODEs.jl @@ -72,8 +72,6 @@ export StageOperator export NonlinearStageOperator export LinearStageOperator -export massless_residual_weights - include("ODESolvers.jl") export ODESolver diff --git a/src/ReferenceFEs/ReferenceFEs.jl b/src/ReferenceFEs/ReferenceFEs.jl index ab0dd1e91..24cf3d310 100644 --- a/src/ReferenceFEs/ReferenceFEs.jl +++ b/src/ReferenceFEs/ReferenceFEs.jl @@ -104,12 +104,10 @@ export get_face_moments export get_face_nodes_dofs export get_nodes export evaluate! -export evaluate_dof export return_cache export return_type export test_dof export test_dof_array -# export evaluate_dof_array export ReferenceFE export ReferenceFEName From 45ff3e39db01766eb695c5b54c66cdc3ea094262 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 5 Nov 2024 11:57:56 +1100 Subject: [PATCH 11/16] Fixed unbound dependencies by adding compats for Julia base libs to 1 --- Project.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 49303019f..d185b8358 100644 --- a/Project.toml +++ b/Project.toml @@ -46,13 +46,18 @@ ForwardDiff = "0.10.10" JLD2 = "0.1.11, 0.3, 0.4, 0.5" JSON = "0.21.0" LineSearches = "7.0.1" +LinearAlgebra = "1" NLsolve = "4.3.0" NearestNeighbors = "0.4.8" PolynomialBases = "0.4.12" Preferences = "1.4" QuadGK = "2.3.1, 2.4" +Random = "1" +SparseArrays = "1" SparseMatricesCSR = "0.6.4" StaticArrays = "0.12.1, 1.0" +Statistics = "1" +Test = "1" WriteVTK = "1.12.0" julia = "1.3" @@ -61,4 +66,4 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua","Test"] +test = ["Aqua", "Test"] From 60fab730b9425f4735ce783a60d5bb79b35ae258 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 5 Nov 2024 14:27:04 +1100 Subject: [PATCH 12/16] Made benchmarks extendable --- benchmark/README.md | 53 +++++++++++++++++++++++++++++++++ benchmark/benchmarks.jl | 31 +++++-------------- benchmark/bm/bm_assembly.jl | 59 +++++++++++++++++++++++++++++++++++++ benchmark/drivers.jl | 22 -------------- 4 files changed, 120 insertions(+), 45 deletions(-) create mode 100644 benchmark/README.md create mode 100644 benchmark/bm/bm_assembly.jl delete mode 100644 benchmark/drivers.jl diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 000000000..989a1865f --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,53 @@ +# Benchmarking Suite + +The following benchmarking suite uses `PkgBenchmark.jl` and `BenchmarkTools.jl` to compare the performance of different branches of Gridap. + +## Running the benchmarks + +### Running as CI job + +The benchmarks are setup as a manual Github Actions workflow in `.github/workflows/benchmark.yml`. To run the workflow, you will need administrator access to the Gridap repository, then follow instructions [here](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow). + +The workflow will has two inputs: `target` and `base`, which are the branches/tags/commits you want to compare. The workflow will run the benchmarks on the `target` branch and compare them with the `base` branch (`master` by default). + +### Running Locally + +To run the benchmarks locally, you can have a look at the [documentation for `PkgBenchmark.jl`](https://juliaci.github.io/PkgBenchmark.jl/stable/run_benchmarks/). + +Alternatively, you can run the CI script locally from a local copy of the repository. From the Gridap root directory, run the following commands: + +```bash +# Instantiate Gridap and Gridap/benchmark +julia -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' +julia --project=benchmark/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' +# Run the benchmarks +export BM_TARGET = "your target branch" +export BM_BASE = "your reference branch" +julia --project=benchmark/ --color=yes benchmark/run_benchmarks.jl +``` + +where `BM_TARGET` and `BM_BASE` are the branches/tags/commits you want to compare. + +## Adding a new benchmark + +To add a new benchmark suite `xyx`, create a new file `bm/bm_xyx.jl` that with the following structure: + +```julia +module bm_xyx + +using PkgBenchmark, BenchmarkTools + +const SUITE = BenchmarkGroup() + +[... Add your benchmarks here ...] + +end # module +``` + +Then, add the following line to the `benchmarks.jl` file: + +```julia +@include_bm "bm_xyz" +``` + +This should automatically include the new benchmarks into the global benchmarking suite. diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index e14106e0a..ad8aa0aa6 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -1,29 +1,14 @@ using BenchmarkTools +using PkgBenchmark using Gridap -include("drivers.jl") +macro include_bm(SUITE,name) + quote + include("bm/$($name).jl") + SUITE["$($name)"] = $(Symbol(name)).SUITE + end +end const SUITE = BenchmarkGroup() -for (D,ncells) in [(2,20),(3,8)] - for order in [1,2,3] - basis_cases = [ - ("lagrangian",lagrangian,Float64,order), - ("vector_lagragian",lagrangian,VectorValue{D,Float64},order), - ("raviart_thomas",raviart_thomas,Float64,order-1), - ] - for (basis_name,basis,T,degree) in basis_cases - biform_cases = [ - ("mass",mass,2*order), - ("laplacian",laplacian,2*(order-1)), - ] - for (biform_name,biform,qdegree) in biform_cases - reffe = ReferenceFE(basis, T, degree) - name = "assembly_$(D)D_$(basis_name)_$(biform_name)_$(order)" - SUITE[name] = @benchmarkable bm_matrix_assembly( - $(D),$(ncells),$(reffe),$(qdegree),$(biform) - ) - end - end - end -end +@include_bm SUITE "bm_assembly" diff --git a/benchmark/bm/bm_assembly.jl b/benchmark/bm/bm_assembly.jl new file mode 100644 index 000000000..80b378163 --- /dev/null +++ b/benchmark/bm/bm_assembly.jl @@ -0,0 +1,59 @@ +module bm_assembly + +using PkgBenchmark, BenchmarkTools +using Gridap +using Gridap.Geometry + +mass(u,v,dΩ) = ∫(u⋅v)dΩ +laplacian(u,v,dΩ) = ∫(∇(u)⊙∇(v))dΩ +graddiv(u,v,dΩ) = ∫((∇⋅u)⋅(∇⋅v))dΩ + +function driver( + Ω :: Triangulation, + reffe :: Tuple, + qdegree :: Integer, + biform :: Function +) + model = get_background_model(Ω) + dΩ = Measure(Ω,qdegree) + V = TestFESpace(model, reffe) + a(u,v) = biform(u,v,dΩ) + A = assemble_matrix(a, V, V) +end + +const SUITE = BenchmarkGroup() + +for (D,n) in [(2,10),(3,6)] + domain = Tuple([repeat([0,1], D)...]) + partition = Tuple(fill(n, D)) + model = UnstructuredDiscreteModel(CartesianDiscreteModel(domain, partition)) + trian_cases = [ + ("bulk",Triangulation(model)), + ("view",Triangulation(model,collect(1:div(n^D,2)))), # About half of the cells + ] + for (trian_name, trian) in trian_cases + for order in [1,2,3] + basis_cases = [ + ("lagrangian",lagrangian,Float64,order), + ("vector_lagragian",lagrangian,VectorValue{D,Float64},order), + ("raviart_thomas",raviart_thomas,Float64,order-1), + ] + for (basis_name,basis,T,degree) in basis_cases + biform_cases = [ + ("mass",mass,2*order), + ("laplacian",laplacian,2*(order-1)), + ("graddiv",graddiv,2*(order-1)), + ] + for (biform_name,biform,qdegree) in biform_cases + reffe = ReferenceFE(basis, T, degree) + name = "assembly_$(D)D_$(trian_name)_$(basis_name)_$(biform_name)_$(order)" + SUITE[name] = @benchmarkable driver( + $(trian),$(reffe),$(qdegree),$(biform) + ) + end + end + end + end +end + +end # module \ No newline at end of file diff --git a/benchmark/drivers.jl b/benchmark/drivers.jl deleted file mode 100644 index 6ac5bf6a5..000000000 --- a/benchmark/drivers.jl +++ /dev/null @@ -1,22 +0,0 @@ - -using Gridap.Geometry - -mass(u,v,dΩ) = ∫(u⋅v)dΩ -laplacian(u,v,dΩ) = ∫(∇(u)⊙∇(v))dΩ - -function bm_matrix_assembly( - D :: Integer, - n :: Integer, - reffe :: Tuple, - qdegree :: Integer, - biform :: Function -) - domain = Tuple([repeat([0,1], D)...]) - partition = Tuple(fill(n, D)) - model = UnstructuredDiscreteModel(CartesianDiscreteModel(domain, partition)) - Ω = Triangulation(model) - dΩ = Measure(Ω,qdegree) - V = TestFESpace(model, reffe) - a(u,v) = biform(u,v,dΩ) - A = assemble_matrix(a, V, V) -end From fa0e471c672e0da64896dbde6320ee71334ed964 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 5 Nov 2024 14:35:30 +1100 Subject: [PATCH 13/16] Minor --- benchmark/run_benchmarks.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/benchmark/run_benchmarks.jl b/benchmark/run_benchmarks.jl index db3cc5fa3..0db9aedab 100644 --- a/benchmark/run_benchmarks.jl +++ b/benchmark/run_benchmarks.jl @@ -12,15 +12,15 @@ config_kwargs = (; ) if haskey(ENV,"BM_TARGET") # Provided by CI workflow - target = BenchmarkConfig(config_kwargs..., id = ENV["BM_TARGET"]) + target = BenchmarkConfig(;config_kwargs..., id = ENV["BM_TARGET"]) else # Default to the current commit - target = BenchmarkConfig(config_kwargs...) + target = BenchmarkConfig(;config_kwargs...) end if haskey(ENV,"BM_BASE") # Provided by CI workflow - base = BenchmarkConfig(config_kwargs..., id = ENV["BM_BASE"]) + base = BenchmarkConfig(;config_kwargs..., id = ENV["BM_BASE"]) else # Default to master - base = BenchmarkConfig(config_kwargs..., id = "master") + base = BenchmarkConfig(;config_kwargs..., id = "master") end results = judge(Gridap, target, base) From 8299da7d78f62b055cf46cdbb580e098da44437d Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 5 Nov 2024 14:53:21 +1100 Subject: [PATCH 14/16] Trigger CI for the first time --- .github/workflows/benchmark.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e7c29485a..8581f6420 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -12,6 +12,7 @@ on: required: true default: 'master' type: string + pull_request: jobs: benchmark: From 040e278cda47553508a78f33eec3fef50c27317c Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 5 Nov 2024 14:56:47 +1100 Subject: [PATCH 15/16] Remove pr trigger now that the workflow is registered --- .github/workflows/benchmark.yml | 1 - benchmark/README.md | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 8581f6420..e7c29485a 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -12,7 +12,6 @@ on: required: true default: 'master' type: string - pull_request: jobs: benchmark: diff --git a/benchmark/README.md b/benchmark/README.md index 989a1865f..e2b35fd2d 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -10,6 +10,12 @@ The benchmarks are setup as a manual Github Actions workflow in `.github/workflo The workflow will has two inputs: `target` and `base`, which are the branches/tags/commits you want to compare. The workflow will run the benchmarks on the `target` branch and compare them with the `base` branch (`master` by default). +You can also run the workflow using Github CLI and the following command: + +```bash +gh workflow run benchmark.yml -f target=your_target_branch -f base=your_base_branch +``` + ### Running Locally To run the benchmarks locally, you can have a look at the [documentation for `PkgBenchmark.jl`](https://juliaci.github.io/PkgBenchmark.jl/stable/run_benchmarks/). From c657b3a9049858c5297ba81418664228bc0c556a Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 5 Nov 2024 15:15:29 +1100 Subject: [PATCH 16/16] Updated NEWS.md --- NEWS.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index aae1f43b6..72dd89b72 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,11 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Implemented automatic differentiation `gradient` and `laplacian` for second order tensor, and `divergence` for third order tensors. - Added `AbstractSymTensorValue`, an abstract type for second order symmetric tensors, and `SymTracelessTensorValue` (aliased to `QTensorValue`), a type for traceless symmetric tensors. `SymTensorValue` is now subtype of `AbstractSymTensorValue`. - A convergence test for Poisson problem of `QTensorValue` unknown field validates the implementation. -- Added support for benchmarking, through PkgBenchmark.jl. Since PR[#1039](https://github.com/gridap/Gridap.jl/pull/1039). +- Added support for benchmarking, through `PkgBenchmark.jl`. Since PR[#1039](https://github.com/gridap/Gridap.jl/pull/1039). +- Added code quality tests, through `Aqua.jl`. Since PR[#1039](https://github.com/gridap/Gridap.jl/pull/1039). - ### Fixed +### Fixed - - Fixed constructor of RungeKutta with only one solver. Since PR[#999](https://github.com/gridap/Gridap.jl/pull/999). +- Fixed constructor of RungeKutta with only one solver. Since PR[#999](https://github.com/gridap/Gridap.jl/pull/999). ## [0.18.6] - 2024-08-29