PyTorch-based Pfaffian computation for skew-symmetric matrices.
Project description
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},
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchpfaffian-0.0.4.tar.gz.
File metadata
- Download URL: torchpfaffian-0.0.4.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b2bb907e841215226c97300f6bb53ba087221a0a054984d8c91fc90b6c0aef3
|
|
| MD5 |
e61660d4677986ebd9a5b60a27f6cf5c
|
|
| BLAKE2b-256 |
08765951ce47d2dfd230edaf2b056911359f55734402daa8d360c780a034c70e
|
Provenance
The following attestation bundles were made for torchpfaffian-0.0.4.tar.gz:
Publisher:
build_dist.yml on MatchCake/TorchPfaffian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchpfaffian-0.0.4.tar.gz -
Subject digest:
7b2bb907e841215226c97300f6bb53ba087221a0a054984d8c91fc90b6c0aef3 - Sigstore transparency entry: 1917035073
- Sigstore integration time:
-
Permalink:
MatchCake/TorchPfaffian@bd4a54e16ca34ba3c8cd64504efa2058418b298a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MatchCake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_dist.yml@bd4a54e16ca34ba3c8cd64504efa2058418b298a -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchpfaffian-0.0.4-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: torchpfaffian-0.0.4-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 238.7 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28a87f600f6f845b39394ccdb6b87b9e037bff3b3aa56db0b9618cdcb0f30371
|
|
| MD5 |
415b7df38764e7f2fc77b35b11ffe474
|
|
| BLAKE2b-256 |
80239b1e0d5ecc04b11da4e515c49acf4dffaa83b394db2e1b6569da93af1f2f
|
Provenance
The following attestation bundles were made for torchpfaffian-0.0.4-cp310-abi3-win_amd64.whl:
Publisher:
build_dist.yml on MatchCake/TorchPfaffian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchpfaffian-0.0.4-cp310-abi3-win_amd64.whl -
Subject digest:
28a87f600f6f845b39394ccdb6b87b9e037bff3b3aa56db0b9618cdcb0f30371 - Sigstore transparency entry: 1917035656
- Sigstore integration time:
-
Permalink:
MatchCake/TorchPfaffian@bd4a54e16ca34ba3c8cd64504efa2058418b298a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MatchCake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_dist.yml@bd4a54e16ca34ba3c8cd64504efa2058418b298a -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchpfaffian-0.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: torchpfaffian-0.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 360.4 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70efc27ddc46a8e7ac979688c77195dc4ec5b251caed9848e5beea5fce69eae2
|
|
| MD5 |
bac9f0a9ed0981b614bc23928f008133
|
|
| BLAKE2b-256 |
0ba2a6acbae1742431ba0967032d6d17c6bdaebb14fa0e64c24565417c7d5fec
|
Provenance
The following attestation bundles were made for torchpfaffian-0.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
build_dist.yml on MatchCake/TorchPfaffian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchpfaffian-0.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
70efc27ddc46a8e7ac979688c77195dc4ec5b251caed9848e5beea5fce69eae2 - Sigstore transparency entry: 1917035322
- Sigstore integration time:
-
Permalink:
MatchCake/TorchPfaffian@bd4a54e16ca34ba3c8cd64504efa2058418b298a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MatchCake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_dist.yml@bd4a54e16ca34ba3c8cd64504efa2058418b298a -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchpfaffian-0.0.4-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: torchpfaffian-0.0.4-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 350.8 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b0623135c40fe6587e935c2d5f6399022995aa43564c995bdf7a4ddccba3dd3
|
|
| MD5 |
63792bed3f903ab596daef54b515a850
|
|
| BLAKE2b-256 |
29d4855e880263d0194c0ef2e9578a776b683703d4ab476e9c0c420ee699c48b
|
Provenance
The following attestation bundles were made for torchpfaffian-0.0.4-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
build_dist.yml on MatchCake/TorchPfaffian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchpfaffian-0.0.4-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
0b0623135c40fe6587e935c2d5f6399022995aa43564c995bdf7a4ddccba3dd3 - Sigstore transparency entry: 1917035451
- Sigstore integration time:
-
Permalink:
MatchCake/TorchPfaffian@bd4a54e16ca34ba3c8cd64504efa2058418b298a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MatchCake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_dist.yml@bd4a54e16ca34ba3c8cd64504efa2058418b298a -
Trigger Event:
push
-
Statement type: