Skip to main content
physure

Unit-aware, dimension-correct physics computing — from a shared Rust core

The same dimensional analysis and uncertainty engine, exposed as a standalone DSL (phs), this Python library, a Rust crate, and a JVM package — with zero overhead under torch.compile / jax.jit where it matters.

PyPI crates.io Maven Central CI Python 3.11–3.14 License: MIT


This is the Python package. physure also ships as a standalone CLI/DSL that needs no Python (PHS), a pure Rust crate, and JVM bindings on Maven Central — see the project README for all four and INSTALL.md for every install path.

Why physure?

Most unit libraries make you choose between correctness and speed. physure (physics + measure) refuses the trade-off:

  • Correlated uncertainty propagation. Full sparse-covariance tracking between quantities (GUM-style), not just independent error bars. If x and y share history, x - y knows it.
  • Native-speed dimensional analysis. Unit arithmetic runs in Rust (~50 ns per operation) with rational exponents — no floating-point drift in dimensions, zero-copy buffer FFI to NumPy.
  • ML-ready. Quantity wraps NumPy, PyTorch, and JAX arrays. Under @physure.jit, units are validated at trace time and evaporate at runtime: ~1.17× vs. raw compiled PyTorch.
  • Static unit checking. A mypy plugin narrows Q_(3, "m/s") to Quantity[..., Literal["m/s"]], so unit mismatches can fail before your code even runs.
  • Zero runtime dependencies. pip install physure pulls in nothing else. NumPy/PyTorch/JAX/pandas support activates automatically when those packages are present.

Quick start

from physure import Q_

d = Q_(10, "km")
t = Q_(2, "hr")
print((d / t).to("m/s"))    # 1.3888888888888888 m/s

# Uncertainty propagates automatically — correlations included
g = Q_(9.8, "m/s^2", uncertainty=0.02)
m = Q_(2.5, "kg", uncertainty=0.001)
E = m * g * Q_(12, "m")
print(E.to("J"))            # (294.0 ± 0.61) J

Or straight from the command line — physure ships a unit-aware calculator and REPL:

$ python -m physure "500 N / 2 m^2 => kPa"
0.25 kPa

Highlights

Units that vanish at compile time

@physure.jit traces your function once, validates every dimension in Rust, then runs on raw tensors — dimensional safety with no per-call cost:

from physure import Q_, jit

@jit
def kinetic_energy(mass, velocity):
    return 0.5 * mass * velocity**2

kinetic_energy(Q_(10.0, "kg"), Q_(5.0, "m/s"))   # 125.0 kg·m²/s²
kinetic_energy(Q_(1.0, "m"), Q_(1.0, "s"))       # raises at trace time: incompatible units

Works with plain floats, NumPy arrays, PyTorch tensors (via __torch_dispatch__ + torch.compile), and JAX (jax.jit).

Uncertainty done properly

Choose the propagation mode globally or per-block:

import physure

physure.propagation_mode("uncorrelated")   # independent errors (default: correlated)

with physure.uncertainty_mode("uncorrelated"):
    ...                                    # scoped override

Backends include Gaussian (first-order), Monte Carlo, and Unscented Transform. Covariance lives in a sparse Rust store, so large lineages stay fast and memory stays flat.

The default is correlated because the alternative is quietly wrong: with independent errors x - x reports σ·√2 instead of zero, which looks plausible enough to publish. [Settings] propagation_mode in physure.conf sets it for a project, and both the core and PHS read it, so they cannot disagree.

Batteries included, loaded lazily

Pandas ExtensionArray, pydantic validation, SymPy symbolic quantities, unit-aware torch.nn layers, and Arrow IPC serialization each activate only when you use them. Cold import stays around 20 ms.

How it compares

physure pint astropy.units unyt
Correlated uncertainty (covariance) ✅ — — —
Built-in uncertainty propagation ✅ via uncertainties limited —
Rust-accelerated core ✅ — — —
torch.compile / jax.jit compatible ✅ — — —
Static unit checking (mypy) ✅ — — —
Standalone CLI/DSL, no Python required ✅ — — —
Runtime dependencies none none astropy stack numpy
Ecosystem maturity new ✅ mature ✅ mature mature

If you need a battle-tested converter with a decade of integrations, pint and astropy are excellent. physure is for when you also need uncertainty you can defend and units inside compiled ML code.

Performance

Benchmark Result
Cold import ~21 ms
Unit multiply/divide (Rust core) ~54 ns
Scalar add with dimension check ~40 ns
10⁶-element tensor op, @torch.compile 1.17× vs. pure PyTorch
Covariance propagation (sparse blocks) ~7 µs

Full methodology and reproduction steps: BENCHMARKS.md.

Installation

pip install physure            # Rust-compiled wheel, no other dependencies
pip install "physure[numpy]"   # + NumPy/SciPy/Numba acceleration
pip install "physure[torch]"   # + PyTorch backend
pip install "physure[jax]"     # + JAX backend
pip install "physure[all]"     # everything

From source

git clone https://github.com/Alexisrx96/physure
cd physure
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh   # Rust, if needed
cd physure-python
maturin develop --release
uv sync --group dev

Architecture

physure/                     # Cargo workspace root
├── physure-core/            # 🦀 Pure Rust physics engine — no FFI deps
│   └── src/                 #    units, quantity, covariance, uncertainty,
│                            #    symbolic, Arrow serialization
└── physure-python/          # 🐍 PyO3 bindings + Python application layer (this package)
    └── physure/
        ├── domain/          # Quantity, units, dimensions, uncertainty
        ├── application/     # Q_ factory, unit-system context, startup
        ├── backends/        # NumPy / PyTorch / JAX adapters
        ├── _jit/            # tracing + compile-time dimension checks
        ├── ext/             # IO, pandas, numba, chemistry, symbolic regression,
        │                    #   AOT compiler, PHS plugin loader
        └── nn/              # unit-aware neural network layers

The rule: physure-core is the single source of truth. All math lives in Rust; Python is a thin, zero-copy translation layer.

Documentation

Contributing

Issues and PRs are welcome. The quality bar is enforced in CI: ruff clean, tests green on Python 3.11–3.14 with ≥ 80 % coverage, and zero new SonarQube violations. See CLAUDE.md for the full development guide.

License

MIT — Irvin Torres

Metadata

Release files for physure 0.3.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 physure 0.3.0
File Size Uploaded Provenance Actions
physure-0.3.0.tar.gz 1.2 MB With provenance Details for physure-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for physure 0.3.0
File Actions
physure-0.3.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for physure-0.3.0-cp311-abi3-win_amd64.whl
physure-0.3.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for physure-0.3.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
physure-0.3.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for physure-0.3.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
physure-0.3.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for physure-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
physure-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for physure-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 12.1 MB

Release files / physure-0.3.0.tar.gz

Download URL physure-0.3.0.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
fbb246d904e77ca859532475ca09840660716e048bb803fda4861c749d6347da
BLAKE2b-256 checksum
How to use checksums
3e3a2ce38f565a850a39c0721deb4d655c1e24efb18fed86d06ba09a4c67d8fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Oct 30, 2026.

Transparency log

Release files / physure-0.3.0-cp311-abi3-win_amd64.whl

Download URL physure-0.3.0-cp311-abi3-win_amd64.whl
Size 2.2 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
158b0d0f365120689e5e018b92afc975c24307e3d6a8f2c697436dfc62f9e672
BLAKE2b-256 checksum
How to use checksums
16ca44f9e271baace256d40cb96747eaaab792f885c83b64d153618b13269bac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Oct 30, 2026.

Transparency log

Release files / physure-0.3.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL physure-0.3.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 2.2 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
7829e900ff58144ce7a8f715e4c23f3200fbb52c86e36d82980d014b1f268f1c
BLAKE2b-256 checksum
How to use checksums
7886d6c24946e7528f9b0d9afd000bbb26367d7b1c32dface7cc2a009f4767b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Oct 30, 2026.

Transparency log

Release files / physure-0.3.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL physure-0.3.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 2.1 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a4c11656ecbb63fd54b450a6ddd105750466e4c10fc49670bedfa15f1919a02e
BLAKE2b-256 checksum
How to use checksums
5747376de28889dd415a2125f62204b1f1d4bb5feae996f919e7ff889d94b602
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Oct 30, 2026.

Transparency log

Release files / physure-0.3.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL physure-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
Size 2.1 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
db41711fe57fd7dfa971a7a51de5156f8dcd90ad84325f09b0684d777cfd8d98
BLAKE2b-256 checksum
How to use checksums
b093533afde69289b70de94048a3d47553b7e92c4a16f5311396c28473ea9d19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Oct 30, 2026.

Transparency log

Release files / physure-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL physure-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 2.2 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c42f7aca8fa9eba1fda3e2bf3611b0e40259760f20759e6c50751b79181447d5
BLAKE2b-256 checksum
How to use checksums
f31b51822ea2a8e4a0ccb6113d32cdb697230f4906562b3337960d2d231a6d61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Oct 30, 2026.

Transparency log

Security for physure 0.3.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 physure-0.3.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 Oct 30, 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.

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