-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add benchmarks for interpolated images (#100)
* test: add benchmarks for interpolated images * fix: blacken * ci: add codspeed config * fix: add pytest-codspeed to the setup.py * test: need to list the dep here * ci: bump the CI for codspeed * doc: add codspeed badge * test: make sure to block until ready so that benchmarks work on devices * fix: block at proper part of code for benchmarks
- Loading branch information
Showing
5 changed files
with
83 additions
and
3 deletions.
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,45 @@ | ||
name: benchmarks | ||
|
||
env: | ||
PY_COLORS: "1" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: null | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.11",] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install pytest pytest-codspeed | ||
python -m pip install . | ||
- name: Run benchmarks | ||
uses: CodSpeedHQ/action@v2 | ||
with: | ||
token: ${{ secrets.CODSPEED_TOKEN }} | ||
run: | | ||
git submodule update --init --recursive | ||
pytest -vvs --codspeed |
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
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
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
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,35 @@ | ||
import jax | ||
|
||
import jax_galsim as jgs | ||
|
||
|
||
def test_benchmarks_interpolated_image_jit_compile(benchmark): | ||
gal = jgs.Gaussian(fwhm=1.2) | ||
im_gal = gal.drawImage(nx=32, ny=32, scale=0.2) | ||
igal = jgs.InterpolatedImage( | ||
im_gal, gsparams=jgs.GSParams(minimum_fft_size=128, maximum_fft_size=128) | ||
) | ||
|
||
def f(): | ||
return igal.drawImage(nx=32, ny=32, scale=0.2) | ||
|
||
benchmark(lambda: jax.jit(f)().array.block_until_ready()) | ||
|
||
|
||
def test_benchmarks_interpolated_image_jit_run(benchmark): | ||
gal = jgs.Gaussian(fwhm=1.2) | ||
im_gal = gal.drawImage(nx=32, ny=32, scale=0.2) | ||
igal = jgs.InterpolatedImage( | ||
im_gal, gsparams=jgs.GSParams(minimum_fft_size=128, maximum_fft_size=128) | ||
) | ||
|
||
def f(): | ||
return igal.drawImage(nx=32, ny=32, scale=0.2) | ||
|
||
jitf = jax.jit(f) | ||
|
||
# run once to compile | ||
jitf().array.block_until_ready() | ||
|
||
# now benchmark | ||
benchmark(lambda: jitf().array.block_until_ready()) |