Skip to content

Commit 906fb8f

Browse files
authored
build: implement performance tracking workflow (#443)
1 parent b507a32 commit 906fb8f

File tree

9 files changed

+219
-41
lines changed

9 files changed

+219
-41
lines changed

.github/workflows/Benchmarks.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Benchmark Tracking
2+
on:
3+
push:
4+
branches:
5+
- 'master'
6+
paths:
7+
- '.github/workflows/Benchmarks.yml'
8+
- 'src/**'
9+
- 'ext/**'
10+
- 'test/runtests.jl'
11+
- 'test/core-test/**'
12+
- 'test/ext-test/cpu/**'
13+
- 'Project.toml'
14+
pull_request:
15+
branches:
16+
- 'master'
17+
paths:
18+
- '.github/workflows/Benchmarks.yml'
19+
- 'src/**'
20+
- 'ext/**'
21+
- 'test/**'
22+
- 'Project.toml'
23+
types:
24+
- opened
25+
- reopened
26+
- synchronize
27+
- ready_for_review
28+
workflow_dispatch:
29+
30+
permissions:
31+
actions: write
32+
contents: write
33+
deployments: write
34+
35+
jobs:
36+
benchmark:
37+
runs-on: ubuntu-latest
38+
if: ${{ !github.event.pull_request.draft }}
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: julia-actions/setup-julia@v2
42+
with:
43+
version: '1'
44+
arch: x64
45+
- uses: julia-actions/cache@v2
46+
- name: Run benchmark
47+
run: |
48+
cd benchmarks
49+
julia --project --threads=2 --color=yes -e '
50+
using Pkg;
51+
Pkg.develop(PackageSpec(path=joinpath(pwd(), "..")));
52+
Pkg.instantiate();
53+
include("runbenchmarks.jl")'
54+
55+
# this will update benchmarks/data.js in gh-pages branch
56+
- name: Parse & Upload Benchmark Results
57+
uses: benchmark-action/github-action-benchmark@v1
58+
with:
59+
name: Benchmark Results
60+
tool: "julia"
61+
output-file-path: benchmarks/benchmarks_output.json
62+
github-token: ${{ secrets.GITHUB_TOKEN }}
63+
alert-threshold: "130%"
64+
fail-threshold: "170%"
65+
comment-on-alert: true
66+
fail-on-alert: true
67+
benchmark-data-dir-path: benchmarks
68+
max-items-in-chart: 100
69+
auto-push: ${{ github.event_name != 'pull_request' }}

.github/workflows/downgrade.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

benchmarks/KPO.jl

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using HarmonicBalance, HarmonicSteadyState
2+
using HarmonicSteadyState: HomotopyContinuationProblem, OrderedDict
3+
using HarmonicSteadyState: sort_solutions, _classify_default!
4+
5+
function benchmark_kpo!(SUITE)
6+
@variables ω₀ γ λ F η α ω t x(t)
7+
8+
natural_equation =
9+
d(d(x, t), t) +
10+
γ * d(x, t) +
11+
(ω₀^2 - λ * cos(2 * ω * t)) * x +
12+
α * x^3 +
13+
η * d(x, t) * x^2
14+
forces = F * cos* t)
15+
diff_eq = DifferentialEquation(natural_equation + forces, x)
16+
add_harmonic!(diff_eq, x, ω)
17+
18+
harmonic_eq = get_harmonic_equations(diff_eq)
19+
20+
SUITE["Construction"]["Harmonic Equation"]["One Frequency"] = @benchmarkable begin
21+
get_harmonic_equations($diff_eq)
22+
end seconds = 10
23+
24+
krylov_eq = get_krylov_equations(diff_eq; order=1)
25+
krylov_eq2 = get_krylov_equations(diff_eq; order=2)
26+
27+
SUITE["Construction"]["Krylov Equation"]["Order 1"] = @benchmarkable begin
28+
get_krylov_equations($diff_eq; order=1)
29+
end seconds = 10
30+
SUITE["Construction"]["Krylov Equation"]["Order 2"] = @benchmarkable begin
31+
get_krylov_equations($diff_eq; order=2)
32+
end seconds = 10
33+
34+
fixed = OrderedDict(ω₀ => 1.0, γ => 1e-2, λ => 5e-2, F => 1e-3, α => 1.0, η => 0.3)
35+
varied = OrderedDict=> range(0.9, 1.1, 100))
36+
37+
problem = HomotopyContinuationProblem(harmonic_eq, varied, fixed)
38+
SUITE["Construction"]["Problem"]["HomotopyContinuationProblem"] = @benchmarkable begin
39+
HomotopyContinuationProblem($harmonic_eq, $varied, $fixed)
40+
end seconds = 10
41+
42+
show_progress = false
43+
sorting = "no_sorting"
44+
classify_default = false
45+
46+
method = WarmUp(; thread=false)
47+
result = get_steady_states(problem, method; show_progress, sorting, classify_default)
48+
49+
SUITE["Steady states"]["Homotopy Problem"]["Warm up method"] = @benchmarkable begin
50+
get_steady_states(
51+
$problem,
52+
$method;
53+
show_progress=false,
54+
sorting="no_sorting",
55+
classify_default=false,
56+
)
57+
end seconds = 10
58+
59+
method = TotalDegree(; thread=false)
60+
result = get_steady_states(problem, method; show_progress, sorting, classify_default)
61+
62+
SUITE["Steady states"]["Homotopy Problem"]["Total degree homotopy"] = @benchmarkable begin
63+
get_steady_states(
64+
$problem,
65+
$method;
66+
show_progress=false,
67+
sorting="no_sorting",
68+
classify_default=false,
69+
)
70+
end seconds = 10
71+
72+
method = Polyhedral(; thread=false)
73+
result = get_steady_states(problem, method; show_progress, sorting, classify_default)
74+
75+
SUITE["Steady states"]["Homotopy Problem"]["Polyhedral homotopy"] = @benchmarkable begin
76+
get_steady_states(
77+
$problem,
78+
$method;
79+
show_progress=false,
80+
sorting="no_sorting",
81+
classify_default=false,
82+
)
83+
end seconds = 10
84+
85+
solutions_not_sorted = result.solutions
86+
sort_solutions(solutions_not_sorted; sorting="nearest", show_progress=false)
87+
sort_solutions(solutions_not_sorted; sorting="hilbert", show_progress=false)
88+
89+
SUITE["Sorting"]["One dimensional"]["Nearest-neighbor sorting"] = @benchmarkable begin
90+
sort_solutions($solutions_not_sorted; show_progress=false, sorting="nearest")
91+
end seconds = 10
92+
93+
SUITE["Sorting"]["One dimensional"]["Hilbert sorting"] = @benchmarkable begin
94+
sort_solutions($solutions_not_sorted; show_progress=false, sorting="hilbert")
95+
end seconds = 10
96+
97+
_classify_default!(deepcopy(result))
98+
SUITE["Classification"]["One Dimensional"]["Default classifications"] = @benchmarkable begin
99+
_classify_default!(x)
100+
end setup = (x = deepcopy($result)) evals = 1 seconds = 10
101+
102+
method = WarmUp(; thread=false)
103+
result = get_steady_states(problem, method; show_progress)
104+
105+
Ω_range = range(0.95, 1.05, 100)
106+
get_jacobian_response(result, x, Ω_range, 3; show_progress=false)
107+
get_rotframe_jacobian_response(result, Ω_range, 3; show_progress=false, damping_mod=1.0)
108+
109+
SUITE["Linear response"]["Lab frame"]["Jacobian Response"] = @benchmarkable begin
110+
get_jacobian_response($result, $x, $(Ω_range), 3; show_progress=false)
111+
end seconds = 10
112+
113+
SUITE["Linear response"]["Rotating frame"]["Jacobian Response"] = @benchmarkable begin
114+
get_rotframe_jacobian_response(
115+
$result, $(Ω_range), 3; show_progress=false, damping_mod=1.0
116+
)
117+
end seconds = 10
118+
119+
return nothing
120+
end

benchmarks/Project.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[deps]
2+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
4+
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
5+
HarmonicBalance = "e13b9ff6-59c3-11ec-14b1-f3d2cc6c135e"
6+
HarmonicSteadyState = "1158f75c-a779-4b85-8bfb-8fcf6bf02ced"
7+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
8+
OrdinaryDiffEqRosenbrock = "43230ef6-c299-4910-a778-202eb28ce4ce"
9+
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
10+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
11+
QuantumCumulants = "35bcea6d-e19f-57db-af74-8011de6c7255"
12+
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
13+
14+
[compat]
15+
Documenter = "1"
16+
julia = "1.10"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

benchmarks/runbenchmarks.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using BenchmarkTools
2+
using HarmonicBalance, HarmonicSteadyState, QuantumCumulants
3+
4+
const SUITE = BenchmarkGroup()
5+
6+
include("KPO.jl")
7+
8+
benchmark_kpo!(SUITE)
9+
10+
BenchmarkTools.tune!(SUITE)
11+
results = BenchmarkTools.run(SUITE; verbose=true)
12+
display(median(results))
13+
14+
BenchmarkTools.save("benchmarks_output.json", median(results))

0 commit comments

Comments
 (0)