Skip to content

Commit

Permalink
chore: add Python bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
moldhouse committed Feb 13, 2024
1 parent 77101ee commit a115cf3
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 120 deletions.
120 changes: 120 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# This file is autogenerated by maturin v1.4.0
# To update, run
#
# maturin generate-ci github
#
name: CI

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

windows:
runs-on: windows-latest
strategy:
matrix:
target: [x64, x86]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

macos:
runs-on: macos-latest
strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
76 changes: 73 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,76 @@
/target/
/target

# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
.venv/
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
include/
man/
venv/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
pip-selfcheck.json

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

.DS_Store

# Sphinx documentation
docs/_build/

# PyCharm
.idea/

# VSCode
.vscode/

# Pyenv
.python-version

**/*.rs.bk
Cargo.lock
.criterion
.vscode/
.DS_Store
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
[package]
edition = "2021"
name = "score-rs"
version = "0.0.0"
name = "score_rs"
version = "0.0.1"
authors = ["Moritz Althaus <[email protected]>"]
license = "MIT"
repository = "https://github.com/moldhouse/score-rs.git"
homepage = "https://github.com/moldhouse/score-rs.git"
readme = "README.md"

[lib]
name = "score_rs"
crate-type = ["cdylib"]

[features]
default = ["rayon"]

[dependencies]
pyo3 = "0.20.0"
cfg-if = "1.0.0"
failure = "^0.1.1"
flat_projection = "0.4.0"
Expand All @@ -20,13 +25,9 @@ ordered-float = "2.0.1"
ord_subset = "^3.1.0"
rayon = { version = "^1.0", optional = true }
itertools = "0.10.0"
numpy = "0.20.0"

[dev-dependencies]
assert_approx_eq = "^1.0.0"
criterion = "^0.3.0"
igc = "0.2.2"
env_logger = "0.8.2"

[[bench]]
name = "free"
harness = false
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# score-rs

Find the seven GPS points of a single flight whose straight connection gives the maximum total distance.
Find `n` points out of a set of possible tens of thousands of GPS points, such that the straight distance between them is maximized.
There is one constraint: The finish altitude must not be more than 1000 m less than the start altitude.

The algorithm does the same optimization that [WeGlide](https://www.weglide.org) does to assign a distance to every flight:
Expand All @@ -17,14 +17,38 @@ The code is based on the excellent [aeroscore-rs](https://github.com/glide-rs/ae
2. If the 1000 m altitude is satisfied by the best result, the optimization is similar. If not, this library uses a caching system to quickly determine if start candidates can give a better solution than the current best without traversing the whole graph.
3. Also look for potential solutions by adjusting the start- and end points of a given solution and keeping the middle points constant. This is not used to find the actual solution (as it does not guarantee optimality), but it speeds up the optimization by helping to find better intermediate results and discard candidates that do not offer a better solution

## Test
## Develop

Python bindings are generated with [maturin](https://github.com/PyO3/maturin/). Create a virtual env first with

```bash
cargo test
python -m venv ./env && source .env/bin/activate
```

## Bench
and install numpy in your virtual env:

```bash
cargo bench
pip install numpy
```

To develop, run

```bash
maturin develop
```

or for a (faster) release version

```bash
maturin build --release
pip install .
```

## Test

You can run the tests with

```bash
cargo test
python -m pytest
```
51 changes: 0 additions & 51 deletions benches/free.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[build-system]
requires = ["maturin>=1.4,<2.0"]
build-backend = "maturin"

[project]
name = "score-rs"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]

[tool.maturin]
features = ["pyo3/extension-module"]
Loading

0 comments on commit a115cf3

Please sign in to comment.