Observable
We use a similar tree structure for calculating observables. For instance, we first generate a random product state.
using FiniteMPS
# construct a random MPS
L = 4
Ψ = randMPS(L, ℂ^2, ℂ^1)
# display
for i in 1:L
println(Ψ[i])
end
MPSTensor{3}(TensorMap((ℂ^1 ⊗ ℂ^2) ← ℂ^1):
[:, :, 1] =
-0.5548825211008388 0.831928715562083
)
MPSTensor{3}(TensorMap((ℂ^1 ⊗ ℂ^2) ← ℂ^1):
[:, :, 1] =
-0.9993260886819206 0.03670651821807647
)
MPSTensor{3}(TensorMap((ℂ^1 ⊗ ℂ^2) ← ℂ^1):
[:, :, 1] =
-0.7718808685210725 0.6357671938777234
)
MPSTensor{3}(TensorMap((ℂ^1 ⊗ ℂ^2) ← ℂ^1):
[:, :, 1] =
-0.10724699565836393 -0.9942324084047224
)
Here we use randMPS
to construct a random MPS whose physical spaces are all $\mathbb{C}^2$ and bond spaces are all $\mathbb{C}^1$ thus represents a random produce state.
Next, we calculate the on-site values and spin correlations.
# define the S^z operator following the syntax of TensorKit.jl
Sz = TensorMap([0.5 0.0; 0.0 -0.5], ℂ^2, ℂ^2)
# construct the observable tree
Tree = ObservableTree(L)
for i in 1:L
addObs!(Tree, (Sz,), (i,), (false,); name = (:Sz,))
end
for i in 1:L, j in 1:L
addObs!(Tree, (Sz, Sz), (i, j), (false, false); name = (:Sz, :Sz))
end
calObs!(Tree, Ψ)
Obs = convert(Dict, Tree)
Dict{String, Dict} with 2 entries:
"SzSz" => Dict{Tuple{Int64, Int64}, Number}((1, 2)=>-0.0957939, (3, 1)=>-0.01…
"Sz" => Dict{Tuple{Int64}, Number}((4,)=>-0.488498, (2,)=>0.498653, (3,)=>0…
Here Tree
is an ObservableTree
object that contains all observables to be calculated, and addObs!
is the standard interface to add terms to it, analog to InteractionTree
and addIntr!
. Then, we call calObs!
to trigger the in-place calculation in the tree, with the given MPS Ψ
. Finally, we use the convert
method to extract the data from the tree to a dictionary Obs
. For example,
Obs["SzSz"][(1, 2)]
-0.09579385714411875
is the correlation $\langle S_1^z S_2^z\rangle$. One can perform a simple quantum mechanics calculation to check this result.
Here is just a simple example to show the basic usage, more complex examples that contain fermion correlations and multi-site correlations (e.g. pairing correlations) can be found in the concrete example for Hubbard model.