All Projects → ITensor → Itensors.jl

ITensor / Itensors.jl

Licence: apache-2.0
A Julia library for efficient tensor computations and tensor network calculations

Programming Languages

julia
2034 projects

Projects that are alternatives of or similar to Itensors.jl

Quimb
A python library for quantum information and many-body calculations including tensor networks.
Stars: ✭ 170 (-14.57%)
Mutual labels:  tensors, physics
Cadabra2
A field-theory motivated approach to computer algebra.
Stars: ✭ 112 (-43.72%)
Mutual labels:  tensors, physics
Itensor
A C++ library for efficient tensor network calculations
Stars: ✭ 269 (+35.18%)
Mutual labels:  tensors, physics
Awesome Physics
🌌 A collaborative list of awesome software for exploring Physics concepts
Stars: ✭ 154 (-22.61%)
Mutual labels:  physics
Ttpy
Python implementation of the TT-Toolbox
Stars: ✭ 153 (-23.12%)
Mutual labels:  tensors
Classic Pool Game
Classic 8 Ball pool game written in JavaScript
Stars: ✭ 177 (-11.06%)
Mutual labels:  physics
Salva
2 and 3-dimensional fluid simulation library in Rust.
Stars: ✭ 182 (-8.54%)
Mutual labels:  physics
Godot Jigglebones
An addon that brings jigglebones to Godot Engine 3.0.
Stars: ✭ 175 (-12.06%)
Mutual labels:  physics
Apple Music Animation
Apple music animation demo in Android
Stars: ✭ 153 (-23.12%)
Mutual labels:  physics
Slither.io Clone
Learn how to make Slither.io with JavaScript and Phaser! This game clones all the core features of Slither.io, including mouse-following controls, snake collisions, food, snake growth, eyes, and more. Progress through each part of the source code with our Slither.io tutorial series.
Stars: ✭ 168 (-15.58%)
Mutual labels:  physics
Scatteract
Project which implements extraction of data from scatter plots
Stars: ✭ 181 (-9.05%)
Mutual labels:  tensors
Visual Interaction Networks Pytorch
This's an implementation of deepmind Visual Interaction Networks paper using pytorch
Stars: ✭ 164 (-17.59%)
Mutual labels:  physics
Vivegrip
Physics-based grabbing for SteamVR development in Unity.
Stars: ✭ 159 (-20.1%)
Mutual labels:  physics
Springy facebook rebound
Springy makes Android Property animation easy to use.
Stars: ✭ 176 (-11.56%)
Mutual labels:  physics
Qcodes
Modular data acquisition framework
Stars: ✭ 153 (-23.12%)
Mutual labels:  physics
Feyncalc
Mathematica package for algebraic calculations in elementary particle physics.
Stars: ✭ 184 (-7.54%)
Mutual labels:  physics
Physx.net
A .NET wrapper for NVIDIA PhysX 4.1.0 written using C++/CLI.
Stars: ✭ 153 (-23.12%)
Mutual labels:  physics
Theoretical Physics
Source code of the Theoretical Physics Reference online book
Stars: ✭ 163 (-18.09%)
Mutual labels:  physics
Arcadecarphysics
Arcade Car Physics - Vehicle Simulation for Unity3D
Stars: ✭ 189 (-5.03%)
Mutual labels:  physics
Xtensor
C++ tensors with broadcasting and lazy computing
Stars: ✭ 2,453 (+1132.66%)
Mutual labels:  tensors

Introduction

Documentation
Build Status
Tests codecov
Citation
arXiv

ITensors is a library for rapidly creating correct and efficient tensor network algorithms.

An ITensor is a tensor whose interface is independent of its memory layout. ITensor indices are objects which carry extra information and which 'recognize' each other (compare equal to each other).

The ITensor library also includes composable and extensible algorithms for optimizing and transforming tensor networks, such as matrix product state and matrix product operators, such as the DMRG algorithm.

Development of ITensor is supported by the Flatiron Institute, a division of the Simons Foundation.

Installation

The ITensors package can be installed with the Julia package manager. From the Julia REPL, type ] to enter the Pkg REPL mode and run:

~ julia
julia> ]

pkg> add ITensors

Or, equivalently, via the Pkg API:

julia> import Pkg; Pkg.add("ITensors")

Please note that right now, ITensors.jl requires that you use Julia v1.3 or later (since ITensors.jl relies on a feature that was introduced in Julia v1.3).

We recommend using ITensors.jl with Intel MKL in order to get the best possible performance. If you have not done so already, you can replace your current BLAS and LAPACK implementation with MKL by using the MKL.jl package. Please follow the instructions here.

Documentation

  • STABLE -- documentation of the most recently tagged version.
  • DEVEL -- documentation of the in-development version.

Citation

If you use ITensors.jl in your work, for now please cite the arXiv preprint:

@misc{itensor,
    title={The \mbox{ITensor} Software Library for Tensor Network Calculations},
    author={Matthew Fishman and Steven R. White and E. Miles Stoudenmire},
    year={2020},
    eprint={2007.14822},
    archivePrefix={arXiv}
}

Code Examples

The ITensors.jl package contains a directory of examples, which we will continue to add to. You can find them online here. Additionally, once you have installed ITensors.jl you can find a local version of the examples in the directory ITensors.examples_dir(), and you can run them as follows from the Julia REPL:

julia> using ITensors

julia> cd(ITensors.examples_dir())

julia> readdir()
7-element Array{String,1}:
 "basic_ops"
 "ctmrg"
 "dmrg"
 "gate_evolution"
 "krylov_methods"
 "src"
 "trg"

julia> cd("dmrg")

julia> readdir()
8-element Array{String,1}:
 "1d_heisenberg.jl"
 "1d_heisenberg_conserve_spin.jl"
 "1d_hubbard_extendend.jl"
 "1d_ising_with_observer.jl"
 "2d_heisenberg_conserve_spin.jl"
 "2d_hubbard_conserve_momentum.jl"
 "2d_hubbard_conserve_particles.jl"
 "input_files"

julia> include("1d_heisenberg.jl")
sweeps = Sweeps
1 cutoff=1.0E-11, maxdim=10, mindim=1, noise=0.0E+00
2 cutoff=1.0E-11, maxdim=20, mindim=1, noise=0.0E+00
3 cutoff=1.0E-11, maxdim=100, mindim=1, noise=0.0E+00
4 cutoff=1.0E-11, maxdim=100, mindim=1, noise=0.0E+00
5 cutoff=1.0E-11, maxdim=200, mindim=1, noise=0.0E+00

After sweep 1 energy=-138.837988775764 maxlinkdim=10 time=13.760
After sweep 2 energy=-138.937408365962 maxlinkdim=20 time=0.249
After sweep 3 energy=-138.940084788852 maxlinkdim=100 time=1.867
After sweep 4 energy=-138.940086091070 maxlinkdim=100 time=3.824
After sweep 5 energy=-138.940086113999 maxlinkdim=122 time=4.527
Final energy = -138.940086113999

julia> pwd()
"[path_to_package_installation]/ITensors/examples/dmrg"

You can use your favorite text editor to view these examples. If you would like to modify them, either copy them into your own directory, or checkout ITensors.jl in development mode using the instructions in Developing ITensors.jl.

Basic Overview

ITensor construction, setting of elements, contraction, and addition. Before constructing an ITensor, one constructs Index objects representing tensor indices.

using ITensors
let
  i = Index(3)
  j = Index(5)
  k = Index(2)
  l = Index(7)

  A = ITensor(i,j,k)
  B = ITensor(j,l)

  # Set elements of A
  A[i=>1,j=>1,k=>1] = 11.1
  A[i=>2,j=>1,k=>2] = -21.2
  A[k=>1,i=>3,j=>1] = 31.1  # can provide Index values in any order
  # ...

  # A[k(1),i(3),j(1)] = 31.1  # alternative notation

  # Contract over shared index j
  C = A * B

  @show hasinds(C,i,k,l) # = true

  D = randomITensor(k,j,i) # ITensor with random elements

  # Add two ITensors
  # must have same set of indices
  # but can be in any order
  R = A + D

  nothing
end

# output

hasinds(C, i, k, l) = true

Singular Value Decomposition (SVD) of a Matrix

In this example, we create a random 10x20 matrix and compute its SVD. The resulting factors can be simply multiplied back together using the ITensor * operation, which automatically recognizes the matching indices between U and S, and between S and V and contracts (sums over) them.

using ITensors
let
  i = Index(10)           # index of dimension 10
  j = Index(20)           # index of dimension 20
  M = randomITensor(i,j)  # random matrix, indices i,j
  U,S,V = svd(M,i)        # compute SVD with i as row index
  @show M ≈ U*S*V         # = true

  nothing
end

# output

M ≈ U * S * V = true

Singular Value Decomposition (SVD) of a Tensor

In this example, we create a random 4x4x4x4 tensor and compute its SVD, temporarily treating the first and third indices (i and k) as the "row" index and the second and fourth indices (j and l) as the "column" index for the purposes of the SVD. The resulting factors can be simply multiplied back together using the ITensor * operation, which automatically recognizes the matching indices between U and S, and between S and V and contracts (sums over) them.

using ITensors
let
  i = Index(4,"i")
  j = Index(4,"j")
  k = Index(4,"k")
  l = Index(4,"l")
  T = randomITensor(i,j,k,l)
  U,S,V = svd(T,i,k)   # compute SVD with (i,k) as row indices (indices of U)
  @show hasinds(U,i,k) # = true
  @show hasinds(V,j,l) # = true
  @show T ≈ U*S*V      # = true

  nothing
end

# output

hasinds(U, i, k) = true
hasinds(V, j, l) = true
T ≈ U * S * V = true

Tensor Indices: Tags and Prime Levels

Before making an ITensor, you have to define its indices. Tensor Index objects carry extra information beyond just their dimension.

All Index objects carry a permanent, immutable id number which is determined when it is constructed, and allow it to be matched (compare equal) with copies of itself.

Additionally, an Index can have up to four tag strings, and an integer primelevel. If two Index objects have different tags or different prime levels, they do not compare equal even if they have the same id.

Tags are also useful for identifying Index objects when printing tensors, and for performing certain Index manipulations (e.g. priming indices having certain sets of tags).

using ITensors
let
  i = Index(3)     # Index of dimension 3
  @show dim(i)     # = 3
  @show id(i)      # = 0x5d28aa559dd13001 or similar

  ci = copy(i)
  @show ci == i    # = true

  j = Index(5,"j") # Index with a tag "j"

  @show j == i     # = false

  s = Index(2,"n=1,Site") # Index with two tags,
                          # "Site" and "n=1"
  @show hastags(s,"Site") # = true
  @show hastags(s,"n=1")  # = true

  i1 = prime(i) # i1 has a "prime level" of 1
                # but otherwise same properties as i
  @show i1 == i # = false, prime levels do not match

  nothing
end

# output

dim(i) = 3
id(i) = 0x5d28aa559dd13001
ci == i = true
j == i = false
hastags(s, "Site") = true
hastags(s, "n=1") = true
i1 == i = false

DMRG Calculation

DMRG is an iterative algorithm for finding the dominant eigenvector of an exponentially large, Hermitian matrix. It originates in physics with the purpose of finding eigenvectors of Hamiltonian (energy) matrices which model the behavior of quantum systems.

using ITensors
let
  # Create 100 spin-one indices
  N = 100
  sites = siteinds("S=1",N)

  # Input operator terms which define 
  # a Hamiltonian matrix, and convert
  # these terms to an MPO tensor network
  # (here we make the 1D Heisenberg model)
  ampo = AutoMPO()
  for j=1:N-1
    ampo += "Sz",j,"Sz",j+1
    ampo += 0.5,"S+",j,"S-",j+1
    ampo += 0.5,"S-",j,"S+",j+1
  end
  H = MPO(ampo,sites)

  # Create an initial random matrix product state
  psi0 = randomMPS(sites)

  # Plan to do 5 passes or 'sweeps' of DMRG,
  # setting maximum MPS internal dimensions 
  # for each sweep and maximum truncation cutoff
  # used when adapting internal dimensions:
  sweeps = Sweeps(5)
  maxdim!(sweeps, 10,20,100,100,200)
  cutoff!(sweeps, 1E-10)
  @show sweeps

  # Run the DMRG algorithm, returning energy 
  # (dominant eigenvalue) and optimized MPS
  energy, psi = dmrg(H,psi0, sweeps)
  println("Final energy = $energy")

  nothing
end

# output

sweeps = Sweeps
1 cutoff=1.0E-10, maxdim=10, mindim=1, noise=0.0E+00
2 cutoff=1.0E-10, maxdim=20, mindim=1, noise=0.0E+00
3 cutoff=1.0E-10, maxdim=100, mindim=1, noise=0.0E+00
4 cutoff=1.0E-10, maxdim=100, mindim=1, noise=0.0E+00
5 cutoff=1.0E-10, maxdim=200, mindim=1, noise=0.0E+00

After sweep 1 energy=-137.954199761732 maxlinkdim=9 maxerr=2.43E-16 time=9.356
After sweep 2 energy=-138.935058943878 maxlinkdim=20 maxerr=4.97E-06 time=0.671
After sweep 3 energy=-138.940080155429 maxlinkdim=92 maxerr=1.00E-10 time=4.522
After sweep 4 energy=-138.940086009318 maxlinkdim=100 maxerr=1.05E-10 time=11.644
After sweep 5 energy=-138.940086058840 maxlinkdim=96 maxerr=1.00E-10 time=12.771
Final energy = -138.94008605883985
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].