Skip to content
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

Rust Integration: Perform Max Flow in Rust instead of Python #1

Merged
merged 43 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e85d6f8
set up PR for naive implementation that copies each iteration
ohjuny Oct 18, 2024
9bd30b8
set up py03 directories
ohjuny Oct 18, 2024
5af0b31
add rust dependencies
ohjuny Oct 18, 2024
67979ae
add networkx dependency for testing
ohjuny Oct 18, 2024
e4f9b3f
rust-side PhillipsDessouky
ohjuny Oct 18, 2024
743336f
python-side profiling code
ohjuny Oct 18, 2024
43f0832
integrate rust-side library with python solver
ohjuny Oct 18, 2024
4048d9f
black formatting
ohjuny Oct 18, 2024
463dd20
remove unnecessary dependency
ohjuny Oct 18, 2024
5a7d108
factor out rust interop pre/post-processing
ohjuny Oct 18, 2024
3e07341
replace second max_flow call with rust
ohjuny Oct 18, 2024
556940a
black formatting
ohjuny Oct 18, 2024
9041daf
readd commented old max flow code for potential future where we provi…
ohjuny Oct 18, 2024
4acad7b
fix refactoring, need to double check with run
ohjuny Oct 19, 2024
af5897c
comment second max flow (issue with replacing second, will find out)
ohjuny Oct 19, 2024
cd5c40e
remove rust-side commented i64 code
ohjuny Oct 19, 2024
45dabdb
rust-side cleanup
ohjuny Oct 19, 2024
93a1a78
implement 2nd max flow + attempt pimpl for rust-side. note that using…
ohjuny Nov 5, 2024
1f37443
remove unused pimpl implementation
ohjuny Nov 5, 2024
dbb90d9
fix lint errors + rust comments
ohjuny Nov 5, 2024
2c5c5bc
rename lowtime_rust to lowtime_rs
ohjuny Nov 5, 2024
7b14211
figuring out how to package rust/pyo3 module within python distribution
ohjuny Nov 5, 2024
87a204a
restructure as single package using maturin
ohjuny Nov 5, 2024
10cc0c7
fix nodeview type annotations
ohjuny Nov 5, 2024
8ae5b7b
pyi for pyo3 python module
ohjuny Nov 7, 2024
54e97f3
py.typed for pyright check
ohjuny Nov 7, 2024
a4bb48d
fix pyi for _lowtime_rs
ohjuny Nov 7, 2024
e4aff75
fix type hint
ohjuny Nov 7, 2024
b4a814c
remove unnecessary comment
ohjuny Nov 7, 2024
f945bff
refactor class impl out of lib
ohjuny Nov 7, 2024
61c7fcd
remove unnecessary pyo3 getters
ohjuny Nov 7, 2024
18031b7
Update pyproject.toml
ohjuny Nov 7, 2024
061f054
remove version in cargo.toml
ohjuny Nov 7, 2024
92656ff
fix + reformat pyi
ohjuny Nov 7, 2024
8f421b6
add author ohjun
ohjuny Nov 7, 2024
7d6fb08
black formatting for pyio
ohjuny Nov 8, 2024
85ffca7
Update src/phillips_dessouky.rs
ohjuny Nov 8, 2024
cb7e66f
Update src/phillips_dessouky.rs
ohjuny Nov 8, 2024
5a98d92
remove unused Duration
ohjuny Nov 8, 2024
376f17f
Update src/phillips_dessouky.rs
ohjuny Nov 8, 2024
e22c3b0
remove nested gitignore + hardcode version in configs
ohjuny Nov 8, 2024
642d4a9
rename conflicting ci
ohjuny Nov 8, 2024
9c509a6
rename generated maturin ci yaml
ohjuny Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions .github/workflows/maturin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# This file is autogenerated by maturin v1.7.4
# 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: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

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

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

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

release:
name: Release
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
needs: [linux, musllinux, windows, macos, sdist]
permissions:
# Use to sign the release artifacts
id-token: write
# Used to upload release artifacts
contents: write
# Used to generate artifact attestation
attestations: write
steps:
- uses: actions/download-artifact@v4
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-path: 'wheels-*/*'
- name: Publish to PyPI
if: "startsWith(github.ref, 'refs/tags/')"
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push

jobs:
ci:
style-lint-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
79 changes: 76 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,82 @@
.envrc
.env
.test
temp*
results
figures
dist
workloads*
*.egg-info
**/__pycache__
**/*.png
Cargo.lock

/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
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "_lowtime_rs"
version = "0.2.0" # keep synced with __init__.py, pyproject.toml
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "_lowtime_rs"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.22.0"
pyo3-log = "0.11.0"
log = "0.4"
ordered-float = { version = "4.0", default-features = false }
pathfinding = "4.11.0"
2 changes: 1 addition & 1 deletion lowtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

"""A library for solving the time-cost tradeoff problem."""

__version__ = "0.2.0"
__version__ = "0.2.0" # keep synced with pyproject.toml, Cargo.toml
13 changes: 13 additions & 0 deletions lowtime/_lowtime_rs.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations

import networkx as nx

class PhillipsDessouky:
def __init__(
self,
node_ids: list[int] | nx.classes.reportviews.NodeView,
source_node_id: int,
sink_node_id: int,
edges_raw: list[tuple[tuple[int, int], float]],
) -> None: ...
def max_flow(self) -> list[tuple[tuple[int, int], float]]: ...
ohjuny marked this conversation as resolved.
Show resolved Hide resolved
Empty file added lowtime/py.typed
Empty file.
Loading
Loading