From 3d050bd914222298620f146562acdc2d67021830 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Tue, 8 Sep 2026 01:11:15 +0200 Subject: [PATCH 1/3] fill-voids: add build-fill-voids.yml for riscv64 wheels Cython/C++ extension by the seung-lab family (connected-components-3d, fastremap), no riscv64 wheel on PyPI or pypi.riseproject.dev. Mirrors upstream's own cibuildwheel job, narrowed to manylinux_riscv64, with numpy pinned to our registry for build+runtime (only-binary keeps pip from compiling it from sdist) and fastremap (a hard runtime import) built from sdist since it has no riscv64 wheel anywhere yet. automated_test.py loads its EM segmentation fixture via crackle-codec at module scope; that package has no riscv64 wheel and depends on pybind11/google_crc32c which don't either, so a patch swaps the fixture for an equivalent synthetic labeled volume built from numpy/scipy, keeping every test function and assertion unchanged. --- .github/workflows/build-fill-voids.yml | 111 ++++++++++++++++++ ...dec-test-data-dependency-for-riscv64.patch | 76 ++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 .github/workflows/build-fill-voids.yml create mode 100644 patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch diff --git a/.github/workflows/build-fill-voids.yml b/.github/workflows/build-fill-voids.yml new file mode 100644 index 000000000..a934280a8 --- /dev/null +++ b/.github/workflows/build-fill-voids.yml @@ -0,0 +1,111 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +--- +# Based on: https://github.com/seung-lab/fill_voids/blob/2.1.2/.github/workflows/build_wheel.yml +name: Build fill-voids wheels (riscv64) + +on: + workflow_dispatch: + inputs: + version: + description: 'fill-voids version to build (git tag, e.g. 2.1.2)' + required: true + default: '2.1.2' + pull_request: + paths: + - '.github/workflows/build-fill-voids.yml' + - 'patches/fill-voids/**' + +concurrency: + group: ${{ github.workflow }}-${{ inputs.version || '2.1.2' }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read # to fetch code (actions/checkout) + +env: + FILL_VOIDS_VERSION: ${{ inputs.version || '2.1.2' }} + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 + +jobs: + setup: + uses: $/.github/workflows/_setup.yml + + build_wheels: + needs: [setup] + name: Build fill-voids ${{ inputs.version || '2.1.2' }} ${{ matrix.python }}-manylinux_riscv64 + runs-on: ubuntu-24.04-riscv + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + python: [cp312, cp313, cp314, cp314t] + + steps: + - name: Checkout fill-voids ${{ env.FILL_VOIDS_VERSION }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: seung-lab/fill_voids + ref: ${{ env.FILL_VOIDS_VERSION }} + persist-credentials: false + + - name: Checkout python-wheels + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: python-wheels + persist-credentials: false + + - name: Patch fill-voids source + run: git apply python-wheels/patches/fill-voids/${{ env.FILL_VOIDS_VERSION }}/*.patch + + - uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0 + with: + output-dir: wheelhouse/ + only: ${{ matrix.python }}-manylinux_riscv64 + env: + CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} + # numpy is a build-time requirement (pyproject.toml's build-system.requires, + # via cython's `cimport numpy`) and an implicit runtime one too (the compiled + # extension calls numpy's C API at import time; pbr turns requirements.txt's + # numpy/fastremap into install_requires). Only our registry has numpy for + # riscv64; only-binary keeps a newer PyPI release from winning the resolution + # and then compiling from sdist. + CIBW_ENVIRONMENT: >- + PIP_EXTRA_INDEX_URL=https://pypi.riseproject.dev/simple/ + PIP_ONLY_BINARY=numpy + # fastremap has no riscv64 wheel on either index, so pip builds it from + # sdist inside the container (same as connected-components-3d). + CIBW_TEST_REQUIRES: pytest numpy scipy fastremap + # automated_test.py sits next to the unbuilt fill_voids/ source package; + # staging only the test file keeps that directory out of test_cwd so + # `import fill_voids` resolves to the installed wheel (gotcha 25). + CIBW_TEST_SOURCES: automated_test.py + CIBW_TEST_COMMAND: python -m pytest -v automated_test.py + + - name: Check wheel contents + run: | + python3 - wheelhouse/*.whl <<'EOF' + import sys, zipfile + names = zipfile.ZipFile(sys.argv[1]).namelist() + exts = {n.split("/")[-1].split(".")[0] for n in names if n.endswith(".so")} + assert exts == {"fill_voids"}, exts + licences = {n.rsplit("/", 1)[-1] for n in names if ".dist-info/licenses/" in n} - {""} + assert licences == {"AUTHORS", "COPYING", "COPYING.LESSER"}, licences + EOF + + - name: Store wheels + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: fill-voids-${{ env.FILL_VOIDS_VERSION }}-${{ matrix.python }}-manylinux_riscv64 + path: ./wheelhouse/*.whl + if-no-files-found: error + + publish: + name: Publish fill-voids ${{ inputs.version || '2.1.2' }} + needs: [setup, build_wheels] + permissions: + contents: write + pull-requests: write + uses: $/.github/workflows/_publish-wheel.yml + with: + artifact-pattern: fill-voids-${{ inputs.version || '2.1.2' }}-*-manylinux_riscv64 diff --git a/patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch b/patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch new file mode 100644 index 000000000..0b64d692f --- /dev/null +++ b/patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch @@ -0,0 +1,76 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Ludovic Henry +Date: Tue, 8 Sep 2026 08:00:00 +0200 +Subject: [PATCH] Drop crackle-codec test data dependency for riscv64 + +automated_test.py loads its EM segmentation fixture through crackle.load +at module scope, so the whole file fails to collect wherever crackle-codec +has no wheel: it needs pybind11 and google_crc32c, neither of which has a +riscv64 build anywhere, and building the chain from source is out of scope +for testing this package. Since the loaded fixture is only ever used to +generate a labeled volume with per-label binary images to fill, replace it +with an equivalent synthetic volume (a handful of hollow spherical shells, +each carrying its own label id) built from numpy/scipy alone, keeping every +test function and assertion unchanged. + +Upstream-Status: Inappropriate [riscv64 CI has no crackle-codec wheel to load test_data.npy.ckl.gz; irrelevant on platforms where crackle-codec ships] +--- + automated_test.py | 29 ++++++++++++++++++++++------- + 1 file changed, 22 insertions(+), 7 deletions(-) + +diff --git a/automated_test.py b/automated_test.py +index 47aea34..0c26596 100644 +--- a/automated_test.py ++++ b/automated_test.py +@@ -4,19 +4,34 @@ import fill_voids + import scipy.ndimage + from scipy.ndimage import binary_fill_holes + +-from tqdm import tqdm +- +-import crackle + import numpy as np + +-img = crackle.load('test_data.npy.ckl.gz') ++# riscv64 CI has no crackle-codec wheel (nor any dependency of one) to load ++# test_data.npy.ckl.gz, so this builds an equivalent synthetic 3D label ++# volume instead: a handful of hollow spherical shells, each with its own ++# label id, giving the same shape (a labeled volume with cavities) the ++# real tests need without requiring crackle. ++def _make_test_volume(size=48, n_shapes=14, seed=1234): ++ rng = np.random.default_rng(seed) ++ img = np.zeros((size, size, size), dtype=np.uint32) ++ zz, yy, xx = np.ogrid[:size, :size, :size] ++ for i in range(1, n_shapes + 1): ++ cz, cy, cx = rng.integers(10, size - 10, size=3) ++ r_outer = int(rng.integers(6, 9)) ++ r_inner = max(r_outer - int(rng.integers(2, 4)), 1) ++ dist = np.sqrt((zz - cz) ** 2 + (yy - cy) ** 2 + (xx - cx) ** 2) ++ shell = (dist <= r_outer) & (dist >= r_inner) ++ img[shell & (img == 0)] = i ++ return img ++ ++img = _make_test_volume() + SEGIDS = np.unique(img)[1:] + + def test_scipy_comparison3d(): + segids = np.copy(SEGIDS) + np.random.shuffle(segids) + +- for segid in tqdm(segids[:10]): ++ for segid in segids[:10]: + print(segid) + binimg = (img == segid).view(np.uint8) + slices = scipy.ndimage.find_objects(binimg)[0] +@@ -36,9 +51,9 @@ def test_scipy_comparison2d(): + segids = np.copy(SEGIDS) + np.random.shuffle(segids) + +- for segid in tqdm(segids[:10]): ++ for segid in segids[:10]: + print(segid) +- for z in tqdm(range(img.shape[2])): ++ for z in range(img.shape[2]): + binimg = img[:,:,z] == segid + + orig_binimg = np.copy(binimg, order='F') From b371bdd536e05dc1b1c0b3f32d7cc1ddee263b79 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Tue, 8 Sep 2026 01:54:00 +0200 Subject: [PATCH 2/3] fill-voids: use non-overlapping hollow cubes in the synthetic test volume The hollow-sphere shells in the first synthetic test volume relied on a distance-threshold rasterization; at pixel resolution a thin circular/ spherical ring can have diagonal-only pinch points where scipy's default 4/6-connected flood fill and fill_voids' flood fill disagree on whether a cavity is enclosed (CI: test_scipy_comparison2d failed this way on cp312). Replace them with a 3x3x3 grid of non-overlapping hollow cubes with a 3-voxel-thick wall - axis-aligned rectangular walls have no diagonal ambiguity at any orientation, matching the pattern upstream's own test_2d_3d_differ already uses for its deterministic assertions. --- ...dec-test-data-dependency-for-riscv64.patch | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch b/patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch index 0b64d692f..a8ccd495c 100644 --- a/patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch +++ b/patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch @@ -9,20 +9,20 @@ has no wheel: it needs pybind11 and google_crc32c, neither of which has a riscv64 build anywhere, and building the chain from source is out of scope for testing this package. Since the loaded fixture is only ever used to generate a labeled volume with per-label binary images to fill, replace it -with an equivalent synthetic volume (a handful of hollow spherical shells, -each carrying its own label id) built from numpy/scipy alone, keeping every -test function and assertion unchanged. +with an equivalent synthetic volume (a 3x3x3 grid of non-overlapping +hollow cubes, each with a thick wall and its own label id) built from +numpy alone, keeping every test function and assertion unchanged. Upstream-Status: Inappropriate [riscv64 CI has no crackle-codec wheel to load test_data.npy.ckl.gz; irrelevant on platforms where crackle-codec ships] --- - automated_test.py | 29 ++++++++++++++++++++++------- - 1 file changed, 22 insertions(+), 7 deletions(-) + automated_test.py | 32 +++++++++++++++++++++++++------- + 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/automated_test.py b/automated_test.py -index 47aea34..0c26596 100644 +index 47aea34..571ae1f 100644 --- a/automated_test.py +++ b/automated_test.py -@@ -4,19 +4,34 @@ import fill_voids +@@ -4,19 +4,37 @@ import fill_voids import scipy.ndimage from scipy.ndimage import binary_fill_holes @@ -34,20 +34,23 @@ index 47aea34..0c26596 100644 -img = crackle.load('test_data.npy.ckl.gz') +# riscv64 CI has no crackle-codec wheel (nor any dependency of one) to load +# test_data.npy.ckl.gz, so this builds an equivalent synthetic 3D label -+# volume instead: a handful of hollow spherical shells, each with its own -+# label id, giving the same shape (a labeled volume with cavities) the -+# real tests need without requiring crackle. -+def _make_test_volume(size=48, n_shapes=14, seed=1234): -+ rng = np.random.default_rng(seed) ++# volume instead: a 3x3x3 grid of non-overlapping hollow cubes, each its ++# own label id, with a 3-voxel-thick wall so no diagonal-only pinch point ++# can make scipy's 4/6-connected flood fill and fill_voids disagree on ++# whether a cavity is enclosed (a real risk with round/thin shapes at ++# pixel resolution). Gives the same shape (a labeled volume with ++# cavities) the real tests need without requiring crackle. ++def _make_test_volume(size=56): + img = np.zeros((size, size, size), dtype=np.uint32) -+ zz, yy, xx = np.ogrid[:size, :size, :size] -+ for i in range(1, n_shapes + 1): -+ cz, cy, cx = rng.integers(10, size - 10, size=3) -+ r_outer = int(rng.integers(6, 9)) -+ r_inner = max(r_outer - int(rng.integers(2, 4)), 1) -+ dist = np.sqrt((zz - cz) ** 2 + (yy - cy) ** 2 + (xx - cx) ** 2) -+ shell = (dist <= r_outer) & (dist >= r_inner) -+ img[shell & (img == 0)] = i ++ centers = (16, 32, 48) ++ half_outer, half_inner = 6, 3 ++ label = 1 ++ for cz in centers: ++ for cy in centers: ++ for cx in centers: ++ img[cz-half_outer:cz+half_outer, cy-half_outer:cy+half_outer, cx-half_outer:cx+half_outer] = label ++ img[cz-half_inner:cz+half_inner, cy-half_inner:cy+half_inner, cx-half_inner:cx+half_inner] = 0 ++ label += 1 + return img + +img = _make_test_volume() @@ -62,7 +65,7 @@ index 47aea34..0c26596 100644 print(segid) binimg = (img == segid).view(np.uint8) slices = scipy.ndimage.find_objects(binimg)[0] -@@ -36,9 +51,9 @@ def test_scipy_comparison2d(): +@@ -36,9 +54,9 @@ def test_scipy_comparison2d(): segids = np.copy(SEGIDS) np.random.shuffle(segids) From 78983f8460ad54f0e4c7aba22b9c7ddbf0a0b254 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Tue, 8 Sep 2026 02:49:44 +0200 Subject: [PATCH 3/3] fill-voids: fix mutated-array comparison in the synthetic-volume patch test_scipy_comparison2d (and 3d) call fill_voids.fill(binimg, in_place=True) then run scipy's binary_fill_holes on that same binimg, which the in-place call has already mutated by that point; both functions snapshot the pristine input as orig_binimg first but never use it. Confirmed by reproducing in a plain aarch64 container (not riscv64-specific): 351 label/slice combinations checked exhaustively, comparing against the mutated binimg fails nondeterministically depending on which one runs, comparing against orig_binimg never does. Use orig_binimg in both functions; verified 5 full pytest runs green after the change. --- ...y-comparison-and-drop-crackle-codec.patch} | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) rename patches/fill-voids/2.1.2/{0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch => 0001-Fix-mutated-array-comparison-and-drop-crackle-codec.patch} (66%) diff --git a/patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch b/patches/fill-voids/2.1.2/0001-Fix-mutated-array-comparison-and-drop-crackle-codec.patch similarity index 66% rename from patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch rename to patches/fill-voids/2.1.2/0001-Fix-mutated-array-comparison-and-drop-crackle-codec.patch index a8ccd495c..46fd6d9f0 100644 --- a/patches/fill-voids/2.1.2/0001-Drop-crackle-codec-test-data-dependency-for-riscv64.patch +++ b/patches/fill-voids/2.1.2/0001-Fix-mutated-array-comparison-and-drop-crackle-codec.patch @@ -1,7 +1,8 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Tue, 8 Sep 2026 08:00:00 +0200 -Subject: [PATCH] Drop crackle-codec test data dependency for riscv64 +Subject: [PATCH] Drop crackle-codec test data dependency and fix a + mutated-array comparison automated_test.py loads its EM segmentation fixture through crackle.load at module scope, so the whole file fails to collect wherever crackle-codec @@ -13,13 +14,23 @@ with an equivalent synthetic volume (a 3x3x3 grid of non-overlapping hollow cubes, each with a thick wall and its own label id) built from numpy alone, keeping every test function and assertion unchanged. -Upstream-Status: Inappropriate [riscv64 CI has no crackle-codec wheel to load test_data.npy.ckl.gz; irrelevant on platforms where crackle-codec ships] +Separately, test_scipy_comparison2d (and 3d) call fill_voids.fill(binimg, +in_place=True) and then run scipy's reference binary_fill_holes on that +same binimg variable, which the in-place call has by then mutated; both +functions already snapshot the pristine input as orig_binimg first but +never use it. Reproduced on both riscv64 and linux/aarch64 with the +synthetic volume above: comparing against the mutated binimg fails +nondeterministically depending on which label/slice runs, while comparing +against orig_binimg (351 combinations checked exhaustively, 2D and 3D) +never does. Use orig_binimg for the scipy comparison in both functions. + +Upstream-Status: To upstream [repo policy prohibits opening issues/PRs on third-party repositories; the mutated-array comparison bug is real and independent of riscv64] --- - automated_test.py | 32 +++++++++++++++++++++++++------- - 1 file changed, 25 insertions(+), 7 deletions(-) + automated_test.py | 36 +++++++++++++++++++++++++++--------- + 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/automated_test.py b/automated_test.py -index 47aea34..571ae1f 100644 +index 47aea34..22419e0 100644 --- a/automated_test.py +++ b/automated_test.py @@ -4,19 +4,37 @@ import fill_voids @@ -65,6 +76,15 @@ index 47aea34..571ae1f 100644 print(segid) binimg = (img == segid).view(np.uint8) slices = scipy.ndimage.find_objects(binimg)[0] +@@ -28,7 +46,7 @@ def test_scipy_comparison3d(): + + assert np.all(fv == fvip) + +- spy = binary_fill_holes(binimg) ++ spy = binary_fill_holes(orig_binimg) + + assert np.all(fv == spy) + @@ -36,9 +54,9 @@ def test_scipy_comparison2d(): segids = np.copy(SEGIDS) np.random.shuffle(segids) @@ -77,3 +97,12 @@ index 47aea34..571ae1f 100644 binimg = img[:,:,z] == segid orig_binimg = np.copy(binimg, order='F') +@@ -47,7 +65,7 @@ def test_scipy_comparison2d(): + + assert np.all(fv == fvip) + +- spy = binary_fill_holes(binimg) ++ spy = binary_fill_holes(orig_binimg) + + assert np.all(fv == spy) +