ITensorBase.jl
Support

ITensorBase.jl is supported by the Flatiron Institute, a division of the Simons Foundation.
Installation instructions
This package resides in the ITensor/ITensorRegistry local registry. In order to install, simply add that registry through your package manager. This step is only required once.
julia> using Pkg: Pkg
julia> Pkg.Registry.add(url="https://github.com/ITensor/ITensorRegistry")or:
julia> Pkg.Registry.add(url="git@github.com:ITensor/ITensorRegistry.git")if you want to use SSH credentials, which can make it so you don't have to enter your Github ursername and password when registering packages.
Then, the package can be added as usual through the package manager:
julia> Pkg.add("ITensorBase")Examples
Load the package, along with a factorization from MatrixAlgebraKit.jl.
using ITensorBase: Index
using MatrixAlgebraKit: qr_compactAn Index labels one dimension of a tensor and carries its length. Each call makes a new, distinct index, so a tensor identifies its dimensions by index rather than by position.
i = Index(2)
j = Index(2)
k = Index(2)Index(length=2|id=508fe079)Make a random ITensor with indices i and j.
a = randn(i, j)Index(length=2|id=65cb786a)×Index(length=2|id=c36865b7) ITensor:
2×2 Matrix{Float64}:
-0.33589 0.0550623
0.0749366 -0.423924Read off an element by giving each index a value with i[value]. The indices can be given in any order, since elements are looked up by index, not by position.
a[j[2], i[1]]0.05506227250066939Contract a with another tensor over their shared index j. j is summed over and the result keeps the remaining indices i and k.
b = randn(j, k)
a * bIndex(length=2|id=65cb786a)×Index(length=2|id=508fe079) ITensor:
2×2 Matrix{Float64}:
-0.338878 -0.258463
0.589014 -0.208505Add two tensors. They are matched up by index, so a and c don't need their indices in the same order.
c = randn(j, i)
a + cIndex(length=2|id=65cb786a)×Index(length=2|id=c36865b7) ITensor:
2×2 Matrix{Float64}:
1.47176 1.24332
0.494906 -0.718556Factorize a over index i into a q with orthonormal columns and an upper-triangular r. The factors share a new index that qr_compact introduces.
q, r = qr_compact(a, (i,))([-0.9760055495266566 -0.21774564816126388; 0.21774564816126388 -0.9760055495266566][Index(length=2|id=65cb786a), Index(length=2|id=b2448cd4)], [0.3441473627840827 -0.1460486131256386; -0.0 0.40176226321563896][Index(length=2|id=b2448cd4), Index(length=2|id=c36865b7)])Contracting the factors back together recovers a.
q * rIndex(length=2|id=65cb786a)×Index(length=2|id=c36865b7) ITensor:
2×2 Matrix{Float64}:
-0.33589 0.0550623
0.0749366 -0.423924This page was generated using Literate.jl.