Getting Started with iTensor

Set up the environment and perform your first tensor calculations for general relativity and differential geometry

Prerequisites

iTensor requires the following components:

Core Requirements

  • Python: Version 3.8 or higher
  • NumPy: For array operations and numerical computation
  • SymPy: For symbolic mathematics
  • SciPy: For numerical integration and special functions

For Advanced Features

  • C/C++ Compiler: GCC 9+, Clang 10+, or MSVC 2019+ for compiling extensions
  • CUDA Toolkit: Version 11.2+ for GPU acceleration (NVIDIA GPUs only)
  • OpenBLAS/LAPACK: For optimized linear algebra operations

Installation

Using PyPI (Recommended)

pip install itensorpy

For GPU acceleration support (requires CUDA Toolkit):

pip install itensorpy[cuda]

From Source

git clone https://github.com/itensor/itensorpy.git cd itensorpy pip install -e .

When installing from source, use pip install -e .[dev] to include development dependencies for contributing to the project.

Online Calculator

If you prefer not to install anything, use the web calculator at https://itensor.online.

The online calculator provides:

  • Metric definition and tensor calculation interface
  • Step-by-step derivation visualization
  • LaTeX export for publications
  • Limited computational capabilities compared to the full package

First Steps: Computing the Schwarzschild Tensors

Let's compute the Ricci tensor for the Schwarzschild metric:

from itensorpy import Metric # Create a Schwarzschild metric with mass M=1 schwarzschild = Metric.schwarzschild(M=1) print(schwarzschild) # Calculate the Christoffel symbols christoffel = schwarzschild.compute_christoffel_symbols() # Calculate and display the Ricci tensor ricci = schwarzschild.compute_ricci_tensor() print(ricci.display())

Expected output:

Schwarzschild metric:
ds² = -(1 - 2M/r)dt² + (1 - 2M/r)⁻¹dr² + r²dθ² + r²sin²θdφ²

Ricci tensor components:
R_{00} = 0
R_{01} = 0
R_{02} = 0
R_{03} = 0
R_{10} = 0
R_{11} = 0
R_{12} = 0
R_{13} = 0
R_{20} = 0
R_{21} = 0
R_{22} = 0
R_{23} = 0
R_{30} = 0
R_{31} = 0
R_{32} = 0
R_{33} = 0

All components are zero, confirming the Schwarzschild metric is a vacuum solution to Einstein's field equations.

Computing the Einstein Tensor

# Calculate the Einstein tensor einstein = schwarzschild.compute_einstein_tensor() print(einstein.display()) # Verify the vacuum solution: G_μν = 0 print("Maximum absolute component value:", einstein.max_abs_component())

If you want to numerically evaluate tensors at specific coordinates, use:

# Evaluate Riemann tensor at r=10M riemann_at_r10 = schwarzschild.compute_riemann_tensor().evaluate(r=10) print(riemann_at_r10[0, 1, 0, 1]) # R^t_{rtr} component

Creating a Custom Metric

Define your own metric using symbolic variables:

from itensorpy import Metric from sympy import symbols, cos, sin, exp # Define coordinate symbols t, r, theta, phi = symbols('t r theta phi') # Define a simple wormhole metric alpha = 1 # Wormhole throat parameter g_tt = -exp(2*alpha) g_rr = 1 g_thth = (r**2 + alpha**2) g_phph = (r**2 + alpha**2) * sin(theta)**2 # Create the metric from components wormhole = Metric([t, r, theta, phi], [ [g_tt, 0, 0, 0], [0, g_rr, 0, 0], [0, 0, g_thth, 0], [0, 0, 0, g_phph] ], name="Ellis-Bronnikov Wormhole") # Compute the scalar curvature R = wormhole.compute_scalar_curvature() print("Scalar curvature R =", R.simplify())

Important Note on Coordinates

iTensor uses the convention that timelike coordinates come first in the coordinate list, followed by spacelike coordinates. This affects the signature of the metric and the sign conventions in tensor calculations.