-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic benchmarking on pull requests #468
Draft
MilesCranmer
wants to merge
4
commits into
QuantumBFS:master
Choose a base branch
from
MilesCranmer:auto-bench
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Benchmark a pull request | ||
|
||
on: | ||
pull_request_target: | ||
branches: | ||
- master | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
jobs: | ||
generate_plots: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: julia-actions/setup-julia@v1 | ||
with: | ||
version: "1.8" | ||
- uses: julia-actions/cache@v1 | ||
- name: Extract Package Name from Project.toml | ||
id: extract-package-name | ||
run: | | ||
PACKAGE_NAME=$(grep "^name" Project.toml | sed 's/^name = "\(.*\)"$/\1/') | ||
echo "::set-output name=package_name::$PACKAGE_NAME" | ||
- name: Build AirspeedVelocity | ||
env: | ||
JULIA_NUM_THREADS: 2 | ||
run: | | ||
# Lightweight build step, as sometimes the runner runs out of memory: | ||
julia -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; import Pkg; Pkg.add(;url="https://github.com/MilesCranmer/AirspeedVelocity.jl.git")' | ||
julia -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; import Pkg; Pkg.build("AirspeedVelocity")' | ||
- name: Add ~/.julia/bin to PATH | ||
run: | | ||
echo "$HOME/.julia/bin" >> $GITHUB_PATH | ||
- name: Run benchmarks | ||
run: | | ||
echo $PATH | ||
ls -l ~/.julia/bin | ||
mkdir results | ||
benchpkg ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --url=${{ github.event.repository.clone_url }} --bench-on="${{github.event.pull_request.head.sha}}" --output-dir=results/ --tune | ||
- name: Create plots from benchmarks | ||
run: | | ||
mkdir -p plots | ||
benchpkgplot ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --npart=10 --format=png --input-dir=results/ --output-dir=plots/ | ||
- name: Upload plot as artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: plots | ||
path: plots | ||
- name: Create markdown table from benchmarks | ||
run: | | ||
benchpkgtable ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --input-dir=results/ --ratio > table.md | ||
echo '### Benchmark Results' > body.md | ||
echo '' >> body.md | ||
echo '' >> body.md | ||
cat table.md >> body.md | ||
echo '' >> body.md | ||
echo '' >> body.md | ||
echo '### Benchmark Plots' >> body.md | ||
echo 'A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.' >> body.md | ||
echo 'Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).' >> body.md | ||
|
||
- name: Find Comment | ||
uses: peter-evans/find-comment@v2 | ||
id: fcbenchmark | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: Benchmark Results | ||
|
||
- name: Comment on PR | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
comment-id: ${{ steps.fcbenchmark.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body-path: body.md | ||
edit-mode: replace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[deps] | ||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" | ||
BitBasis = "50ba71b6-fa0f-514d-ae9a-0916efc90dcf" | ||
LuxurySparse = "d05aeea4-b7d4-55ac-b691-9e7fabb07ba2" | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d" | ||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module BenchmarkUtils | ||
""" | ||
Replace instances of, for example, `using YaoAPI` with `using Yao.YaoAPI`. | ||
""" | ||
const libs = (:YaoAPI, :YaoArrayRegister, :YaoBlocks, :YaoSym) | ||
function replace_imports(ex) | ||
return _replace_imports(ex) | ||
end | ||
function _replace_imports(ex) | ||
if isa(ex, Expr) && ex.head == :using | ||
foreach(ex.args) do e | ||
if isa(e, Expr) && first(e.args) in libs | ||
pushfirst!(e.args, :Yao) | ||
end | ||
end | ||
elseif isa(ex, Expr) | ||
map!(_replace_imports, ex.args, ex.args) | ||
end | ||
return ex | ||
end | ||
end | ||
|
||
module YaoArrayRegisterBenchmarks | ||
using ..BenchmarkUtils: replace_imports | ||
using Yao | ||
using Yao.YaoBlocks: sprand_hermitian | ||
include(replace_imports, "../lib/YaoArrayRegister/benchmark/benchmarks.jl") | ||
end | ||
|
||
module YaoBlocksBenchmarks | ||
using ..BenchmarkUtils: replace_imports | ||
using Yao | ||
include(replace_imports, "../lib/YaoBlocks/benchmark/benchmarks.jl") | ||
end | ||
|
||
using BenchmarkTools | ||
import .YaoArrayRegisterBenchmarks: SUITE as yarSUITE | ||
import .YaoBlocksBenchmarks: SUITE as ybSUITE | ||
|
||
const SUITE = BenchmarkGroup() | ||
SUITE["YaoArrayRegister"] = yarSUITE | ||
SUITE["YaoBlocks"] = ybSUITE |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This line can probably be deleted once the benchmark is fixed)