Skip to content

Commit 2079a76

Browse files
committed
2 parents 58a7c3e + f2087f0 commit 2079a76

86 files changed

Lines changed: 20870 additions & 641 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/core-wheels.yml‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: "Native wheels"
2+
3+
# Build the wheels and the sdist of loop-interpolation-core.
4+
# pypi.yml calls this workflow and then publishes the files.
5+
# A pull request that changes the crate also runs it, so a broken wheel
6+
# build shows before a release.
7+
#
8+
# The crate uses abi3-py39, so one wheel for each platform works with all
9+
# Python versions from 3.9.
10+
11+
on:
12+
workflow_call:
13+
pull_request:
14+
branches:
15+
- master
16+
paths:
17+
- 'packages/loop_interpolation_core/**'
18+
- '.github/workflows/core-wheels.yml'
19+
workflow_dispatch:
20+
21+
permissions:
22+
contents: read
23+
24+
env:
25+
MANIFEST: packages/loop_interpolation_core/Cargo.toml
26+
27+
jobs:
28+
wheels:
29+
name: Wheel ${{ matrix.platform.name }}
30+
runs-on: ${{ matrix.platform.runner }}
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
platform:
35+
- { name: linux-x86_64, runner: ubuntu-latest, target: x86_64, smoke: true }
36+
- { name: linux-aarch64, runner: ubuntu-24.04-arm, target: aarch64, smoke: true }
37+
- { name: macos-arm64, runner: macos-latest, target: aarch64, smoke: true }
38+
# Cross-compiled on the arm64 runner, so it is not run here.
39+
- { name: macos-x86_64, runner: macos-latest, target: x86_64, smoke: false }
40+
- { name: windows-x86_64, runner: windows-latest, target: x64, smoke: true }
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: actions/setup-python@v5
44+
with:
45+
python-version: '3.12'
46+
# On Linux the build runs in a manylinux container.
47+
- name: Build the wheel
48+
uses: PyO3/maturin-action@v1
49+
with:
50+
target: ${{ matrix.platform.target }}
51+
manylinux: auto
52+
args: --release --out dist --manifest-path ${{ env.MANIFEST }}
53+
- name: Install the wheel and solve a small problem
54+
if: matrix.platform.smoke
55+
shell: bash
56+
run: |
57+
python -m pip install numpy
58+
python -m pip install --no-index --find-links dist loop-interpolation-core
59+
python - <<'EOF'
60+
import numpy as np
61+
import loop_interpolation_core as core
62+
63+
problem = core.Problem([0.0, 0.0, 0.0], [8, 8, 8], [1.0, 1.0, 1.0])
64+
points = np.array([2.0, 2.0, 2.0, 5.0, 5.0, 5.0])
65+
problem.add_value(points, np.array([0.0, 1.0]), np.ones(2))
66+
field, report = problem.solve({})
67+
assert report["converged"], report
68+
assert field.shape == (512,), field.shape
69+
print("solve converged in", report["iterations"], "iterations")
70+
EOF
71+
- uses: actions/upload-artifact@v4
72+
with:
73+
name: core-wheel-${{ matrix.platform.name }}
74+
path: dist/*.whl
75+
if-no-files-found: error
76+
77+
sdist:
78+
name: Sdist
79+
runs-on: ubuntu-latest
80+
steps:
81+
- uses: actions/checkout@v4
82+
- name: Build the sdist
83+
uses: PyO3/maturin-action@v1
84+
with:
85+
command: sdist
86+
args: --out dist --manifest-path ${{ env.MANIFEST }}
87+
- uses: actions/upload-artifact@v4
88+
with:
89+
name: core-sdist
90+
path: dist/*.tar.gz
91+
if-no-files-found: error

‎.github/workflows/linter.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ jobs:
4646
- name: Lint with ruff
4747
run: |
4848
ruff check ${{ env.PROJECT_FOLDERS }} --fix --exit-zero
49+
# A pull request from a fork gets a read-only GITHUB_TOKEN, so it
50+
# cannot push the style branch. Skip the push and the PR for it.
4951
- uses: stefanzweifel/git-auto-commit-action@v5
52+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
5053
with:
5154
commit_message: "style: style fixes by ruff and autoformatting by black"
5255
branch: lint/style-fixes-${{ github.run_id }}
5356
create_branch: true
5457
- name: Create Pull Request
58+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
5559
uses: peter-evans/create-pull-request@v6
5660
with:
5761
token: ${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/native.yml‎

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
name: "Native solver"
2+
3+
# This workflow checks the Rust crate loop_interpolation_core.
4+
# It runs only when the crate, the Python adapter or this file changes.
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
paths:
11+
- 'packages/loop_interpolation_core/**'
12+
- 'packages/loop_interpolation/src/loop_interpolation/_native.py'
13+
- '.github/workflows/native.yml'
14+
pull_request:
15+
branches:
16+
- master
17+
paths:
18+
- 'packages/loop_interpolation_core/**'
19+
- 'packages/loop_interpolation/src/loop_interpolation/_native.py'
20+
- '.github/workflows/native.yml'
21+
workflow_dispatch:
22+
23+
permissions:
24+
contents: read
25+
26+
env:
27+
CARGO_TERM_COLOR: always
28+
MANIFEST: packages/loop_interpolation_core/Cargo.toml
29+
30+
jobs:
31+
# Format, lint and test the crate with all feature sets.
32+
rust:
33+
name: Rust checks
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
- name: Install the Rust toolchain
38+
run: |
39+
rustup toolchain install stable --profile minimal --component rustfmt --component clippy --target wasm32-unknown-unknown
40+
rustup default stable
41+
- uses: actions/cache@v4
42+
with:
43+
path: |
44+
~/.cargo/registry
45+
~/.cargo/git
46+
packages/loop_interpolation_core/target
47+
key: rust-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }}
48+
restore-keys: rust-${{ runner.os }}-
49+
- name: Format
50+
run: cargo fmt --manifest-path "$MANIFEST" --check
51+
- name: Clippy, no features
52+
run: cargo clippy --manifest-path "$MANIFEST" --all-targets -- -D warnings
53+
- name: Clippy, parallel
54+
run: cargo clippy --manifest-path "$MANIFEST" --all-targets --features parallel -- -D warnings
55+
- name: Clippy, python
56+
run: cargo clippy --manifest-path "$MANIFEST" --all-targets --features python -- -D warnings
57+
- name: Clippy, wasm
58+
run: cargo clippy --manifest-path "$MANIFEST" --all-targets --features wasm --target wasm32-unknown-unknown -- -D warnings
59+
# Use --release. Debug test runs take many minutes.
60+
- name: Test, no features
61+
run: cargo test --manifest-path "$MANIFEST" --release
62+
- name: Test, parallel
63+
run: cargo test --manifest-path "$MANIFEST" --release --features parallel
64+
65+
# Build the Python wheel and run the Python tests with the native core installed.
66+
wheel:
67+
name: Wheel ${{ matrix.os }}
68+
runs-on: ${{ matrix.os }}
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
os: [ubuntu-latest, windows-latest, macos-latest]
73+
steps:
74+
- uses: actions/checkout@v4
75+
- uses: actions/setup-python@v5
76+
with:
77+
python-version: '3.12'
78+
- uses: actions/cache@v4
79+
with:
80+
path: |
81+
~/.cargo/registry
82+
~/.cargo/git
83+
packages/loop_interpolation_core/target
84+
key: wheel-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }}
85+
restore-keys: wheel-${{ runner.os }}-
86+
# maturin develop needs a virtual environment.
87+
# The Linux and macOS folder is bin. The Windows folder is Scripts.
88+
- name: Install, build and test
89+
shell: bash
90+
run: |
91+
python -m venv .venv
92+
if [ -f .venv/Scripts/activate ]; then source .venv/Scripts/activate; else source .venv/bin/activate; fi
93+
python -m pip install --upgrade pip
94+
python -m pip install maturin numpy scipy pytest
95+
python -m pip install -e packages/loop_common -e packages/loop_interpolation
96+
maturin develop --release -m packages/loop_interpolation_core/Cargo.toml
97+
python -m pytest packages/loop_interpolation/tests -q
98+
99+
# Build the WebAssembly package, check its size and run the browser tests.
100+
wasm:
101+
name: WebAssembly
102+
runs-on: ubuntu-latest
103+
steps:
104+
- uses: actions/checkout@v4
105+
- uses: actions/setup-python@v5
106+
with:
107+
python-version: '3.12'
108+
- uses: actions/setup-node@v4
109+
with:
110+
node-version: '20'
111+
- name: Install the Rust toolchain
112+
run: |
113+
rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown
114+
rustup default stable
115+
- uses: actions/cache@v4
116+
with:
117+
path: |
118+
~/.cargo/registry
119+
~/.cargo/git
120+
packages/loop_interpolation_core/target
121+
key: wasm-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }}
122+
restore-keys: wasm-${{ runner.os }}-
123+
# The wasm-bindgen CLI version must equal the wasm-bindgen version in Cargo.lock.
124+
- name: Read the wasm-bindgen version
125+
run: |
126+
V=$(grep -A1 '^name = "wasm-bindgen"$' packages/loop_interpolation_core/Cargo.lock | sed -n 's/^version = "\(.*\)"$/\1/p')
127+
echo "Version: $V"
128+
test -n "$V"
129+
echo "WASM_BINDGEN_VERSION=$V" >> "$GITHUB_ENV"
130+
- name: Cache the wasm-bindgen CLI
131+
id: bindgen-cache
132+
uses: actions/cache@v4
133+
with:
134+
path: ~/.cargo/bin/wasm-bindgen
135+
key: wasm-bindgen-cli-${{ runner.os }}-${{ env.WASM_BINDGEN_VERSION }}
136+
- name: Install the wasm-bindgen CLI
137+
if: steps.bindgen-cache.outputs.cache-hit != 'true'
138+
run: cargo install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION" --locked
139+
- name: Build the WebAssembly package
140+
run: bash packages/loop_interpolation_core/scripts/build_wasm.sh
141+
- name: Check the size
142+
run: python -I packages/loop_interpolation_core/scripts/check_wasm_size.py
143+
- name: Install the browser test packages
144+
working-directory: packages/loop_interpolation_core/tests_web
145+
run: |
146+
npm ci
147+
npx playwright install --with-deps chromium
148+
- name: Browser tests
149+
working-directory: packages/loop_interpolation_core/tests_web
150+
run: npm test
151+
152+
# Slow reference runs. Start these by hand only.
153+
reference:
154+
name: Reference problems
155+
if: github.event_name == 'workflow_dispatch'
156+
runs-on: ubuntu-latest
157+
steps:
158+
- uses: actions/checkout@v4
159+
- uses: actions/setup-node@v4
160+
with:
161+
node-version: '20'
162+
- name: Install the Rust toolchain
163+
run: |
164+
rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown
165+
rustup default stable
166+
- uses: actions/cache@v4
167+
with:
168+
path: |
169+
~/.cargo/registry
170+
~/.cargo/git
171+
packages/loop_interpolation_core/target
172+
key: reference-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }}
173+
restore-keys: reference-${{ runner.os }}-
174+
- name: Read the wasm-bindgen version
175+
run: |
176+
V=$(grep -A1 '^name = "wasm-bindgen"$' packages/loop_interpolation_core/Cargo.lock | sed -n 's/^version = "\(.*\)"$/\1/p')
177+
test -n "$V"
178+
echo "WASM_BINDGEN_VERSION=$V" >> "$GITHUB_ENV"
179+
- name: Cache the wasm-bindgen CLI
180+
id: bindgen-cache
181+
uses: actions/cache@v4
182+
with:
183+
path: ~/.cargo/bin/wasm-bindgen
184+
key: wasm-bindgen-cli-${{ runner.os }}-${{ env.WASM_BINDGEN_VERSION }}
185+
- name: Install the wasm-bindgen CLI
186+
if: steps.bindgen-cache.outputs.cache-hit != 'true'
187+
run: cargo install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION" --locked
188+
# The test f32_250_cubed_within_budget is too slow for CI. Skip it.
189+
- name: Ignored Rust tests
190+
run: |
191+
set -o pipefail
192+
cargo test --manifest-path "$MANIFEST" --release --test reference_problems -- --ignored --nocapture --test-threads=1 --skip f32_250_cubed_within_budget 2>&1 | tee rust_reference.log
193+
- name: Write the reference field
194+
run: cargo test --manifest-path "$MANIFEST" --release --test reference_problems r1_write_field -- --ignored
195+
- name: Build the WebAssembly package
196+
run: bash packages/loop_interpolation_core/scripts/build_wasm.sh
197+
- name: Browser reference spec
198+
working-directory: packages/loop_interpolation_core/tests_web
199+
env:
200+
RUN_REFERENCE: '1'
201+
run: |
202+
set -o pipefail
203+
npm ci
204+
npx playwright install --with-deps chromium
205+
npm test -- reference 2>&1 | tee "$GITHUB_WORKSPACE/browser_reference.log"
206+
- name: Write the job summary
207+
if: always()
208+
run: |
209+
{
210+
echo "## Rust reference problems"
211+
echo '```'
212+
cat rust_reference.log 2>/dev/null || echo "No output."
213+
echo '```'
214+
echo "## Browser reference spec"
215+
echo '```'
216+
cat browser_reference.log 2>/dev/null || echo "No output."
217+
echo '```'
218+
} >> "$GITHUB_STEP_SUMMARY"

‎.github/workflows/pypi.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@ permissions:
66
contents: read
77

88
jobs:
9+
# loop-interpolation-core is the Rust core behind the optional extra
10+
# loop-interpolation[native]. It has compiled wheels, so it is built by
11+
# core-wheels.yml and not by the sdist matrix below. No other package
12+
# waits for it: a failed core upload does not stop their release.
13+
build_core:
14+
name: Build loop-interpolation-core
15+
uses: ./.github/workflows/core-wheels.yml
16+
17+
# Trusted publishing (OIDC): no password. PyPI must list this repository
18+
# and the workflow file pypi.yml as a trusted publisher of the project.
19+
upload_core_to_pypi:
20+
name: Upload loop-interpolation-core to PyPI
21+
needs: ["build_core"]
22+
runs-on: ubuntu-latest
23+
permissions:
24+
id-token: write
25+
steps:
26+
- uses: actions/download-artifact@v4
27+
with:
28+
pattern: core-*
29+
path: dist
30+
merge-multiple: true
31+
- uses: pypa/gh-action-pypi-publish@release/v1
32+
with:
33+
skip-existing: true
34+
verbose: true
35+
936
# loop_common/loop_interpolation/loopstructural_visualisation are
1037
# workspace-local deps of LoopStructural (see [tool.uv.sources] in
1138
# pyproject.toml) — loop_common/loop_interpolation are runtime deps,

‎.gitignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ sandbox/*
143143

144144
# codebase-graph
145145
.codebaseGraph/
146+
147+
# loop_interpolation_core build output (wasm pkg) and browser test dependencies
148+
packages/loop_interpolation_core/pkg/
149+
packages/loop_interpolation_core/tests_web/node_modules/
150+
packages/loop_interpolation_core/tests_web/test-results/
151+
packages/loop_interpolation_core/tests_web/playwright-report/

0 commit comments

Comments
 (0)