Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 46 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,34 @@ on:
pull_request:

jobs:
# Warms the OFT cache once. Without this every job below misses the same cache
# key at the same time and GitHub throttles the parallel 90 MB downloads.
setup-oft:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v5

- uses: astral-sh/setup-uv@v7

- name: Cache OFT
uses: actions/cache@v5
with:
path: submodules/OpenFUSIONToolkit
key: oft-v1.0.0-beta6-ubuntu-22.04

- name: Install
run: ./install.sh

lint:
needs: setup-oft
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: astral-sh/setup-uv@v5
- uses: astral-sh/setup-uv@v7

- name: Cache OFT
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: submodules/OpenFUSIONToolkit
key: oft-v26.9-ubuntu-22.04
Expand All @@ -32,21 +51,26 @@ jobs:
run: uv run isort synthwave/

test:
needs: setup-oft
runs-on: ubuntu-22.04
strategy:
matrix:
test-file:
- test_utils.py
- test_equilibrium_field.py
- test_filaments.py
- test_lazy_imports.py
- test_flux_matrix.py
- test_filament_discretization.py
- test_trace_regression.py
name: test (${{ matrix.test-file }})
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: astral-sh/setup-uv@v5
- uses: astral-sh/setup-uv@v7

- name: Cache OFT
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: submodules/OpenFUSIONToolkit
key: oft-v26.9-ubuntu-22.04
Expand All @@ -58,15 +82,16 @@ jobs:
run: uv run pytest synthwave/tests/${{ matrix.test-file }}

test-thincurr-other:
needs: setup-oft
runs-on: ubuntu-22.04
name: test (test_thincurr.py - other)
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: astral-sh/setup-uv@v5
- uses: astral-sh/setup-uv@v7

- name: Cache OFT
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: submodules/OpenFUSIONToolkit
key: oft-v26.9-ubuntu-22.04
Expand All @@ -77,19 +102,24 @@ jobs:
- name: Run tests
run: uv run pytest synthwave/tests/test_thincurr.py --deselect synthwave/tests/test_thincurr.py::test_toroidal_angles

# Separate process: OFT_env can only be created once per process
- name: Run direct response tests
run: uv run pytest synthwave/tests/test_direct_response.py

test-thincurr-toroidal-angles:
needs: setup-oft
runs-on: ubuntu-22.04
strategy:
matrix:
mode: ["m2n1", "m3n2", "m-3n2", "m3n1", "m4n3"]
name: test (test_toroidal_angles[${{ matrix.mode }}])
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: astral-sh/setup-uv@v5
- uses: astral-sh/setup-uv@v7

- name: Cache OFT
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: submodules/OpenFUSIONToolkit
key: oft-v26.9-ubuntu-22.04
Expand All @@ -101,14 +131,15 @@ jobs:
run: uv run pytest "synthwave/tests/test_thincurr.py::test_toroidal_angles[${{ matrix.mode }}]"

notebooks:
needs: setup-oft
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- uses: astral-sh/setup-uv@v5
- uses: astral-sh/setup-uv@v7

- name: Cache OFT
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: submodules/OpenFUSIONToolkit
key: oft-v26.9-ubuntu-22.04
Expand Down
16 changes: 14 additions & 2 deletions install.sh

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See note to PR #15: proposing to change to PyPi implementation of OFT, instead of Git binary version, and move the install requirement to pyproject.toml

Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,25 @@ else
TEMP_DIR=$(mktemp -d)
trap "rm -rf $TEMP_DIR" EXIT

curl -L -o "$TEMP_DIR/$TARBALL" "$URL" || wget -O "$TEMP_DIR/$TARBALL" "$URL"
# -f makes HTTP errors a real failure instead of saving the error page as the
# tarball. Concurrent CI jobs can get throttled by GitHub, so retry with backoff.
curl -fL --retry 5 --retry-delay 5 --retry-all-errors \
-o "$TEMP_DIR/$TARBALL" "$URL" \
|| wget --tries=5 --waitretry=5 -O "$TEMP_DIR/$TARBALL" "$URL" \
|| error "Download failed: $URL"

# A throttled or redirected response can still land as a tiny file
DOWNLOAD_BYTES=$(stat -c %s "$TEMP_DIR/$TARBALL" 2>/dev/null || echo 0)
if [ "$DOWNLOAD_BYTES" -lt 1000000 ]; then
error "Download is only ${DOWNLOAD_BYTES} bytes, expected ~90 MB. GitHub likely rate-limited this request."
fi

# Verify checksum if available
if [ -n "${CHECKSUMS[$TARBALL]}" ]; then
info "Verifying checksum..."
if command -v sha256sum &>/dev/null; then
echo "${CHECKSUMS[$TARBALL]} $TEMP_DIR/$TARBALL" | sha256sum -c - || error "Checksum verification failed!"
echo "${CHECKSUMS[$TARBALL]} $TEMP_DIR/$TARBALL" | sha256sum -c - \
|| error "Checksum mismatch for $TARBALL - the download is corrupt or the release asset changed."
success "Checksum verified"
else
warn "sha256sum not available, skipping checksum verification"
Expand Down
10 changes: 7 additions & 3 deletions synthwave/magnetic_geometry/equilibrium_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
def biot_savart_cartesian(
eval_point: np.ndarray, filament_points: np.ndarray, filament_current: float
):
"""Biot-savart law in cartesian coordinates."""
r_prime = eval_point - filament_points
"""Biot-savart law in cartesian coordinates.

Segment-midpoint rule, one current element per polyline segment.
"""
dl = filament_points[1:] - filament_points[:-1]
midpoints = 0.5 * (filament_points[1:] + filament_points[:-1])
r_prime = eval_point - midpoints
r_prime_norm = np.linalg.norm(r_prime, axis=1)
dl = np.gradient(filament_points, axis=0)
dl_cross_r = np.cross(dl, r_prime)
B_segments = (
(mu_0 / (4 * np.pi))
Expand Down
Loading