Skip to content

Commit

Permalink
Move many MPS related autofermion tests to LegacyMPS
Browse files Browse the repository at this point in the history
  • Loading branch information
emstoudenmire committed Sep 23, 2023
1 parent b963535 commit 9da26e3
Show file tree
Hide file tree
Showing 3 changed files with 354 additions and 400 deletions.
122 changes: 65 additions & 57 deletions test/ITensorLegacyMPS/base/test_autompo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -937,67 +937,75 @@ end
end

@testset "Chemical Hamiltonian Test" begin
N = 6
t = randn(N, N)
V = randn(N, N, N, N)
s = siteinds("Electron", N; conserve_qns=true)

ost = OpSum()
for i in 1:N, j in 1:N
ost += t[i, j], "Cdagup", i, "Cup", j
ost += t[i, j], "Cdagdn", i, "Cdn", j
end
Ht = MPO(ost, s)

osV = OpSum()
for i in 1:N, j in 1:N, k in 1:N, l in 1:N
osV += V[i, j, k, l], "Cdagup", i, "Cdagup", j, "Cup", k, "Cup", l
osV += V[i, j, k, l], "Cdagup", i, "Cdagdn", j, "Cdn", k, "Cup", l
osV += V[i, j, k, l], "Cdagdn", i, "Cdagup", j, "Cup", k, "Cdn", l
osV += V[i, j, k, l], "Cdagdn", i, "Cdagdn", j, "Cdn", k, "Cdn", l
end
HV = MPO(osV, s)

for i in 1:N, j in 1:N
stᵢ = fill("0", N)
stⱼ = fill("0", N)
stᵢ[i] = "Up"
stⱼ[j] = "Up"
psiᵢ = MPS(s, stᵢ)
psiⱼ = MPS(s, stⱼ)
@test abs(inner(psiᵢ', Ht, psiⱼ) - t[i, j]) < 1E-10
end
for auto_fermion in [false, true]
if auto_fermion
ITensors.enable_auto_fermion()
else
ITensors.disable_auto_fermion()
end
N = 6
t = randn(N, N)
V = randn(N, N, N, N)
s = siteinds("Electron", N; conserve_qns=true)

ost = OpSum()
for i in 1:N, j in 1:N
ost += t[i, j], "Cdagup", i, "Cup", j
ost += t[i, j], "Cdagdn", i, "Cdn", j
end
Ht = MPO(ost, s)

osV = OpSum()
for i in 1:N, j in 1:N, k in 1:N, l in 1:N
osV += V[i, j, k, l], "Cdagup", i, "Cdagup", j, "Cup", k, "Cup", l
osV += V[i, j, k, l], "Cdagup", i, "Cdagdn", j, "Cdn", k, "Cup", l
osV += V[i, j, k, l], "Cdagdn", i, "Cdagup", j, "Cup", k, "Cdn", l
osV += V[i, j, k, l], "Cdagdn", i, "Cdagdn", j, "Cdn", k, "Cdn", l
end
HV = MPO(osV, s)

for i in 1:N, j in 1:N
stᵢ = fill("0", N)
stⱼ = fill("0", N)
stᵢ[i] = "Up"
stⱼ[j] = "Up"
psiᵢ = MPS(s, stᵢ)
psiⱼ = MPS(s, stⱼ)
@test abs(inner(psiᵢ', Ht, psiⱼ) - t[i, j]) < 1E-10
end

for i in 1:N, j in 1:N, k in 1:N, l in 1:N
((i == j) || (k == l)) && continue

stᵢⱼ = fill("0", N)
stᵢⱼ[i] = "Up"
stᵢⱼ[j] = "Up"
psiᵢⱼ = MPS(s, stᵢⱼ)

stₖₗ = fill("0", N)
stₖₗ[k] = "Up"
stₖₗ[l] = "Up"
psiₖₗ = MPS(s, stₖₗ)

mpo_val = inner(psiᵢⱼ', HV, psiₖₗ)
exact_val = 0.0
for m in 1:N, n in 1:N, p in 1:N, q in 1:N
if m == i && n == j && p == l && q == k
exact_val += V[i, j, l, k]
elseif m == i && n == j && p == k && q == l
exact_val += -V[i, j, k, l]
elseif m == j && n == i && p == l && q == k
exact_val += -V[j, i, l, k]
elseif m == j && n == i && p == k && q == l
exact_val += V[j, i, k, l]
for i in 1:N, j in 1:N, k in 1:N, l in 1:N
((i == j) || (k == l)) && continue

stᵢⱼ = fill("0", N)
stᵢⱼ[i] = "Up"
stᵢⱼ[j] = "Up"
psiᵢⱼ = MPS(s, stᵢⱼ)

stₖₗ = fill("0", N)
stₖₗ[k] = "Up"
stₖₗ[l] = "Up"
psiₖₗ = MPS(s, stₖₗ)

mpo_val = inner(psiᵢⱼ', HV, psiₖₗ)
exact_val = 0.0
for m in 1:N, n in 1:N, p in 1:N, q in 1:N
if m == i && n == j && p == l && q == k
exact_val += V[i, j, l, k]
elseif m == i && n == j && p == k && q == l
exact_val += -V[i, j, k, l]
elseif m == j && n == i && p == l && q == k
exact_val += -V[j, i, l, k]
elseif m == j && n == i && p == k && q == l
exact_val += V[j, i, k, l]
end
end
(k > l) && (exact_val *= -1)
(i > j) && (exact_val *= -1)
@test abs(mpo_val - exact_val) < 1E-10
end
(k > l) && (exact_val *= -1)
(i > j) && (exact_val *= -1)
@test abs(mpo_val - exact_val) < 1E-10
end
ITensors.disable_auto_fermion()
end

@testset "Complex OpSum Coefs" begin
Expand Down
Loading

0 comments on commit 9da26e3

Please sign in to comment.