PYTHON LIBRARY

iTENSORPY

A meticulously crafted Python library for symbolic tensor calculus and differential geometry with unparalleled precision.

EXAMPLES

ELEGANT SYNTAX

iTensorPy's intuitive API makes complex tensor operations straightforward and readable

Schwarzschild Spacetime

from itensorpy import *
# Define coordinates and parameters
t, r, theta, phi = symbols('t r theta phi')
M = symbols('M', positive=True)
# Define Schwarzschild metric
g = MetricTensor('g')
g[t,t] = -(1 - 2*M/r)
g[r,r] = 1/(1 - 2*M/r)
g[theta,theta] = r**2
g[phi,phi] = r**2 * sin(theta)**2
# Compute curvature tensors
Riemann = g.riemann_tensor()
Ricci = g.ricci_tensor()
R = g.ricci_scalar()
Einstein = g.einstein_tensor()
# Verify vacuum field equations
print(Einstein.simplify())
# Output: 0

Geodesic Equations

from itensorpy import *
import numpy as np
import matplotlib.pyplot as plt
# Use the Schwarzschild metric from before
# ...
# Generate geodesic equations
geodesic_eqs = g.geodesic_equations()
# Solve for a specific initial condition
initial_pos = [0, 10*M, np.pi/2, 0] # [t, r, θ, φ]
initial_vel = [1, 0, 0, 0.07] # Initial 4-velocity
# Numerically integrate
solution = geodesic_eqs.solve(
initial_position=initial_pos,
initial_velocity=initial_vel,
proper_time_range=(0, 1000),
steps=10000
)
# Extract trajectory in r-φ plane
r_values = solution[:, 1]
phi_values = solution[:, 3]

Maxwell's Equations in Curved Spacetime

from itensorpy import *
# Define spacetime and metric (can be any metric)
# ...
# Define electromagnetic field tensor
F = AntisymmetricTensor('F')
# Maxwell's equations in curved spacetime
# Homogeneous equation: dF = 0 (written in index notation)
dF = F.exterior_derivative()
print(dF.is_zero()) # Should be True for physically valid fields
# Inhomogeneous equation: ∇_μ F^μν = J^ν
J = TensorField('J', rank=(1,0)) # Four-current
maxwell_eq = Eq(
g.covariant_derivative(F, raised_indices=[(0,1)]),
J
)
print(maxwell_eq.components()) # Show equations by component
GETTING STARTED

INSTALLATION & SETUP

Get up and running with iTensorPy in minutes

Quick Installation

Install iTensorPy using pip:

pip install itensorpy

For GPU acceleration support:

pip install itensorpy[gpu]

System Requirements

  • Python 3.8+
  • NumPy ≥ 1.20.0
  • SymPy ≥ 1.8
  • SciPy ≥ 1.7.0
  • Optional: JAX ≥ 0.3.4 (for GPU acceleration)

Getting Started

After installation, import the library and start using it:

from itensorpy import *
# Hello World example
print("iTensorPy version:", __version__)
# Define a simple Euclidean space
x, y, z = symbols('x y z')
euclidean = MetricTensor('g')
euclidean[x,x] = 1
euclidean[y,y] = 1
euclidean[z,z] = 1
# Compute Christoffel symbols (should be zero in flat space)
connection = euclidean.christoffel_symbols()
print(connection.is_zero()) # True
Intuitive pythonic syntax
Comprehensive error messages
Extensive documentation and examples
TRANSFORM YOUR RESEARCH

Ready to Revolutionize
Your Tensor Calculations?

iTensorPy combines mathematical rigor with computational efficiency, enabling you to tackle complex physics problems with unprecedented clarity and speed.