Index

Description

ITensors.IndexType

An Index represents a single tensor index with fixed dimension dim. Copies of an Index compare equal unless their tags are different.

An Index carries a TagSet, a set of tags which are small strings that specify properties of the Index to help distinguish it from other Indices. There is a special tag which is referred to as the integer tag or prime level which can be incremented or decremented with special priming functions.

Internally, an Index has a fixed id number, which is how the ITensor library knows two indices are copies of a single original Index. Index objects must have the same id, as well as the tags to compare equal.

source
ITensors.QNIndexType

A QN Index is an Index with QN block storage instead of just an integer dimension. The QN block storage is a vector of pairs of QNs and block dimensions. The total dimension of a QN Index is the sum of the dimensions of the blocks of the Index.

source

Constructors

ITensors.IndexMethod
Index(dim::Int; tags::Union{AbstractString, TagSet} = "",
                plev::Int = 0)

Create an Index with a unique id, a TagSet given by tags, and a prime level plev.

Examples

julia> i = Index(2; tags="l", plev=1)
(dim=2|id=818|"l")'

julia> dim(i)
2

julia> plev(i)
1

julia> tags(i)
"l"
source
ITensors.IndexMethod
Index(dim::Integer, tags::Union{AbstractString, TagSet}; plev::Int = 0)

Create an Index with a unique id and a tagset given by tags.

Examples

julia> i = Index(2, "l,tag")
(dim=2|id=58|"l,tag")

julia> dim(i)
2

julia> plev(i)
0

julia> tags(i)
"l,tag"
source
ITensors.IndexMethod
Index(qnblocks::Pair{QN, Int64}...; dir::Arrow = Out,
                                    tags = "",
                                    plev::Integer = 0)

Construct a QN Index from a list of pairs of QN and block dimensions.

Example

Index(QN("Sz", -1) => 1, QN("Sz", 1) => 1; tags = "i")
source
ITensors.IndexMethod
Index(qnblocks::Vector{Pair{QN, Int64}}; dir::Arrow = Out,
                                         tags = "",
                                         plev::Integer = 0)

Construct a QN Index from a Vector of pairs of QN and block dimensions.

Note: in the future, this may enforce that all blocks have the same QNs (which would allow for some optimizations, for example when constructing random QN ITensors).

Example

Index([QN("Sz", -1) => 1, QN("Sz", 1) => 1]; tags = "i")
source
ITensors.IndexMethod
Index(qnblocks::Vector{Pair{QN, Int64}}, tags; dir::Arrow = Out,
                                               plev::Integer = 0)

Construct a QN Index from a Vector of pairs of QN and block dimensions.

Example

Index([QN("Sz", -1) => 1, QN("Sz", 1) => 1], "i"; dir = In)
source

Properties

ITensors.idMethod
id(i::Index)

Obtain the id of an Index, which is a unique 64 digit integer.

source
ITensors.hasidMethod
hasid(i::Index, id::ITensors.IDType)

Check if an Index i has the provided id.

Examples

julia> i = Index(2)
(dim=2|id=321)

julia> hasid(i, id(i))
true

julia> j = Index(2)
(dim=2|id=17)

julia> hasid(i, id(j))
false
source
ITensors.TagSets.set_strict_tags!Method
set_strict_tags!(enable::Bool) -> Bool

Enable or disable checking for overflow of the number of tags of a TagSet or the number of characters of a tag. If enabled (set to true), an error will be thrown if overflow occurs, otherwise the overflow will be ignored and the extra tags or tag characters will be dropped. This could cause unexpected bugs if tags are being used to distinguish Index objects that have the same ids and prime levels, but that is generally discouraged and should only be used if you know what you are doing.

See also ITensors.using_strict_tags.

source
ITensors.TagSets.hastagsMethod
hastags(i::Index, ts::Union{AbstractString,TagSet})

Check if an Index i has the provided tags, which can be a string of comma-separated tags or a TagSet object.

Examples

julia> i = Index(2, "SpinHalf,Site,n=3")
(dim=2|id=861|"Site,SpinHalf,n=3")

julia> hastags(i, "SpinHalf,Site")
true

julia> hastags(i, "Link")
false
source
ITensors.hasplevMethod
hasplev(i::Index, plev::Int)

Check if an Index i has the provided prime level.

Examples

julia> i = Index(2; plev=2)
(dim=2|id=543)''

julia> hasplev(i, 2)
true

julia> hasplev(i, 1)
false
source
NDTensors.dimMethod
dim(i::Index)

Obtain the dimension of an Index.

For a QN Index, this is the sum of the block dimensions.

source
Base.:==Method
==(i1::Index, i1::Index)

Compare indices for equality. First the id's are compared, then the prime levels are compared, and finally the tags are compared.

source
ITensors.dirMethod
dir(i::Index)

Return the direction of an Index (ITensors.In, ITensors.Out, or ITensors.Neither).

source

Priming and tagging methods

ITensors.primeMethod
prime(i::Index, plinc::Int = 1)

Return a copy of Index i with its prime level incremented by the amount plinc

source
Base.:^Method
^(i::Index, pl::Int)

Prime an Index using the notation i^3.

source
ITensors.setprimeMethod
setprime(i::Index, plev::Int)

Return a copy of Index i with its prime level set to plev

source
ITensors.settagsMethod
settags(i::Index, ts)

Return a copy of Index i with tags replaced by the ones given The ts argument can be a comma-separated string of tags or a TagSet.

Examples

julia> i = Index(2, "SpinHalf,Site,n=3")
(dim=2|id=543|"Site,SpinHalf,n=3")

julia> hastags(i, "Link")
false

julia> j = settags(i, "Link,n=4")
(dim=2|id=543|"Link,n=4")

julia> hastags(j, "Link")
true

julia> hastags(j, "n=4,Link")
true
source
ITensors.TagSets.addtagsMethod
addtags(i::Index,ts)

Return a copy of Index i with the specified tags added to the existing ones. The ts argument can be a comma-separated string of tags or a TagSet.

source
ITensors.TagSets.removetagsMethod
removetags(i::Index, ts)

Return a copy of Index i with the specified tags removed. The ts argument can be a comma-separated string of tags or a TagSet.

source
ITensors.TagSets.replacetagsMethod
replacetags(i::Index, tsold, tsnew)

replacetags(i::Index, tsold => tsnew)

If the tag set of i contains the tags specified by tsold, replaces these with the tags specified by tsnew, preserving any other tags. The arguments tsold and tsnew can be comma-separated strings of tags, or TagSet objects.

Examples

julia> i = Index(2; tags="l,x", plev=1)
(dim=2|id=83|"l,x")'

julia> replacetags(i, "l", "m")
(dim=2|id=83|"m,x")'

julia> replacetags(i, "l" => "m")
(dim=2|id=83|"m,x")'
source

Methods

NDTensors.simMethod
sim(i::Index; tags = tags(i), plev = plev(i), dir = dir(i))

Produces an Index with the same properties (dimension or QN structure) but with a new id.

source

Iterating

ITensors.eachvalMethod
eachval(i::Index)

Create an iterator whose values range over the dimension of the provided Index.

source
ITensors.eachindvalMethod
eachindval(i::Index)

Create an iterator whose values are Pairs of the form i=>n with n from 1:dim(i). This iterator is useful for accessing elements of an ITensor in a loop without needing to know the ordering of the indices. See also eachindval(is::Index...).

source