Skip to main content

EinsteinEngine

EinsteinEngine is a symbolic tensor library for General Relativity built around a simple idea: make tensor calculations faster and more structured without giving up exact symbolic mathematics.

The project combines Python with SymEngine for the heavy symbolic work, and exposes an object-oriented API for common relativistic objects such as metrics, Christoffel symbols, curvature tensors, Ricci tensors, Einstein tensors, geodesics, tetrads and spin connections.

What the library can do today

EinsteinEngine currently provides a practical toolkit for symbolic GR workflows, including:

  • Metric tensor construction and validation
  • Metric inversion for diagonal and standard symbolic cases
  • Christoffel symbol computation
  • Riemann tensor construction
  • Ricci tensor and Ricci scalar computation
  • Einstein tensor construction
  • Geodesic equation generation
  • Tetrad and spin connection support
  • Tensor component access, contraction, index raising/lowering and basic tensor arithmetic
  • Rich LaTeX-style rendering for notebooks and a plain-text fallback for lighter output

The focus of the library is not only correctness, but also performance in symbolic pipelines that would otherwise become very expensive in pure SymPy.

Installation

From PyPI:

pip install einsteinengine

From source:

git clone https://github.com/RSalazarD/EinsteinEngine.git
cd EinsteinEngine
pip install -e .

Quick start

import sympy as sp
from einsteinengine.symbolic.metric import MetricTensor
from einsteinengine.symbolic.riemann import RiemannCurvatureTensor

# Coordinates and parameters
t, r, theta, phi = sp.symbols('t r theta phi', real=True)
M = sp.symbols('M', real=True)

# Schwarzschild metric
g_schwarzschild = [
    [-(1 - 2*M/r), 0, 0, 0],
    [0, 1/(1 - 2*M/r), 0, 0],
    [0, 0, r**2, 0],
    [0, 0, 0, r**2 * sp.sin(theta)**2],
]

metric = MetricTensor(g_schwarzschild, [t, r, theta, phi], name="Schwarzschild")
riemann = RiemannCurvatureTensor.from_metric(metric, verbose=False)

print(riemann.get_component(1, 0, 1, 0))

A typical output for the Schwarzschild case is the known exact component:

2*M*(2*M - r)/r**4

Current strengths

EinsteinEngine is particularly useful when you want to:

  • build symbolic curvature tensors from a metric,
  • test GR expressions quickly in notebooks or scripts,
  • compare symbolic performance against pure SymPy,
  • explore exact tensor structures without writing all the algebra by hand.

Benchmarks

A simple benchmark script is available in the benchmarks folder to compare EinsteinEngine against pure SymPy on a representative symbolic workload.

Run it from the project root with:

python benchmarks/compare_sympy_vs_einsteinengine.py

The script prints timing information for both engines and a rough speedup estimate.

Testing

The project includes a pytest suite covering core computations such as metric handling, curvature tensors, geodesics and rendering behaviour.

Run tests with:

pytest

Roadmap and future directions

This project is already usable for a broad set of symbolic GR tasks, but there is still room to grow. Possible future work includes:

  • more optimized tensor contractions and higher-rank workflows,
  • broader support for non-diagonal and more general metrics,
  • improved simplification strategies with configurable modes,
  • additional GR utilities such as more advanced invariants and field equations,
  • better documentation and more benchmark examples.

The goal is to keep the library practical today while expanding toward a more complete symbolic GR toolkit over time.

Release files for einsteinengine 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for einsteinengine 1.0.0
File Size Uploaded
einsteinengine-1.0.0.tar.gz 23.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for einsteinengine 1.0.0
File Interpreter ABI Platform
einsteinengine-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.9 kB

Release files / einsteinengine-1.0.0.tar.gz

Download URL einsteinengine-1.0.0.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fdbf94aa3b19a7d23b375f8946096264efa0ea5b9f0f1d93752aaed7a84e9067
BLAKE2b-256 checksum
How to use checksums
018f1c4e7dd86757b75815370c8ba42905cc91894f9d74e433d39d1e393f3f60
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 Jun 29, 2026.

Transparency log

Release files / einsteinengine-1.0.0-py3-none-any.whl

Download URL einsteinengine-1.0.0-py3-none-any.whl
Size 26.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24139e199d1d53950fc5fc24c97e489b633848e32704856fbdf4dfc1791164f5
BLAKE2b-256 checksum
How to use checksums
3e16e792ae42e7314dcea8ae29d0a434e3ae0b11fe7a0d55638d22f6a231b5c8
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 Jun 29, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page