relativistic-simulator
Research-grade, lightweight Python simulator for 1D special-relativistic massive-particle dynamics under a constant external force.
This package is the ground-truth physics engine for a synthetic-data/ML research pipeline. It generates data from known equations; it does not discover physics and it does not contain an ML model.
Scientific assumptions
- flat Minkowski spacetime and special relativity;
- one spatial dimension;
- constant rest mass;
- externally applied constant 1D force;
- SI units;
- no gravity, curved spacetime, electromagnetic-field model, radiation reaction, quantum effects, or FTL dynamics.
The governing equation is dp/dt = F with p = gamma*m*v, not classical F = m*a.
Installation
pip install relativistic-simulator
pip install "relativistic-simulator[all]" # optional pandas + matplotlib
Development uses uv:
uv sync
Quick start
from relativistic_simulator import C, simulate
result = simulate(
mass=1000.0, force=1e6, initial_velocity=0.9 * C,
duration=100.0, dt=0.01,
)
print(result.beta)
print(result.gamma)
print(result.momentum)
print(result.kinetic_energy)
print(result.total_energy)
print(result.proper_time)
print(result.validate().summary())
simulate() returns a Trajectory exposing time, position, velocity, beta, gamma, momentum, kinetic_energy, total_energy, and proper_time, plus to_numpy(), to_dict(), to_dataframe(), and final_state().
Equations and numerical method
For initial momentum p0 = gamma0*m*v0:
p(t) = p0 + F*t
q(t) = p(t)/(m*c)
gamma(t) = hypot(1, q(t))
v(t) = c*q(t)/gamma(t)
E(t) = c*hypot(m*c, p(t))
K(t) = p(t)^2*c^2 / (E(t) + m*c^2)
x(t) = x0 + c*t*(q(t) + q0)/(gamma(t) + gamma0) [F != 0]
The position formula is algebraically equivalent to (K-K0)/F, but avoids catastrophic cancellation at high beta and small impulse. Proper time uses dτ = dt/gamma and a stable log1p rapidity-increment form. simulate(method="numerical") supplies an independent RK4 cross-check.
See docs/physics.md for derivations and precision details.
Relativity API
from relativistic_simulator import (
C, beta_from_velocity, velocity_from_beta, gamma_from_beta,
gamma_from_velocity, momentum_from_velocity, velocity_from_momentum,
energy_from_velocity, energy_from_momentum,
kinetic_energy_from_velocity, kinetic_energy_from_momentum, rest_energy,
)
gamma = gamma_from_beta(0.99999)
All functions accept scalars and NumPy arrays where practical. Massive-particle states must satisfy abs(v) < C and abs(beta) < 1; invalid states raise typed exceptions and are never silently clipped.
Dataset generation
from relativistic_simulator import generate_dataset
dataset = generate_dataset(
n_samples=100_000,
mass_range=(100.0, 10_000.0),
force_range=(1e4, 1e7),
beta_range=(0.0, 0.8),
time_range=(0.0, 100.0),
random_seed=42,
)
dataset.to_csv("train.csv")
print(dataset.input_columns)
print(dataset.output_columns)
print(dataset.validate().summary())
Generation is fully vectorized with NumPy and uses numpy.random.default_rng, so seeded datasets are reproducible without global randomness. Inputs are mass, force, initial_velocity, initial_beta, and time; targets are exact position, velocity, beta, gamma, momentum, kinetic_energy, total_energy, and proper_time.
Regimes are configurable rather than hard-coded:
low = generate_dataset(beta_range=(0.0, 0.5), random_seed=1)
relativistic = generate_dataset(beta_range=(0.5, 0.9), random_seed=2)
ultra = generate_dataset(beta_range=(0.9, 0.9999), random_seed=3)
training = generate_dataset(beta_range=(0.0, 0.8), random_seed=42)
extrapolation = generate_dataset(beta_range=(0.8, 0.9999), random_seed=43)
Validation
validate_trajectory and validate_dataset report quantitative errors for p = gamma*m*v, E = gamma*m*c², the energy-momentum invariant, central finite differences for dp/dt and dx/dt, proper time, initial conditions, velocity bound, and tau <= t. They use independent routes rather than merely repeating the generating expression.
report = result.validate()
print(report.max_energy_momentum_error)
print(report.max_force_error)
print(report.max_velocity_difference_error)
print(report.passed)
Optional plotting and classical comparison
from relativistic_simulator.plotting import plot_trajectory, plot_gamma_vs_beta
plot_trajectory(result, path="trajectory.png", show=False)
plot_gamma_vs_beta(path="gamma.png", show=False)
The classical module is comparison-only: it provides Newtonian p=m*v, K=0.5*m*v**2, and x=x0+v0*t+0.5*(F/m)*t**2. It is not used by the relativistic engine.
Examples
uv run python examples/basic_simulation.py
uv run python examples/high_beta.py
uv run python examples/generate_dataset.py
uv run python examples/benchmark.py
Development, testing, and build
uv sync
uv run pytest
uv build
The suite covers high beta through 0.99999c, invalid physical states, exact/RK4 agreement, vectorization, reproducibility, dataset validation, and optional plotting. uv build creates wheel and source distributions in dist/. Review and test those artifacts before any deliberate uv publish.
Precision and limitations
The numerical representation is IEEE-754 float64. The package rejects |v| >= c rather than clipping and rejects states for which floating-point arithmetic cannot represent a strictly subluminal velocity. It does not model gravity, curved spacetime, electromagnetic fields, variable mass, radiation reaction, quantum effects, or FTL/spacelike trajectories.
License
MIT License. See LICENSE.
Metadata
Release files for relativistic-simulator 0.1.3
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 |
|---|---|---|---|---|
| relativistic_simulator-0.1.3.tar.gz | 135.4 kB | Without provenance | Details for relativistic_simulator-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| relativistic_simulator-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for relativistic_simulator-0.1.3-py3-none-any.whl |
Total release size: 168.3 kB
Release files / relativistic_simulator-0.1.3.tar.gz
| Download URL | relativistic_simulator-0.1.3.tar.gz |
|---|---|
| Size | 135.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f69635aee10b22858bf3a81f84ef260dc7fad4ecb11073bac6e3bf7de5983b17
|
|
BLAKE2b-256 checksum How to use checksums |
d606764a54fb2e029856158fdb423637a990792d26e7b20e679db112a87b9b9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.14
|
Release files / relativistic_simulator-0.1.3-py3-none-any.whl
| Download URL | relativistic_simulator-0.1.3-py3-none-any.whl |
|---|---|
| Size | 32.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8365396fbfa058f317f2c5e94fc882a592a60d52174797edec9b9ad606811c7e
|
|
BLAKE2b-256 checksum How to use checksums |
4e91e2edd68e61b25661cedc948624d79921993a8b278442baf3750a492d2d3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.14
|
Security for relativistic-simulator 0.1.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.