diff --git a/.github/workflows/PerformanceCheck.yml b/.github/workflows/PerformanceCheck.yml index f61db1d9e..2b93d2a43 100644 --- a/.github/workflows/PerformanceCheck.yml +++ b/.github/workflows/PerformanceCheck.yml @@ -1,6 +1,10 @@ name: Performance Check + on: - workflow_dispatch: + pull_request: + branches: [master] + paths-ignore: ['docs/**'] + jobs: build-and-benchmark: runs-on: ${{ matrix.os }} diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index a7303b11a..000000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Benchmark this PR - -on: - pull_request: - branches: [master] - paths-ignore: ['docs/**'] - -permissions: - pull-requests: write - contents: read - -jobs: - benchmark: - runs-on: ubuntu-latest - timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - version: ["1", "lts"] - env: - # Force consistent Julia depot path for self-hosted runners - JULIA_DEPOT_PATH: ~/.julia - steps: - - uses: MilesCranmer/AirspeedVelocity.jl@action-v1 - with: - julia-version: ${{ matrix.version }} - script: "benchmark/benchmarks.jl" - extra-pkgs: "" - job-summary: true diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl deleted file mode 100644 index a9fd5eb02..000000000 --- a/benchmark/benchmarks.jl +++ /dev/null @@ -1,42 +0,0 @@ -using StructuralIdentifiability, BenchmarkTools - -const SUITE = BenchmarkGroup() - -# ============================================================================= -# Model construction — linear compartment models -# ============================================================================= - -SUITE["construction"] = BenchmarkGroup() - -graph3 = [[2], [1, 3], [1, 2]] -graph4 = [[2, 4], [1, 3], [2, 4], [1, 3]] - -SUITE["construction"]["lincomp_3"] = @benchmarkable linear_compartment_model( - $graph3; inputs = [1], outputs = [1], leaks = [] -) -SUITE["construction"]["lincomp_4"] = @benchmarkable linear_compartment_model( - $graph4; inputs = [2], outputs = [1], leaks = [2, 3] -) - -# ============================================================================= -# Identifiability assessment — the core workload: differential algebra + -# rational function field computation -# ============================================================================= - -SUITE["identifiability"] = BenchmarkGroup() - -ode3 = linear_compartment_model(graph3; inputs = [1], outputs = [1]) -ode4 = linear_compartment_model(graph4; inputs = [2], outputs = [1], leaks = [2, 3]) - -SUITE["identifiability"]["local_3"] = @benchmarkable assess_local_identifiability($ode3) -SUITE["identifiability"]["local_4"] = @benchmarkable assess_local_identifiability($ode4) -SUITE["identifiability"]["global_3"] = @benchmarkable assess_identifiability($ode3) seconds = 600 - -# ============================================================================= -# IO-equation derivation and identifiable function extraction -# ============================================================================= - -SUITE["ioequations"] = BenchmarkGroup() - -SUITE["ioequations"]["find_3"] = @benchmarkable find_ioequations($ode3) -SUITE["ioequations"]["find_4"] = @benchmarkable find_ioequations($ode4) diff --git a/benchmarking/CI-scripts/Project.toml b/benchmarking/CI-scripts/Project.toml index 2f6685d27..02f62dfcf 100644 --- a/benchmarking/CI-scripts/Project.toml +++ b/benchmarking/CI-scripts/Project.toml @@ -6,3 +6,6 @@ Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a" PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae" TestSetExtensions = "98d24dd4-01ad-11ea-1b02-c9a08f80db04" + +[compat] +PrettyTables = "3" diff --git a/benchmarking/CI-scripts/run_benchmarks.jl b/benchmarking/CI-scripts/run_benchmarks.jl index 3b04b3fae..ed227365f 100644 --- a/benchmarking/CI-scripts/run_benchmarks.jl +++ b/benchmarking/CI-scripts/run_benchmarks.jl @@ -8,8 +8,6 @@ stopwatch = time_ns() # TTFX t1 = @timed using StructuralIdentifiability -include("../benchmarks.jl") - suite = [] push!( @@ -17,12 +15,16 @@ push!( (problem_name = "using StructuralIdentifiability", type = :time, result = [t1.time]), ) +# Record the load time before @ODEmodel introduces model parameters such as t1. +include("../benchmarks.jl") + # Allocations # Coming soon # Runtime import Primes import Nemo +using Logging function nemo_make_prime_finite_field(p) return if p < typemax(UInt) @@ -47,31 +49,37 @@ function perform_operation( times = [] for _ in 1:trials GC.gc() - time = @elapsed fun(ode; kws...) + time = @elapsed fun(ode; loglevel = Logging.Error, kws...) push!(times, time) end return times end fun_name = "assess_identifiability" -perform_operation(benchmarks[:LV_simple][:ode]) -for m in [:SIWR, :LV_simple, :Pharm] +perform_operation(benchmarks[:LV][:ode]) +for (m, trials) in [(:SIWR_orig, 3), (:LV, 30), (:Pharm, 3)] push!( suite, ( problem_name = benchmarks[m][:name] * " " * fun_name, type = :time, - result = perform_operation(benchmarks[m][:ode]), + result = perform_operation( + benchmarks[m][:ode], + StructuralIdentifiability.assess_identifiability, + trials, + ), ), ) end fun_name = "assess_local_identifiability" perform_operation( - benchmarks[:LV_simple][:ode], + benchmarks[:LV][:ode], StructuralIdentifiability.assess_local_identifiability, ) -for m in [:SIWR, :Pharm, :MAPK5, :MAPK5bis, :Goodwin] +for (m, trials) in [ + (:SIWR_orig, 30), (:Pharm, 30), (:MAPK_5out, 3), (:MAPK_5out_bis, 3), (:Goodwin, 30), + ] push!( suite, ( @@ -80,6 +88,7 @@ for m in [:SIWR, :Pharm, :MAPK5, :MAPK5bis, :Goodwin] result = perform_operation( benchmarks[m][:ode], StructuralIdentifiability.assess_local_identifiability, + trials, ), ), ) @@ -87,10 +96,12 @@ end fun_name = "find_identifiable_functions" perform_operation( - benchmarks[:LV_simple][:ode], + benchmarks[:LV][:ode], StructuralIdentifiability.find_identifiable_functions, ) -for m in [:Goodwin, :SEAIJRC, :Sntg, :LLW, :Bilirubin] +for (m, trials) in [ + (:Goodwin, 30), (:SEAIJRC, 3), (:St, 3), (:LLW, 30), (:Bilirubin, 30), + ] push!( suite, ( @@ -99,6 +110,7 @@ for m in [:Goodwin, :SEAIJRC, :Sntg, :LLW, :Bilirubin] result = perform_operation( benchmarks[m][:ode], StructuralIdentifiability.find_identifiable_functions, + trials, ), ), ) @@ -106,10 +118,10 @@ end fun_name = "reparametrize_global" perform_operation( - benchmarks[:LV_simple][:ode], + benchmarks[:LV][:ode], StructuralIdentifiability.reparametrize_global, ) -for m in [:Goodwin, :SEAIJRC, :SEUIR] +for (m, trials) in [(:Goodwin, 30), (:SEAIJRC, 3), (:SEUIR, 30)] push!( suite, ( @@ -118,6 +130,7 @@ for m in [:Goodwin, :SEAIJRC, :SEUIR] result = perform_operation( benchmarks[m][:ode], StructuralIdentifiability.reparametrize_global, + trials, ), ), ) diff --git a/benchmarking/CI-scripts/runtests.jl b/benchmarking/CI-scripts/runtests.jl index fd9f0325c..b91626f39 100644 --- a/benchmarking/CI-scripts/runtests.jl +++ b/benchmarking/CI-scripts/runtests.jl @@ -128,13 +128,11 @@ function compare() master = 1.0e9 .* master nightly = 1.0e9 .* nightly f, unit = best_unit(maximum(master)) - m1 = round(mean(master) / f, digits = 2) - d1 = round(std(master) / f, digits = 2) - label_master = "$m1 ± $d1 $unit" - m2 = round(mean(nightly) / f, digits = 2) - d2 = round(std(nightly) / f, digits = 2) - label_nightly = "$m2 ± $d2 $unit" - indicator = if mean(master) < 1.0e9 * IGNORE_SMALL + m1 = median(master) + label_master = "$(round(m1 / f, digits = 2)) $unit" + m2 = median(nightly) + label_nightly = "$(round(m2 / f, digits = 2)) $unit" + indicator = if m1 < 1.0e9 * IGNORE_SMALL 0, "insignificant" elseif (1 + MAX_DEVIATION) * m1 < m2 fail = true @@ -170,6 +168,8 @@ function post(fail, table) comment_header = """ ## Running times benchmark + Reported times are medians across all measurements. + Note, that these numbers may fluctuate on the CI servers, so take them with a grain of salt. """ @@ -181,7 +181,13 @@ function post(fail, table) println(io, "No regressions detected✅") end table_header = ["Problem", "Master", "This commit", "Result"] - pretty_table(io, table, header = table_header, alignment = [:l, :r, :r, :r]) + pretty_table( + io, table, + column_labels = table_header, + alignment = [:l, :r, :r, :r], + fit_table_in_display_horizontally = false, + fit_table_in_display_vertically = false, + ) comment_str = String(take!(io)) return println(comment_str) end