TorchPfaffian: PyTorch-Based Pfaffian Computation
Description
TorchPfaffian is a Python package for efficiently computing the Pfaffian of skew-symmetric matrices using PyTorch. Designed as a PyTorch-based alternative to pfapack, it enables GPU acceleration and supports automatic differentiation, making it particularly useful in physics, quantum computing, and machine learning applications.
Features:
- Efficient Pfaffian computation for skew-symmetric matrices
- GPU acceleration via PyTorch
- Support for automatic differentiation
- Seamless integration with PyTorch tensors
Installation
With python and pip installed, run the following commands to install TorchPfaffian:
pip install torchpfaffian
For development, this project uses uv. Clone the repository and set up the environment with:
uv sync --dev --extra cpu
Use the cu128 or cu130 extra instead of cpu to install a CUDA-enabled build of PyTorch. See
.github/CONTRIBUTING.md for the full contribution workflow.
Native acceleration (optional)
A Rust-accelerated signed-Pfaffian strategy (RustPfaffianParlettReid) is available when the
package is built with its native extension. Building from source requires a Rust toolchain
(https://rustup.rs); the project builds with maturin:
uv run maturin develop --release -m rust/Cargo.toml
Use --release for an optimized build: maturin develop compiles in debug mode by default,
which makes the Rust kernel much slower. Installing a prebuilt wheel (or maturin build) is already
optimized, so this only matters for local development builds.
If the native extension is not present, the package still works using the pure-Python strategies.
Usage
import torch
from torch_pfaffian import pfaffian
# Any skew-symmetric matrix of shape (..., 2n, 2n).
matrix = torch.tensor([[0.0, -3.0], [3.0, 0.0]])
pf = pfaffian(matrix) # signed Pfaffian (default)
magnitude = pfaffian(matrix, sign=False) # |pf|, using the faster det-based path
pfaffian() selects a strategy from the input: sign=True (the default) returns the
signed Pfaffian, using the native RustPfaffianParlettReid when the extension is built and
falling back to the pure-Python PfaffianParlettReid otherwise; sign=False returns the magnitude
using a determinant-based strategy (PfaffianFDBPf when gradients are needed, otherwise
PfaffianDet). For explicit strategy selection, use get_pfaffian_function(name).
Important Links
- Documentation at https://MatchCake.github.io/TorchPfaffian/.
- Github at https://github.com/MatchCake/TorchPfaffian/.
Found a bug or have a feature request?
License
Acknowledgements
Citation
Repository:
@misc{torchpfaffian_Gince2025,
title={Torch Pfaffian},
author={Jérémie Gince},
year={2025},
publisher={Université de Sherbrooke},
url={https://github.com/MatchCake/TorchPfaffian},
}
Metadata
Release files for torchpfaffian 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torchpfaffian-0.0.5.tar.gz | 31.7 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torchpfaffian-0.0.5-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| torchpfaffian-0.0.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| torchpfaffian-0.0.5-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 1.1 MB
Release files / torchpfaffian-0.0.5.tar.gz
| Download URL | torchpfaffian-0.0.5.tar.gz |
|---|---|
| Size | 31.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7fb8b259da91bf6368159c4803ee66422c717ad08a647dcbea0cb899723915b2
|
|
BLAKE2b-256 checksum How to use checksums |
98b152b741b6dc99b681fa05e29786c25f8f59d5da3b4bba5d64cf40c9e70fd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 13, 2026.
Transparency logRelease files / torchpfaffian-0.0.5-cp310-abi3-win_amd64.whl
| Download URL | torchpfaffian-0.0.5-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 275.7 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0d1a24309eb72b997caf9a50b0b9d8bb139f05070c9154605af418407f400f34
|
|
BLAKE2b-256 checksum How to use checksums |
035ffcd64680da45fff3fe0733f602e443c4548342f4357b0150e638c15148cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 13, 2026.
Transparency logRelease files / torchpfaffian-0.0.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | torchpfaffian-0.0.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 392.4 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
66973fd6e0aab694040ea4613957ceb570369183d264ea08dc8427096ed1a54b
|
|
BLAKE2b-256 checksum How to use checksums |
0efaa76b9cab3944fcc9544f276658929c474129c5ec96dd9ca0603bd6aa7673
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 13, 2026.
Transparency logRelease files / torchpfaffian-0.0.5-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | torchpfaffian-0.0.5-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 383.9 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3939ad259db3f727d6b84f4b00d24eded0052e650637ad9c02f9bf0dac7d1ec3
|
|
BLAKE2b-256 checksum How to use checksums |
fce979895965d21f796a52193343738d43ff69720ad4f25498e5d83bf38eeb29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 13, 2026.
Transparency log