Skip to content

Commit

Permalink
perf: add visibility benchmark and codspeed integration
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Nov 19, 2024
1 parent 2677b24 commit 982c92a
Show file tree
Hide file tree
Showing 7 changed files with 2,062 additions and 3 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CodSpeed

on:
push:
branches:
- main # Run on pushes to the main branch
pull_request: # Run on all pull requests

jobs:
codspeed:
name: Run benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Generate virtual environment
run: python -m venv .venv
- name: Build Python wrapper
uses: PyO3/maturin-action@v1
with:
command: develop
args: --release --extras dev -m crates/lox-space/Cargo.toml
- uses: CodSpeedHQ/action@v3
with:
run: |
. .venv/bin/activate
pytest crates/lox-space/tests/ --codspeed
token: ${{ secrets.CODSPEED_TOKEN }} # Optional for public repositories
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
install: |
apt-get update
apt-get install -y --no-install-recommends python3 python3-pip
pip3 install -U pip pytest
pip3 install -U pip pytest pytest-codspeed
run: |
set -e
pip3 install lox-space --find-links dist --force-reinstall
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:
environment: release
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
needs: [linux, windows, macos, sdist]
needs: [ linux, windows, macos, sdist ]
permissions:
# Use to sign the release artifacts
id-token: write
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.DS_Store
flamegraph.svg
.mise.local.toml
.codspeed/
1 change: 1 addition & 0 deletions crates/lox-space/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dev = [
"ipython",
"numpy",
"pytest",
"pytest-codspeed",
]

[build-system]
Expand Down
39 changes: 38 additions & 1 deletion crates/lox-space/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,50 @@
# file, you can obtain one at https://mozilla.org/MPL/2.0/.

import pathlib
import numpy as np

import pytest
import lox_space as lox

DATA_DIR = pathlib.Path(__file__).parents[3].joinpath("data")


@pytest.fixture
@pytest.fixture(scope="session")
def provider():
return lox.UT1Provider(str(DATA_DIR.joinpath("finals2000A.all.csv")))


@pytest.fixture(scope="session")
def oneweb():
with open(DATA_DIR.joinpath("oneweb_tle.txt")) as f:
lines = f.readlines()

t0 = lox.SGP4("".join(lines[0:3])).time()
times = [t0 + t for t in lox.TimeDelta.range(0, 86400, 60)]

trajectories = []
for i in range(0, len(lines), 3):
tle = lines[i : i + 3]
name = tle[0].strip()
trajectory = lox.SGP4("".join(tle)).propagate(times)
trajectories.append((name, trajectory))

return dict(trajectories)


@pytest.fixture(scope="session")
def estrack():
stations = [
("Kiruna", 67.858428, 20.966880),
("Esrange Space Center", 67.8833, 21.1833),
("Kourou", 5.2360, -52.7686),
("Redu", 50.00205516, 5.14518047),
("Cebreros", 40.3726, -4.4739),
("New Norcia", -30.9855, 116.2041),
]
return {
name: lox.GroundLocation(
lox.Planet("Earth"), np.radians(lon), np.radians(lat), 0
)
for name, lat, lon in stations
}
36 changes: 36 additions & 0 deletions crates/lox-space/tests/test_benchmarks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2024. Helge Eichhorn and the LOX contributors
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at https://mozilla.org/MPL/2.0/.

import itertools
import pytest

import lox_space as lox


@pytest.mark.benchmark()
def test_visibility_benchmark(provider, oneweb, estrack):
mask = lox.ElevationMask.fixed(0)
t0 = next(iter(oneweb.values())).states()[0].time()
times = [t0 + t for t in lox.TimeDelta.range(0, 86400, 3000)]

passes = {}

for (gs_name, gs), (sc_name, sc) in filter(
lambda pair: isinstance(pair[0][1], lox.GroundLocation)
and isinstance(pair[1][1], lox.Trajectory),
itertools.combinations(itertools.chain(estrack.items(), oneweb.items()), 2),
):
assert isinstance(gs, lox.GroundLocation)
assert isinstance(sc, lox.Trajectory)

if not sc_name in passes:
passes[sc_name] = {}

passes[sc_name][gs_name] = lox.visibility(times, gs, mask, sc, provider)

assert len(passes) == len(oneweb)
for sc_passes in passes.values():
assert len(sc_passes) == len(estrack)
Loading

0 comments on commit 982c92a

Please sign in to comment.