e3nn

0.6.0 · active · verified Wed Apr 15

e3nn is a Python library built on PyTorch for developing Euclidean (E(3)) equivariant neural networks. It focuses on symmetries related to 3D rotations, translations, and mirrors, providing fundamental mathematical operations like tensor products and spherical harmonics. The library is under active development, with version 0.6.0 being the current release, and follows a release cadence where the second version number is incremented for breaking changes.

Warnings

Install

Imports

Quickstart

This example demonstrates how to define irreducible representations (Irreps), apply a linear transformation, and compute a tensor product using e3nn's o3 submodule. It showcases basic operations for building equivariant neural networks.

import torch
from e3nn import o3

# Create a random array made of scalar (0e) and a vector (1o) representations
# '0e' denotes a scalar with even parity, '1o' denotes a vector with odd parity.
irreps_in = o3.Irreps("0e + 1o")
x = irreps_in.randn(-1)

# Define output representations and apply a linear layer
irreps_out = o3.Irreps("2x0e + 2x1o") # Two scalars and two vectors
linear = o3.Linear(irreps_in=irreps_in, irreps_out=irreps_out)
y = linear(x)

# Compute a tensor product of the input with itself
tp = o3.FullTensorProduct(irreps_in1=irreps_in, irreps_in2=irreps_in)
z = tp(x, x)

print(f"Input (x) shape: {x.shape}, irreps: {irreps_in}")
print(f"Linear output (y) shape: {y.shape}, irreps: {irreps_out}")
print(f"Tensor product output (z) shape: {z.shape}, irreps: {tp.irreps_out}")

# For performance, modules can optionally be compiled with torch.compile
# tp_pt2 = torch.compile(tp, fullgraph=True)
# z_pt2 = tp_pt2(x, x)
# torch.testing.assert_close(z, z_pt2)

view raw JSON →