Phaethon
The End-to-End Physics-Constrained Scientific Computing & Sci-ML Framework.
Phaethon is a Python framework that unifies strict dimensional tensor algebra, Scientific Machine Learning (Sci-ML), and declarative data engineering. It is designed to ensure mathematical and physical integrity from the data ingestion layer to the final neural prediction.
📖 Documentation
For complete tutorials, API references, and architectural concepts, visit the official documentation:
⚡ Core Ecosystem
Phaethon builds directly upon the NumPy Array Protocol to operate as a zero-overhead native proxy, extending physical safety to modern ML ecosystems.
- Metaclass-Driven Algebra: Dynamic dimensional synthesis (e.g.,
u.Meter / u.Second -> MeterPerSecond). Inherently evaluates isomorphic firewalls, domain locks, and logarithmic math. - Scientific Compute: Physics-aware linear algebra (
ptn.linalg) and strictly bounded stochastic tensor generation (ptn.random). - Classic Sci-ML: Equips Scikit-Learn with dimensional meta-estimators, axiom validators, and automated Buckingham Pi feature synthesis.
- Neural PDEs (PINNs): Deep PyTorch integration. The
PTensorallows gradients to flow safely through physical laws using native calculus (pnn.grad,pnn.laplace). - Hybrid Data Engineering: Normalizes raw CSVs/DataFrames and enforces physical limits at the ingestion layer using a Rust backend, bridging directly into PyTorch via
.phxor.parquetformats.
⚛️ The Physics Engine: A Modern Alternative
Legacy unit libraries (like Pint or Astropy) rely on generic object wrappers and runtime string evaluation, resulting in high computational overhead and blind IDEs. Phaethon rebuilds dimensional analysis from the ground up using modern Python architecture:
- Zero-Overhead NumPy Proxies (NEP 13/18):
BaseUnitdoes not strictly subclassnp.ndarrayto avoid the brittle inheritance trap. Instead, it acts as a duck-typed protocol proxy, intercepting operations at the NumPy C-API layer. This allows it to natively fuse physics into floats, massivendarrays, and evenMaskedArrayswithout Python-level bottlenecks. - Metaclass JIT Caching: Physical dimensions are concrete Python classes. When dimensions interact algebraically, the
_PhaethonUnitMetadynamically synthesizes a new class blueprint in memory and caches it via LRU. Math operations operate at raw C-speed without string parsing. - Flawless Static Typing (DX): Because every dimension is a real class, IDEs (Mypy/Pylance) can strictly type-check physics out of the box (e.g.,
def calc(x: u.LengthUnit)will statically rejectu.Kilogram).
Scientific Computing Example
Phaethon extends dimensional safety into advanced linear algebra and stochastic generation.
import phaethon as ptn
import phaethon.units as u
# 1. Zero-overhead NumPy tensor creation
mass_matrix = ptn.array([[10.0, 2.0], [3.0, 5.0]], u.Kilogram)
force_vector = u.Newton([50.0, 25.0]) # or just instantiate directly
# 2. Native Linear Algebra - Automatically synthesizes Acceleration (m/s²)
acceleration = ptn.linalg.solve(mass_matrix, force_vector)
# 3. Logarithmic Algebra & Isomorphic Firewalls natively supported
signal = u.DecibelMilliwatt(30) + u.DecibelMilliwatt(30)
# Evaluates precisely to ~33.01 dBm via implicit linearization
🚀 End-to-End Example: Physics-Informed Neural Networks
The following workflow demonstrates Phaethon's end-to-end capability: parsing raw sensor data, extracting it into a dimension-aware dataset, and training a neural network to solve Burgers' Equation while mathematically guaranteeing dimensional integrity.
Step 1: Ingesting Data (Schema)
Normalize chaotic inputs, apply boundary constraints, and extract data into PyTorch-ready tensors.
import pandas as pd
import phaethon as ptn
import phaethon.units as u
# Declaratively enforce physical laws on incoming data
class SensorSchema(ptn.Schema):
x_pos: u.Meter = ptn.Field("Position", parse_string=True)
t_time: u.Second = ptn.Field("Time", min=0.0, on_error="clip")
# Load and normalize a raw DataFrame
messy_df = pd.read_csv("sensor_telemetry.csv")
clean_df = SensorSchema.normalize(messy_df)
# Bridge directly into PyTorch PTensors (Physics-Aware Tensors)
dataset = SensorSchema.astensor(clean_df, requires_grad=['x_pos', 't_time'])
x_sensor = dataset['x_pos'].tensor
t_sensor = dataset['t_time'].tensor
Step 2: Neural Architecture (Assembly)
Standard PyTorch layers cannot digest physical metadata. Phaethon's assemble securely standardizes and strips the units, feeding pure features to the network before resurrecting the physics on the output.
import torch.nn as nn
import phaethon.pinns as pnn
class ShockwaveNet(nn.Module):
def __init__(self):
super().__init__()
self.net = nn.Sequential(
nn.Linear(2, 128), nn.SiLU(),
nn.Linear(128, 128), nn.SiLU(),
nn.Linear(128, 1)
)
def forward(self, x_raw, t_raw):
# 1. Standardize inputs to base units safely
x_std = x_raw.asunit(u.Meter)
t_std = t_raw.asunit(u.Second)
# 2. Assemble physical tensors into naked PyTorch features
features = pnn.assemble(x_std, t_std, dim=-1)
# 3. Forward Pass & Resurrect Physical Identity (Velocity)
u_mag = self.net(features)
return pnn.PTensor(u_mag, unit=u.MeterPerSecond), x_std, t_std
Step 3: Native Calculus & Loss Evaluation
Train the network using native differential calculus. Phaethon automatically synthesizes derivative units, and the ResidualLoss strictly ensures dimensional balance on the PDE.
model = ShockwaveNet()
pde_loss_fn = pnn.ResidualLoss()
nu = pnn.PTensor(0.01 / 3.14159, unit=u.SquareMeterPerSecond)
# Forward pass
u_pred, x_s, t_s = model(x_sensor, t_sensor)
# Native PyTorch Calculus (Automatically synthesizes derived units)
du_dt = pnn.grad(u_pred, t_s, create_graph=True)
du_dx = pnn.grad(u_pred, x_s, create_graph=True)
d2u_dx2 = pnn.laplace(u_pred, x_s)
# Formulate the PDE Residual (Burgers' Equation)
# If dimensions mismatch (e.g., subtracting Force from Acceleration), execution halts.
pde_residual = du_dt + (u_pred * du_dx) - (nu * d2u_dx2)
# Compute Physics-Informed Penalty
loss = pde_loss_fn(pde_residual, target=0.0)
loss.backward()
📦 Installation & Modularity
Phaethon requires Python >= 3.11 and is compiled via Maturin (Rust backend). Install only the scientific stack you need to avoid environment bloat:
# Core Physics Engine Only
pip install phaethon
# Data Engineering (Pandas + Rapidfuzz)
pip install 'phaethon[dataframe]'
# Neural PDEs & PINNs (PyTorch)
pip install 'phaethon[torch]'
# Classic Sci-ML (Scikit-learn)
pip install 'phaethon[sklearn]'
# The Complete Sci-ML Ecosystem
pip install 'phaethon[all]'
🤝 Contributing
Contributions from the open-source community are greatly appreciated. Whether you are adding a new physical domain, optimizing the Rust backend, or expanding the Scikit-Learn transformers, your help is welcome.
Please read our CONTRIBUTING.md to set up your development environment, install the [dev] dependencies, and run the test suite.
📜 License
Distributed under the MIT License. See the LICENSE file for more information.
Metadata
Release files for phaethon 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| phaethon-0.4.2.tar.gz | 331.5 kB | With provenance | Details for phaethon-0.4.2.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| phaethon-0.4.2-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details for phaethon-0.4.2-cp311-cp311-win_amd64.whl |
| phaethon-0.4.2-cp311-cp311-manylinux_2_34_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.34+ x86-64 | Details for phaethon-0.4.2-cp311-cp311-manylinux_2_34_x86_64.whl |
| phaethon-0.4.2-cp311-cp311-macosx_11_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 11.0+ ARM64 | Details for phaethon-0.4.2-cp311-cp311-macosx_11_0_arm64.whl |
| phaethon-0.4.2-cp311-cp311-macosx_10_12_x86_64.whl | CPython 3.11 | CPython 3.11 | macOS 10.12+ x86-64 | Details for phaethon-0.4.2-cp311-cp311-macosx_10_12_x86_64.whl |
Total release size: 1.9 MB
Release files / phaethon-0.4.2.tar.gz
| Download URL | phaethon-0.4.2.tar.gz |
|---|---|
| Size | 331.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f39c158cdd3570aa2ce697ba508b4307a6d60233cae04ca4eb9f64b2b96747a
|
|
BLAKE2b-256 checksum How to use checksums |
1fbd938bbcdd6e6344a780a1076ad356974a859c07fe756e1f6586d1584ec878
|
| 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 Apr 11, 2026.
Transparency logRelease files / phaethon-0.4.2-cp311-cp311-win_amd64.whl
| Download URL | phaethon-0.4.2-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 308.4 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f9e2d633f0b7e620a652788f981a37e69be7b4fdba6a8da24d07e7003f3fc290
|
|
BLAKE2b-256 checksum How to use checksums |
82bb61f7408d9a454d9b6701d8c14439302392f49a4ebb7bb8ef97f953853750
|
| 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 Apr 11, 2026.
Transparency logRelease files / phaethon-0.4.2-cp311-cp311-manylinux_2_34_x86_64.whl
| Download URL | phaethon-0.4.2-cp311-cp311-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 452.8 kB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
4ce20a00e11cc4c70ae27be28cfb95da1513439420655cb6b91b9d453eec3609
|
|
BLAKE2b-256 checksum How to use checksums |
531867e5341c0e7c08f9d8ae25fa33a7a2b66be406800040c6158486b2b2bfeb
|
| 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 Apr 11, 2026.
Transparency logRelease files / phaethon-0.4.2-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | phaethon-0.4.2-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 411.7 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1769960bde30015fb2fa22192f834f0b1a755eff41a5a446224598b13fd85275
|
|
BLAKE2b-256 checksum How to use checksums |
46cb1a9289684faed90d3c02a5413e86a1b6a7c0efd19f90bd19210f06327eea
|
| 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 Apr 11, 2026.
Transparency logRelease files / phaethon-0.4.2-cp311-cp311-macosx_10_12_x86_64.whl
| Download URL | phaethon-0.4.2-cp311-cp311-macosx_10_12_x86_64.whl |
|---|---|
| Size | 417.0 kB |
| Tags | CPython 3.11 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
a4542ab23087e8dfd5edb30f3d8aac945731333f72e86a4602611a90e7a174a4
|
|
BLAKE2b-256 checksum How to use checksums |
10a4afa6eba2a321d5166441d09059ed6ee22ea44f746512a33834b82be03fb5
|
| 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 Apr 11, 2026.
Transparency logSecurity for phaethon 0.4.2
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 5 files in this release have been uploaded with provenance metadata.
Attestation for phaethon-0.4.2.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 Apr 11, 2026.
Transparency logA 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.