-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
using ITensors, ITensorMPS | ||
using LinearAlgebra | ||
using Printf | ||
using Random | ||
using Strided | ||
|
||
Random.seed!(1234) | ||
BLAS.set_num_threads(1) | ||
Strided.set_num_threads(1) | ||
ITensors.enable_threaded_blocksparse() | ||
#ITensors.disable_threaded_blocksparse() | ||
|
||
let | ||
N = 100 | ||
|
||
sites = siteinds("S=1", N; conserve_qns=true) | ||
using SymmetrySectors | ||
|
||
function heisenberg(N) | ||
os = OpSum() | ||
for j in 1:(N - 1) | ||
os += 0.5, "S+", j, "S-", j + 1 | ||
os += 0.5, "S-", j, "S+", j + 1 | ||
os += "Sz", j, "Sz", j + 1 | ||
end | ||
H = MPO(os, sites) | ||
return os | ||
end | ||
|
||
Random.seed!(1234) | ||
|
||
state = [isodd(n) ? "Up" : "Dn" for n in 1:N] | ||
psi0 = random_mps(sites, state; linkdims=10) | ||
N = 10 | ||
|
||
# Plan to do 5 DMRG sweeps: | ||
nsweeps = 5 | ||
# Set maximum MPS bond dimensions for each sweep | ||
maxdim = [10, 20, 100, 100, 200] | ||
# Set maximum truncation error allowed when adapting bond dimensions | ||
cutoff = [1E-11] | ||
s = siteinds("S=1/2", N; gradings=("Sz",)) | ||
|
||
# Run the DMRG algorithm, returning energy and optimized MPS | ||
energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff) | ||
@printf("Final energy = %.12f\n", energy) | ||
end | ||
os = heisenberg(N) | ||
|
||
# Input operator terms which define a Hamiltonian | ||
# Convert these terms to an MPO tensor network | ||
H = MPO(os, s) | ||
|
||
# Create an initial random matrix product state | ||
# psi0 = random_mps(s; linkdims=10) | ||
psi0 = MPS(s, j -> isodd(j) ? "↑" : "↓") | ||
|
||
# Plan to do 5 DMRG sweeps: | ||
nsweeps = 5 | ||
# Set maximum MPS bond dimensions for each sweep | ||
maxdim = [10] | ||
# Set maximum truncation error allowed when adapting bond dimensions | ||
cutoff = [1E-11] | ||
|
||
# Run the DMRG algorithm, returning energy and optimized MPS | ||
energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff) | ||
@show inner(psi', H, psi) | ||
@show inner(psi, psi) | ||
@printf("Final energy = %.12f\n", energy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
using ITensors: Index, settag | ||
using ITensors: ITensors, Index, settag | ||
using QuantumOperatorDefinitions: SiteType | ||
|
||
# TODO: Move to `ITensorSites.jl`? | ||
# TODO: Add support for symmetry sectors. | ||
function siteinds(t::String, n::Int) | ||
return [settag(Index(length(SiteType(t))), "sitetype", t) for _ in 1:n] | ||
function siteinds(t::String, n::Int; kwargs...) | ||
return [settag(Index(SiteType(t; kwargs...)), "n", string(j)) for j in 1:n] | ||
end |