Repository navigation
Diagrams
EinsumDiagram draws the tensor network of an einsum: the tensors are nodes, and each index is drawn by the number of
places it appears in. Options show the dimensions, the names of the tensors and the order of the contractions. Every
block on this page runs after
Needs["Summa`"]The product of two matrices: the tensors are named A, B, ... in order, the summed index j is a bond between them, and
the indices of the result, i and k, are open legs (blue).
EinsumDiagram["ij,jk->ik"]
Each index is drawn as a delta tensor with one leg for each time it appears, plus one if it is in the result:
- two legs make a line: a bond between two tensors, an open leg, or a loop on one tensor (a trace);
- one leg is an index summed in one tensor: a dashed leg ending in a small circle (a contraction with a vector of ones);
- three legs or more make a hyperedge: a purple dot joined to every tensor that has the index.
All of them in one network: i twice in A (a trace), j in A and B (a bond), k and m in the result (open legs),
h in B, C and D (a hyperedge), x in C only (a sum).
EinsumDiagram["iij,jkh,xh,mh->km"]
A batch index is a hyperedge with an open leg: in "bij,bjk->bik", b is in A, in B and in the result.
EinsumDiagram["bij,bjk->bik"]
In a notebook, hovering over a tensor or an index shows its indices, its dimension and its role.
With the tensors, or their dimensions, the labels show the dimensions, and the lines are thicker for larger ones;
"ShowDimensions" -> False hides the numbers.
EinsumDiagram["ij,jk,kl->il", {{1000, 10}, {10, 1000}, {1000, 10}}]
Tensors given as symbols are named after them:
rho = RandomReal[1, {4, 4}]; op = RandomReal[1, {4, 4}];
EinsumDiagram["ij,ji->", rho, op]
"TensorNames" names them by hand, and tensors with the same name have the same colour: the norm of a matrix-product
state, the state in the top row and its conjugate in the bottom one.
mps = "pa,aqb,brc,cs,pA,AqB,BrC,Cs->";
EinsumDiagram[mps, "TensorNames" -> {"A", "B", "B", "C", "A*", "B*", "B*", "C*"}]
The automatic layout (classical multidimensional scaling of the distances in the network, refined by stress
majorisation) draws chains straight, rings round and grids as grids. "Layout" -> "Circle" puts the tensors on a
circle in their order, "Line" on a line, and a list of coordinates where you want them:
EinsumDiagram["ab,bc,cd,de,ea->", "Layout" -> "Circle"]
"Highlight" draws a thick border around the tensors at the positions given:
EinsumDiagram[mps, "Highlight" -> {1, 5}]
"ShowPath" -> True writes on each index the step at which it is summed, in the order that Summa chooses for the
dimensions given (without them, every index has the dimension 8, the option "DefaultDimension"):
dims = {{2, 32}, {32, 2, 32}, {32, 2, 32}, {32, 2}, {2, 32}, {32, 2, 32}, {32, 2, 32}, {32, 2}};
EinsumDiagram[mps, dims, "ShowPath" -> True]
"Steps" -> True gives one picture for each step, the pair contracted next drawn with a thick border and each
intermediate at the centre of its tensors, and one of the result: ListAnimate plays them.
frames = EinsumDiagram["ij,jk,kl->il", {{1000, 10}, {10, 1000}, {1000, 10}}, "Steps" -> True];
GraphicsColumn[frames]
The option "Path" draws another order. The contraction tree of the order, with the cost of every step, is drawn by
EinsumTree (Orders and costs); EinsumFunction[...]["Diagram"] and
["Tree"] draw those of a compiled einsum.
Start
Recipes
Reference
Documents