Skip to main content

General Relativity computation library built on Symbolica

Project description

Gravica

General Relativity computation library built on Symbolica (Rust-powered CAS).

Gravica computes the full GR tensor chain — from metric tensor to Einstein tensor — using Symbolica's high-performance symbolic algebra engine, achieving 23x–4300x speedup over EinsteinPy/SymPy.

Features

  • Full GR computation chain: Metric → Christoffel → Riemann → Ricci → Einstein → Weyl
  • Curvature invariants: Kretschner scalar, Ricci scalar
  • Schouten tensor, Stress-Energy-Momentum tensor
  • Geodesic equation generator
  • Index raising/lowering utilities
  • Built-in metrics: Minkowski, Schwarzschild, Kerr, FLRW, Reissner-Nordström, de Sitter, anti-de Sitter, Gödel
  • Lazy evaluation with caching
  • Cross-validated against EinsteinPy

Documentation

API reference: https://site.jijinbei.jp/gravica/

Quick Start

uv add gravica
from gravica.metrics.schwarzschild import schwarzschild
from gravica.christoffel import ChristoffelSymbols
from gravica.riemann import RiemannTensor
from gravica.ricci import RicciTensor, ricci_scalar
from gravica.einstein import EinsteinTensor

metric = schwarzschild()
christoffel = ChristoffelSymbols(metric)
riemann = RiemannTensor(christoffel)
ricci = RicciTensor(riemann)
einstein = EinsteinTensor(ricci)

# Verify vacuum solution: G_ab = 0
for a in range(4):
    for b in range(4):
        assert str(einstein[a, b]) == "0"

Benchmarks: Gravica vs EinsteinPy

All benchmarks measured on the same machine. Median of 3 runs with GC disabled.

Speedup Heatmap

Speedup Heatmap

Absolute Time Comparison

Time Comparison

Summary

Computation Minkowski Schwarzschild FLRW
Christoffel 33x 23x 23x
Riemann 91x 149x 147x
Ricci 72x 40x 296x
Ricci Scalar 472x 2021x 544x
Einstein 1391x 4342x 1029x

Metric inverse is ~0.3–0.5x (Python cofactor overhead), but this is amortized by the massive speedups in downstream computations.

Reproduce

uv run benchmarks/run_benchmarks.py    # Run benchmarks
uv run benchmarks/plot_benchmarks.py   # Generate charts

Architecture

MetricTensor → ChristoffelSymbols → RiemannTensor → RicciTensor → EinsteinTensor
                      ↓                   ↓              ↓       → WeylTensor
               GeodesicEquations   KretschnerScalar  SchoutenTensor
                                                              ↓
                                                     StressEnergyTensor
Module Computes
metric.py $g_{ab}$, $g^{ab}$, $\det(g)$
christoffel.py $\Gamma^a_{\ bc} = g^{ad},\tfrac{1}{2}(\partial_b,g_{ac} + \partial_c,g_{ab} - \partial_a,g_{bc})$
riemann.py $R^a_{\ bcd}$, $R_{abcd}$, $R^{abcd}$
ricci.py $R_{ab} = R^c_{\ acb}$, $R = g^{ab},R_{ab}$
einstein.py $G_{ab} = R_{ab} - \tfrac{1}{2},g_{ab},R$
weyl.py $C_{abcd}$ (Weyl conformal tensor)
kretschner.py $K = R_{abcd},R^{abcd}$ (Kretschner scalar)
geodesic.py $\ddot{x}^a + \Gamma^a_{\ bc},\dot{x}^b,\dot{x}^c = 0$
schouten.py $S_{ab} = \tfrac{1}{n-2}\bigl(R_{ab} - \tfrac{R,g_{ab}}{2(n-1)}\bigr)$
stress_energy.py $8\pi G,T_{ab} = G_{ab} + \Lambda,g_{ab}$
indexing.py Index raising / lowering for rank-2 tensors

Tests

uv run pytest

Verified properties:

  • Minkowski: All tensors $= 0$
  • Schwarzschild: $R_{ab} = 0$, $G_{ab} = 0$ (vacuum), $K = 12,r_s^2/r^6$
  • Riemann symmetries: $R^a_{\ bcd} = -R^a_{\ bdc}$
  • Christoffel known values: $\Gamma^r_{\ tt} = r_s(r-r_s)/(2r^3)$
  • de Sitter / anti-de Sitter: Ricci scalar matches analytic values
  • Geodesic equations: Free particle in Minkowski
  • Index roundtrip: Raise then lower recovers original tensor
  • EinsteinPy cross-validation: Christoffel and Ricci match

License

MIT

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

gravica-0.1.0.tar.gz (311.7 kB view details)

Uploaded Source

Built Distribution

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

gravica-0.1.0-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file gravica-0.1.0.tar.gz.

File metadata

  • Download URL: gravica-0.1.0.tar.gz
  • Upload date:
  • Size: 311.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for gravica-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7f56af61d63e11194f48dc50b0dce1accfd7586f43bf70c4abbed3cc4648c7ee
MD5 bcb151cfea5b656c4b53e381155dc6f3
BLAKE2b-256 339966986c33501973b787bccf4ec159c0a30eb8a65328962e313f31d311d021

See more details on using hashes here.

File details

Details for the file gravica-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gravica-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for gravica-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d41f6d6148666f63d8ee8487e8533bc0c4e5a435d7ee203e2b89c7adc24a3e1
MD5 9fa3f30c27a4c8f7be20b60a4ffba4c1
BLAKE2b-256 2df3a9b48bb8dfa40920fd2b3b97a8e8f47af501c795aef19d52e69c38a90efc

See more details on using hashes here.

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