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 Python 3.11–3.14 License: MIT Rust core


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.0.tar.gz (781.0 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.0-cp311-abi3-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11+Windows x86-64

physure-0.2.0-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.0-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.0-cp311-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

physure-0.2.0-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.0.tar.gz.

File metadata

  • Download URL: physure-0.2.0.tar.gz
  • Upload date:
  • Size: 781.0 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.0.tar.gz
Algorithm Hash digest
SHA256 38d88377cee280ddb429297fcda230bfb99cd2a41ac19f21fe477ae551ab1721
MD5 fd830b861464ecc0312cff8b6f98881e
BLAKE2b-256 e9fd256b844c2456322524b65244505c48f6294a4f5e19c935d831f53e1249e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.0.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.0-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: physure-0.2.0-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.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a0ee1a81be483824eeeae1141f1e893f15b60359c845e0ba1af4e93b062b95ef
MD5 f3ac8091ed45079c86fd6d2fc3da6db5
BLAKE2b-256 54fca9d3b0a001daa77a6763223dfafb38d2f0e0c65e69607b2b640131092a06

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.0-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.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for physure-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1d401961d95c04828df24d281c7ec01f0b993888cd0c22b074e4cb5bc74f1aae
MD5 898fbf4957a61336bdb3fb6418e54104
BLAKE2b-256 694b1b9f2b15abec18df597c18eb155443836b70195401a37c99b4cf1ce7e1fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.0-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.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for physure-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fd6b4ea72cf355b1408cfedd3155e66696238e368b88b5c26f6e9cf89a7a510d
MD5 3586e3170167f47c08e4aa8786bd1ece
BLAKE2b-256 63020f9c3d93df5e268b2e0d389708dbe9737ba946aa1519cc245c62551f5a67

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.0-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.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for physure-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f11cb41c1e14fb0ea76af6bb20bf4dea09f8907a7d8dac592c1e34c3ab613bf
MD5 47e68657124f4979ea7bbf37172e7e1c
BLAKE2b-256 bb1f75b0a449dad83ba64883b7de9d923df192ee91eaf276c09725c2bed06600

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.0-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.0-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for physure-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5970b01d2168277c4d46c83e8d4383903d808c991b98c578a4d9352742777521
MD5 2b53e7854cc9a05f507cda3726d303cf
BLAKE2b-256 dd4def8390cb787d962e2025c23d9377ab185129b31f40e6b7ccd5b5db72610b

See more details on using hashes here.

Provenance

The following attestation bundles were made for physure-0.2.0-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