# SiteType and op

## Description

ITensors.SiteTypeType

SiteType is a parameterized type which allows making Index tags into Julia types. Use cases include overloading functions such as op, siteinds, and state which generate custom operators, Index arrays, and IndexVals associated with Index objects having a certain tag.

To make a SiteType type, you can use the string macro notation: SiteType"MyTag"

To make a SiteType value or object, you can use the notation: SiteType("MyTag")

There are currently a few built-in site types recognized by ITensors.jl. The system is easily extensible by users. To add new operators to an existing site type, you can follow the instructions here. To create new site types, you can follow the instructions here and here.

The current built-in site types are:

• SiteType"S=1/2" (or SiteType"S=½")
• SiteType"S=1"
• SiteType"Fermion"
• SiteType"tJ"
• SiteType"Electron"

Examples

Tags on indices get turned into SiteTypes internally, and then we search for overloads of functions like op and siteind. For example:

julia> s = siteind("S=1/2")
(dim=2|id=862|"S=1/2,Site")

julia> @show op("Sz", s);
op(s, "Sz") = ITensor ord=2
Dim 1: (dim=2|id=862|"S=1/2,Site")'
Dim 2: (dim=2|id=862|"S=1/2,Site")
NDTensors.Dense{Float64,Array{Float64,1}}
2×2
0.5   0.0
0.0  -0.5

julia> @show op("Sx", s);
op(s, "Sx") = ITensor ord=2
Dim 1: (dim=2|id=862|"S=1/2,Site")'
Dim 2: (dim=2|id=862|"S=1/2,Site")
NDTensors.Dense{Float64,Array{Float64,1}}
2×2
0.0  0.5
0.5  0.0

julia> @show op("Sy", s);
op(s, "Sy") = ITensor ord=2
Dim 1: (dim=2|id=862|"S=1/2,Site")'
Dim 2: (dim=2|id=862|"S=1/2,Site")
NDTensors.Dense{Complex{Float64},Array{Complex{Float64},1}}
2×2
0.0 + 0.0im  -0.0 - 0.5im
0.0 + 0.5im   0.0 + 0.0im

julia> s = siteind("Electron")
(dim=4|id=734|"Electron,Site")

julia> @show op("Nup", s);
op(s, "Nup") = ITensor ord=2
Dim 1: (dim=4|id=734|"Electron,Site")'
Dim 2: (dim=4|id=734|"Electron,Site")
NDTensors.Dense{Float64,Array{Float64,1}}
4×4
0.0  0.0  0.0  0.0
0.0  1.0  0.0  0.0
0.0  0.0  0.0  0.0
0.0  0.0  0.0  1.0

Many operators are available, for example:

• SiteType"S=1/2": "Sz", "Sx", "Sy", "S+", "S-", ...
• SiteType"Electron": "Nup", "Ndn", "Nupdn", "Ntot", "Cup", "Cdagup", "Cdn", "Cdagup", "Sz", "Sx", "Sy", "S+", "S-", ...
• ...

You can view the source code for the internal SiteType definitions and operators that are defined here.

source

## Methods

ITensors.opFunction
op(opname::String, s::Index; kwargs...)

Return an ITensor corresponding to the operator named opname for the Index s. The operator is constructed by calling an overload of either the op or op! methods which take a SiteType argument that corresponds to one of the tags of the Index s and an OpName"opname" argument that corresponds to the input operator name.

Operator names can be combined using the "*" symbol, for example "S+*S-" or "Sz*Sz*Sz". The result is an ITensor made by forming each operator then contracting them together in a way corresponding to the usual operator product or matrix multiplication.

The op system is used by the AutoMPO system to convert operator names into ITensors, and can be used directly such as for applying operators to MPS.

Example

s = Index(2, "Site,S=1/2")
Sz = op("Sz", s)
source
op(opname::String,sites::Vector{<:Index},n::Int; kwargs...)

Return an ITensor corresponding to the operator named opname for the n'th Index in the array sites.

Example

s = siteinds("S=1/2", 4)
Sz2 = op("Sz", s, 2)
source