Skip to content

Commit 245182b

Browse files
author
Jack Dunham
committed
Format test files and improve comparisons for readabilty on failure
1 parent 7a51966 commit 245182b

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

test/solvers/test_applyexp.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ function chain_plus_ancilla(; nchain)
1212
for j in 1:nchain
1313
add_vertex!(g, j)
1414
end
15-
for j in 1:(nchain - 1)
16-
add_edge!(g, j=>j+1)
15+
for j in 1:(nchain-1)
16+
add_edge!(g, j => j + 1)
1717
end
1818
# Add ancilla vertex near middle of chain
1919
add_vertex!(g, 0)
20-
add_edge!(g, 0=>nchain÷2)
20+
add_edge!(g, 0 => nchain ÷ 2)
2121
return g
2222
end
2323

@@ -31,10 +31,10 @@ end
3131

3232
# Make Heisenberg model Hamiltonian
3333
h = OpSum()
34-
for j in 1:(N - 1)
35-
h += "Sz", j, "Sz", j+1
36-
h += 1/2, "S+", j, "S-", j+1
37-
h += 1/2, "S-", j, "S+", j+1
34+
for j in 1:(N-1)
35+
h += "Sz", j, "Sz", j + 1
36+
h += 1 / 2, "S+", j, "S-", j + 1
37+
h += 1 / 2, "S-", j, "S+", j + 1
3838
end
3939
H = ttn(h, sites)
4040

@@ -54,7 +54,7 @@ end
5454
E, gs_psi = dmrg(H, psi0; insert_kwargs=(; trunc), nsites, nsweeps, outputlevel)
5555
(outputlevel >= 1) && println("2-site DMRG energy = ", E)
5656

57-
insert_kwargs=(; trunc)
57+
insert_kwargs = (; trunc)
5858
nsites = 1
5959
tmax = 0.10
6060
time_range = 0.0:0.02:tmax
@@ -73,7 +73,7 @@ end
7373

7474
# Test that accumulated phase angle is E*tmax
7575
z = inner(psi1_t, gs_psi)
76-
@test abs(atan(imag(z)/real(z)) - E*tmax) < 1E-4
76+
@test atan(imag(z) / real(z)) E * tmax atol = 1E-4
7777
end
7878

7979
@testset "Applyexp Time Point Handling" begin
@@ -83,10 +83,10 @@ end
8383

8484
# Make Heisenberg model Hamiltonian
8585
h = OpSum()
86-
for j in 1:(N - 1)
87-
h += "Sz", j, "Sz", j+1
88-
h += 1/2, "S+", j, "S-", j+1
89-
h += 1/2, "S-", j, "S+", j+1
86+
for j in 1:(N-1)
87+
h += "Sz", j, "Sz", j + 1
88+
h += 1 / 2, "S+", j, "S-", j + 1
89+
h += 1 / 2, "S-", j, "S+", j + 1
9090
end
9191
H = ttn(h, sites)
9292

@@ -99,23 +99,23 @@ end
9999

100100
nsites = 2
101101
trunc = (; cutoff=1E-8, maxdim=100)
102-
insert_kwargs=(; trunc)
102+
insert_kwargs = (; trunc)
103103

104104
# Test that all time points are reached and reported correctly
105-
time_points = [0.0,0.1,0.25,0.32,0.4]
105+
time_points = [0.0, 0.1, 0.25, 0.32, 0.4]
106106
times = Real[]
107107
function collect_times(problem; kws...)
108108
push!(times, ITensorNetworks.current_time(problem))
109109
end
110-
time_evolve(H, time_points, psi0; insert_kwargs, nsites, sweep_callback=collect_times,outputlevel=1)
111-
@test norm(times - time_points) < 10*eps(Float64)
110+
time_evolve(H, time_points, psi0; insert_kwargs, nsites, sweep_callback=collect_times, outputlevel=1)
111+
@test times time_points atol = 10 * eps(Float64)
112112

113113
# Test that all exponents are reached and reported correctly
114-
exponent_points = [-0.0,-0.1,-0.25,-0.32,-0.4]
114+
exponent_points = [-0.0, -0.1, -0.25, -0.32, -0.4]
115115
exponents = Real[]
116116
function collect_exponents(problem; kws...)
117117
push!(exponents, ITensorNetworks.current_exponent(problem))
118118
end
119-
applyexp(H, exponent_points, psi0; insert_kwargs, nsites, sweep_callback=collect_exponents,outputlevel=1)
120-
@test norm(exponents - exponent_points) < 10*eps(Float64)
119+
applyexp(H, exponent_points, psi0; insert_kwargs, nsites, sweep_callback=collect_exponents, outputlevel=1)
120+
@test exponents exponent_points atol = 10 * eps(Float64)
121121
end

test/solvers/test_eigsolve.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ include("utilities/tree_graphs.jl")
2020
for edge in edges(sites)
2121
i, j = src(edge), dst(edge)
2222
h += "Sz", i, "Sz", j
23-
h += 1/2, "S+", i, "S-", j
24-
h += 1/2, "S-", i, "S+", j
23+
h += 1 / 2, "S+", i, "S-", j
24+
h += 1 / 2, "S-", i, "S+", j
2525
end
2626
H = ttn(h, sites)
2727

@@ -48,7 +48,7 @@ include("utilities/tree_graphs.jl")
4848
insert_kwargs = (; trunc)
4949
E, psi = dmrg(H, psi0; insert_kwargs, nsites, nsweeps, outputlevel)
5050
(outputlevel >= 1) && println("2-site DMRG energy = ", E)
51-
@test abs(E-Ex) < 1E-5
51+
@test E Ex atol = 1E-5
5252

5353
#
5454
# Test 1-site DMRG with subspace expansion
@@ -60,5 +60,5 @@ include("utilities/tree_graphs.jl")
6060
insert_kwargs = (; trunc)
6161
E, psi = dmrg(H, psi0; extract_kwargs, insert_kwargs, nsites, nsweeps, outputlevel)
6262
(outputlevel >= 1) && println("1-site+subspace DMRG energy = ", E)
63-
@test abs(E-Ex) < 1E-5
63+
@test E Ex atol = 1E-5
6464
end

0 commit comments

Comments
 (0)