Skip to content

Commit e773bce

Browse files
filchristougdalle
andauthored
Bringing the .github/workflows/postbench.yml to master (#350)
* First try on benchmark CI (#315) (WIP) TODO: store results and PR label triggering * Test consecutive PR (#346) Merge all new advancements on the `benchx` branch in order to do a follow up consecutive PR to test github actions * Trivial change, test PR (#347) * Trivial change, test PR * Add PR write permission * Test full permissions * Granular permissions * try write-all * try label event * labeled in pull_request * Store results as artifact and trigger a consecutive workflow_run * Workflow chain almost complete (WIP) * correct .benchmarkci path * Add benchx support branch * Just try pull_request_target instead * Remove target * Get rid of s to get the chain going --------- Co-authored-by: Guillaume Dalle <[email protected]> * Simplify for master merge * Fixed formatting * Integrate review comments --------- Co-authored-by: Guillaume Dalle <[email protected]>
1 parent d1081b0 commit e773bce

18 files changed

+914
-165
lines changed

.github/workflows/postbench.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: PostBenchmarks
2+
on:
3+
workflow_run:
4+
workflows: [RunUploadBenchmarks]
5+
types: [completed]
6+
branches: [master, benchx]
7+
jobs:
8+
on-success:
9+
runs-on: ubuntu-latest
10+
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
11+
steps:
12+
- run: echo 'The triggering workflow passed'
13+
- name: 'Download artifact'
14+
uses: actions/github-script@v6
15+
with:
16+
script: |
17+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
run_id: context.payload.workflow_run.id,
21+
});
22+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
23+
return artifact.name == "BenchmarkResults"
24+
})[0];
25+
let download = await github.rest.actions.downloadArtifact({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
artifact_id: matchArtifact.id,
29+
archive_format: 'zip',
30+
});
31+
let fs = require('fs');
32+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/BenchmarkResults.zip`, Buffer.from(download.data));
33+
34+
- name: 'Unzip artifact'
35+
run: unzip BenchmarkResults.zip -d .benchmarkci/
36+
- name: 'Post results test 1'
37+
run: julia -e 'using BenchmarkCI; BenchmarkCI.postjudge()'
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
- name: 'Comment on PR test 2'
41+
uses: actions/github-script@v6
42+
with:
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
script: |
45+
let fs = require('fs');
46+
let issue_number = Number(fs.readFileSync('./pr_number'));
47+
await github.rest.issues.createComment({
48+
owner: context.repo.owner,
49+
repo: context.repo.repo,
50+
issue_number: issue_number,
51+
body: 'Thank you for the PR!'
52+
});
53+
- name: 'Comment on PR test 3'
54+
run: gh pr comment "$NUMBER" --body "$BODY"
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
GH_REPO: ${{ github.repository }}
58+
NUMBER: ${{ github.event.pull_request.number }}
59+
BODY: >
60+
This pr comment is testing.
61+
**This should be bold**
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: RunUploadBenchmarks
2+
env:
3+
JULIA_NUM_THREADS: auto
4+
on:
5+
pull_request:
6+
types: [labeled]
7+
branches:
8+
- master
9+
- benchx
10+
jobs:
11+
benchmark:
12+
if: ${{ github.event.label.name == 'to-benchmark' }}
13+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
14+
runs-on: ${{ matrix.os }}
15+
continue-on-error: ${{ matrix.allow_failure }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
version:
20+
- '1'
21+
os:
22+
- ubuntu-latest
23+
arch:
24+
- x64
25+
include:
26+
- version: '1'
27+
allow_failure: false
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: julia-actions/setup-julia@latest
31+
with:
32+
version: ${{ matrix.version }}
33+
arch: ${{ matrix.arch }}
34+
- uses: actions/cache@v3
35+
env:
36+
cache-name: cache-artifacts
37+
with:
38+
path: ~/.julia/artifacts
39+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
40+
restore-keys: |
41+
${{ runner.os }}-test-${{ env.cache-name }}-
42+
${{ runner.os }}-test-
43+
${{ runner.os }}-
44+
- uses: julia-actions/julia-buildpkg@latest
45+
- name: install dependencies
46+
run: julia -e 'using Pkg; pkg"add PkgBenchmark [email protected]"'
47+
- name: Run benchmark judge
48+
run: julia -e "
49+
using BenchmarkCI, PkgBenchmark;
50+
jd=BenchmarkCI.judge(baseline=\"origin/${GITHUB_BASE_REF}\");
51+
"
52+
- name: Save PR number
53+
env:
54+
PR_NUMBER: ${{ github.event.pull_request.number }}
55+
run: |
56+
echo $PR_NUMBER > .benchmarkci/pr_number
57+
- uses: actions/upload-artifact@v3
58+
with:
59+
name: BenchmarkResults
60+
path: .benchmarkci/
61+

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ docs/build/
66
docs/site/
77
benchmark/.results/*
88
benchmark/.tune.jld
9+
benchmark/Manifest.toml
10+
.benchmarkci
911
*.cov
1012
/Manifest.toml
1113
/docs/Manifest.toml

benchmark/Project.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[deps]
2+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
4+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
5+
6+
[compat]
7+
BenchmarkTools = "1.5"

benchmark/benchmarks.jl

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1-
using BenchmarkTools
2-
using Graphs
1+
using BenchmarkTools, Graphs
32

4-
DIGRAPHS = Dict{String,DiGraph}(
3+
const BENCHDIR = dirname(@__FILE__)
4+
5+
const DIGRAPHS = Dict{String,DiGraph}(
56
"complete100" => complete_digraph(100), "path500" => path_digraph(500)
67
)
78

8-
GRAPHS = Dict{String,Graph}(
9+
const GRAPHS = Dict{String,Graph}(
910
"complete100" => complete_graph(100),
1011
"tutte" => smallgraph(:tutte),
1112
"path500" => path_graph(500),
1213
)
1314

14-
suite = BenchmarkGroup()
15-
include("core.jl")
15+
serialbenchmarks = [
16+
"serial/core.jl",
17+
"serial/connectivity.jl",
18+
"serial/centrality.jl",
19+
"serial/edges.jl",
20+
"serial/insertions.jl",
21+
"serial/traversals.jl",
22+
]
23+
24+
const SUITE = BenchmarkGroup()
25+
26+
foreach(serialbenchmarks) do bm
27+
include(bm)
28+
end
29+
30+
parallelbenchmarks = ["parallel/egonets.jl"]
1631

17-
tune!(suite);
18-
results = run(suite; verbose=true, seconds=10)
32+
foreach(parallelbenchmarks) do bm
33+
include(joinpath(BENCHDIR, bm))
34+
end

benchmark/centrality.jl

-26
This file was deleted.

benchmark/connectivity.jl

-14
This file was deleted.

benchmark/core.jl

-39
This file was deleted.

benchmark/insertions.jl

-4
This file was deleted.

benchmark/parallel/egonets.jl

+46-51
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,57 @@
11
using Graphs
22
using BenchmarkTools
3-
@show Threads.nthreads()
4-
5-
@benchgroup "parallel" begin
6-
@benchgroup "egonet" begin
7-
function vertex_function(g::Graph, i::Int)
8-
a = 0
9-
for u in neighbors(g, i)
10-
a += degree(g, u)
11-
end
12-
return a
13-
end
14-
15-
function twohop(g::Graph, i::Int)
16-
a = 0
17-
for u in neighbors(g, i)
18-
for v in neighbors(g, u)
19-
a += degree(g, v)
20-
end
21-
end
22-
return a
23-
end
243

25-
function mapvertices(f, g::Graph)
26-
n = nv(g)
27-
a = zeros(Int, n)
28-
Threads.@threads for i in 1:n
29-
a[i] = f(g, i)
30-
end
31-
return a
32-
end
4+
SUITE["parallel"] = BenchmarkGroup([], "egonet" => BenchmarkGroup([]))
335

34-
function mapvertices_single(f, g)
35-
n = nv(g)
36-
a = zeros(Int, n)
37-
for i in 1:n
38-
a[i] = f(g, i)
39-
end
40-
return a
41-
end
6+
SUITE["serial"] = BenchmarkGroup([], "egonet" => BenchmarkGroup([]))
427

43-
function comparison(f, g)
44-
println("Mulithreaded on $(Threads.nthreads())")
45-
b1 = @benchmarkable mapvertices($f, $g)
46-
println(b1)
8+
function vertex_function(g::Graph, i::Int)
9+
a = 0
10+
for u in neighbors(g, i)
11+
a += degree(g, u)
12+
end
13+
return a
14+
end
4715

48-
println("singlethreaded")
49-
b2 = @benchmarkable mapvertices_single($f, $g)
50-
println(b2)
51-
return println("done")
16+
function twohop(g::Graph, i::Int)
17+
a = 0
18+
for u in neighbors(g, i)
19+
for v in neighbors(g, u)
20+
a += degree(g, v)
5221
end
22+
end
23+
return a
24+
end
5325

54-
nv_ = 10000
55-
g = SimpleGraph(nv_, 64 * nv_)
56-
f = vertex_function
57-
println(g)
26+
function mapvertices(f, g::Graph)
27+
n = nv(g)
28+
a = zeros(Int, n)
29+
Threads.@threads for i in 1:n
30+
a[i] = f(g, i)
31+
end
32+
return a
33+
end
5834

59-
comparison(vertex_function, g)
60-
comparison(twohop, g)
35+
function mapvertices_single(f, g)
36+
n = nv(g)
37+
a = zeros(Int, n)
38+
for i in 1:n
39+
a[i] = f(g, i)
6140
end
41+
return a
42+
end
43+
44+
let
45+
nv_ = 10000
46+
g = SimpleGraph(nv_, 64 * nv_)
47+
48+
SUITE["parallel"]["egonet"]["vertexfunction"] = @benchmarkable mapvertices(
49+
$vertex_function, $g
50+
)
51+
SUITE["parallel"]["egonet"]["twohop"] = @benchmarkable mapvertices($twohop, $g)
52+
53+
SUITE["serial"]["egonet"]["vertexfunction"] = @benchmarkable mapvertices_single(
54+
$vertex_function, $g
55+
)
56+
SUITE["serial"]["egonet"]["twohop"] = @benchmarkable mapvertices_single($twohop, $g)
6257
end

0 commit comments

Comments
 (0)