Skip to main content

High-performance physical dimension engine. Rust-first, zero-copy FFI. Successor to physure.

Project description

physure

Unit-aware, dimension-correct computing for Python — powered by a Rust core

Units, dimensions, and correlated uncertainty tracked through every calculation, with zero overhead under torch.compile / jax.jit.

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


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("correlated")     # full covariance (default: uncorrelated)

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.

Batteries included, loaded lazily

Pandas ExtensionArray, pydantic validation, SymPy symbolic quantities, unit-aware torch.nn layers, Arrow IPC serialization, plotting helpers, and a physics-as-text DSL (stress = 500 N / 2 m^2) — each activates only when you use it. 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)
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
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
    └── 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/             # grammar DSL, IO, pandas, numba
        └── 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

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

physure-0.2.1.tar.gz (785.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

physure-0.2.1-cp311-abi3-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11+Windows x86-64

physure-0.2.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

physure-0.2.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

physure-0.2.1-cp311-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

physure-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file physure-0.2.1.tar.gz.

File metadata

  • Download URL: physure-0.2.1.tar.gz
  • Upload date:
  • Size: 785.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for physure-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ac8bec1a17b7900eead05ad37a386c38d1f15d76f1994f09f1f6601023cda1b6
MD5 e4a3c0618e1756ce01a1e92955b324d9
BLAKE2b-256 d096198710a5d28d53cf10a975f54139171c43a008c60a2628d7293693560fcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.1.tar.gz:

Publisher: release.yml on Alexisrx96/physure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file physure-0.2.1-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: physure-0.2.1-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for physure-0.2.1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cc657b133ffa89d0cd22adf71d1b3affedb4528e0dd7ae60c1f9df3112040815
MD5 cdebf75142e3a45e0201871aea8916de
BLAKE2b-256 8603763221cf206a70a953e1303d6c8c38492d03aa0c3e6cd892389c05cea903

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.1-cp311-abi3-win_amd64.whl:

Publisher: release.yml on Alexisrx96/physure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file physure-0.2.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for physure-0.2.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dcf7ffa5e84308651b05929cdb5efb6e2adcaebc0cde44f769929a2cd4a308ef
MD5 2b51143f1090734ddccae433a5c0dad0
BLAKE2b-256 a334ea873cb452d7cde27072a9a57d3fb1e202e7e42dd3bb3432c817bbd8ed7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Alexisrx96/physure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file physure-0.2.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for physure-0.2.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 80849cd87cf4b6c76347473df6bf81c0214ff6a40fbc4404a3b061c85cfc2b83
MD5 6d17c77574a3ebd295a23753ab71a592
BLAKE2b-256 1b2201b4ce0d5358a380123e66f00a21d7c0b1b0df00f53b0d5d3a96c6977a5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on Alexisrx96/physure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file physure-0.2.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for physure-0.2.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 742789b795a379d2bcb0b6b640cc77c7421e9d0e212b5be7dbf2021d0b0f707e
MD5 e50acb2a8452402d7657ba6d4ae34971
BLAKE2b-256 25558b2a37ac1169c156040a4862f19efb253ab906a7819b0e271a1b05507000

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.1-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on Alexisrx96/physure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file physure-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for physure-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6f57abc69ab5196c8ca3cfbd216c1f544153e7a8f263b7312aa54dd6cef1cb68
MD5 22fdd4279a2a59598b14e442bc82ea4a
BLAKE2b-256 0160a9b24fcb3ea9882b9021785c03300cb2ba31c1397b82dbbf0c2a6bb36beb

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on Alexisrx96/physure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page