Skip to content

Commit

Permalink
Stabilize tests by fixing seeds, reduce verbosity, use more elegant H…
Browse files Browse the repository at this point in the history
…eisenberg Hamiltonian
  • Loading branch information
pbrehmer committed May 14, 2024
1 parent f6f10ea commit fcd6056
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MPSKit = "bb1c41ca-d63c-52ed-829e-0820dda26502"
MPSKitModels = "ca635005-6f8c-4cd1-b51d-8491250ef2ab"
OptimKit = "77e91f04-9b3b-57a6-a776-40b61faaebe0"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec"
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
Expand All @@ -34,8 +34,8 @@ Zygote = "0.6"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "SafeTestsets"]
21 changes: 8 additions & 13 deletions examples/heisenberg.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
using LinearAlgebra
using TensorKit, MPSKitModels, OptimKit
using TensorKit, OptimKit
using PEPSKit, KrylovKit

# Square lattice Heisenberg Hamiltonian
# We use the parameters (J₁, J₂, J₃) = (-1, 1, -1) by default to capture
# the ground state in a single-site unit cell. This can be seen from
# sublattice rotating H from parameters (1, 1, 1) to (-1, 1, -1).
function square_lattice_heisenberg(; Jx=-1, Jy=1, Jz=-1)
Sx, Sy, Sz, _ = spinmatrices(1//2)
Vphys =^2
σx = TensorMap(Sx, Vphys, Vphys)
σy = TensorMap(Sy, Vphys, Vphys)
σz = TensorMap(Sz, Vphys, Vphys)

@tensor H[-1 -3; -2 -4] :=
Jx * σx[-1, -2] * σx[-3, -4] +
Jy * σy[-1, -2] * σy[-3, -4] +
Jz * σz[-1, -2] * σz[-3, -4]

return NLocalOperator{NearestNeighbor}(H)
physical_space = ComplexSpace(2)
T = ComplexF64
σx = TensorMap(T[0 1; 1 0], physical_space, physical_space)
σy = TensorMap(T[0 im; -im 0], physical_space, physical_space)
σz = TensorMap(T[1 0; 0 -1], physical_space, physical_space)
H = (Jx * σx σx) + (Jy * σy σy) + (Jz * σz σz)
return NLocalOperator{NearestNeighbor}(H / 4)
end

# Parameters
Expand Down
6 changes: 4 additions & 2 deletions test/boundarymps/vumps.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
using Test
using Random
using PEPSKit
using TensorKit
using MPSKit
using LinearAlgebra

Random.seed!(29384293742893)
psi = InfinitePEPS(ComplexSpace(2), ComplexSpace(2))

T = PEPSKit.InfiniteTransferPEPS(psi, 1, 1)
mps = PEPSKit.initializeMPS(T, [ComplexSpace(8)])

mps, envs, ϵ = leading_boundary(mps, T, VUMPS())
mps, envs, ϵ = leading_boundary(mps, T, VUMPS(; verbosity=2))
N = sum(expectation_value(mps, T))

ctm = leading_boundary(
psi, CTMRG(; verbosity=2, fixedspace=true), CTMRGEnv(psi; Venv=ComplexSpace(8))
psi, CTMRG(; verbosity=1, fixedspace=true), CTMRGEnv(psi; Venv=ComplexSpace(8))
)
N2 = norm(psi, ctm)

Expand Down
27 changes: 9 additions & 18 deletions test/ctmrg/gaugefix.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Test
using Random
using PEPSKit
using TensorKit

Expand All @@ -17,6 +18,7 @@ end

@testset "Trivial symmetry ($T) - ($unitcell)" for (T, unitcell) in
Iterators.product(scalartypes, unitcells)
Random.seed!(12345678)
physical_space = ComplexSpace(2)
peps_space = ComplexSpace(2)
ctm_space = ComplexSpace(16)
Expand All @@ -25,17 +27,11 @@ end
psi = _make_symmetric(psi)
ctm = CTMRGEnv(psi; Venv=ctm_space)

verbosity = 1
alg = CTMRG(;
trscheme=truncdim(dim(ctm_space)), tol=1e-10, miniter=4, maxiter=100, verbosity=2
)
alg_fixed = CTMRG(;
trscheme=truncdim(dim(ctm_space)),
tol=1e-10,
miniter=4,
maxiter=100,
verbosity=2,
fixedspace=true,
trscheme=truncdim(dim(ctm_space)), tol=1e-10, miniter=4, maxiter=200, verbosity
)
alg_fixed = CTMRG(; trscheme=truncdim(dim(ctm_space)), verbosity, fixedspace=true)

ctm = leading_boundary(psi, alg, ctm)
ctm2, = ctmrg_iter(psi, ctm, alg_fixed)
Expand All @@ -45,6 +41,7 @@ end

@testset "Z2 symmetry ($T) - ($unitcell)" for (T, unitcell) in
Iterators.product(scalartypes, unitcells)
Random.seed!(12345678)
physical_space = Z2Space(0 => 1, 1 => 1)
peps_space = Z2Space(0 => 2, 1 => 2)
ctm_space = Z2Space(0 => 8, 1 => 8)
Expand All @@ -53,17 +50,11 @@ end
psi = _make_symmetric(psi)
ctm = CTMRGEnv(psi; Venv=ctm_space)

verbosity = 1
alg = CTMRG(;
trscheme=truncdim(dim(ctm_space)), tol=1e-10, miniter=4, maxiter=100, verbosity=2
)
alg_fixed = CTMRG(;
trscheme=truncdim(dim(ctm_space)),
tol=1e-10,
miniter=4,
maxiter=100,
verbosity=2,
fixedspace=true,
trscheme=truncdim(dim(ctm_space)), tol=1e-10, miniter=4, maxiter=200, verbosity
)
alg_fixed = CTMRG(; trscheme=truncdim(dim(ctm_space)), verbosity, fixedspace=true)

ctm = leading_boundary(psi, alg, ctm)
ctm2, = ctmrg_iter(psi, ctm, alg_fixed)
Expand Down
22 changes: 10 additions & 12 deletions test/ctmrg/gradients.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
using Test
using Random
using PEPSKit
using TensorKit
using PEPSKit
using Zygote
using OptimKit
using KrylovKit

# Square lattice Heisenberg Hamiltonian
function square_lattice_heisenberg(; Jx=-1.0, Jy=1.0, Jz=-1.0)
function square_lattice_heisenberg(; Jx=-1, Jy=1, Jz=-1)
physical_space = ComplexSpace(2)
T = ComplexF64
Vphys =^2
σx = TensorMap(T[0 1; 1 0], Vphys, Vphys)
σy = TensorMap(T[0 im; -im 0], Vphys, Vphys)
σz = TensorMap(T[1 0; 0 -1], Vphys, Vphys)

@tensor H[-1 -3; -2 -4] :=
Jx * σx[-1, -2] * σx[-3, -4] +
Jy * σy[-1, -2] * σy[-3, -4] +
Jz * σz[-1, -2] * σz[-3, -4]

return NLocalOperator{NearestNeighbor}(H)
σx = TensorMap(T[0 1; 1 0], physical_space, physical_space)
σy = TensorMap(T[0 im; -im 0], physical_space, physical_space)
σz = TensorMap(T[1 0; 0 -1], physical_space, physical_space)
H = (Jx * σx σx) + (Jy * σy σy) + (Jz * σz σz)
return NLocalOperator{NearestNeighbor}(H / 4)
end

h = TensorMap(randn, Float64, ComplexSpace(2)^2, ComplexSpace(2)^2)
Expand All @@ -38,6 +35,7 @@ gradmodes = [nothing, GeomSum(; tol), ManualIter(; tol), KrylovKit.GMRES(; tol)]

@testset "$alg_rrule" for alg_rrule in gradmodes
# random point, random direction
Random.seed!(42039482038)
dir = InfinitePEPS(2, χbond)
psi = InfinitePEPS(2, χbond)
env = leading_boundary(psi, boundary_alg, CTMRGEnv(psi; Venv=^χenv))
Expand Down
2 changes: 2 additions & 0 deletions test/heisenberg.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Test
using Random
using PEPSKit
using TensorKit
using KrylovKit
Expand Down Expand Up @@ -34,6 +35,7 @@ opt_alg = PEPSOptimize(;
)

# initialize states
Random.seed!(91283219347)
psi_init = InfinitePEPS(2, χbond)
env_init = leading_boundary(psi_init, ctm_alg, CTMRGEnv(psi_init; Venv=ComplexSpace(χenv)))

Expand Down

0 comments on commit fcd6056

Please sign in to comment.