A high-performance, object-oriented symbolic tensor engine for General Relativity.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file einsteinengine-1.0.0.tar.gz.
File metadata
- Download URL: einsteinengine-1.0.0.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdbf94aa3b19a7d23b375f8946096264efa0ea5b9f0f1d93752aaed7a84e9067
|
|
| MD5 |
468877934344d63a0e869e732ede9087
|
|
| BLAKE2b-256 |
018f1c4e7dd86757b75815370c8ba42905cc91894f9d74e433d39d1e393f3f60
|
Provenance
The following attestation bundles were made for einsteinengine-1.0.0.tar.gz:
Publisher:
publish.yml on RSalazarD/EinsteinEngine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
einsteinengine-1.0.0.tar.gz -
Subject digest:
fdbf94aa3b19a7d23b375f8946096264efa0ea5b9f0f1d93752aaed7a84e9067 - Sigstore transparency entry: 2011227605
- Sigstore integration time:
-
Permalink:
RSalazarD/EinsteinEngine@a4b078039f898e75dc0b27ef2ba80e0c99c4c63d -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/RSalazarD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a4b078039f898e75dc0b27ef2ba80e0c99c4c63d -
Trigger Event:
push
-
Statement type:
File details
Details for the file einsteinengine-1.0.0-py3-none-any.whl.
File metadata
- Download URL: einsteinengine-1.0.0-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24139e199d1d53950fc5fc24c97e489b633848e32704856fbdf4dfc1791164f5
|
|
| MD5 |
6019a1d1c8222373abc16103b7599bf2
|
|
| BLAKE2b-256 |
3e16e792ae42e7314dcea8ae29d0a434e3ae0b11fe7a0d55638d22f6a231b5c8
|
Provenance
The following attestation bundles were made for einsteinengine-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on RSalazarD/EinsteinEngine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
einsteinengine-1.0.0-py3-none-any.whl -
Subject digest:
24139e199d1d53950fc5fc24c97e489b633848e32704856fbdf4dfc1791164f5 - Sigstore transparency entry: 2011227720
- Sigstore integration time:
-
Permalink:
RSalazarD/EinsteinEngine@a4b078039f898e75dc0b27ef2ba80e0c99c4c63d -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/RSalazarD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a4b078039f898e75dc0b27ef2ba80e0c99c4c63d -
Trigger Event:
push
-
Statement type: