Skip to main content

FastWarp

GPU image registration for Python, packaged as a wheel. FastWarp was developed by Richard Köhler (Wyss Center for Bio and Neuroengineering) and Jan Philipp Payonk (University of Rostock) as the registration engine of Wyss DBS Localizer. It runs a full Rigid → Affine → SyN normalization in one call, and rigid or affine fits (coregistration, template alignment, brain-shift refinement) in a session that keeps the image pair on the GPU.

The engine is a port of ANTs/ITK's registration (Mattes mutual information and cross-correlation metrics, conjugate-gradient linear stages, SyN with Gaussian field regularisation and field inversion) to GPU compute shaders via wgpu. It runs on Metal (macOS), Vulkan (Linux, Windows) and DX12 (Windows), from one wheel per platform for every Python ≥ 3.11. Outputs are ANTs files (Composite.h5, InverseComposite.h5, 0GenericAffine.mat) that ANTsPy and antsApplyTransforms read as is.

Licence: Apache-2.0. The files ported from ANTs/ITK carry their Apache-2.0 notices (NOTICE, docs/THIRD_PARTY_PORTS.md). Every file states its licence in an SPDX header or through REUSE.toml (REUSE).

Documentation: https://fastwarp.readthedocs.io

Speed

T1w + T2w of Lead-Tutor sub-57245 (raw T1w, T2w aligned to it by one rigid fit) onto the MNI 2009b template (0.5 mm), 1 mm registration grid, default recipe, a development build before 0.1.0 (internal version 0.4.0); median of three runs, the engine's own linear_s / syn_s / total_s (2026-11-09):

Hardware Linear SyN Registration total
NVIDIA RTX A4000 (Linux, Vulkan) 3.5 s 6.4 s 12.4 s
Apple M5 Pro (MacBook Pro, Metal) 4.1 s 9.4 s 13.7 s
Intel Lunar Lake integrated GPU (Linux laptop, Vulkan) 3.5 s 16.4 s 21.0 s
AMD Radeon Pro 5500 XT (Intel iMac, Metal) 6.1 s 16.7 s 23.5 s
NVIDIA Quadro K620, 2 GB (Windows Server 2022, Vulkan), T1w only¹ 10.6 s 54.7 s 67.3 s
ANTs on 16 CPU threads, same recipe 1000–1500 s

The total includes preparing and uploading the images. The A4000 machine was under heavy CPU load (load average about 110 on 48 cores) during its runs.

¹ 2 GB is too little for T1w + T2w at 1 mm (1.6 GB): the capacity check refuses it up front (GpuCapacityError), so a caller falls back to ANTs. T1w alone needs 1.4 GB and ran only with FASTWARP_GPU_MEMORY_BUDGET_MB=1900, since the default budget keeps 1 GB free for the desktop.

Linear sessions: one rigid fit of the T2w onto the T1w (the default rigid stage) takes 1.2 s on the M5 Pro, 1.6 s on the RTX A4000, 1.8 s on the Radeon Pro 5500 XT, 2.1 s on Lunar Lake and 2.7 s on the Quadro K620. In a typical DBS localisation workflow on the Lead-Tutor cohort: a post-op CT onto the T1w anchor, five coarse and two full rigid fits, takes 17 s on the laptop GPU where ANTs takes 32 s; the masked affine brain-shift fit takes 2.4–4.8 s on the RTX A4000 where ANTs takes 5–11 s.

After the registration, turning the composites into displacement fields on the 0.5 mm template and anchor grids and the Lanczos re-warp of the anchor (what Lead-DBS does next):

Laptop, 8 threads ANTs (ITK) compose_field / apply_transforms
Forward field (69 M voxels) 36.5 s 1.4 s
Inverse field (37 M voxels) 20.9 s 0.95 s
Lanczos re-warp 31.0 s 2.7 s

Install

From PyPI (wheels for macOS arm64 / x86_64, Linux x86_64 / aarch64, Windows x86_64):

pip install fastwarp

The same wheels are attached to each GitHub release.

From source (needs a Rust toolchain; rust-toolchain.toml pins the version):

pip install "git+https://github.com/WyssCenter/fastwarp.git"

Use

import ants
import fastwarp

fixed = [ants.image_read("tpl_t1.nii"), ants.image_read("tpl_t2.nii")]
moving = [ants.image_read("sub_T1w.nii.gz"), ants.image_read("sub_T2w_in_T1w.nii.gz")]

if fastwarp.fits_gpu(fixed[0], iso_mm=1.0, channels=2):
    info = fastwarp.register_syn(fixed, moving, "out/sub_", iso_mm=1.0)
    warped = ants.apply_transforms(fixed[0], moving[0], ["out/sub_Composite.h5"])
    print(info["adapter"], f'{info["total_s"]:.1f} s')
else:
    ...  # no GPU or too little GPU memory: use ANTs
  • register_syn(fixed, moving, out_prefix, *, iso_mm=1.0, write_warped=False, adapter=None, cancel=None, recipe=None): one image or a list of two (T1w + T2w) on each side; images are ANTsImages or (array, spacing, origin, direction) tuples in ITK (LPS) geometry. Writes <out_prefix>Composite.h5 ([Affine, Warp]), <out_prefix>InverseComposite.h5 ([InverseWarp, Affine⁻¹]) and <out_prefix>0GenericAffine.mat. Returns timings, the registration grid, per-level SyN diagnostics, the affine and peak GPU memory. Releases the GIL.
  • CancelToken(): pass as cancel=, call .cancel() from another thread; the run stops at the next iteration with RegistrationCancelled.
  • compose_field(transforms, reference, out_path, *, compression_level=None): the transforms as one displacement field on reference's grid, the file antsApplyTransforms --compose writes (float32, parallel gzip; compression_level=0 stores the data as valid gzip without compressing it, which suits displacement fields).
  • apply_transforms(moving, reference, transforms, *, interpolation="linear", default_value=0.0): antsApplyTransforms with linear, nearestNeighbor or lanczosWindowedSinc; returns an ANTsImage like reference (or an array for a tuple reference). transforms is a list as ants.apply_transforms takes it. Both run on all CPU cores and need no GPU; they equal ANTs to float32 rounding (tests/test_post.py).
  • linear_session(fixed, moving, *, fixed_mask=None, winsorize=None, adapter=None): linear fits of one image pair (Mattes MI, regular sampling, one Rigid or Affine stage per fit from any start), the pair prepared, winsorized and uploaded once and its smoothed copies kept between fits, for a multi-start or a rigid fit followed by an affine one. session.register(stage=None, initial=None, use_mask=True, out_prefix=None, *, transform="rigid", mask=None) returns the collapsed affine (parameters, center) and the final MI value; initial is (12 parameters, centre) of an ITK affine (None = centres of intensity mass), and the fitted transform starts as the identity centred there, as an ANTs stage after --initial-moving-transform does; stage the fields of cohort_recipe()["rigid"]; transform "rigid" or "affine"; mask a fixed-image mask for this fit (None = the session's fixed_mask; ANTs' moving-image mask has no equivalent); out_prefix writes <prefix>0GenericAffine.mat. Use it in a with block. register_rigid(...) does one rigid fit in one call. rigid_session / RigidSession are the 0.3 names of linear_session / LinearSession.
  • gpu_available(), gpu_info(), fits_gpu(fixed, iso_mm=, channels=), iso_grid_dims(img, iso_mm).
  • Errors: GpuUnavailableError and GpuCapacityError (checked before any work: fall back to ANTs), RegistrationError, RegistrationCancelled.

Environment

The former DBSLOC_ names (for example DBSLOC_GPU_BACKEND for FASTWARP_GPU_BACKEND) are still read when the FASTWARP_ name is unset.

Variable Effect
FASTWARP_GPU_BACKEND vulkan, metal, dx12 or auto (default)
FASTWARP_GPU_ADAPTER pick the adapter whose name contains this text
FASTWARP_GPU_ALLOW_SOFTWARE=1 accept a software adapter (lavapipe, WARP); slow, for tests
FASTWARP_GPU_MEMORY_BUDGET_MB override the memory budget of the capacity check
FASTWARP_GPU_WAIT_TIMEOUT_S seconds to wait for the GPU before failing (default 300)

The capacity check uses the device memory the graphics API reports, halved on integrated GPUs (they share memory with the host, e.g. Apple Silicon).

Recipe

The schedule is the caller's: register_syn(..., recipe={"rigid": {...}, "affine": {...}, "syn": {...}}). The structure:

  • centre-of-mass initialisation, then rigid and affine on Mattes MI over the first channel (fields gradient_step, iterations, convergence_threshold, convergence_window, shrink_factors, smoothing_sigmas, sigma_units ("vox" / "mm"), bins, sampling_percentage, seed; regular sampling),
  • then syn on CC over every channel (gradient_step, update_field_variance, total_field_variance, cc_radius, channel_weights, and the same schedule fields),
  • winsorize [0.005, 0.995], no histogram matching, all on an isotropic grid (iso_mm) built from the fixed image.

A stage or field left out keeps the dbs-localizer cohort value, which cohort_recipe(channels) returns in full: Rigid and Affine MI[32 bins, regular 25 %], 1000x500x250x100; SyN [0.1, 3, 0] with CC[radius 4] (T1w + T2w: weight 0.5 each), 100x70x50x20; shrink 8x4x2x1, smoothing 3x2x1x0 vox. An unknown key, a value of the wrong type, mismatched level counts, or what the GPU kernels do not support (MI bins other than 32, a CC radius above 8) is a ValueError before any work. The result's "recipe" is the full recipe that ran.

Tests

The commands are under Development below; the same commands with the CI settings, the tests against real ANTs and the software-GPU runs are in docs/testing.md.

uv run --no-sync pytest -rs   # -rs lists every skipped test and its reason

Development

The Python tools (maturin, pytest, ruff; ANTsPy in the ants group) are locked in uv.lock:

export UV_PYTHON=3.13   # ANTsPy has no Python 3.14 wheels yet; see below
uv sync --locked --no-install-project --group ants
uv run --no-sync maturin develop --uv --release && uv run --no-sync pytest   # Python tests (skip without a GPU)
PYO3_PYTHON=.venv/bin/python cargo nextest run --locked --workspace --features fastwarp-gpu/dev-tools   # Windows: .venv/Scripts/python.exe
cargo clippy --locked --workspace --all-targets --features fastwarp-gpu/dev-tools -- -D warnings

Development uses Python 3.14 (.python-version). ANTsPy, which the comparisons with ANTs need, has no 3.14 wheels yet, so work with the ants group sets UV_PYTHON=3.13, as CI does; without it a later uv sync rebuilds the environment on 3.14 and drops ANTsPy. The lock covers every Python the wheel supports, 3.11 and later. PYO3_PYTHON is the Python the binding's Rust tests are built against.

constraint-dependencies = ["scipy>=1.15"] keeps the resolver from trading SciPy down to 1.6 (no wheels, open advisories) for a newer NumPy; drop it once ANTsPy's dependencies resolve to a current SciPy without it.

Test variables (the former DBSLOC_ names are still read when the FASTWARP_ name is unset):

Variable Effect
FASTWARP_GPU_REQUIRE_ADAPTER=1 a missing GPU adapter fails the Rust and Python GPU tests instead of skipping them
FASTWARP_REQUIRE_ANTSPY=1 ANTsPy failing to import fails the Python tests instead of skipping the comparisons with ANTs
WGPU_FORCE_FALLBACK_ADAPTER=1 select software adapters only (with FASTWARP_GPU_ALLOW_SOFTWARE=1)
FASTWARP_ATLAS_INDEX_MAT path to an atlas index .mat for a fastwarp-matfile test; unset skips it, a missing file fails it
FASTWARP_UIPREFS_DIR folder of real .mat files for an #[ignore]d fastwarp-matfile test
FASTWARP_REG_AB_DIR folder of a real subject (ANTs outputs) for the #[ignore]d A/B tests in fastwarp-gpu
FASTWARP_REG_PROTO_DIR folder of prototype composite transforms for a fastwarp-reg test; unset skips it
FASTWARP_REG_ANTS_COMPOSITE path of a real ANTs composite .h5 for a fastwarp-reg test; unset skips it
FASTWARP_GPU_BENCH enables the #[ignore]d GPU benchmarks in syn_bench

The Rust tests that compare the engine with the real ANTs programs (antsRegistration, antsApplyTransforms, N4BiasFieldCorrection) are #[ignore]d. Run them with FASTWARP_ANTS_DIR set to the folder holding ANTs 2.6.5; unset, they skip, and a folder without the program fails them:

FASTWARP_ANTS_DIR=/path/to/ants/bin cargo nextest run --locked -p fastwarp-reg --run-ignored only \
  -E 'binary_id(fastwarp-reg::ants_compat) | binary_id(fastwarp-reg::coreg_metric) | binary_id(fastwarp-reg::n4_ants)'

CI (ci.yml) runs the Rust and Python tests on Linux with Mesa's software Vulkan driver, and fails when the adapter or ANTsPy is missing. full.yml runs the ANTs comparison tests on non-draft PRs, nightly when main moved and by hand, with the three programs from the official ANTs 2.6.5 Ubuntu 24.04 release, checked against the SHA256 sums in .github/ants-2.6.5-ubuntu-24.04.sha256 and cached. audit.yml runs cargo deny and uv audit when a lockfile or manifest changes and weekly; Dependabot opens one combined monthly PR. wheels.yml builds all wheels on a v* tag (and creates the GitHub release) or by hand (gh workflow run wheels). Release: bump version in Cargo.toml ([workspace.package]; the wheel takes it from there), add a CHANGELOG.md section, tag v<version>.

Source and credit

crates/fastwarp-{core,niftiio,matfile,reg,gpu} are copies of the registration engine of Wyss DBS Localizer, the project in which the code was first developed, taken at revision 90c1df3 (2026-11-10) of an earlier standalone copy of that engine, which this repository replaces (ENGINE_SOURCE names that revision); later changes are in CHANGELOG.md. crates/fastwarp-py is the Python binding (PyO3). Please cite the engine as in CITATION.cff.

Metadata

Release files for fastwarp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastwarp 0.1.0
File Size Uploaded Provenance Actions
fastwarp-0.1.0.tar.gz 393.0 kB With provenance Details for fastwarp-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for fastwarp 0.1.0
File Actions
fastwarp-0.1.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for fastwarp-0.1.0-cp311-abi3-win_amd64.whl
fastwarp-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details for fastwarp-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl
fastwarp-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details for fastwarp-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl
fastwarp-0.1.0-cp311-abi3-macosx_11_0_x86_64.whl CPython 3.11 abi3 macOS 11.0+ x86-64 Details for fastwarp-0.1.0-cp311-abi3-macosx_11_0_x86_64.whl
fastwarp-0.1.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for fastwarp-0.1.0-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 16.7 MB

Release files / fastwarp-0.1.0.tar.gz

Download URL fastwarp-0.1.0.tar.gz
Size 393.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fb229ae5d390ec6f33d3415856d2455dce7a39e228c23fc906322ddb3ebec5d6
BLAKE2b-256 checksum
How to use checksums
352f41e264ead6c3aa1514ce1a35f7e3175199982f2c4029e565483e25bde5f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / fastwarp-0.1.0-cp311-abi3-win_amd64.whl

Download URL fastwarp-0.1.0-cp311-abi3-win_amd64.whl
Size 3.5 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fa7b2a6472ce909d8ed9637baac7568986c04206b622d406c4de0aa5b01415d2
BLAKE2b-256 checksum
How to use checksums
cc34d0d6009cdc33acb8759b064cd992ba1c809402006d8ad79fd5dface9c4af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / fastwarp-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL fastwarp-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl
Size 3.5 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
8eaff0ae747f890b25fdae4b63a36ee01d80e10209adf086d541a447020e4c70
BLAKE2b-256 checksum
How to use checksums
ee18d35b6cbd9d2d55e1d5ce8e6a312591ba430659dcdda61750a01dc0b215db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / fastwarp-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL fastwarp-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl
Size 3.6 MB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
ae85d00f6a4d8d6da7504fc69d3fd56b19e06b625aabe65ea180c2ab55673c91
BLAKE2b-256 checksum
How to use checksums
def089698d08ae1dc11af763e6a6782b0452d3d9306263e86fa6f3d10af58fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / fastwarp-0.1.0-cp311-abi3-macosx_11_0_x86_64.whl

Download URL fastwarp-0.1.0-cp311-abi3-macosx_11_0_x86_64.whl
Size 2.9 MB
Tags CPython 3.11 abi3 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
f9d15a85a19e992258174d8d29486ae8a113c864710ea9d121e38aac35eecb57
BLAKE2b-256 checksum
How to use checksums
3121180932b2a76b2d0576db9f4d860d23a49e8532c3ea4f1236ef885892e230
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / fastwarp-0.1.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL fastwarp-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Size 2.8 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ff25de161a83caab0ecb55d94440064d5563959603713d631e1f41ca70a64d4b
BLAKE2b-256 checksum
How to use checksums
27be11b4fd831a63d368ca575e2fe36822842a4ce33b420149faa0f2bc30f944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for fastwarp 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for fastwarp-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

6 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page