# Euclidean neural networks¶

## What is `e3nn`

?¶

`e3nn`

is a python library based on pytorch to create equivariant neural networks for the group \(O(3)\).

## Where to start?¶

Guide to the

`Irreps`

: Irreducible representationsGuide to implement a Convolution

The simplest example to start with is Tetris Polynomial Example.

Guide to implement a Transformer

## Demonstration¶

All the functions to manipulate rotations (rotation matrices, Euler angles, quaternions, convertions, …) can be found here Parametrization of Rotations.
The irreducible representations of \(O(3)\) (more info at Irreps) are represented by the class `Irrep`

.
The direct sum of multiple irrep is described by an object `Irreps`

.

If two tensors \(x\) and \(y\) transforms as \(D_x = 2 \times 1_o\) (two vectors) and \(D_y = 0_e + 1_e\) (a scalar and a pseudovector) respectively, where the indices \(e\) and \(o\) stand for even and odd – the representation of parity,

```
import torch
from e3nn import o3
irreps_x = o3.Irreps('2x1o')
irreps_y = o3.Irreps('0e + 1e')
x = irreps_x.randn(-1)
y = irreps_y.randn(-1)
irreps_x.dim, irreps_y.dim
```

```
(6, 4)
```

their outer product is a \(6 \times 4\) matrix of two indices \(A_{ij} = x_i y_j\).

```
A = torch.einsum('i,j', x, y)
A
```

```
tensor([[-0.1529, 1.1014, 0.9727, -0.4403],
[-0.0310, 0.2236, 0.1975, -0.0894],
[ 0.1444, -1.0403, -0.9188, 0.4159],
[-0.2630, 1.8946, 1.6733, -0.7574],
[-0.3386, 2.4393, 2.1543, -0.9752],
[ 0.3474, -2.5022, -2.2098, 1.0003]])
```

If a rotation is applied to the system, this matrix will transform with the representation \(D_x \otimes D_y\) (the tensor product representation).

Which can be represented by

```
R = o3.rand_matrix()
D_x = irreps_x.D_from_matrix(R)
D_y = irreps_y.D_from_matrix(R)
plt.imshow(torch.kron(D_x, D_y), cmap='bwr', vmin=-1, vmax=1);
```

This representation is not irreducible (is reducible). It can be decomposed into irreps by a change of basis. The outerproduct followed by the change of basis is done by the class `FullTensorProduct`

.

```
tp = o3.FullTensorProduct(irreps_x, irreps_y)
print(tp)
tp(x, y)
```

```
FullTensorProduct(2x1o x 1x0e+1x1e -> 2x0o+4x1o+2x2o | 8 paths | 0 weights)
```

```
tensor([ 0.9900, 2.9152, -0.1529, -0.0310, 0.1444, -0.2630, -0.3386, 0.3474,
0.5865, -0.4243, 0.5297, 0.8731, -1.2338, -0.5417, -1.0470, 0.8459,
-0.4582, -0.7129, -0.4847, -2.3049, 2.9080, 0.5771, -2.2521, -0.6324])
```

As a sanity check, we can verify that the representation of the tensor prodcut is block diagonal and of the same dimension.

```
D = tp.irreps_out.D_from_matrix(R)
plt.imshow(D, cmap='bwr', vmin=-1, vmax=1);
```

`FullTensorProduct`

is a special case of `TensorProduct`

, other ones like `FullyConnectedTensorProduct`

can contained weights what can be learned, very useful to create neural networks.