Learn to Use ITensor

main / classes / itensor C++v3 | C++v2


An ITensor is a tensor with named indices (of type Index). The key feature of the ITensor is automatic contraction over all matching indices, similar to Einstein summation.

An ITensor is created with a fixed number of Index objects specifying its indices. Because Index objects carry identifying information, most of the ITensor interface does not depend on the Index order. For example, given an ITensor constructed with indices a and b, calling elt(T,a=2,b=5) and elt(T,b=5,a=2) accesses the same tensor element.

In addition to real-valued storage, ITensors can have other storage types such as complex storage or various sparse storage types.

If an ITensor is constructed with regular indices (Index objects I for which hasQNs(I)==false) then its storage will be dense.

If instead an ITensor is constructed with indices carrying additional quantum number (QN) block structure (Index objects I for which hasQNs(I)==true) then its storage will be block-sparse. (Up through version 2 of ITensor, such ITensors were called IQTensors.)

The ITensor class is defined in the header "itensor/itensor.h"


auto b1 = Index(5);
auto b3 = Index(8);
auto s2 = Index(2,"Site");
auto s3 = Index(2,"Site");

auto phi = ITensor(b1,s2,s3,b3);

phi.set(b1=2,s2=1,s3=2,b3=2, -0.5);
phi.set(b1=3,s2=2,s3=1,b3=6, 1.4);

auto nrm = norm(phi); //save the original norm of phi
phi /= nrm; //division by a scalar
Print(norm(phi)); //prints: 1.0

//The * operator automatically contracts all matching indices.
//The prime(phi,b3) method primes the b3 Index of the second
//ITensor in the product so it is not contracted.

ITensor rho = phi * prime(phi,b3);

Print(order(rho)); //prints 2
Print(hasIndex(rho,b3)); //prints: true
Print(hasIndex(rho,prime(b3))); //prints: true
Print(hasIndex(rho,s2)); //prints: false

Constructors and Accessor Methods

Element Access Methods

ITensor Tag and Prime Methods

ITensors have all of the same tagging and priming methods that are defined for IndexSets. See the Tag and Prime Methods section of the IndexSet documentation for a complete list of methods.

Click to Show Example
  auto i1 = Index(2,"i1");
  auto i2 = Index(2,"i2");
  auto i3 = Index(2,"i3");

  auto T = randomITensor(i1,i2,i3);

  auto Tp = prime(T,i1);  // Make a new ITensor Tp with index i1 primed

  Print(hasIndex(Tp,i1)); //prints: false
  Print(hasIndex(Tp,prime(i1))); //prints: true
  Print(hasIndex(Tp,i2)); //prints: true
  Print(hasIndex(Tp,i3)); //prints: true

  // Add the tag "x" to indices with integer tag (prime level) 1
  auto Tx = addTags(Tp,"x","1");

  Print(hasIndex(Tx,i1)); //prints: false
  Print(hasIndex(Tx,prime(i1))); //prints: false
  Print(hasIndex(Tx,prime(addTags(i1,"x")))); //prints: false
  Print(hasIndex(Tx,i2)); //prints: true
  Print(hasIndex(Tx,i3)); //prints: true

Operators Supported By ITensors

In this section, expressions like ITensor * ITensor -> ITensor are pseudocode indicating that two ITensors can be multiplied using the * operator, and that the result will be an ITensor.

Complex ITensor Methods

Elementwise Transformation Methods

Other Facts About ITensors

Functions for Modifying ITensors

Functions for Transforming ITensors

Extracting Properties of ITensors

Analyzing ITensor Indices

Other Functions

Advanced / Developer Methods

This page current as of version 3.0.0

Back to Classes
Back to Main