Contraction order optimization
OMEinsum does not implicitly optimize the contraction order. Functionalities related to contraction order optimization are mostly defined in OMEinsumContractionOrders
Here, we provide an example, advanced uses can be found in OMEinsumContractionOrders and the performance tips of GenericTensorNetworks. Let us first consider the following contraction order
using OMEinsum
code = ein"ij,jk,kl,li->"
ij, jk, kl, li ->
The time and space complexity can be obtained by calling the timespacereadwrite_complexity
function.
size_dict = uniformsize(code, 10)
timespacereadwrite_complexity(code, size_dict)
(13.287712379549449, 0.0, 8.64745842645492)
The return values are log2
values of the number of iterations, number of elements of the largest tensor and the number of elementwise read-write operations.
optcode = optimize_code(code, size_dict, TreeSA())
SlicedEinsum{Char, DynamicNestedEinsum{Char}}(Char[], kj, jk ->
├─ kl, jl -> kj
│ ├─ kl
│ └─ ij, li -> jl
│ ├─ ij
│ └─ li
└─ jk
)
The output value is a binary contraction tree with type NestedEinsum
type. The time and readwrite complexities are significantly reduced comparing to the direct contraction.
timespacereadwrite_complexity(optcode, size_dict)
(11.036173612553485, 6.643856189774724, 9.64565843240871)