Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kd/indexing tests #53

Merged
merged 147 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
a725e63
simplify tests
bartekGardas Jan 15, 2021
6d1f37c
remove _generate_tensor and related tests
bartekGardas Jan 15, 2021
8f433e8
remove previous rank_reveal
bartekGardas Jan 15, 2021
685f002
fix some bug in MPO
bartekGardas Jan 15, 2021
b1750bb
small changes befor merging with Krzysiek
bartekGardas Jan 15, 2021
30810fe
Merge remote-tracking branch 'origin/kd_graphic' into gowina
bartekGardas Jan 15, 2021
1e8a408
all tests pass!
bartekGardas Jan 15, 2021
3466a3e
start adding more tests
bartekGardas Jan 15, 2021
7e56f50
add explicit energy calculation for pathological instance
bartekGardas Jan 15, 2021
658ca2c
add more tests
bartekGardas Jan 15, 2021
7db20f4
add new MPO that admits a state
bartekGardas Jan 15, 2021
0a70581
ready to merge!
bartekGardas Jan 15, 2021
2edb2fe
add more test
bartekGardas Jan 16, 2021
460ff08
Merge branch 'gowina' into sasina
bartekGardas Jan 16, 2021
7b6360b
test Rank reveal correctly decomposes energy into projector, energy, …
annamariadziubyna Jan 16, 2021
c396336
add more test to see if the issue persists
bartekGardas Jan 16, 2021
a5e0caf
Merge branch 'sasina' of github.com:iitis/SpinGlassPEPS.jl into sasina
bartekGardas Jan 16, 2021
1f9fc39
add more tests
bartekGardas Jan 16, 2021
ba5bf14
include right transposition of energy in MPO
bartekGardas Jan 16, 2021
e2fe67d
add tests to PEPS
bartekGardas Jan 16, 2021
16c4954
change length to eachindex and uniformize in vs ∈
lpawela Jan 16, 2021
5a3f008
almost working indexing with states
lpawela Jan 17, 2021
f11eb55
Merge branch 'master' into lp/indexing
lpawela Jan 17, 2021
e72903d
partition function is not calculated correctely
bartekGardas Jan 17, 2021
d9b5fe0
still index not found?
lpawela Jan 17, 2021
6d33927
add missing eval
lpawela Jan 17, 2021
28cbb1a
resotre old version in spectrum.jl
lpawela Jan 17, 2021
ac7d2d7
working indexing!!! for refs now
lpawela Jan 18, 2021
92caae1
support assignment and transposition
lpawela Jan 18, 2021
11699ef
add tests for partition function
bartekGardas Jan 18, 2021
a76a2df
fix notation
lpawela Jan 18, 2021
cf5bfef
not working example
kdomino Jan 18, 2021
7e04db7
fix a bug
bartekGardas Jan 18, 2021
7c91a85
add minor stuff
bartekGardas Jan 18, 2021
323b2a9
expand the not working example
kdomino Jan 19, 2021
c16511f
corrections in benchmarks
kdomino Jan 19, 2021
7c7d7c8
test for low energy configuration
annamariadziubyna Jan 19, 2021
2499261
fix PEPS
bartekGardas Jan 19, 2021
bd0c883
Merge branch 'sasina' of github.com:iitis/SpinGlassPEPS.jl into sasina
bartekGardas Jan 19, 2021
ec0caa9
a correction and merge
kdomino Jan 20, 2021
57293b4
indexing_example.jl with tests
kdomino Jan 20, 2021
d606aae
add tensor product
kdomino Jan 20, 2021
688c951
correction
kdomino Jan 20, 2021
59e1658
a bit more corrections
kdomino Jan 20, 2021
506ca34
add tests
bartekGardas Jan 20, 2021
5080caf
small changes
bartekGardas Jan 20, 2021
9f1af8c
work on benchmark
kdomino Jan 21, 2021
09fd807
test on configurations' energy
annamariadziubyna Jan 21, 2021
c3959be
Merge branch 'sasina' of https://github.com/iitis/SpinGlassPEPS.jl in…
annamariadziubyna Jan 21, 2021
69d9d79
some changes
kdomino Jan 21, 2021
cbaa64b
some discussion
kdomino Jan 21, 2021
cb6220b
some discussion
kdomino Jan 21, 2021
66a668c
tests on vertices
kdomino Jan 21, 2021
aa9802f
correction
kdomino Jan 21, 2021
2d20bbb
add second fg to tests
bartekGardas Jan 21, 2021
c18bb88
add proj
bartekGardas Jan 21, 2021
44f1297
modify BF
bartekGardas Jan 21, 2021
b42bfca
example on 3 spins
kdomino Jan 21, 2021
c853eca
correct test for configurations' energy
annamariadziubyna Jan 21, 2021
433f2f3
correction
kdomino Jan 21, 2021
5a26e54
a simplest example that fails
kdomino Jan 21, 2021
25bfd2f
a simplest example that fails
kdomino Jan 21, 2021
126034e
simplest example
kdomino Jan 21, 2021
279deb5
correction
kdomino Jan 21, 2021
2f49892
add pectrum comparison
bartekGardas Jan 21, 2021
0aece88
start testing indexing
bartekGardas Jan 22, 2021
7c28029
Merge branch 'sasina' of github.com:iitis/SpinGlassPEPS.jl into sasina
bartekGardas Jan 22, 2021
90d8965
correction
kdomino Jan 22, 2021
5838dec
correction
kdomino Jan 22, 2021
64cee8c
some think over
kdomino Jan 22, 2021
c4c7092
correction
kdomino Jan 22, 2021
54de7f4
corrections in indexing tests
kdomino Jan 22, 2021
456f344
allow num_sates for each site
lpawela Jan 22, 2021
fe4c67f
add simple test for indexing
bartekGardas Jan 22, 2021
e101969
Merge remote-tracking branch 'origin/lp/spectrum' into sasina
bartekGardas Jan 22, 2021
10c64bc
add _full_spectrum
bartekGardas Jan 22, 2021
03f4425
Revert "Merge branch 'sasina' of github.com:iitis/SpinGlassPEPS.jl in…
bartekGardas Jan 22, 2021
fbc34a7
add test for factor_graph
lpawela Jan 22, 2021
2b53e22
add partition function - not working yet
annamariadziubyna Jan 22, 2021
c29cb4b
testing clusters
bartekGardas Jan 24, 2021
b7a7ddd
add not working example for indexing
bartekGardas Jan 24, 2021
5feec8a
fix when num_states>rank
lpawela Jan 24, 2021
f7052b7
fix the example
bartekGardas Jan 24, 2021
88b3274
let the users shoot themselves in the foot
lpawela Jan 24, 2021
343f165
restore tests
lpawela Jan 24, 2021
04ff14a
Merge remote-tracking branch 'origin/lp/spectrum' into sasina
bartekGardas Jan 24, 2021
cadcd5a
change example
bartekGardas Jan 24, 2021
50261a1
change the indexing example slightly
bartekGardas Jan 24, 2021
39a95ab
Merge branch 'kd/indexing-tests' of github.com:iitis/SpinGlassPEPS.jl…
bartekGardas Jan 24, 2021
8663022
Merge remote-tracking branch 'origin/sasina' into kd/indexing-tests
bartekGardas Jan 24, 2021
8f36341
improve fg
bartekGardas Jan 24, 2021
55d4f05
add test for partition function
bartekGardas Jan 25, 2021
b133437
correction of tests
kdomino Jan 25, 2021
e0dba0c
correction
kdomino Jan 25, 2021
9148e56
second case
kdomino Jan 25, 2021
69e1dc5
add random t4est
kdomino Jan 25, 2021
3506f20
tensors forms
kdomino Jan 25, 2021
829fb4e
without cuttiong off it works
kdomino Jan 25, 2021
92e3f6f
an example where the solution of A1 is not correct
kdomino Jan 25, 2021
cbe57dc
correction
kdomino Jan 25, 2021
473fd8e
simplify krzysiek's example
bartekGardas Jan 25, 2021
e382ad7
modify example
bartekGardas Jan 25, 2021
a149b44
simple example of solving a simple problem
kdomino Jan 25, 2021
d10c08c
Merge branch 'kd/indexing-tests' of github.com:iitis/SpinGlassPEPS.jl…
kdomino Jan 25, 2021
78c3856
Merge branch 'kd/indexing-tests' of github.com:iitis/SpinGlassPEPS.jl…
bartekGardas Jan 25, 2021
bd7d5a4
add patch
bartekGardas Jan 25, 2021
cf80a62
move to Dict of ranks
lpawela Jan 25, 2021
315a4b1
uncomment tests
lpawela Jan 25, 2021
1faa026
fix gibbs tensor building
lpawela Jan 25, 2021
4a867de
add explicit tensor test
annamariadziubyna Jan 25, 2021
624f29e
test tensor in new example
annamariadziubyna Jan 25, 2021
03e1edf
correct tests
kdomino Jan 26, 2021
bbd851a
Merge branch 'kd/indexing-tests' of github.com:iitis/SpinGlassPEPS.jl…
kdomino Jan 26, 2021
227cba4
correction in ising
kdomino Jan 26, 2021
0ffcd7a
correction
kdomino Jan 26, 2021
7682c7c
some corrections
annamariadziubyna Jan 26, 2021
11ff028
Merge remote-tracking branch 'origin/lp/rank-fix' into sasina
bartekGardas Jan 26, 2021
db6a0e0
merge
kdomino Jan 26, 2021
cfb16d8
corrections
kdomino Jan 26, 2021
d7f8162
add Krzysiek's requests
bartekGardas Jan 26, 2021
ede645d
cd
bartekGardas Jan 26, 2021
a4e61c7
correction to benchmarks
kdomino Jan 26, 2021
530e041
fix u/d transpose
lpawela Jan 26, 2021
9b8fead
correction
kdomino Jan 26, 2021
e02ae2b
another correction
kdomino Jan 26, 2021
655b69b
correct all states
kdomino Jan 26, 2021
beca677
correct typo
kdomino Jan 26, 2021
80abc4c
some additional tests
kdomino Jan 26, 2021
f34a0cd
corrections
kdomino Jan 26, 2021
6740b9e
corrections
kdomino Jan 26, 2021
7af8f02
tests are passing with higher beta
kdomino Jan 27, 2021
c35c56d
correct tests
kdomino Jan 27, 2021
4207d30
correction
kdomino Jan 27, 2021
da57b34
preprare random tests
kdomino Jan 27, 2021
0257395
correction
kdomino Jan 27, 2021
0c873c0
Merge branch 'kd/indexing-tests' into sasina
bartekGardas Jan 27, 2021
b43fe8b
add projectors from factor graph
bartekGardas Jan 27, 2021
b9b81bf
rm unnecessary functions
bartekGardas Jan 27, 2021
2099b00
add notes
kdomino Jan 27, 2021
222807a
rm _full_spectrum
bartekGardas Jan 28, 2021
4a07ec4
add origin to Krzysiek's tests
bartekGardas Jan 28, 2021
c7909eb
modify examples
bartekGardas Jan 28, 2021
d6aa705
add some improvments
bartekGardas Jan 28, 2021
75adf74
merge sasina
kdomino Jan 28, 2021
39f7d39
correction due to comments
kdomino Jan 28, 2021
99ef15c
Merge branch 'sasina' of github.com:iitis/SpinGlassPEPS.jl into kd/in…
kdomino Jan 28, 2021
c56ed17
correct issues
kdomino Jan 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
272 changes: 272 additions & 0 deletions benchmarks/indexing_example_short.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
using SpinGlassPEPS
using MetaGraphs
using LightGraphs
using Test
using TensorCast

function make_particular_tensors(D)
h1 = D[(1,1)]
h2 = D[(2,2)]
J12 = D[(1,2)]
J23 = D[(2,3)]
h3 = D[(3,3)]

if D[(1, 2)] == 0.652
A1ex = reshape([exp(h1+h2-J12) 0. exp(-h1+h2+J12) 0.; 0. exp(h1-h2+J12) 0. exp(-h1-h2-J12)], (1,1,2,1,4))
A2ex = reshape([exp(h3-J23) exp(-h3+J23); exp(h3+J23) exp(-h3-J23)],(2,1,1,1,2))
C = [exp(h1+h2-J12+h3-J23) exp(h1-h2+J12+h3+J23) exp(-h1+h2+J12+h3-J23) exp(-h1-h2-J12+h3+J23); exp(h1+h2-J12-h3+J23) exp(h1-h2+J12-h3-J23) exp(-h1+h2+J12-h3+J23) exp(-h1-h2-J12-h3-J23)]
else
A1ex = reshape([exp(-h1-h2-J12) 0. 0. exp(h1-h2+J12); 0. exp(h1+h2-J12) exp(-h1+h2+J12) 0.], (1,1,2,1,4))
A2ex = reshape([exp(-h3-J23) exp(h3+J23); exp(-h3+J23) exp(h3-J23)],(2,1,1,1,2))
C = [exp(-h1-h2-J12-h3-J23) exp(h1+h2-J12-h3+J23) exp(-h1+h2+J12-h3+J23) exp(h1-h2+J12-h3-J23); exp(-h1-h2-J12+h3+J23) exp(h1+h2-J12+h3-J23) exp(-h1+h2+J12+h3-J23) exp(h1-h2+J12+h3+J23)]
end
A1ex, A2ex, C
end

function show_dificult_example(C, fg)

println("states of T1 ", get_prop(fg, 1, :spectrum).states)
println("x")
println("states of T2 ", get_prop(fg, 2, :spectrum).states)
println("D2, tensor with beta = 1")
display(C)
println()

println("D2, tensor with beta = $β")
display(C.^β)
println()
end

@testset "Test if the solution of the tensor agreeds with the BF" begin

# grid
# A1 | A2
# |
# 1 -- 2 -|- 3


D1 = Dict((1, 2) => 0.652,(2, 3) => 0.73,(3, 3) => 0.592,(2, 2) => 0.704,(1, 1) => 0.868)
D2 = Dict((1, 2) => -0.9049,(2, 3) => 0.2838,(3, 3) => -0.7928,(2, 2) => 0.1208,(1, 1) => -0.3342)

for D in [D1, D2]

m = 1
n = 2
t = 2

L = m * n * t
g_ising = ising_graph(D, L)

# brute force solution
bf = brute_force(g_ising; num_states = 1)
states = bf.states[1]
sol_A1 = states[[1,2]]
sol_A2 = states[[3]]

#particular form of peps tensors
update_cells!(
g_ising,
rule = square_lattice((m, 1, n, 1, t)),
)

fg = factor_graph(
g_ising,
Dict(1=>4, 2=>2),
energy=energy,
spectrum = brute_force
)

for origin ∈ (:NW, :SW)

β = 2.

x, y = m, n
peps = PepsNetwork(x, y, fg, β, origin)
pp = PEPSRow(peps, 1)


# the solution without cutting off
M1 = pp[1][1,1,:,1,:]
M2 = pp[2][:,1,1,1,:]
@reduce MM[a,b] |= sum(x) M1[x,a] * M2[x,b]

_, inds = findmax(MM)

A1ex, A2ex, C = make_particular_tensors(D)

@test pp[1] ≈ A1ex.^β
@test pp[2] ≈ A2ex.^β
@test MM ≈ transpose(C.^β)


# peps solution, first tensor
Aa1 = pp[1]
Aa2 = MPO(pp)[2]

@reduce A12[l, u, d, uu, rr, dd, σ] |= sum(x) Aa1[l, u, x, d, σ] * Aa2[x, uu, rr, dd]
A12 = dropdims(A12, dims=(1,2,3,4,5,6))
_, spins = findmax(A12)

#solution from the first tensor
st = get_prop(fg, 1, :spectrum).states
@test st[spins] == sol_A1
@test st[inds[1]] == sol_A1

# reading projector
p1, en, p2 = projectors(fg, 1, 2)
if D[(1, 2)] == 0.652
@test p1 == [1.0 0.0; 0.0 1.0; 1.0 0.0; 0.0 1.0]
@test en == [0.73 -0.73; -0.73 0.73]
@test p2 == [1.0 0.0; 0.0 1.0]
end
r1, rn, r2 = projectors(fg, 2, 1)
@test p1 == r2
@test p2 == r1
@test en == rn
@test projectors(fg, 3, 1) == (ones(1,1), ones(1,1), ones(1,1))

@reduce C[a, b, c, d] := sum(x) p1[$spins, x] * pp[$2][x, a, b, c, d]
_, s = findmax(C[1,1,1,:])

# solution form the second tensor
st = get_prop(fg, 2, :spectrum).states
@test st[s] == sol_A2
@test st[inds[2]] == sol_A2
end
end
end

@testset "larger example" begin
# grid
# A1 | A2
# |
# 1 -- 3 -|- 5 -- 7
# | | | | |
# | | | | |
# 2 -- 4 -|- 6 -- 8
# |

D = Dict((5, 7) => -0.0186,(5, 6) => 0.0322,(2, 2) => -0.5289544745642463,(4, 4) => -0.699,(4, 6) => 0.494,(3, 3) => -0.4153941108520631,(8, 8) => 0.696,(6, 8) => 0.552,(1, 3) => -0.739,(7, 8) => -0.0602,(2, 4) => -0.0363,(1, 1) => 0.218,(7, 7) => -0.931,(1, 2) => 0.162,(6, 6) => 0.567,(5, 5) => -0.936,(3, 4) => 0.0595,(3, 5) => -0.9339)


m = 1
n = 2
t = 4


L = m * n * t

g_ising = ising_graph(D, L)

update_cells!(
g_ising,
rule = square_lattice((m, 1, n, 1, t)),
)

fg1 = factor_graph(
g_ising,
Dict(1=>16, 2=>16),
energy=energy,
spectrum = brute_force,
)

fg2 = factor_graph(
g_ising,
Dict(1=>16, 2=>16),
energy=energy,
spectrum = full_spectrum,
)

for fg in [fg1, fg2]

#Partition function
β = 2.
states = collect.(all_states(rank_vec(g_ising)))

ρ = exp.(-β .* energy.(states, Ref(g_ising)))
Z = sum(ρ)
@test gibbs_tensor(g_ising, β) ≈ ρ ./ Z

for origin ∈ (:NW, :SW, :WS, :WN, :NE, :EN, :SE, :ES)

peps = PepsNetwork(m, n, fg, β, origin)

ψ = MPO(PEPSRow(peps, 1))

for i ∈ 2:peps.i_max
W = MPO(PEPSRow(peps, i))
M = MPO(peps, i-1, i)

ψ = (ψ * M) * W

@test length(W) == peps.j_max
for A ∈ ψ @test size(A, 2) == 1 end
@test size(ψ[1], 1) == 1 == size(ψ[peps.j_max], 3)
end
for A ∈ ψ @test size(A, 4) == 1 end
#println("ψ ", ψ)

ZZ = []
for A ∈ ψ
#println("A ", A)
push!(ZZ, dropdims(A, dims=(2, 4)))
#println("ZZ ", ZZ)
end
@test Z ≈ prod(ZZ)[]
end


origin = :NW

x, y = m, n
peps = PepsNetwork(x, y, fg, β, origin)
pp = PEPSRow(peps, 1)


# brute force solution
bf = brute_force(g_ising; num_states = 1)
states = bf.states[1]

cluster = props(fg, 1)[:cluster]
println(cluster.vertices)

cluster = props(fg, 2)[:cluster]
println(cluster.vertices)
sol_A1 = states[[1,2,3,4]]
sol_A2 = states[[5,6,7,8]]

Aa1 = pp[1]

# A2 traced
# index 1 (left is not trivial)

Aa2 = MPO(pp)[2]

# contraction of A1 with A2
#
# . .
# . .
# A1 -- A2 = A12
#

@reduce A12[l, u, d, uu, rr, dd, σ] |= sum(x) Aa1[l, u, x, d, σ] * Aa2[x, uu, rr, dd]

A12 = dropdims(A12, dims=(1,2,3,4,5,6))

_, spins = findmax(A12)

st = get_prop(fg, 1, :spectrum).states

@test st[spins] == sol_A1

p1, _, _ = projectors(fg, 1, 2)

@reduce C[a, b, c, d] := sum(x) p1[$spins, x] * pp[$2][x, a, b, c, d]

_, s = findmax(C[1,1,1,:])

st = get_prop(fg, 2, :spectrum).states

@test st[s] == sol_A2
end
end