From 5a95b8fae4fb63c483c28261244f53e55eddcbb4 Mon Sep 17 00:00:00 2001 From: bartek Date: Wed, 9 Dec 2020 11:13:40 +0100 Subject: [PATCH 001/137] add Cluster and Edge --- src/PEPS.jl | 8 ----- src/SpinGlassPEPS.jl | 2 +- src/graph.jl | 83 ++++++++++++-------------------------------- src/ising.jl | 65 +++++++++++++++++++++++++++++----- test/graph.jl | 11 ------ 5 files changed, 79 insertions(+), 90 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 7865c0f3..8b137891 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,9 +1 @@ -struct PEPSTensor{T <: AbstractArray{<:Number, 5}} - cluster::Cluster - cluster_state::Vector{Int} - data::T -end -struct PEPS - tensors::Matrix{PEPSTensor} -end diff --git a/src/SpinGlassPEPS.jl b/src/SpinGlassPEPS.jl index 62ee0c95..fe841cac 100644 --- a/src/SpinGlassPEPS.jl +++ b/src/SpinGlassPEPS.jl @@ -15,7 +15,7 @@ module SpinGlassPEPS include("contractions.jl") include("ising.jl") include("graph.jl") - # include("PEPS.jl") + include("PEPS.jl") include("search.jl") include("utils.jl") diff --git a/src/graph.jl b/src/graph.jl index 650d79e7..f408ef8a 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,38 +1,27 @@ -export Chimera, outer_connections, factor_graph, cluster +export Chimera, factor_graph +export Cluster, Spectrum + mutable struct Chimera size::NTuple{3, Int} graph::MetaGraph - outer_connections::Dict{Tuple, Vector} function Chimera(size::NTuple{3, Int}, graph::MetaGraph) - c = new(size, graph) + cg = new(size, graph) m, n, t = size linear = LinearIndices((1:m, 1:n)) for i=1:m, j=1:n, u=1:2, k=1:t - v = c[i, j, u, k] + v = cg[i, j, u, k] ij = linear[i, j] - set_prop!(c, v, :cluster, ij) + set_prop!(cg, v, :cell, ij) end - outer_connections = Dict{Tuple, Vector}() - for e in edges(c) - src_cluster = get_prop(c, src(e), :cluster) - dst_cluster = get_prop(c, dst(e), :cluster) - # if src_cluster == dst_cluster - # set_prop!(c, e, :outer, false) - # else - key = (src_cluster, dst_cluster) - set_prop!(c, e, :cluster, key) - if haskey(outer_connections, key) - push!(outer_connections[key], e) - else - outer_connections[key] = [e] - end - # end + for e in edges(cg) + v = get_prop(cg, src(e), :cell) + w = get_prop(cg, dst(e), :cell) + set_prop!(cg, e, :cells, (v, w)) end - c.outer_connections = outer_connections - c + cg end end @@ -97,26 +86,12 @@ function Base.getindex(c::Chimera, i::Int, j::Int) c.graph[idx] end - -outer_connections(c::Chimera, i, j, k, l) = outer_connections(c::Chimera, (i, j), (k, l)) - -function outer_connections(c::Chimera, src, dst) - ret = get(c.outer_connections, (src, dst), []) - if length(ret) == 0 - ret = get(c.outer_connections, (dst, src), []) - end - ret +function Cluster(c::Chimera, v::Int) + elist = filter_edges(c.graph, :cells, (v, v)) + vlist = filter_vertices(c.graph, :cell, v) + Cluster(c.graph, v, enum(vlist), elist) end -function Cluster(c::Chimera, v::Int, w::Int) - vv = collect(filter_vertices(c.graph, :cluster, v)) - vw = collect(filter_vertices(c.graph, :cluster, w)) - ve = filter_edges(c.graph, :cluster, (v, w)) - Cluster(c.graph, enum(union(vv, vw)), ve) -end - -Cluster(c::Chimera, v::Int) = Cluster(c, v, v) - #Spectrum(cl::Cluster) = brute_force(cl, num_states=256) function Spectrum(cl::Cluster) @@ -125,7 +100,7 @@ function Spectrum(cl::Cluster) Spectrum(energies, σ) end -function factor_graph(c::Chimera) +function factor_graph(c::Chimera, cell::NTuple=(1,1)) m, n, _ = c.size fg = MetaGraph(grid([m, n])) @@ -133,30 +108,16 @@ function factor_graph(c::Chimera) cl = Cluster(c, v) set_prop!(fg, v, :cluster, cl) set_prop!(fg, v, :spectrum, Spectrum(cl)) - - - for w ∈ unique_neighbors(fg, v) - set_prop!(fg, v, w, :cluster, Cluster(c, v, w)) - end - end - #= - for v ∈ vertices(fg) - for w ∈ unique_neighbors(fg, v) - cl = Cluster(c, v, w) - set_prop!(fg, v, w, :cluster, cl) + for e ∈ edges(fg) + v = get_prop(fg, src(e), :cluster) + w = get_prop(fg, dst(e), :cluster) - σ = get_prop(fg, v, :spectrum) - η = get_prop(fg, w, :spectrum) - - #E = [ energy(x, cl) for x ∈ σ.states ] - E = energy.(σ.states, cl) - #E = [ energy(x, cl, y) for x ∈ σ.states, y ∈ η.states ] - end + edge = Edge(fg, v, w) + set_prop!(fg, e, :edge, edge) + set_prop!(fg, e, :energy, energy(fg, edge)) end - =# fg end - diff --git a/src/ising.jl b/src/ising.jl index 5800a735..54413fe8 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -1,10 +1,11 @@ export ising_graph, energy export gibbs_tensor, brute_force -export State, Cluster, Spectrum +export State, Cluster, Edge, Spectrum const State = Union{Vector, NTuple} const Instance = Union{String, Dict} -const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter} +const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge +const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter, Array} struct Spectrum energies::Array{<:Number} @@ -12,14 +13,15 @@ struct Spectrum end mutable struct Cluster + tag::Int vertices::Dict{Int,Int} edges::EdgeIter rank::Vector J::Matrix{<:Number} h::Vector{<:Number} - function Cluster(ig::MetaGraph, vertices::Dict, edges::EdgeIter) - cl = new(vertices, edges) + function Cluster(ig::MetaGraph, v::Int, vertices::Dict, edges::EdgeIter) + cl = new(v, vertices, edges) L = length(cl.vertices) cl.J = zeros(L, L) @@ -33,14 +35,48 @@ mutable struct Cluster cl.rank = rank[1:L] cl.h = zeros(L) - for (v, i) ∈ cl.vertices - cl.h[i] = get_prop(ig, v, :h) - cl.rank[i] = rank[v] + for (w, i) ∈ cl.vertices + cl.h[i] = get_prop(ig, w, :h) + cl.rank[i] = rank[w] end cl end end +function MetaGraphs.filter_edges(ig::MetaGraph, v::Cluster, w::Cluster) + edges = [] + for i ∈ keys(v.vertices) + for j ∈ unique_neighbors(ig, i) + if j ∈ keys(w.vertices) + push!(edges, SimpleEdge(i, j)) + end + end + end + edges +end + +mutable struct Edge + tag::NTuple + edges::EdgeIter + J::Matrix{<:Number} + + function Edge(ig::MetaGraph, v::Cluster, w::Cluster) + ed = new((v.tag, w.tag)) + ed.edges = filter_edges(ig, v, w) + + m = length(v.vertices) + n = length(w.vertices) + + ed.J = zeros(m, n) + for e ∈ ed.edges + i = v.vertices[src(e)] + j = w.vertices[dst(e)] + ed.J[i, j] = get_prop(ig, e, :J) + end + ed + end +end + """ $(TYPEDSIGNATURES) @@ -54,7 +90,7 @@ of a classical Ising Hamiltonian """ function brute_force(ig::MetaGraph; num_states::Int=1) - cl = Cluster(ig, enum(vertices(ig)), edges(ig)) + cl = Cluster(ig, 0, num(vertices(ig)), edges(ig)) brute_force(cl, num_states=num_states) end @@ -120,10 +156,21 @@ function energy(σ::Vector, cl::Cluster, η::Vector=σ; sgn::Float64=-1.0) end function energy(σ::Vector, ig::MetaGraph; sgn::Float64=-1.0) - cl = Cluster(ig, enum(vertices(ig)), edges(ig)) + cl = Cluster(ig, 0, enum(vertices(ig)), edges(ig)) energy(σ, cl, sgn=sgn) end +function energy(fg::MetaGraph, edge::Edge) + v, w = edge.tag + vSp = get_prop(fg, v, :spectrum).states + wSp = get_prop(fg, w, :spectrum).states + + σ = reshape(vSp, prod(vSp)) + η = reshape(wSp, prod(wSp)) + + [ energy.(σ, edge.J, x) for x ∈ η] +end + """ $(TYPEDSIGNATURES) diff --git a/test/graph.jl b/test/graph.jl index 0fe66ba9..4255d582 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -14,17 +14,6 @@ g = Chimera(m, n, t) @show g[1, 1] end -@testset "Chimera outer connections" begin - @test length(outer_connections(g, 1, 1, 3, 3)) == 0 - @test all(outer_connections(g, 1, 1, 1, 2) .== outer_connections(g, 1, 2, 1, 1)) - - # This still does not work - println(outer_connections(g, 1, 1, 1, 2)) - println(typeof(g)) - - edges = filter_edges(g.graph, :cluster, (1, 2)) - println(collect(edges)) -end @testset "Chimera/factor graph" begin m = 16 From 8ac075ff44d16e2a65b6dffe0d3c08de3005224d Mon Sep 17 00:00:00 2001 From: bartek Date: Wed, 9 Dec 2020 12:25:46 +0100 Subject: [PATCH 002/137] add unit_cell for chimera and the energy decomposition --- src/graph.jl | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index f408ef8a..3742a695 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -86,12 +86,14 @@ function Base.getindex(c::Chimera, i::Int, j::Int) c.graph[idx] end -function Cluster(c::Chimera, v::Int) +function unit_cell(c::Chimera, v::Int) elist = filter_edges(c.graph, :cells, (v, v)) vlist = filter_vertices(c.graph, :cell, v) Cluster(c.graph, v, enum(vlist), elist) end +Cluster(c::Chimera, v::Int) = unit_cell(c, v) + #Spectrum(cl::Cluster) = brute_force(cl, num_states=256) function Spectrum(cl::Cluster) @@ -100,7 +102,7 @@ function Spectrum(cl::Cluster) Spectrum(energies, σ) end -function factor_graph(c::Chimera, cell::NTuple=(1,1)) +function factor_graph(c::Chimera) m, n, _ = c.size fg = MetaGraph(grid([m, n])) @@ -116,8 +118,20 @@ function factor_graph(c::Chimera, cell::NTuple=(1,1)) edge = Edge(fg, v, w) set_prop!(fg, e, :edge, edge) - set_prop!(fg, e, :energy, energy(fg, edge)) + + en = energy(fg, edge) + eexp = unique(en) + + set_prop!(fg, e, :exp, eexp) + set_prop!(fg, e, :proj, indexin(eexp, en)) end fg end + +function peps_tensor(fg::MetaGraph, v::Int) + for w ∈ unique_neighbors(fg, v) + + end +end + From e499dd61c12a154672fdbd7967ff45421f9296d1 Mon Sep 17 00:00:00 2001 From: bartek Date: Wed, 9 Dec 2020 15:28:32 +0100 Subject: [PATCH 003/137] add peps tensor --- src/graph.jl | 16 ++++++++++------ test/graph.jl | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 3742a695..758766bf 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -118,20 +118,24 @@ function factor_graph(c::Chimera) edge = Edge(fg, v, w) set_prop!(fg, e, :edge, edge) - - en = energy(fg, edge) - eexp = unique(en) - - set_prop!(fg, e, :exp, eexp) - set_prop!(fg, e, :proj, indexin(eexp, en)) + set_prop!(fg, e, :energy, energy(fg, edge)) end fg end function peps_tensor(fg::MetaGraph, v::Int) + T = Dict{String, AbstractArray}() + for w ∈ unique_neighbors(fg, v) + + #to_exp = unique(en) + + #set_prop!(fg, e, :energy, to_exp) + #set_prop!(fg, e, :projector, indexin(to_exp, en)) end + + @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] end diff --git a/test/graph.jl b/test/graph.jl index 4255d582..13ae0777 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -16,8 +16,8 @@ end @testset "Chimera/factor graph" begin - m = 16 - n = 16 + m = 4 + n = 4 t = 4 L = 2 * n * m * t From 6eaaa366373e3815e0885c780c4adec4e073d440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Wed, 9 Dec 2020 15:59:06 +0100 Subject: [PATCH 004/137] remnove sgn --- src/ising.jl | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/ising.jl b/src/ising.jl index 54413fe8..5efaaa17 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -143,21 +143,13 @@ E = -\\sum_ s_i J_{ij} * s_j - \\sum_j h_i s_j. ``` """ -function energy(σ::Vector, J::Matrix, η::Vector=σ; sgn::Float64=-1.0) - sgn * dot(σ, J, η) -end - -function energy(σ::Vector, h::Vector; sgn::Float64=-1.0) - sgn * dot(h, σ) -end - -function energy(σ::Vector, cl::Cluster, η::Vector=σ; sgn::Float64=-1.0) - energy(σ, cl.J, η, sgn=sgn) + energy(cl.h, σ, sgn=sgn) -end +energy(σ::Vector, J::Matrix, η::Vector=σ) = dot(σ, J, η) +energy(σ::Vector, h::Vector) = dot(h, σ) +energy(σ::Vector, cl::Cluster, η::Vector=σ) = energy(σ, cl.J, η) + energy(cl.h, σ) -function energy(σ::Vector, ig::MetaGraph; sgn::Float64=-1.0) +function energy(σ::Vector, ig::MetaGraph) cl = Cluster(ig, 0, enum(vertices(ig)), edges(ig)) - energy(σ, cl, sgn=sgn) + energy(σ, cl) end function energy(fg::MetaGraph, edge::Edge) From cae15b0aeda65aa76f16761204b3df01abf71116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Wed, 9 Dec 2020 16:06:47 +0100 Subject: [PATCH 005/137] something still broken --- src/ising.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ising.jl b/src/ising.jl index 5efaaa17..f5ca8c52 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -157,10 +157,12 @@ function energy(fg::MetaGraph, edge::Edge) vSp = get_prop(fg, v, :spectrum).states wSp = get_prop(fg, w, :spectrum).states - σ = reshape(vSp, prod(vSp)) - η = reshape(wSp, prod(wSp)) + σ = vec(vSp) + η = vec(wSp) + # σ = reshape(vSp, prod(vSp)) + # η = reshape(wSp, prod(wSp)) - [ energy.(σ, edge.J, x) for x ∈ η] + [ energy.(σ, Ref(edge.J), Ref(x)) for x ∈ η] end """ From 7780010ded8fbe57c7215a7de0681aa72eee8f35 Mon Sep 17 00:00:00 2001 From: bartek Date: Wed, 9 Dec 2020 19:04:15 +0100 Subject: [PATCH 006/137] finish writting factro graph --- src/graph.jl | 6 +++--- src/ising.jl | 7 +------ test/graph.jl | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 758766bf..991398a9 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -116,14 +116,14 @@ function factor_graph(c::Chimera) v = get_prop(fg, src(e), :cluster) w = get_prop(fg, dst(e), :cluster) - edge = Edge(fg, v, w) + edge = Edge(c.graph, v, w) set_prop!(fg, e, :edge, edge) set_prop!(fg, e, :energy, energy(fg, edge)) end fg end - +#= function peps_tensor(fg::MetaGraph, v::Int) T = Dict{String, AbstractArray}() @@ -138,4 +138,4 @@ function peps_tensor(fg::MetaGraph, v::Int) @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] end - +=# diff --git a/src/ising.jl b/src/ising.jl index f5ca8c52..3d961de7 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -157,12 +157,7 @@ function energy(fg::MetaGraph, edge::Edge) vSp = get_prop(fg, v, :spectrum).states wSp = get_prop(fg, w, :spectrum).states - σ = vec(vSp) - η = vec(wSp) - # σ = reshape(vSp, prod(vSp)) - # η = reshape(wSp, prod(wSp)) - - [ energy.(σ, Ref(edge.J), Ref(x)) for x ∈ η] + [ energy.(vec(vSp), Ref(edge.J), Ref(η)) for η ∈ vec(wSp)] end """ diff --git a/test/graph.jl b/test/graph.jl index 13ae0777..4255d582 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -16,8 +16,8 @@ end @testset "Chimera/factor graph" begin - m = 4 - n = 4 + m = 16 + n = 16 t = 4 L = 2 * n * m * t From dab79bd87d43fd344c7033e0ed628abd0ddd6eec Mon Sep 17 00:00:00 2001 From: bartek Date: Wed, 9 Dec 2020 20:36:57 +0100 Subject: [PATCH 007/137] add tests --- src/graph.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 991398a9..abcc883d 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -123,7 +123,7 @@ function factor_graph(c::Chimera) fg end -#= + function peps_tensor(fg::MetaGraph, v::Int) T = Dict{String, AbstractArray}() @@ -138,4 +138,4 @@ function peps_tensor(fg::MetaGraph, v::Int) @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] end -=# + From e75649bd0e5e737b481252cb8edf743e6baabcec Mon Sep 17 00:00:00 2001 From: bartek Date: Thu, 10 Dec 2020 12:30:17 +0100 Subject: [PATCH 008/137] add directed fg --- src/graph.jl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/graph.jl b/src/graph.jl index abcc883d..78cea4b0 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -139,3 +139,22 @@ function peps_tensor(fg::MetaGraph, v::Int) @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] end +function diGrid(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) + dg = SimpleDiGraph(m * n) + linear = LinearIndices((1:width, 1:height)) + + for i ∈ 1:m + for j ∈ 1:n-1 + v, w = linear[i, j], linear[i, j+1] + if hdir == 1 ? e = (v, w) : e = (w, e) + add_edge!(dg, e) + end + end + + for i ∈ 1:n + for j ∈ 1:m-1 + add_edge!(dg, vert_dir(linear[j+1, i], linear[j, i])...) + end + end + dg +end \ No newline at end of file From c53abdd3b604352591b902c75250adc0f932f067 Mon Sep 17 00:00:00 2001 From: Bartlomiej Gardas Date: Thu, 10 Dec 2020 12:30:59 +0100 Subject: [PATCH 009/137] cleaning instances --- test/instances/chimera_droplets/128power/groundstates_TN.txt | 1 + test/instances/chimera_droplets/2048power/groundstates_TN.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 test/instances/chimera_droplets/128power/groundstates_TN.txt create mode 100644 test/instances/chimera_droplets/2048power/groundstates_TN.txt diff --git a/test/instances/chimera_droplets/128power/groundstates_TN.txt b/test/instances/chimera_droplets/128power/groundstates_TN.txt new file mode 100644 index 00000000..d7a9f9a0 --- /dev/null +++ b/test/instances/chimera_droplets/128power/groundstates_TN.txt @@ -0,0 +1 @@ +001.txt : -210.933333 1 0 1 1 0 1 1 1 0 1 1 0 0 1 0 1 1 1 0 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 1 0 0 1 1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 0 0 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 1 diff --git a/test/instances/chimera_droplets/2048power/groundstates_TN.txt b/test/instances/chimera_droplets/2048power/groundstates_TN.txt new file mode 100644 index 00000000..7ea30fd8 --- /dev/null +++ b/test/instances/chimera_droplets/2048power/groundstates_TN.txt @@ -0,0 +1 @@ +001.txt : -3336.773333 0 1 1 0 1 0 0 1 0 0 1 1 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 1 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 1 0 1 1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1 1 0 0 0 1 0 1 1 1 1 0 0 1 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 0 1 1 1 1 0 0 1 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 1 1 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 0 0 0 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 0 1 1 0 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 0 1 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 1 0 1 1 1 1 1 0 1 1 1 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 0 1 1 0 0 1 0 1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 1 0 1 0 1 1 0 0 0 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 1 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 1 1 1 0 0 0 1 0 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 1 1 0 1 1 0 0 0 1 1 1 0 0 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 0 0 1 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0 0 1 1 0 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 0 1 0 0 1 0 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 0 1 0 1 0 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 0 1 0 0 1 0 1 1 1 0 0 1 1 1 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 1 1 1 0 0 0 1 0 0 0 0 0 1 1 1 0 1 0 1 0 1 1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 0 1 0 0 0 0 0 1 1 1 1 0 1 1 0 1 0 0 1 0 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 1 1 1 1 1 1 0 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 0 0 1 0 1 1 1 0 1 1 0 1 0 0 1 1 0 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 0 1 1 1 1 0 1 0 0 0 0 0 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 1 0 0 0 1 1 1 0 0 1 0 1 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 0 0 0 0 1 0 0 1 0 0 0 1 1 1 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 0 0 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 0 0 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 0 1 1 0 1 1 1 0 1 0 1 1 0 0 0 1 1 0 0 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 1 0 1 0 1 1 1 0 0 1 1 0 1 1 0 0 1 1 0 1 0 1 0 1 1 1 1 1 0 1 1 0 1 0 0 0 0 1 0 0 0 0 1 1 1 0 1 0 1 1 0 1 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 1 1 0 0 0 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 1 1 1 0 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 0 0 1 1 1 0 1 1 1 0 1 1 0 0 1 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 0 1 0 1 0 1 0 1 1 0 1 0 0 0 1 1 0 1 1 0 0 1 0 0 0 1 0 1 1 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 0 0 1 0 1 0 0 1 1 1 0 0 0 1 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1 1 0 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 1 1 0 1 1 1 0 1 0 1 1 0 0 0 0 1 0 1 1 0 0 0 1 0 1 1 0 1 1 1 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 1 1 1 1 0 0 1 From 930ee70f13a870b9c36486a32cf0b2732dfba055 Mon Sep 17 00:00:00 2001 From: Bartlomiej Gardas Date: Thu, 10 Dec 2020 12:31:15 +0100 Subject: [PATCH 010/137] cleaning some more --- test/instances/chimera_droplets/512power/groundstates_TN.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/instances/chimera_droplets/512power/groundstates_TN.txt diff --git a/test/instances/chimera_droplets/512power/groundstates_TN.txt b/test/instances/chimera_droplets/512power/groundstates_TN.txt new file mode 100644 index 00000000..04a70c87 --- /dev/null +++ b/test/instances/chimera_droplets/512power/groundstates_TN.txt @@ -0,0 +1 @@ +001.txt : -846.960000 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 0 0 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 0 1 0 0 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 0 1 1 0 1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 1 1 0 0 1 0 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 0 1 1 1 0 1 0 0 1 0 0 1 1 1 1 0 0 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 0 1 0 0 1 1 0 1 0 1 1 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 0 0 1 0 1 0 1 0 0 1 1 0 1 1 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 0 1 0 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 1 1 0 0 0 1 1 1 1 1 0 0 1 0 1 1 0 1 0 0 1 1 0 0 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 0 1 0 1 0 1 1 1 1 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 1 0 1 1 1 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 From 657856a9d3b96cca54e48c2a627653658521f319 Mon Sep 17 00:00:00 2001 From: Bartlomiej Gardas Date: Thu, 10 Dec 2020 21:24:29 +0100 Subject: [PATCH 011/137] modify factor graph --- src/graph.jl | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 78cea4b0..23511d6f 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -102,6 +102,28 @@ function Spectrum(cl::Cluster) Spectrum(energies, σ) end +function factor_graph(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) + dg = SimpleDiGraph(m * n) + linear = LinearIndices((1:m, 1:n)) + + for i ∈ 1:m + for j ∈ 1:n-1 + v, w = linear[i, j], linear[i, j+1] + hdir == 1 ? e = (v, w) : e = (w, v) + add_edge!(dg, e) + end + end + + for i ∈ 1:n + for j ∈ 1:m-1 + v, w = linear[i, j], linear[i, j+1] + vdir == 1 ? e = (v, w) : e = (w, v) + add_edge!(dg, e) + end + end + dg +end + function factor_graph(c::Chimera) m, n, _ = c.size fg = MetaGraph(grid([m, n])) @@ -138,23 +160,3 @@ function peps_tensor(fg::MetaGraph, v::Int) @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] end - -function diGrid(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) - dg = SimpleDiGraph(m * n) - linear = LinearIndices((1:width, 1:height)) - - for i ∈ 1:m - for j ∈ 1:n-1 - v, w = linear[i, j], linear[i, j+1] - if hdir == 1 ? e = (v, w) : e = (w, e) - add_edge!(dg, e) - end - end - - for i ∈ 1:n - for j ∈ 1:m-1 - add_edge!(dg, vert_dir(linear[j+1, i], linear[j, i])...) - end - end - dg -end \ No newline at end of file From 6d499be9d2205938c0f84b5fc7e8743f284f7d79 Mon Sep 17 00:00:00 2001 From: bartek Date: Fri, 11 Dec 2020 09:47:25 +0100 Subject: [PATCH 012/137] add working directed factor graph --- src/graph.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 23511d6f..63bc4d15 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -103,9 +103,10 @@ function Spectrum(cl::Cluster) end function factor_graph(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) - dg = SimpleDiGraph(m * n) - linear = LinearIndices((1:m, 1:n)) + dg = MetaGraph(SimpleDiGraph(m * n)) + set_prop!(dg, :order, (hdir, vdir)) + linear = LinearIndices((1:m, 1:n)) for i ∈ 1:m for j ∈ 1:n-1 v, w = linear[i, j], linear[i, j+1] @@ -126,7 +127,7 @@ end function factor_graph(c::Chimera) m, n, _ = c.size - fg = MetaGraph(grid([m, n])) + fg = factor_graph(m, n) for v ∈ vertices(fg) cl = Cluster(c, v) @@ -146,6 +147,7 @@ function factor_graph(c::Chimera) end +#= function peps_tensor(fg::MetaGraph, v::Int) T = Dict{String, AbstractArray}() @@ -160,3 +162,4 @@ function peps_tensor(fg::MetaGraph, v::Int) @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] end +=# \ No newline at end of file From 1fddb9bbf27f1db2573c1f6e26b50ec6f3a56d1b Mon Sep 17 00:00:00 2001 From: bartek Date: Fri, 11 Dec 2020 18:48:59 +0100 Subject: [PATCH 013/137] start building peps --- src/graph.jl | 11 ++++++----- test/graph.jl | 3 --- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 63bc4d15..f08c20f4 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -147,13 +147,15 @@ function factor_graph(c::Chimera) end -#= function peps_tensor(fg::MetaGraph, v::Int) T = Dict{String, AbstractArray}() - for w ∈ unique_neighbors(fg, v) + for w ∈ inneighbors(fg, v) - #to_exp = unique(en) + #en = get_prop(fg, :energy) + + # to_exp = unique(en) + # indexin(to_exp, en) #set_prop!(fg, e, :energy, to_exp) #set_prop!(fg, e, :projector, indexin(to_exp, en)) @@ -161,5 +163,4 @@ function peps_tensor(fg::MetaGraph, v::Int) end @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] -end -=# \ No newline at end of file +end \ No newline at end of file diff --git a/test/graph.jl b/test/graph.jl index 4255d582..7f7e8b64 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -27,8 +27,5 @@ end ig = ising_graph(instance, L) cg = Chimera((m, n, t), ig) - #cl = Cluster(cg, 2) - #@time Spectrum(cl) - @time fg = factor_graph(cg) end From 874d5bcb305e251c0dfef371d47efde2c4254850 Mon Sep 17 00:00:00 2001 From: dexter2206 Date: Fri, 11 Dec 2020 18:52:23 +0100 Subject: [PATCH 014/137] Add draft of decomposition method --- src/graph.jl | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 63bc4d15..ce26ad9d 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,6 +1,16 @@ export Chimera, factor_graph export Cluster, Spectrum +@enum HorizontalDeirections begin + left_to_right = 1 + right_to_left = -1 +end + +@enum VerticalDirections begin + top_to_bottom = -1 + bottom_to_top = 1 +end + mutable struct Chimera size::NTuple{3, Int} graph::MetaGraph @@ -102,7 +112,11 @@ function Spectrum(cl::Cluster) Spectrum(energies, σ) end -function factor_graph(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) +function factor_graph( + m::Int, + n::Int, + hdir::HorizontalDeirections=HorizontalDeirections.left_to_right, + vdir::VerticalDirections=VerticalDirections.bottom_to_top) dg = MetaGraph(SimpleDiGraph(m * n)) set_prop!(dg, :order, (hdir, vdir)) @@ -112,6 +126,7 @@ function factor_graph(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) v, w = linear[i, j], linear[i, j+1] hdir == 1 ? e = (v, w) : e = (w, v) add_edge!(dg, e) + set_prop!(dg, e, :orientation, "horizontal") end end @@ -120,6 +135,7 @@ function factor_graph(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) v, w = linear[i, j], linear[i, j+1] vdir == 1 ? e = (v, w) : e = (w, v) add_edge!(dg, e) + set_prop!(dg, e, :orientation, "vertical") end end dg @@ -147,13 +163,30 @@ function factor_graph(c::Chimera) end -#= +function decompose_edges!(fg::MetaGraph, beta::AbstractFloat) + for edge ∈ edges(fg) + energies = get_prop(fg, edge, :energy) + truncated_energies, projector = rank_reveal(energies) + exponents = exp.(beta .* btruncated_energies) + set_prop!(fg, edge, :projector, projector) + set_prop!(fg, edge, :exponents, exponents) + end +end + + function peps_tensor(fg::MetaGraph, v::Int) T = Dict{String, AbstractArray}() + outgoing = outneighbors(fg, v) + incoming = inneighbours(fg, v) + + hor_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "horizontal"] + hor_incoming = [u for u in incoming if get_prop!(fg, (u, v), :orientation) == "horizontal"] + ver_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "vertical"] + ver_incoming = [u for u in incoming if get_prop!(fg, (u, v), :orientation) == "vertical"] for w ∈ unique_neighbors(fg, v) - - #to_exp = unique(en) + + #to_exp = unique(en) #set_prop!(fg, e, :energy, to_exp) #set_prop!(fg, e, :projector, indexin(to_exp, en)) @@ -162,4 +195,3 @@ function peps_tensor(fg::MetaGraph, v::Int) @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] end -=# \ No newline at end of file From bb890ab8ccab696dae878e9bd1c19d698fe151fa Mon Sep 17 00:00:00 2001 From: bartek Date: Fri, 11 Dec 2020 19:31:50 +0100 Subject: [PATCH 015/137] add orientation --- src/graph.jl | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index f08c20f4..7e69ae1a 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -112,6 +112,7 @@ function factor_graph(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) v, w = linear[i, j], linear[i, j+1] hdir == 1 ? e = (v, w) : e = (w, v) add_edge!(dg, e) + set_prop!(fg, :orientation, "horizontal") end end @@ -120,6 +121,7 @@ function factor_graph(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) v, w = linear[i, j], linear[i, j+1] vdir == 1 ? e = (v, w) : e = (w, v) add_edge!(dg, e) + set_prop!(fg, :orientation, "vertical") end end dg @@ -150,16 +152,9 @@ end function peps_tensor(fg::MetaGraph, v::Int) T = Dict{String, AbstractArray}() - for w ∈ inneighbors(fg, v) - - #en = get_prop(fg, :energy) - - # to_exp = unique(en) - # indexin(to_exp, en) - - #set_prop!(fg, e, :energy, to_exp) - #set_prop!(fg, e, :projector, indexin(to_exp, en)) + for w ∈ inneighbors(fg, v) + end @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] From 5bd25fba897fd053d3e5eacb7a6a0b3a3db49af8 Mon Sep 17 00:00:00 2001 From: bartek Date: Fri, 11 Dec 2020 20:34:40 +0100 Subject: [PATCH 016/137] add comments to kj --- src/graph.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/graph.jl b/src/graph.jl index ce26ad9d..3e7b473c 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -117,6 +117,7 @@ function factor_graph( n::Int, hdir::HorizontalDeirections=HorizontalDeirections.left_to_right, vdir::VerticalDirections=VerticalDirections.bottom_to_top) + dg = MetaGraph(SimpleDiGraph(m * n)) set_prop!(dg, :order, (hdir, vdir)) @@ -179,6 +180,8 @@ function peps_tensor(fg::MetaGraph, v::Int) outgoing = outneighbors(fg, v) incoming = inneighbours(fg, v) + # do not like it -- too long. But first and formost, it does not solve the problem! + #Still no idea which is l, r, etc -- indexing matter hor_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "horizontal"] hor_incoming = [u for u in incoming if get_prop!(fg, (u, v), :orientation) == "horizontal"] ver_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "vertical"] From 429eed5c3e4bc663dc68d1f5733fea3b97afe09b Mon Sep 17 00:00:00 2001 From: bartek Date: Sat, 12 Dec 2020 12:36:10 +0100 Subject: [PATCH 017/137] fix a minor bug --- src/graph.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 7e69ae1a..aa15f3c7 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -112,7 +112,7 @@ function factor_graph(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) v, w = linear[i, j], linear[i, j+1] hdir == 1 ? e = (v, w) : e = (w, v) add_edge!(dg, e) - set_prop!(fg, :orientation, "horizontal") + set_prop!(dg, :orientation, "horizontal") end end @@ -121,7 +121,7 @@ function factor_graph(m::Int, n::Int, hdir::Int=1, vdir::Int=-1) v, w = linear[i, j], linear[i, j+1] vdir == 1 ? e = (v, w) : e = (w, v) add_edge!(dg, e) - set_prop!(fg, :orientation, "vertical") + set_prop!(dg, :orientation, "vertical") end end dg @@ -148,7 +148,7 @@ function factor_graph(c::Chimera) fg end - +#= function peps_tensor(fg::MetaGraph, v::Int) T = Dict{String, AbstractArray}() @@ -158,4 +158,5 @@ function peps_tensor(fg::MetaGraph, v::Int) end @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] -end \ No newline at end of file +end +=# \ No newline at end of file From 1c632608c145a236bcf7e446e353fa25a9ae4ab0 Mon Sep 17 00:00:00 2001 From: bartek Date: Mon, 14 Dec 2020 09:29:07 +0100 Subject: [PATCH 018/137] fix bugs --- src/graph.jl | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 3e7b473c..80f8708e 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -177,24 +177,19 @@ end function peps_tensor(fg::MetaGraph, v::Int) T = Dict{String, AbstractArray}() - outgoing = outneighbors(fg, v) - incoming = inneighbours(fg, v) + #outgoing = outneighbors(fg, v) + #incoming = inneighbours(fg, v) # do not like it -- too long. But first and formost, it does not solve the problem! #Still no idea which is l, r, etc -- indexing matter - hor_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "horizontal"] - hor_incoming = [u for u in incoming if get_prop!(fg, (u, v), :orientation) == "horizontal"] - ver_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "vertical"] - ver_incoming = [u for u in incoming if get_prop!(fg, (u, v), :orientation) == "vertical"] + #hor_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "horizontal"] + #hor_incoming = [u for u in incoming if get_prop!(fg, (u, v), :orientation) == "horizontal"] + #ver_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "vertical"] + #ver_incoming = [u for u in incoming if get_prop!(fg, (u, v), :orientation) == "vertical"] - for w ∈ unique_neighbors(fg, v) + nbrs = unique_neighbors(fg, v) + hor = [w for w ∈ nbrs if get_prop!(fg, (v, w), :orientation) == "horizontal"] + ver = [w for w ∈ nbrs if get_prop!(fg, (v, w), :orientation) == "vertical"] - #to_exp = unique(en) - - #set_prop!(fg, e, :energy, to_exp) - #set_prop!(fg, e, :projector, indexin(to_exp, en)) - - end - - @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][r, σ] * T["d"][d, σ] * T["u"][u, σ] + @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][σ, r] * T["u"][u, σ] * T["d"][σ, d] end From a3f70bf4742b937e6b6f69463ff94cc3c3ed8e1f Mon Sep 17 00:00:00 2001 From: bartek Date: Mon, 14 Dec 2020 10:56:44 +0100 Subject: [PATCH 019/137] add l, r, u, d extraction --- src/graph.jl | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 80f8708e..675bf67d 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -176,20 +176,36 @@ end function peps_tensor(fg::MetaGraph, v::Int) + hdir, vdir = get_prop!(dg, :order) + + outgoing = outneighbors(fg, v) + incoming = inneighbours(fg, v) + + hor_outgoing = [u for u ∈ outgoing if get_prop!(fg, (v, u), :orientation) == "horizontal"] + hor_incoming = [u for u ∈ incoming if get_prop!(fg, (u, v), :orientation) == "horizontal"] + ver_outgoing = [u for u ∈ outgoing if get_prop!(fg, (v, u), :orientation) == "vertical"] + ver_incoming = [u for u ∈ incoming if get_prop!(fg, (u, v), :orientation) == "vertical"] + T = Dict{String, AbstractArray}() - #outgoing = outneighbors(fg, v) - #incoming = inneighbours(fg, v) - - # do not like it -- too long. But first and formost, it does not solve the problem! - #Still no idea which is l, r, etc -- indexing matter - #hor_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "horizontal"] - #hor_incoming = [u for u in incoming if get_prop!(fg, (u, v), :orientation) == "horizontal"] - #ver_outgoing = [u for u in outgoing if get_prop!(fg, (v, u), :orientation) == "vertical"] - #ver_incoming = [u for u in incoming if get_prop!(fg, (u, v), :orientation) == "vertical"] - - nbrs = unique_neighbors(fg, v) - hor = [w for w ∈ nbrs if get_prop!(fg, (v, w), :orientation) == "horizontal"] - ver = [w for w ∈ nbrs if get_prop!(fg, (v, w), :orientation) == "vertical"] + for (u, w) ∈ zip(hor_outgoing, hor_incoming) + if hdir == 1 + T["l"] = last(get_prop(fg, (w, v), :dec)) + T["r"] = first(get_prop(fg, (u, v), :dec)) + else + T["r"] = first(get_prop(fg, (w, v), :dec)) + T["l"] = last(get_prop(fg, (u, v), :dec)) + end + end + + for (u, w) ∈ zip(ver_outgoing, ver_incoming) + if vdir == 1 + T["u"] = last(get_prop(fg, (w, v), :dec)) + T["d"] = first(get_prop(fg, (u, v), :dec)) + else + T["d"] = first(get_prop(fg, (w, v), :dec)) + T["u"] = last(get_prop(fg, (u, v), :dec)) + end + end @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][σ, r] * T["u"][u, σ] * T["d"][σ, d] end From 1b96d967beb3b9c945ade4c27c36d918375e0c3e Mon Sep 17 00:00:00 2001 From: bartek Date: Mon, 14 Dec 2020 11:31:03 +0100 Subject: [PATCH 020/137] simplify decompose_edges --- src/graph.jl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 675bf67d..2ef48dbe 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -164,13 +164,18 @@ function factor_graph(c::Chimera) end -function decompose_edges!(fg::MetaGraph, beta::AbstractFloat) +function decompose_edges!(fg::MetaGraph, order::Bool, beta::Float64=1.0) + for edge ∈ edges(fg) energies = get_prop(fg, edge, :energy) - truncated_energies, projector = rank_reveal(energies) - exponents = exp.(beta .* btruncated_energies) - set_prop!(fg, edge, :projector, projector) - set_prop!(fg, edge, :exponents, exponents) + en, p = rank_reveal(energies) + + if order + dec = (exp.(beta .* en), p) + else + dec = (p, exp.(beta .* en)) + end + set_prop!(fg, edge, :dec, dec) end end From 4442359d90e7f08b7f74843b3bf2a18b7298f851 Mon Sep 17 00:00:00 2001 From: dexter2206 Date: Mon, 14 Dec 2020 15:25:08 +0100 Subject: [PATCH 021/137] Add PepsTensor structure --- src/graph.jl | 73 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 2ef48dbe..e5966bb6 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -178,39 +178,58 @@ function decompose_edges!(fg::MetaGraph, order::Bool, beta::Float64=1.0) set_prop!(fg, edge, :dec, dec) end end + + + +mutable struct PepsTensor + left::AbstractArray + right::AbstractArray + up::AbstractArray + down::AbstractArray + + function PepsTensor(fg::MetaGraph, v::Int) + pc = new() + outgoing = outneighbors(fg, v) + incoming = inneighbours(fg, v) + + for u ∈ outgoing + if get_prop(fg, (v, u), :orientation) == "horizontal" + pc.right = last(get_prop(fg, (v, u), :dec)) + else + pc.dow = last(get_prop(fg, (v, u), :dec)) + end + end + for u ∈ incoming + if get_prop(fg, (u, v), :orientation) == "horizontal" + pc.left = first(get_prop(fg, (u, v), :dec)) + else + pc.up = first(get_prop(fg, (u, v), :dec)) + end + end + + if pc.left === nothing + pc.left = ones(1, size(pc.right, 1)) + end -function peps_tensor(fg::MetaGraph, v::Int) - hdir, vdir = get_prop!(dg, :order) - - outgoing = outneighbors(fg, v) - incoming = inneighbours(fg, v) - - hor_outgoing = [u for u ∈ outgoing if get_prop!(fg, (v, u), :orientation) == "horizontal"] - hor_incoming = [u for u ∈ incoming if get_prop!(fg, (u, v), :orientation) == "horizontal"] - ver_outgoing = [u for u ∈ outgoing if get_prop!(fg, (v, u), :orientation) == "vertical"] - ver_incoming = [u for u ∈ incoming if get_prop!(fg, (u, v), :orientation) == "vertical"] + if pc.right === nothing + pc.right = ones(size(pc.left, 2), 1) + end - T = Dict{String, AbstractArray}() - for (u, w) ∈ zip(hor_outgoing, hor_incoming) - if hdir == 1 - T["l"] = last(get_prop(fg, (w, v), :dec)) - T["r"] = first(get_prop(fg, (u, v), :dec)) - else - T["r"] = first(get_prop(fg, (w, v), :dec)) - T["l"] = last(get_prop(fg, (u, v), :dec)) + if pc.up === nothing + pc.up = ones(1, size(pc.down, 1)) end - end - for (u, w) ∈ zip(ver_outgoing, ver_incoming) - if vdir == 1 - T["u"] = last(get_prop(fg, (w, v), :dec)) - T["d"] = first(get_prop(fg, (u, v), :dec)) - else - T["d"] = first(get_prop(fg, (w, v), :dec)) - T["u"] = last(get_prop(fg, (u, v), :dec)) + if pc.down === nothing + pc.down = ones(size(pc.up, 2), 1) end + + pc end +end + - @cast A[l, r, u, d, σ] |= T["l"][l, σ] * T["r"][σ, r] * T["u"][u, σ] * T["d"][σ, d] +function peps_tensor(pc::PepsTensor) + @cast A[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] end + From 0c018fbea3c9262b1a3b895dec196f69f9678e0b Mon Sep 17 00:00:00 2001 From: bartek Date: Mon, 14 Dec 2020 18:52:19 +0100 Subject: [PATCH 022/137] add bugs in factor_graph --- src/graph.jl | 46 +++++++++++++++++++++++----------------------- test/graph.jl | 3 --- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index e5966bb6..e6b90386 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,7 +1,12 @@ export Chimera, factor_graph -export Cluster, Spectrum +export Cluster, Spectrum, PepsTensor -@enum HorizontalDeirections begin +@enum TensorsOrder begin + P_then_E = 1 + E_then_P = -1 +end + +@enum HorizontalDirections begin left_to_right = 1 right_to_left = -1 end @@ -112,11 +117,7 @@ function Spectrum(cl::Cluster) Spectrum(energies, σ) end -function factor_graph( - m::Int, - n::Int, - hdir::HorizontalDeirections=HorizontalDeirections.left_to_right, - vdir::VerticalDirections=VerticalDirections.bottom_to_top) +function factor_graph(m::Int, n::Int, hdir=left_to_right, vdir=bottom_to_top) dg = MetaGraph(SimpleDiGraph(m * n)) set_prop!(dg, :order, (hdir, vdir)) @@ -125,8 +126,9 @@ function factor_graph( for i ∈ 1:m for j ∈ 1:n-1 v, w = linear[i, j], linear[i, j+1] - hdir == 1 ? e = (v, w) : e = (w, v) + Int(hdir) == 1 ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) add_edge!(dg, e) + println(e) set_prop!(dg, e, :orientation, "horizontal") end end @@ -134,7 +136,7 @@ function factor_graph( for i ∈ 1:n for j ∈ 1:m-1 v, w = linear[i, j], linear[i, j+1] - vdir == 1 ? e = (v, w) : e = (w, v) + Int(vdir) == 1 ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) add_edge!(dg, e) set_prop!(dg, e, :orientation, "vertical") end @@ -164,28 +166,28 @@ function factor_graph(c::Chimera) end -function decompose_edges!(fg::MetaGraph, order::Bool, beta::Float64=1.0) +function decompose_edges!(fg::MetaGraph, order=P_then_E, beta::Float64=1.0) + set_prop!(dg, :tensorsOrder, order) for edge ∈ edges(fg) energies = get_prop(fg, edge, :energy) en, p = rank_reveal(energies) - if order + if Int(order) == 1 dec = (exp.(beta .* en), p) else dec = (p, exp.(beta .* en)) end - set_prop!(fg, edge, :dec, dec) + set_prop!(fg, edge, :decomposition, dec) end end - - mutable struct PepsTensor left::AbstractArray right::AbstractArray up::AbstractArray down::AbstractArray + tensor::AbstractArray function PepsTensor(fg::MetaGraph, v::Int) pc = new() @@ -194,20 +196,21 @@ mutable struct PepsTensor for u ∈ outgoing if get_prop(fg, (v, u), :orientation) == "horizontal" - pc.right = last(get_prop(fg, (v, u), :dec)) + pc.right = last(get_prop(fg, (v, u), :decomposition)) else - pc.dow = last(get_prop(fg, (v, u), :dec)) + pc.down = last(get_prop(fg, (v, u), :decomposition)) end end for u ∈ incoming if get_prop(fg, (u, v), :orientation) == "horizontal" - pc.left = first(get_prop(fg, (u, v), :dec)) + pc.left = first(get_prop(fg, (u, v), :decomposition)) else - pc.up = first(get_prop(fg, (u, v), :dec)) + pc.up = first(get_prop(fg, (u, v), :decomposition)) end end + # open boundary conditions if pc.left === nothing pc.left = ones(1, size(pc.right, 1)) end @@ -224,12 +227,9 @@ mutable struct PepsTensor pc.down = ones(size(pc.up, 2), 1) end + pc.tensor[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] + pc end end - -function peps_tensor(pc::PepsTensor) - @cast A[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] -end - diff --git a/test/graph.jl b/test/graph.jl index 4255d582..7f7e8b64 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -27,8 +27,5 @@ end ig = ising_graph(instance, L) cg = Chimera((m, n, t), ig) - #cl = Cluster(cg, 2) - #@time Spectrum(cl) - @time fg = factor_graph(cg) end From 02b8c025804523ee6b86e883be38edfc9cd63185 Mon Sep 17 00:00:00 2001 From: bartek Date: Mon, 14 Dec 2020 19:51:55 +0100 Subject: [PATCH 023/137] move PepsTensor to PEPS.jl --- src/PEPS.jl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ src/graph.jl | 53 --------------------------------------------------- test/graph.jl | 16 ++++++++++++++-- 3 files changed, 65 insertions(+), 55 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 8b137891..dfcf35da 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1 +1,52 @@ +export PepsTensor +mutable struct PepsTensor + left::AbstractArray + right::AbstractArray + up::AbstractArray + down::AbstractArray + tensor::AbstractArray + + function PepsTensor(fg::MetaGraph, v::Int) + pc = new() + outgoing = outneighbors(fg, v) + incoming = inneighbours(fg, v) + + for u ∈ outgoing + if get_prop(fg, (v, u), :orientation) == "horizontal" + pc.right = last(get_prop(fg, (v, u), :decomposition)) + else + pc.down = last(get_prop(fg, (v, u), :decomposition)) + end + end + + for u ∈ incoming + if get_prop(fg, (u, v), :orientation) == "horizontal" + pc.left = first(get_prop(fg, (u, v), :decomposition)) + else + pc.up = first(get_prop(fg, (u, v), :decomposition)) + end + end + + # open boundary conditions + if pc.left === nothing + pc.left = ones(1, size(pc.right, 1)) + end + + if pc.right === nothing + pc.right = ones(size(pc.left, 2), 1) + end + + if pc.up === nothing + pc.up = ones(1, size(pc.down, 1)) + end + + if pc.down === nothing + pc.down = ones(size(pc.up, 2), 1) + end + + pc.tensor[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] + + pc + end +end \ No newline at end of file diff --git a/src/graph.jl b/src/graph.jl index e6b90386..fa358117 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -118,7 +118,6 @@ function Spectrum(cl::Cluster) end function factor_graph(m::Int, n::Int, hdir=left_to_right, vdir=bottom_to_top) - dg = MetaGraph(SimpleDiGraph(m * n)) set_prop!(dg, :order, (hdir, vdir)) @@ -128,7 +127,6 @@ function factor_graph(m::Int, n::Int, hdir=left_to_right, vdir=bottom_to_top) v, w = linear[i, j], linear[i, j+1] Int(hdir) == 1 ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) add_edge!(dg, e) - println(e) set_prop!(dg, e, :orientation, "horizontal") end end @@ -182,54 +180,3 @@ function decompose_edges!(fg::MetaGraph, order=P_then_E, beta::Float64=1.0) end end -mutable struct PepsTensor - left::AbstractArray - right::AbstractArray - up::AbstractArray - down::AbstractArray - tensor::AbstractArray - - function PepsTensor(fg::MetaGraph, v::Int) - pc = new() - outgoing = outneighbors(fg, v) - incoming = inneighbours(fg, v) - - for u ∈ outgoing - if get_prop(fg, (v, u), :orientation) == "horizontal" - pc.right = last(get_prop(fg, (v, u), :decomposition)) - else - pc.down = last(get_prop(fg, (v, u), :decomposition)) - end - end - - for u ∈ incoming - if get_prop(fg, (u, v), :orientation) == "horizontal" - pc.left = first(get_prop(fg, (u, v), :decomposition)) - else - pc.up = first(get_prop(fg, (u, v), :decomposition)) - end - end - - # open boundary conditions - if pc.left === nothing - pc.left = ones(1, size(pc.right, 1)) - end - - if pc.right === nothing - pc.right = ones(size(pc.left, 2), 1) - end - - if pc.up === nothing - pc.up = ones(1, size(pc.down, 1)) - end - - if pc.down === nothing - pc.down = ones(size(pc.up, 2), 1) - end - - pc.tensor[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] - - pc - end -end - diff --git a/test/graph.jl b/test/graph.jl index 7f7e8b64..5d9d4bd8 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -14,14 +14,26 @@ g = Chimera(m, n, t) @show g[1, 1] end +@testset "Chimera graph" begin + m = 4 + n = 4 + t = 4 + + L = 2 * n * m * t + instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" -@testset "Chimera/factor graph" begin + ig = ising_graph(instance, L) + cg = Chimera((m, n, t), ig) + + @time fg = factor_graph(cg) +end + +@testset "Factor graph" begin m = 16 n = 16 t = 4 L = 2 * n * m * t - instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" ig = ising_graph(instance, L) From 904c0fb6e9d5a5991980ce671aa37dfb20ba487c Mon Sep 17 00:00:00 2001 From: bartek Date: Mon, 14 Dec 2020 22:03:21 +0100 Subject: [PATCH 024/137] add Lattice structure --- src/graph.jl | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index fa358117..77f9f001 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,5 +1,5 @@ -export Chimera, factor_graph -export Cluster, Spectrum, PepsTensor +export Chimera, factor_graph, decompose_edges! +export Cluster, Spectrum @enum TensorsOrder begin P_then_E = 1 @@ -16,6 +16,18 @@ end bottom_to_top = 1 end +mutable struct Lattice + size::NTuple{3, Int} + graph::MetaGraph + + function Lattice(m::Int, n::Int) + lt = new() + lt.size = (m, n, 0) + lt.graph = MetaGraph(grid([m, n])) + lt + end +end + mutable struct Chimera size::NTuple{3, Int} graph::MetaGraph @@ -63,6 +75,8 @@ function Chimera(m::Int, n::Int=m, t::Int=4) Chimera((m, n, t), g) end +const Graph = Union{Chimera, Lattice} + for op in [ :nv, :ne, @@ -72,7 +86,7 @@ for op in [ :edges, ] - @eval LightGraphs.$op(c::Chimera) = $op(c.graph) + @eval LightGraphs.$op(c::Graph) = $op(c.graph) end for op in [ @@ -83,34 +97,42 @@ for op in [ :outneighbors, :neighbors] - @eval MetaGraphs.$op(c::Chimera, args...) = $op(c.graph, args...) + @eval MetaGraphs.$op(c::Graph, args...) = $op(c.graph, args...) end -@inline has_edge(g::Chimera, x...) = has_edge(g.graph, x...) +@inline has_edge(g::Graph, x...) = has_edge(g.graph, x...) -Base.size(c::Chimera) = c.size -Base.size(c::Chimera, i::Int) = c.size[i] +Base.size(c::Graph) = c.size +Base.size(c::Graph, i::Int) = c.size[i] function Base.getindex(c::Chimera, i::Int, j::Int, u::Int, k::Int) _, n, t = size(c) t * (2 * (n * (i - 1) + j - 1) + u - 1) + k end +function Base.getindex(l::Lattice, i::Int, j::Int) + m, n, _ = size(l) + LinearIndices((1:m, 1:n))[i, j] +end + function Base.getindex(c::Chimera, i::Int, j::Int) t = size(c, 3) idx = vec([c[i, j, u, k] for u=1:2, k=1:t]) c.graph[idx] end +function unit_cell(l::Lattice, v::Int) + Cluster(l.graph, v, enum([v]), []) +end + function unit_cell(c::Chimera, v::Int) elist = filter_edges(c.graph, :cells, (v, v)) vlist = filter_vertices(c.graph, :cell, v) Cluster(c.graph, v, enum(vlist), elist) end -Cluster(c::Chimera, v::Int) = unit_cell(c, v) +Cluster(g::Graph, v::Int) = unit_cell(g, v) #Spectrum(cl::Cluster) = brute_force(cl, num_states=256) - function Spectrum(cl::Cluster) σ = collect.(all_states(cl.rank)) energies = energy.(σ, Ref(cl)) @@ -142,12 +164,12 @@ function factor_graph(m::Int, n::Int, hdir=left_to_right, vdir=bottom_to_top) dg end -function factor_graph(c::Chimera) - m, n, _ = c.size +function factor_graph(g::Graph) + m, n, _ = g.size fg = factor_graph(m, n) for v ∈ vertices(fg) - cl = Cluster(c, v) + cl = Cluster(g, v) set_prop!(fg, v, :cluster, cl) set_prop!(fg, v, :spectrum, Spectrum(cl)) end @@ -156,7 +178,7 @@ function factor_graph(c::Chimera) v = get_prop(fg, src(e), :cluster) w = get_prop(fg, dst(e), :cluster) - edge = Edge(c.graph, v, w) + edge = Edge(g.graph, v, w) set_prop!(fg, e, :edge, edge) set_prop!(fg, e, :energy, energy(fg, edge)) end @@ -172,9 +194,9 @@ function decompose_edges!(fg::MetaGraph, order=P_then_E, beta::Float64=1.0) en, p = rank_reveal(energies) if Int(order) == 1 - dec = (exp.(beta .* en), p) - else dec = (p, exp.(beta .* en)) + else + dec = (exp.(beta .* en), p) end set_prop!(fg, edge, :decomposition, dec) end From bfa112f58f7cedb4c7c8c8e87af21e3a55687a76 Mon Sep 17 00:00:00 2001 From: bartek Date: Tue, 15 Dec 2020 12:56:52 +0100 Subject: [PATCH 025/137] add more tests in graphs --- src/graph.jl | 7 ++++--- test/graph.jl | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 77f9f001..b5bfdcc1 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,4 +1,5 @@ -export Chimera, factor_graph, decompose_edges! +export Chimera, Lattice +export factor_graph, decompose_edges! export Cluster, Spectrum @enum TensorsOrder begin @@ -20,9 +21,9 @@ mutable struct Lattice size::NTuple{3, Int} graph::MetaGraph - function Lattice(m::Int, n::Int) + function Lattice(m::Int, n::Int, k::Int=0) lt = new() - lt.size = (m, n, 0) + lt.size = (m, n, k) lt.graph = MetaGraph(grid([m, n])) lt end diff --git a/test/graph.jl b/test/graph.jl index 5d9d4bd8..4e1fa477 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -26,6 +26,28 @@ end cg = Chimera((m, n, t), ig) @time fg = factor_graph(cg) + + @test collect(vertices(fg)) == collect(1:m * n) + @test nv(fg) == m * n + + @info "Verifying cluster properties for Chimera" m, n, t + + clv = [] + cle = [] + rank = get_prop(ig, :rank) + + for v ∈ vertices(fg) + cl = get_prop(fg, v, :cluster) + push!(clv, keys(cl.vertices)) + push!(cle, collect(cl.edges)) + + for (g, l) ∈ cl.vertices + @test cl.rank[l] == rank[g] + end + end + + println(intersect(clv)...) + #@test isempty(intersect(cle)) end @testset "Factor graph" begin From cc17fe627d1cb54ab6a01942ccf589e2f9403e91 Mon Sep 17 00:00:00 2001 From: dexter2206 Date: Tue, 15 Dec 2020 14:45:15 +0100 Subject: [PATCH 026/137] Implement rank_reveal function --- src/graph.jl | 17 +++++++++++++++++ test/graph.jl | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/graph.jl b/src/graph.jl index b5bfdcc1..e856be5e 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,6 +1,8 @@ export Chimera, Lattice export factor_graph, decompose_edges! export Cluster, Spectrum +export rank_reveal +export P_then_E, E_then_P @enum TensorsOrder begin P_then_E = 1 @@ -203,3 +205,18 @@ function decompose_edges!(fg::MetaGraph, order=P_then_E, beta::Float64=1.0) end end + +function rank_reveal(energy, order=P_then_E) # or E_then_P + dim = order == P_then_E ? 1 : 2 + + E = unique(energy, dims=dim) + idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) + + P = order == P_then_E ? zeros(size(energy, 1), size(E, 1)) : zeros(size(E, 2), size(energy, 2)) + + for (i, elements) ∈ enumerate(eachslice(P, dims=dim)) + elements[idx[i]] = 1 + end + + order == P_then_E ? (P, E) : (E, P) +end \ No newline at end of file diff --git a/test/graph.jl b/test/graph.jl index 4e1fa477..edfb6d62 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -6,7 +6,7 @@ using CSV m = 6 n = 7 t = 4 -g = Chimera(m, n, t) +@time g = Chimera(m, n, t) @testset "Chimera creation" begin @test nv(g) == 2m * n * t @test ne(g) == t^2 * m * n + m * (n -1) * t + (m - 1) * n * t @@ -63,3 +63,19 @@ end @time fg = factor_graph(cg) end + +@testset "Rank reveal correctly decomposes energy row-wise" begin + energy = [[1 2 3]; [0 -1 0]; [1 2 3]] + P, E = rank_reveal(energy, P_then_E) + @test size(P) == (3, 2) + @test size(E) == (2, 3) + @test P * E ≈ energy +end + +@testset "Rank reveal correctly decomposes energy column-wise" begin + energy = [[1, 2, 3] [0, -1, 1] [1, 2, 3]] + E, P = rank_reveal(energy, E_then_P) + @test size(P) == (2, 3) + @test size(E) == (3, 2) + @test E * P ≈ energy +end \ No newline at end of file From 9959ad7d4c0f412721eb80153c29a292df989fc4 Mon Sep 17 00:00:00 2001 From: bartek Date: Tue, 15 Dec 2020 23:43:30 +0100 Subject: [PATCH 027/137] add Revise, add more test in graph --- Manifest.toml | 27 +++++++++++++++++++++++++++ Project.toml | 1 + test/graph.jl | 4 ++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 1d40f97b..b8a882e7 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -56,6 +56,12 @@ git-tree-sha1 = "2ac27f59196a68070e132b25713f9a5bbc5fa0d2" uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597" version = "0.8.3" +[[CodeTracking]] +deps = ["InteractiveUtils", "UUIDs"] +git-tree-sha1 = "8ad457cfeb0bca98732c97958ef81000a543e73e" +uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" +version = "1.0.5" + [[CodecZlib]] deps = ["TranscodingStreams", "Zlib_jll"] git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da" @@ -149,6 +155,9 @@ git-tree-sha1 = "f10c3009373a2d5c4349b8a2932d8accb892892d" uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a" version = "3.3.9+6" +[[FileWatching]] +uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" + [[FillArrays]] deps = ["LinearAlgebra", "Random", "SparseArrays"] git-tree-sha1 = "b955c227b0d1413a1a97e2ca0635a5de019d7337" @@ -230,6 +239,12 @@ git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4" uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" version = "0.21.1" +[[JuliaInterpreter]] +deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"] +git-tree-sha1 = "d4cbb4ccecfbcf2c475c28d186fd1b02479661eb" +uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a" +version = "0.8.6" + [[LLVM]] deps = ["CEnum", "Libdl", "Printf", "Unicode"] git-tree-sha1 = "a662366a5d485dee882077e8da3e1a95a86d097f" @@ -273,6 +288,12 @@ git-tree-sha1 = "945c7da49e1c999956b21b106b238f9bd7ab1a63" uuid = "898213cb-b102-5a47-900c-97e73b919f73" version = "0.4.1" +[[LoweredCodeUtils]] +deps = ["JuliaInterpreter"] +git-tree-sha1 = "9af25a91bda16307caff2a50f9c744c432b8bc1b" +uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" +version = "1.2.6" + [[MKL]] deps = ["Libdl", "MKL_jll", "PackageCompiler"] git-tree-sha1 = "e01175ff53c062c52b6cbe441a4382e132f7c82e" @@ -388,6 +409,12 @@ git-tree-sha1 = "28faf1c963ca1dc3ec87f166d92982e3c4a1f66d" uuid = "ae029012-a4dd-5104-9daa-d747884805df" version = "1.1.0" +[[Revise]] +deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "UUIDs", "Unicode"] +git-tree-sha1 = "b520a7f1a34326c8b5dd23947a71f24f5bb3657b" +uuid = "295af30f-e4ad-537b-8983-00126c2a3abe" +version = "3.1.3" + [[SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" diff --git a/Project.toml b/Project.toml index baf5c2dc..629a132d 100644 --- a/Project.toml +++ b/Project.toml @@ -16,6 +16,7 @@ LowRankApprox = "898213cb-b102-5a47-900c-97e73b919f73" MKL = "33e6dc65-8f57-5167-99aa-e5a354878fb2" MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5" Requires = "ae029012-a4dd-5104-9daa-d747884805df" +Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b" TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/graph.jl b/test/graph.jl index edfb6d62..c65b4cdf 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -46,8 +46,8 @@ end end end - println(intersect(clv)...) - #@test isempty(intersect(cle)) + @test isempty(intersect(clv...)) + @test isempty(intersect(cle...)) end @testset "Factor graph" begin From b1d5f334a3cae364f5bd3653c8c9a451148e0b4e Mon Sep 17 00:00:00 2001 From: dexter2206 Date: Wed, 16 Dec 2020 15:30:10 +0100 Subject: [PATCH 028/137] Start splitting files --- src/graph.jl | 96 ++++++------------------------------------- src/graphs/chimera.jl | 51 +++++++++++++++++++++++ src/graphs/lattice.jl | 11 +++++ src/graphs/model.jl | 32 +++++++++++++++ test/graph.jl | 4 +- 5 files changed, 109 insertions(+), 85 deletions(-) create mode 100644 src/graphs/chimera.jl create mode 100644 src/graphs/lattice.jl create mode 100644 src/graphs/model.jl diff --git a/src/graph.jl b/src/graph.jl index e856be5e..7627ddfe 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -2,83 +2,8 @@ export Chimera, Lattice export factor_graph, decompose_edges! export Cluster, Spectrum export rank_reveal -export P_then_E, E_then_P -@enum TensorsOrder begin - P_then_E = 1 - E_then_P = -1 -end - -@enum HorizontalDirections begin - left_to_right = 1 - right_to_left = -1 -end - -@enum VerticalDirections begin - top_to_bottom = -1 - bottom_to_top = 1 -end - -mutable struct Lattice - size::NTuple{3, Int} - graph::MetaGraph - - function Lattice(m::Int, n::Int, k::Int=0) - lt = new() - lt.size = (m, n, k) - lt.graph = MetaGraph(grid([m, n])) - lt - end -end - -mutable struct Chimera - size::NTuple{3, Int} - graph::MetaGraph - - function Chimera(size::NTuple{3, Int}, graph::MetaGraph) - cg = new(size, graph) - m, n, t = size - linear = LinearIndices((1:m, 1:n)) - - for i=1:m, j=1:n, u=1:2, k=1:t - v = cg[i, j, u, k] - ij = linear[i, j] - set_prop!(cg, v, :cell, ij) - end - - for e in edges(cg) - v = get_prop(cg, src(e), :cell) - w = get_prop(cg, dst(e), :cell) - set_prop!(cg, e, :cells, (v, w)) - end - cg - end -end - -function Chimera(m::Int, n::Int=m, t::Int=4) - max_size = m * n * 2 * t - g = MetaGraph(max_size) - - hoff = 2t - voff = n * hoff - mi = m * voff - ni = n * hoff - - for i=1:hoff:ni, j=i:voff:mi, k0=j:j+t-1, k1=j+t:j+2t-1 - add_edge!(g, k0, k1) - end - - for i=t:2t-1, j=i:hoff:ni-hoff-1, k=j+1:voff:mi-1 - add_edge!(g, k, k+hoff-1) - end - - for i=1:t, j=i:hoff:ni-1, k=j:voff:mi-voff-1 - add_edge!(g, k, k+voff) - end - Chimera((m, n, t), g) -end -const Graph = Union{Chimera, Lattice} for op in [ :nv, @@ -89,7 +14,7 @@ for op in [ :edges, ] - @eval LightGraphs.$op(c::Graph) = $op(c.graph) + @eval LightGraphs.$op(c::Model) = $op(c.graph) end for op in [ @@ -167,14 +92,19 @@ function factor_graph(m::Int, n::Int, hdir=left_to_right, vdir=bottom_to_top) dg end -function factor_graph(g::Graph) +function factor_graph( + g::Graph, + energy::Function=ising_energy, + spectrum::Function=brute_force, + create_cluster::Function=Cluster, +) # how to add typing to functions? m, n, _ = g.size fg = factor_graph(m, n) for v ∈ vertices(fg) - cl = Cluster(g, v) + cl = create_cluster(g, v) set_prop!(fg, v, :cluster, cl) - set_prop!(fg, v, :spectrum, Spectrum(cl)) + set_prop!(fg, v, :spectrum, spectrum(cl)) end for e ∈ edges(fg) @@ -206,17 +136,17 @@ function decompose_edges!(fg::MetaGraph, order=P_then_E, beta::Float64=1.0) end -function rank_reveal(energy, order=P_then_E) # or E_then_P - dim = order == P_then_E ? 1 : 2 +function rank_reveal(energy, order=:PE) # or E_then_P + dim = order == :PE ? 1 : 2 E = unique(energy, dims=dim) idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) - P = order == P_then_E ? zeros(size(energy, 1), size(E, 1)) : zeros(size(E, 2), size(energy, 2)) + P = order == :PE ? zeros(size(energy, 1), size(E, 1)) : zeros(size(E, 2), size(energy, 2)) for (i, elements) ∈ enumerate(eachslice(P, dims=dim)) elements[idx[i]] = 1 end - order == P_then_E ? (P, E) : (E, P) + order == :PE ? (P, E) : (E, P) end \ No newline at end of file diff --git a/src/graphs/chimera.jl b/src/graphs/chimera.jl new file mode 100644 index 00000000..e138671e --- /dev/null +++ b/src/graphs/chimera.jl @@ -0,0 +1,51 @@ +mutable struct Chimera <: Model + size::NTuple{3, Int} + graph::MetaGraph + + function Chimera(size::NTuple{3, Int}, graph::MetaGraph) + cg = new(size, graph) + m, n, t = size + linear = LinearIndices((1:m, 1:n)) + + for i=1:m, j=1:n, u=1:2, k=1:t + v = cg[i, j, u, k] + ij = linear[i, j] + set_prop!(cg, v, :cell, ij) + end + + for e in edges(cg) + v = get_prop(cg, src(e), :cell) + w = get_prop(cg, dst(e), :cell) + set_prop!(cg, e, :cells, (v, w)) + end + cg + end +end + +function Chimera(m::Int, n::Int=m, t::Int=4) + max_size = m * n * 2 * t + g = MetaGraph(max_size) + + hoff = 2t + voff = n * hoff + mi = m * voff + ni = n * hoff + + for i=1:hoff:ni, j=i:voff:mi, k0=j:j+t-1, k1=j+t:j+2t-1 + add_edge!(g, k0, k1) + end + + for i=t:2t-1, j=i:hoff:ni-hoff-1, k=j+1:voff:mi-1 + add_edge!(g, k, k+hoff-1) + end + + for i=1:t, j=i:hoff:ni-1, k=j:voff:mi-voff-1 + add_edge!(g, k, k+voff) + end + Chimera((m, n, t), g) +end + +function Base.getindex(c::Chimera, i::Int, j::Int, u::Int, k::Int) + _, n, t = size(c) + t * (2 * (n * (i - 1) + j - 1) + u - 1) + k +end \ No newline at end of file diff --git a/src/graphs/lattice.jl b/src/graphs/lattice.jl new file mode 100644 index 00000000..88baf354 --- /dev/null +++ b/src/graphs/lattice.jl @@ -0,0 +1,11 @@ +mutable struct Lattice <: Model + size::NTuple{3, Int} + graph::MetaGraph + + function Lattice(m::Int, n::Int, k::Int=0) + lt = new() + lt.size = (m, n, k) + lt.graph = MetaGraph(grid([m, n])) + lt + end +end \ No newline at end of file diff --git a/src/graphs/model.jl b/src/graphs/model.jl new file mode 100644 index 00000000..3da14ce9 --- /dev/null +++ b/src/graphs/model.jl @@ -0,0 +1,32 @@ +export Model + +abstract type Model end + +for op in [ + :nv, + :ne, + :eltype, + :edgetype, + :vertices, + :edges, + ] + + @eval LightGraphs.$op(c::Model) = $op(c.graph) +end + +for op in [ + :get_prop, + :set_prop!, + :has_vertex, + :inneighbors, + :outneighbors, + :neighbors] + + @eval MetaGraphs.$op(c::Model, args...) = $op(c.graph, args...) +end +@inline has_edge(g::Model, x...) = has_edge(g.graph, x...) + +Base.size(c::Model) = c.size +Base.size(c::Model, i::Int) = c.size[i] + +Cluster(g::Model, v::Int) = unit_cell(g, v) \ No newline at end of file diff --git a/test/graph.jl b/test/graph.jl index c65b4cdf..a90dd77b 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -66,7 +66,7 @@ end @testset "Rank reveal correctly decomposes energy row-wise" begin energy = [[1 2 3]; [0 -1 0]; [1 2 3]] - P, E = rank_reveal(energy, P_then_E) + P, E = rank_reveal(energy, :PE) @test size(P) == (3, 2) @test size(E) == (2, 3) @test P * E ≈ energy @@ -74,7 +74,7 @@ end @testset "Rank reveal correctly decomposes energy column-wise" begin energy = [[1, 2, 3] [0, -1, 1] [1, 2, 3]] - E, P = rank_reveal(energy, E_then_P) + E, P = rank_reveal(energy, :EP) @test size(P) == (2, 3) @test size(E) == (3, 2) @test E * P ≈ energy From 50c40146cd4902a09e68bbcffc4074f59f24d7ef Mon Sep 17 00:00:00 2001 From: dexter2206 Date: Thu, 17 Dec 2020 01:19:32 +0100 Subject: [PATCH 029/137] Continue splitting files --- src/SpinGlassPEPS.jl | 11 +-- src/graph.jl | 122 +++++++++++++++++---------------- src/graphs/chimera.jl | 17 ++++- src/graphs/lattice.jl | 16 +++-- src/graphs/model.jl | 9 ++- src/ising.jl | 111 +----------------------------- src/{search.jl => spectrum.jl} | 49 +++++++++++++ 7 files changed, 153 insertions(+), 182 deletions(-) rename src/{search.jl => spectrum.jl} (76%) diff --git a/src/SpinGlassPEPS.jl b/src/SpinGlassPEPS.jl index fe841cac..7fc86ae7 100644 --- a/src/SpinGlassPEPS.jl +++ b/src/SpinGlassPEPS.jl @@ -12,11 +12,14 @@ module SpinGlassPEPS include("base.jl") include("compressions.jl") - include("contractions.jl") - include("ising.jl") + include("contractions.jl") + include("graphs/model.jl") + include("graphs/chimera.jl") + include("graphs/lattice.jl") include("graph.jl") + include("ising.jl") include("PEPS.jl") - include("search.jl") + include("spectrum.jl") include("utils.jl") function __init__() @@ -29,7 +32,7 @@ module SpinGlassPEPS const CuQR = CUDA.CUSOLVER.CuQR # scalar indexing is fine before 0.2 # CUDA.allowscalar(false) - include("cuda/base.jl") + include("cuda/base.jl") include("cuda/contractions.jl") include("cuda/compressions.jl") end diff --git a/src/graph.jl b/src/graph.jl index 7627ddfe..5744b400 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -3,71 +3,75 @@ export factor_graph, decompose_edges! export Cluster, Spectrum export rank_reveal +const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge +const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter, Array} + +mutable struct Cluster + tag::Int + vertices::Dict{Int,Int} + edges::EdgeIter + rank::Vector + J::Matrix{<:Number} + h::Vector{<:Number} + + function Cluster(ig::MetaGraph, v::Int, vertices::Dict, edges::EdgeIter) + cl = new(v, vertices, edges) + L = length(cl.vertices) + + cl.J = zeros(L, L) + for e ∈ cl.edges + i = cl.vertices[src(e)] + j = cl.vertices[dst(e)] + cl.J[i, j] = get_prop(ig, e, :J) + end + rank = get_prop(ig, :rank) + cl.rank = rank[1:L] -for op in [ - :nv, - :ne, - :eltype, - :edgetype, - :vertices, - :edges, - ] - - @eval LightGraphs.$op(c::Model) = $op(c.graph) -end - -for op in [ - :get_prop, - :set_prop!, - :has_vertex, - :inneighbors, - :outneighbors, - :neighbors] - - @eval MetaGraphs.$op(c::Graph, args...) = $op(c.graph, args...) -end -@inline has_edge(g::Graph, x...) = has_edge(g.graph, x...) - -Base.size(c::Graph) = c.size -Base.size(c::Graph, i::Int) = c.size[i] - -function Base.getindex(c::Chimera, i::Int, j::Int, u::Int, k::Int) - _, n, t = size(c) - t * (2 * (n * (i - 1) + j - 1) + u - 1) + k -end - -function Base.getindex(l::Lattice, i::Int, j::Int) - m, n, _ = size(l) - LinearIndices((1:m, 1:n))[i, j] + cl.h = zeros(L) + for (w, i) ∈ cl.vertices + cl.h[i] = get_prop(ig, w, :h) + cl.rank[i] = rank[w] + end + cl + end end -function Base.getindex(c::Chimera, i::Int, j::Int) - t = size(c, 3) - idx = vec([c[i, j, u, k] for u=1:2, k=1:t]) - c.graph[idx] +function MetaGraphs.filter_edges(ig::MetaGraph, v::Cluster, w::Cluster) + edges = [] + for i ∈ keys(v.vertices) + for j ∈ unique_neighbors(ig, i) + if j ∈ keys(w.vertices) + push!(edges, SimpleEdge(i, j)) + end + end + end + edges end -function unit_cell(l::Lattice, v::Int) - Cluster(l.graph, v, enum([v]), []) -end +mutable struct Edge + tag::NTuple + edges::EdgeIter + J::Matrix{<:Number} -function unit_cell(c::Chimera, v::Int) - elist = filter_edges(c.graph, :cells, (v, v)) - vlist = filter_vertices(c.graph, :cell, v) - Cluster(c.graph, v, enum(vlist), elist) -end + function Edge(ig::MetaGraph, v::Cluster, w::Cluster) + ed = new((v.tag, w.tag)) + ed.edges = filter_edges(ig, v, w) -Cluster(g::Graph, v::Int) = unit_cell(g, v) + m = length(v.vertices) + n = length(w.vertices) -#Spectrum(cl::Cluster) = brute_force(cl, num_states=256) -function Spectrum(cl::Cluster) - σ = collect.(all_states(cl.rank)) - energies = energy.(σ, Ref(cl)) - Spectrum(energies, σ) + ed.J = zeros(m, n) + for e ∈ ed.edges + i = v.vertices[src(e)] + j = w.vertices[dst(e)] + ed.J[i, j] = get_prop(ig, e, :J) + end + ed + end end -function factor_graph(m::Int, n::Int, hdir=left_to_right, vdir=bottom_to_top) +function factor_graph(m::Int, n::Int, hdir=:LR, vdir=:BT) dg = MetaGraph(SimpleDiGraph(m * n)) set_prop!(dg, :order, (hdir, vdir)) @@ -75,7 +79,7 @@ function factor_graph(m::Int, n::Int, hdir=left_to_right, vdir=bottom_to_top) for i ∈ 1:m for j ∈ 1:n-1 v, w = linear[i, j], linear[i, j+1] - Int(hdir) == 1 ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) + hdir == :LR ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) add_edge!(dg, e) set_prop!(dg, e, :orientation, "horizontal") end @@ -84,7 +88,7 @@ function factor_graph(m::Int, n::Int, hdir=left_to_right, vdir=bottom_to_top) for i ∈ 1:n for j ∈ 1:m-1 v, w = linear[i, j], linear[i, j+1] - Int(vdir) == 1 ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) + vdir == :BT ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) add_edge!(dg, e) set_prop!(dg, e, :orientation, "vertical") end @@ -93,10 +97,10 @@ function factor_graph(m::Int, n::Int, hdir=left_to_right, vdir=bottom_to_top) end function factor_graph( - g::Graph, - energy::Function=ising_energy, + g::Model, + energy::Function=energy, spectrum::Function=brute_force, - create_cluster::Function=Cluster, + create_cluster::Function=unit_cell, ) # how to add typing to functions? m, n, _ = g.size fg = factor_graph(m, n) diff --git a/src/graphs/chimera.jl b/src/graphs/chimera.jl index e138671e..23b4a3de 100644 --- a/src/graphs/chimera.jl +++ b/src/graphs/chimera.jl @@ -1,3 +1,6 @@ +export Chimera +export unit_cell + mutable struct Chimera <: Model size::NTuple{3, Int} graph::MetaGraph @@ -48,4 +51,16 @@ end function Base.getindex(c::Chimera, i::Int, j::Int, u::Int, k::Int) _, n, t = size(c) t * (2 * (n * (i - 1) + j - 1) + u - 1) + k -end \ No newline at end of file +end + +function Base.getindex(c::Chimera, i::Int, j::Int) + t = size(c, 3) + idx = vec([c[i, j, u, k] for u=1:2, k=1:t]) + c.graph[idx] +end + +function unit_cell(c::Chimera, v::Int) + elist = filter_edges(c.graph, :cells, (v, v)) + vlist = filter_vertices(c.graph, :cell, v) + Cluster(c.graph, v, enum(vlist), elist) +end diff --git a/src/graphs/lattice.jl b/src/graphs/lattice.jl index 88baf354..a9e956eb 100644 --- a/src/graphs/lattice.jl +++ b/src/graphs/lattice.jl @@ -1,11 +1,19 @@ +export Lattice +export unit_cell + mutable struct Lattice <: Model - size::NTuple{3, Int} + size::NTuple{2, Int} graph::MetaGraph - function Lattice(m::Int, n::Int, k::Int=0) + function Lattice(m::Int, n::Int) lt = new() - lt.size = (m, n, k) + lt.size = (m, n) lt.graph = MetaGraph(grid([m, n])) lt end -end \ No newline at end of file +end + +function Base.getindex(l::Lattice, i::Int, j::Int) + m, n = size(l) + LinearIndices((1:m, 1:n))[i, j] +end diff --git a/src/graphs/model.jl b/src/graphs/model.jl index 3da14ce9..b0e26ed9 100644 --- a/src/graphs/model.jl +++ b/src/graphs/model.jl @@ -22,11 +22,10 @@ for op in [ :outneighbors, :neighbors] - @eval MetaGraphs.$op(c::Model, args...) = $op(c.graph, args...) + @eval MetaGraphs.$op(m::Model, args...) = $op(m.graph, args...) end -@inline has_edge(g::Model, x...) = has_edge(g.graph, x...) -Base.size(c::Model) = c.size -Base.size(c::Model, i::Int) = c.size[i] +@inline has_edge(m::Model, x...) = has_edge(m.graph, x...) -Cluster(g::Model, v::Int) = unit_cell(g, v) \ No newline at end of file +Base.size(m::Model) = m.size +Base.size(m::Model, i::Int) = m.size[i] \ No newline at end of file diff --git a/src/ising.jl b/src/ising.jl index 3d961de7..c21d28e1 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -1,116 +1,9 @@ export ising_graph, energy -export gibbs_tensor, brute_force -export State, Cluster, Edge, Spectrum +export gibbs_tensor +export State const State = Union{Vector, NTuple} const Instance = Union{String, Dict} -const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge -const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter, Array} - -struct Spectrum - energies::Array{<:Number} - states::Array{Vector{<:Number}} -end - -mutable struct Cluster - tag::Int - vertices::Dict{Int,Int} - edges::EdgeIter - rank::Vector - J::Matrix{<:Number} - h::Vector{<:Number} - - function Cluster(ig::MetaGraph, v::Int, vertices::Dict, edges::EdgeIter) - cl = new(v, vertices, edges) - L = length(cl.vertices) - - cl.J = zeros(L, L) - for e ∈ cl.edges - i = cl.vertices[src(e)] - j = cl.vertices[dst(e)] - cl.J[i, j] = get_prop(ig, e, :J) - end - - rank = get_prop(ig, :rank) - cl.rank = rank[1:L] - - cl.h = zeros(L) - for (w, i) ∈ cl.vertices - cl.h[i] = get_prop(ig, w, :h) - cl.rank[i] = rank[w] - end - cl - end -end - -function MetaGraphs.filter_edges(ig::MetaGraph, v::Cluster, w::Cluster) - edges = [] - for i ∈ keys(v.vertices) - for j ∈ unique_neighbors(ig, i) - if j ∈ keys(w.vertices) - push!(edges, SimpleEdge(i, j)) - end - end - end - edges -end - -mutable struct Edge - tag::NTuple - edges::EdgeIter - J::Matrix{<:Number} - - function Edge(ig::MetaGraph, v::Cluster, w::Cluster) - ed = new((v.tag, w.tag)) - ed.edges = filter_edges(ig, v, w) - - m = length(v.vertices) - n = length(w.vertices) - - ed.J = zeros(m, n) - for e ∈ ed.edges - i = v.vertices[src(e)] - j = w.vertices[dst(e)] - ed.J[i, j] = get_prop(ig, e, :J) - end - ed - end -end - -""" -$(TYPEDSIGNATURES) - -Return the low energy spectrum - -# Details - -Calculates \$k\$ lowest energy states -together with the coresponding energies -of a classical Ising Hamiltonian -""" - -function brute_force(ig::MetaGraph; num_states::Int=1) - cl = Cluster(ig, 0, num(vertices(ig)), edges(ig)) - brute_force(cl, num_states=num_states) -end - -function brute_force(cl::Cluster; num_states::Int=1) - σ = collect.(all_states(cl.rank)) - states = reshape(σ, prod(cl.rank)) - energies = energy.(states, Ref(cl)) - perm = partialsortperm(energies, 1:num_states) - Spectrum(energies[perm], states[perm]) -end - -_ising(σ::State) = 2 .* σ .- 1 - -function _brute_force(ig::MetaGraph, k::Int=1) - L = nv(ig) - states = _ising.(digits.(0:2^L-1, base=2, pad=L)) - energies = energy.(states, Ref(ig)) - perm = partialsortperm(energies, 1:k) - states[perm], energies[perm] -end """ diff --git a/src/search.jl b/src/spectrum.jl similarity index 76% rename from src/search.jl rename to src/spectrum.jl index 5dcd7712..bd53ad58 100644 --- a/src/search.jl +++ b/src/spectrum.jl @@ -2,6 +2,11 @@ export MPS_from_gates, unique_neighbors export MPSControl export spectrum +struct Spectrum + energies::Array{<:Number} + states::Array{Vector{<:Number}} +end + struct MPSControl max_bond::Int var_ϵ::Number @@ -9,6 +14,15 @@ struct MPSControl β::Vector end + +#Spectrum(cl::Cluster) = brute_force(cl, num_states=256) +function Spectrum(cl::Cluster) + σ = collect.(all_states(cl.rank)) + energies = energy.(σ, Ref(cl)) + Spectrum(energies, σ) +end + + # ρ needs to be in the right canonical form function spectrum(ψ::MPS, keep::Int) @assert keep > 0 "Number of states has to be > 0" @@ -158,3 +172,38 @@ function MPS(ig::MetaGraph, control::MPSControl) ρ end + +""" +$(TYPEDSIGNATURES) + +Return the low energy spectrum + +# Details + +Calculates \$k\$ lowest energy states +together with the coresponding energies +of a classical Ising Hamiltonian +""" +function brute_force(ig::MetaGraph; num_states::Int=1) + cl = Cluster(ig, 0, num(vertices(ig)), edges(ig)) + brute_force(cl, num_states=num_states) +end + + +function brute_force(cl::Cluster; num_states::Int=1) + σ = collect.(all_states(cl.rank)) + states = reshape(σ, prod(cl.rank)) + energies = energy.(states, Ref(cl)) + perm = partialsortperm(energies, 1:num_states) + Spectrum(energies[perm], states[perm]) +end + +_ising(σ::State) = 2 .* σ .- 1 + +function _brute_force(ig::MetaGraph, k::Int=1) + L = nv(ig) + states = _ising.(digits.(0:2^L-1, base=2, pad=L)) + energies = energy.(states, Ref(ig)) + perm = partialsortperm(energies, 1:k) + states[perm], energies[perm] +end From ed410f48fa21404ae47ea2a704c43f8f2722c4a7 Mon Sep 17 00:00:00 2001 From: dexter2206 Date: Thu, 17 Dec 2020 01:59:19 +0100 Subject: [PATCH 030/137] Attempt to merge master into bg/peps-ideas --- Project.toml | 4 ++-- src/spectrum.jl | 3 ++- test/runtests.jl | 14 +++++++------- test/search.jl | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index 7ce15bac..e152872f 100644 --- a/Project.toml +++ b/Project.toml @@ -20,14 +20,14 @@ TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" -NPZ = "15e1cf62-19b3-5cfa-8e77-841668bca605" [compat] TensorOperations = "3.0.1" julia = "1.4, 1.5" [extras] +NPZ = "15e1cf62-19b3-5cfa-8e77-841668bca605" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Test", "NPZ"] diff --git a/src/spectrum.jl b/src/spectrum.jl index 63bfb079..ae2a5e23 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -1,3 +1,4 @@ +export brute_force export MPS_from_gates, unique_neighbors export MPSControl export spectrum @@ -244,7 +245,7 @@ together with the coresponding energies of a classical Ising Hamiltonian """ function brute_force(ig::MetaGraph; num_states::Int=1) - cl = Cluster(ig, 0, num(vertices(ig)), edges(ig)) + cl = Cluster(ig, 0, enum(vertices(ig)), edges(ig)) brute_force(cl, num_states=num_states) end diff --git a/test/runtests.jl b/test/runtests.jl index bbdbba78..502d09dd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,17 +31,17 @@ if CUDA.functional() && CUDA.has_cutensor() end push!(my_tests, - "base.jl", - "contractions.jl", - "compressions.jl", + #"base.jl", + #"contractions.jl", + #"compressions.jl", "ising.jl", "search.jl", "graph.jl", "notation_tests.jl", - "peps_tests.jl", - "mps_tests.jl", - "tests_full_graph.jl", - "tests_on_data.jl" + "peps_tests.jl", + "mps_tests.jl", + "tests_full_graph.jl", + "tests_on_data.jl" ) for my_test in my_tests diff --git a/test/search.jl b/test/search.jl index 2abf9311..31f50de3 100644 --- a/test/search.jl +++ b/test/search.jl @@ -66,7 +66,7 @@ states = all_states(get_prop(ig, :rank)) @test abs(dot(χ, χ) - sum(T)) < ϵ end - @test T ./ sum(T) ≈ ϱ + @test_broken T ./ sum(T) ≈ ϱ end @@ -96,7 +96,7 @@ end end ρ = abs.(ψ) .^ 2 - @test ρ / sum(ρ) ≈ ϱ + @test_broken ρ / sum(ρ) ≈ ϱ @info "Generating MPS from |ρ>" rψ = MPS(ψ) From 31663fcfc08c04dff2cc66891c7190ca31b7d6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Fri, 18 Dec 2020 13:07:41 +0100 Subject: [PATCH 031/137] fix broken tests --- src/ising.jl | 7 ++++--- src/spectrum.jl | 4 ++-- test/runtests.jl | 14 +++++++------- test/search.jl | 18 ++++++++++-------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/ising.jl b/src/ising.jl index c21d28e1..ef1dffc2 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -62,7 +62,7 @@ Create the Ising spin glass model. Store extra information """ -function ising_graph(instance::Instance, L::Int, β::Number=1, sgn::Number=1) +function ising_graph(instance::Instance, L::Int, β::Number=1, sgn::Number=-1) # load the Ising instance if typeof(instance) == String @@ -76,11 +76,12 @@ function ising_graph(instance::Instance, L::Int, β::Number=1, sgn::Number=1) # setup the model (J_ij, h_i) for (i, j, v) ∈ ising + v *= sgn if i == j - set_prop!(ig, i, :h, sgn * v) || error("Node $i missing!") + set_prop!(ig, i, :h, v) || error("Node $i missing!") else add_edge!(ig, i, j) && - set_prop!(ig, i, j, :J, sgn * v) || error("Cannot add Egde ($i, $j)") + set_prop!(ig, i, j, :J, v) || error("Cannot add Egde ($i, $j)") end end diff --git a/src/spectrum.jl b/src/spectrum.jl index ae2a5e23..cf1da530 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -141,7 +141,7 @@ function _apply_bias!(ψ::AbstractMPS, ig::MetaGraph, dβ::Number, i::Int) d = size(M, 2) h = get_prop(ig, i, :h) - v = [exp(0.5 * dβ * h * σ) for σ ∈ local_basis(d)] + v = [exp(-0.5 * dβ * h * σ) for σ ∈ local_basis(d)] @cast M[x, σ, y] = M[x, σ, y] * v[σ] ψ[i] = M @@ -152,7 +152,7 @@ function _apply_exponent!(ψ::AbstractMPS, ig::MetaGraph, dβ::Number, i::Int, j D = I(ψ, i) J = get_prop(ig, i, j, :J) - C = [ exp(0.5 * dβ * k * J * l) for k ∈ local_basis(ψ, i), l ∈ local_basis(ψ, j) ] + C = [ exp(-0.5 * dβ * k * J * l) for k ∈ local_basis(ψ, i), l ∈ local_basis(ψ, j) ] if j == last @cast M̃[(x, a), σ, b] := C[x, σ] * M[a, σ, b] diff --git a/test/runtests.jl b/test/runtests.jl index 502d09dd..cba379f3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -34,14 +34,14 @@ push!(my_tests, #"base.jl", #"contractions.jl", #"compressions.jl", - "ising.jl", + #"ising.jl", "search.jl", - "graph.jl", - "notation_tests.jl", - "peps_tests.jl", - "mps_tests.jl", - "tests_full_graph.jl", - "tests_on_data.jl" + #"graph.jl", + #"notation_tests.jl", + #"peps_tests.jl", + #"mps_tests.jl", + #"tests_full_graph.jl", + #"tests_on_data.jl" ) for my_test in my_tests diff --git a/test/search.jl b/test/search.jl index 31f50de3..8960dc5f 100644 --- a/test/search.jl +++ b/test/search.jl @@ -12,6 +12,7 @@ set_prop!(ig, :β, 1.) #rand(Float64)) r = [3, 2, 5, 4] set_prop!(ig, :rank, r) +sgn = -1. ϵ = 1E-8 D = prod(r) + 1 var_ϵ = 1E-8 @@ -38,7 +39,7 @@ states = all_states(get_prop(ig, :rank)) h = get_prop(ig, i, :h) for σ ∈ states - T[idx.(σ)...] *= exp(β * σ[i] * h) + T[idx.(σ)...] *= exp(sgn * β * σ[i] * h) end nbrs = unique_neighbors(ig, i) @@ -51,7 +52,7 @@ states = all_states(get_prop(ig, :rank)) J = get_prop(ig, i, j, :J) for σ ∈ states - T[idx.(σ)...] *= exp(β * σ[i] * J * σ[j]) + T[idx.(σ)...] *= exp(sgn * β * σ[i] * J * σ[j]) end end @@ -66,10 +67,10 @@ states = all_states(get_prop(ig, :rank)) @test abs(dot(χ, χ) - sum(T)) < ϵ end - @test_broken T ./ sum(T) ≈ ϱ + x = T ./ sum(T) + @test T ./ sum(T) ≈ ϱ end - @testset "MPS from gates" begin @testset "Exact Gibbs pure state (MPS)" begin @@ -86,17 +87,17 @@ end h = get_prop(ig, i, :h) nbrs = unique_neighbors(ig, i) - ψ[idx.(σ)...] *= exp(0.5 * β * h * σ[i]) + ψ[idx.(σ)...] *= exp(sgn * 0.5 * β * h * σ[i]) for j ∈ nbrs J = get_prop(ig, i, j, :J) - ψ[idx.(σ)...] *= exp(0.5 * β * σ[i] * J * σ[j]) + ψ[idx.(σ)...] *= exp(sgn * 0.5 * β * σ[i] * J * σ[j]) end end end ρ = abs.(ψ) .^ 2 - @test_broken ρ / sum(ρ) ≈ ϱ + @test ρ / sum(ρ) ≈ ϱ @info "Generating MPS from |ρ>" rψ = MPS(ψ) @@ -146,6 +147,7 @@ end @info "The largest discarded probability" pCut @test maximum(prob) > pCut + for (j, (p, e)) ∈ enumerate(zip(prob, sp.energies)) σ = states[:, j] @test ϱ[idx.(σ)...] ≈ p @@ -171,7 +173,7 @@ end @info "State with the lowest energy" state @info "Probability of the state with the lowest energy" prob_new[1] @info "The lowest energy" eng_new[1] - + end end end \ No newline at end of file From d6804a6b1cae8fdba1ae38caacca337e198bd4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Fri, 18 Dec 2020 13:09:14 +0100 Subject: [PATCH 032/137] rename search.jl to spectrum.jl --- test/{search.jl => spectrum.jl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{search.jl => spectrum.jl} (100%) diff --git a/test/search.jl b/test/spectrum.jl similarity index 100% rename from test/search.jl rename to test/spectrum.jl From a01edb22a232807b991586983adb81882fff2e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Fri, 18 Dec 2020 13:16:22 +0100 Subject: [PATCH 033/137] all tests but Krzysiek's passes --- test/runtests.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index cba379f3..c1147597 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,17 +31,17 @@ if CUDA.functional() && CUDA.has_cutensor() end push!(my_tests, - #"base.jl", - #"contractions.jl", - #"compressions.jl", - #"ising.jl", - "search.jl", - #"graph.jl", - #"notation_tests.jl", - #"peps_tests.jl", - #"mps_tests.jl", - #"tests_full_graph.jl", - #"tests_on_data.jl" + "base.jl", + "contractions.jl", + "compressions.jl", + "ising.jl", + "spectrum.jl", + "graph.jl", + "notation_tests.jl", + "peps_tests.jl", + "mps_tests.jl", + "tests_full_graph.jl", + "tests_on_data.jl" ) for my_test in my_tests From 85c2bcac10b1cb2964734f89710b068a16a51a74 Mon Sep 17 00:00:00 2001 From: kdomino Date: Fri, 18 Dec 2020 15:04:02 +0100 Subject: [PATCH 034/137] some corrections --- test/notation_tests.jl | 6 +++--- test/peps_tests.jl | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test/notation_tests.jl b/test/notation_tests.jl index 349ba133..5151a359 100644 --- a/test/notation_tests.jl +++ b/test/notation_tests.jl @@ -143,8 +143,8 @@ end g1 = graph4peps(ig, (1,1)) @test props(g1, 1,2)[:M] == [-2.0 2.0; 2.0 -2.0] @test props(g1, 2,4)[:M] == [-2.0 2.0; 2.0 -2.0] - @test props(g1, 1)[:energy] == [1., -1.] - @test props(g1, 2)[:energy] == [1., -1.] + @test props(g1, 1)[:energy] == [-1., 1.] + @test props(g1, 2)[:energy] == [-1., 1.] @test props(g1, 1,2)[:inds] == [1] M = ones(16,16) @@ -156,7 +156,7 @@ end @test size(M) == (4,16) @test M[:,1] == [-4.0, 0.0, 0.0, 4.0] e = [-4.0, 2.0, 2.0, 0.0, 2.0, 0.0, 8.0, -2.0, 2.0, 8.0, 0.0, -2.0, 0.0, -2.0, -2.0, -12.0] - @test props(g1, 1)[:energy] == e + @test props(g1, 1)[:energy] == -e @test props(g1, 1,2)[:inds] == [3, 4] @test props(g1, 1,3)[:inds] == [2, 4] diff --git a/test/peps_tests.jl b/test/peps_tests.jl index b1387778..59272c0c 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -67,6 +67,7 @@ end Mq = ones(4,4) fullM2grid!(Mq, (2,2)) +if false @testset "tensor construction" begin @@ -89,13 +90,13 @@ fullM2grid!(Mq, (2,2)) @test size(t1) == (1, 1, 2, 2) - @test t1[1,1,:,:] ≈ [exp(-1*β) 0.; 0. exp(1*β)] + @test t1[1,1,:,:] ≈ [exp(1*β) 0.; 0. exp(-1*β)] @test size(t2) == (2,1,1,2) - @test t2[:,1,1,:] ≈ [exp(1*β) exp(-1*β); exp(-3*β) exp(3*β)] + @test t2[:,1,1,:] ≈ [exp(-1*β) exp(1*β); exp(3*β) exp(-3*β)] @test size(t3) == (1,2,2,1) - @test t3[1,:,:,1] ≈ [exp(1*β) exp(-1*β); exp(-3*β) exp(3*β)] + @test t3[1,:,:,1] ≈ [exp(-1*β) exp(1*β); exp(3*β) exp(-3*β)] t = compute_single_tensor(g1, 1, β) @@ -112,6 +113,7 @@ fullM2grid!(Mq, (2,2)) @test vec(T1) ≈ vec(T2) end +end Mq = zeros(9,9) Mq[1,1] = 1. From 9b6fba8ddbe6b0c3c549397bdfb37446f0e3c9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Sat, 19 Dec 2020 12:49:04 +0100 Subject: [PATCH 035/137] add basic test for PEPS generation --- src/PEPS.jl | 19 +++++++++++-------- test/PEPS.jl | 18 ++++++++++++++++++ test/runtests.jl | 23 ++++++++++++----------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index dfcf35da..e93f1187 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -10,21 +10,24 @@ mutable struct PepsTensor function PepsTensor(fg::MetaGraph, v::Int) pc = new() outgoing = outneighbors(fg, v) - incoming = inneighbours(fg, v) + incoming = inneighbors(fg, v) + - for u ∈ outgoing - if get_prop(fg, (v, u), :orientation) == "horizontal" - pc.right = last(get_prop(fg, (v, u), :decomposition)) + for u ∈ outgoing + e = SimpleEdge(v, u) + if get_prop(fg, e, :orientation) == "horizontal" + pc.right = last(get_prop(fg, e, :decomposition)) else - pc.down = last(get_prop(fg, (v, u), :decomposition)) + pc.down = last(get_prop(fg, e, :decomposition)) end end for u ∈ incoming - if get_prop(fg, (u, v), :orientation) == "horizontal" - pc.left = first(get_prop(fg, (u, v), :decomposition)) + e = SimpleEdge(u, v) + if get_prop(fg, e, :orientation) == "horizontal" + pc.left = first(get_prop(fg, e, :decomposition)) else - pc.up = first(get_prop(fg, (u, v), :decomposition)) + pc.up = first(get_prop(fg, e, :decomposition)) end end diff --git a/test/PEPS.jl b/test/PEPS.jl index e69de29b..0a18175f 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -0,0 +1,18 @@ + +@testset "PepsTensor correctly builds PEPS tensor" begin +m = 4 +n = 4 +t = 4 + +L = 2 * n * m * t +instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" + +ig = ising_graph(instance, L) +cg = Chimera((m, n, t), ig) + +fg = factor_graph(cg) +decompose_edges!(fg) + +peps = PepsTensor(fg, 5) + +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index c1147597..444eeac5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,17 +31,18 @@ if CUDA.functional() && CUDA.has_cutensor() end push!(my_tests, - "base.jl", - "contractions.jl", - "compressions.jl", - "ising.jl", - "spectrum.jl", - "graph.jl", - "notation_tests.jl", - "peps_tests.jl", - "mps_tests.jl", - "tests_full_graph.jl", - "tests_on_data.jl" + #"base.jl", + #"contractions.jl", + #"compressions.jl", + #"ising.jl", + #"spectrum.jl", + #"graph.jl", + "PEPS.jl" + #"notation_tests.jl", + #"peps_tests.jl", + #"mps_tests.jl", + #"tests_full_graph.jl", + #"tests_on_data.jl" ) for my_test in my_tests From 3c02a5bec56f67bd061e81de8b2bbda0dcda9ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Sat, 19 Dec 2020 14:30:16 +0100 Subject: [PATCH 036/137] befor coding with kd --- src/PEPS.jl | 3 ++- src/graph.jl | 16 ++++++++-------- test/notation_tests.jl | 6 +++--- test/peps_tests.jl | 2 +- test/runtests.jl | 24 ++++++++++++------------ 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index e93f1187..8e215960 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -8,7 +8,8 @@ mutable struct PepsTensor tensor::AbstractArray function PepsTensor(fg::MetaGraph, v::Int) - pc = new() + n = nothing + pc = new(n, n, n, n, n) outgoing = outneighbors(fg, v) incoming = inneighbors(fg, v) diff --git a/src/graph.jl b/src/graph.jl index 5744b400..a7c4a04a 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -100,13 +100,13 @@ function factor_graph( g::Model, energy::Function=energy, spectrum::Function=brute_force, - create_cluster::Function=unit_cell, -) # how to add typing to functions? + cluster::Function=unit_cell, +) m, n, _ = g.size fg = factor_graph(m, n) for v ∈ vertices(fg) - cl = create_cluster(g, v) + cl = cluster(g, v) set_prop!(fg, v, :cluster, cl) set_prop!(fg, v, :spectrum, spectrum(cl)) end @@ -123,17 +123,17 @@ function factor_graph( end -function decompose_edges!(fg::MetaGraph, order=P_then_E, beta::Float64=1.0) - set_prop!(dg, :tensorsOrder, order) +function decompose_edges!(fg::MetaGraph, order=:PE, beta::Float64=1.0) + set_prop!(fg, :tensorsOrder, order) for edge ∈ edges(fg) energies = get_prop(fg, edge, :energy) en, p = rank_reveal(energies) - if Int(order) == 1 - dec = (p, exp.(beta .* en)) + if order == :PE + dec = (p, exp.(-beta .* en)) else - dec = (exp.(beta .* en), p) + dec = (exp.(-beta .* en), p) end set_prop!(fg, edge, :decomposition, dec) end diff --git a/test/notation_tests.jl b/test/notation_tests.jl index 349ba133..5151a359 100644 --- a/test/notation_tests.jl +++ b/test/notation_tests.jl @@ -143,8 +143,8 @@ end g1 = graph4peps(ig, (1,1)) @test props(g1, 1,2)[:M] == [-2.0 2.0; 2.0 -2.0] @test props(g1, 2,4)[:M] == [-2.0 2.0; 2.0 -2.0] - @test props(g1, 1)[:energy] == [1., -1.] - @test props(g1, 2)[:energy] == [1., -1.] + @test props(g1, 1)[:energy] == [-1., 1.] + @test props(g1, 2)[:energy] == [-1., 1.] @test props(g1, 1,2)[:inds] == [1] M = ones(16,16) @@ -156,7 +156,7 @@ end @test size(M) == (4,16) @test M[:,1] == [-4.0, 0.0, 0.0, 4.0] e = [-4.0, 2.0, 2.0, 0.0, 2.0, 0.0, 8.0, -2.0, 2.0, 8.0, 0.0, -2.0, 0.0, -2.0, -2.0, -12.0] - @test props(g1, 1)[:energy] == e + @test props(g1, 1)[:energy] == -e @test props(g1, 1,2)[:inds] == [3, 4] @test props(g1, 1,3)[:inds] == [2, 4] diff --git a/test/peps_tests.jl b/test/peps_tests.jl index b1387778..2ee73f47 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -71,7 +71,7 @@ fullM2grid!(Mq, (2,2)) g = M2graph(Mq) - β = 2. + β = -2. #smaller tensors g1 = graph4peps(g, (1,1)) diff --git a/test/runtests.jl b/test/runtests.jl index 444eeac5..90e73bca 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,18 +31,18 @@ if CUDA.functional() && CUDA.has_cutensor() end push!(my_tests, - #"base.jl", - #"contractions.jl", - #"compressions.jl", - #"ising.jl", - #"spectrum.jl", - #"graph.jl", - "PEPS.jl" - #"notation_tests.jl", - #"peps_tests.jl", - #"mps_tests.jl", - #"tests_full_graph.jl", - #"tests_on_data.jl" + "base.jl", + "contractions.jl", + "compressions.jl", + "ising.jl", + "spectrum.jl", + "graph.jl", + #"PEPS.jl" + "notation_tests.jl", + "peps_tests.jl", + "mps_tests.jl", + "tests_full_graph.jl", + "tests_on_data.jl" ) for my_test in my_tests From 6ed865a1dabc7287a8a264c8384b8e653175ee76 Mon Sep 17 00:00:00 2001 From: dexter2206 Date: Sat, 19 Dec 2020 15:26:41 +0100 Subject: [PATCH 037/137] Debugging problems with PEPS tensor construction --- src/PEPS.jl | 31 +++++++++++++++++++++++-------- src/graph.jl | 10 +++++----- src/ising.jl | 2 +- test/runtests.jl | 24 ++++++++++++------------ 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 8e215960..6842355a 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -8,48 +8,63 @@ mutable struct PepsTensor tensor::AbstractArray function PepsTensor(fg::MetaGraph, v::Int) - n = nothing - pc = new(n, n, n, n, n) + pc = new() outgoing = outneighbors(fg, v) incoming = inneighbors(fg, v) for u ∈ outgoing e = SimpleEdge(v, u) + println(e) + println(get_prop(fg, e, :orientation)) if get_prop(fg, e, :orientation) == "horizontal" + println("Setting right") pc.right = last(get_prop(fg, e, :decomposition)) else + println("Setting down") pc.down = last(get_prop(fg, e, :decomposition)) end end for u ∈ incoming e = SimpleEdge(u, v) + println(e) + println(get_prop(fg, e, :orientation)) if get_prop(fg, e, :orientation) == "horizontal" + println("Setting left") pc.left = first(get_prop(fg, e, :decomposition)) else + println("Setting up") pc.up = first(get_prop(fg, e, :decomposition)) end end # open boundary conditions - if pc.left === nothing + if !isdefined(pc, :left) + println("left was undefined") pc.left = ones(1, size(pc.right, 1)) end - if pc.right === nothing + if !isdefined(pc, :right) + println("right was undefined") pc.right = ones(size(pc.left, 2), 1) end - if pc.up === nothing + if !isdefined(pc, :up) + println("up was undefined") pc.up = ones(1, size(pc.down, 1)) end - if pc.down === nothing + if !isdefined(pc, :down) + println("down was undefined") pc.down = ones(size(pc.up, 2), 1) end - - pc.tensor[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] + println(v) + println(size(pc.left)) + println(size(pc.right)) + println(size(pc.up)) + println(size(pc.down)) + @cast pc.tensor[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] pc end diff --git a/src/graph.jl b/src/graph.jl index a7c4a04a..114f4840 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -14,7 +14,7 @@ mutable struct Cluster J::Matrix{<:Number} h::Vector{<:Number} - function Cluster(ig::MetaGraph, v::Int, vertices::Dict, edges::EdgeIter) + function Cluster(ig::MetaDiGraph, v::Int, vertices::Dict, edges::EdgeIter) cl = new(v, vertices, edges) L = length(cl.vertices) @@ -54,7 +54,7 @@ mutable struct Edge edges::EdgeIter J::Matrix{<:Number} - function Edge(ig::MetaGraph, v::Cluster, w::Cluster) + function Edge(ig::MetaDiGraph, v::Cluster, w::Cluster) ed = new((v.tag, w.tag)) ed.edges = filter_edges(ig, v, w) @@ -72,7 +72,7 @@ mutable struct Edge end function factor_graph(m::Int, n::Int, hdir=:LR, vdir=:BT) - dg = MetaGraph(SimpleDiGraph(m * n)) + dg = MetaDiGraph(SimpleDiGraph(m * n)) set_prop!(dg, :order, (hdir, vdir)) linear = LinearIndices((1:m, 1:n)) @@ -87,7 +87,7 @@ function factor_graph(m::Int, n::Int, hdir=:LR, vdir=:BT) for i ∈ 1:n for j ∈ 1:m-1 - v, w = linear[i, j], linear[i, j+1] + v, w = linear[j, i], linear[j+1, i] vdir == :BT ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) add_edge!(dg, e) set_prop!(dg, e, :orientation, "vertical") @@ -123,7 +123,7 @@ function factor_graph( end -function decompose_edges!(fg::MetaGraph, order=:PE, beta::Float64=1.0) +function decompose_edges!(fg::MetaDiGraph, order=:PE, beta::Float64=1.0) set_prop!(fg, :tensorsOrder, order) for edge ∈ edges(fg) diff --git a/src/ising.jl b/src/ising.jl index ef1dffc2..fcceb93d 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -45,7 +45,7 @@ function energy(σ::Vector, ig::MetaGraph) energy(σ, cl) end -function energy(fg::MetaGraph, edge::Edge) +function energy(fg::MetaDiGraph, edge::Edge) v, w = edge.tag vSp = get_prop(fg, v, :spectrum).states wSp = get_prop(fg, w, :spectrum).states diff --git a/test/runtests.jl b/test/runtests.jl index 90e73bca..444eeac5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,18 +31,18 @@ if CUDA.functional() && CUDA.has_cutensor() end push!(my_tests, - "base.jl", - "contractions.jl", - "compressions.jl", - "ising.jl", - "spectrum.jl", - "graph.jl", - #"PEPS.jl" - "notation_tests.jl", - "peps_tests.jl", - "mps_tests.jl", - "tests_full_graph.jl", - "tests_on_data.jl" + #"base.jl", + #"contractions.jl", + #"compressions.jl", + #"ising.jl", + #"spectrum.jl", + #"graph.jl", + "PEPS.jl" + #"notation_tests.jl", + #"peps_tests.jl", + #"mps_tests.jl", + #"tests_full_graph.jl", + #"tests_on_data.jl" ) for my_test in my_tests From ef0274881fed3855919d7fe27a5bb944d332592b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Sat, 19 Dec 2020 16:06:58 +0100 Subject: [PATCH 038/137] fixing Krzysiek's tests --- Manifest.toml | 35 +++++++++++++++++------------------ Project.toml | 10 +++++----- src/PEPS.jl | 1 + src/SpinGlassPEPS.jl | 1 + src/graph.jl | 5 +++-- test/PEPS.jl | 1 - test/peps_tests.jl | 12 +++++++----- test/runtests.jl | 12 ++++++------ 8 files changed, 40 insertions(+), 37 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index b8a882e7..3938ae97 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -92,6 +92,11 @@ git-tree-sha1 = "a2b4df8e2dc688f2d63b5cfcc00c773218fa9e7f" uuid = "a81c6b42-2e10-5240-aca2-a61377ecd94b" version = "0.9.1" +[[Crayons]] +git-tree-sha1 = "3f71217b538d7aaee0b69ab47d9b7724ca8afa0d" +uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" +version = "4.0.4" + [[DataAPI]] git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" @@ -118,6 +123,12 @@ version = "1.0.0" deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" +[[Debugger]] +deps = ["CodeTracking", "Crayons", "Highlights", "InteractiveUtils", "JuliaInterpreter", "Markdown", "REPL"] +git-tree-sha1 = "c37eca3eff2657c700f32e05500215feac886dcf" +uuid = "31a5f54b-26ea-5ae9-a837-f05ce5417438" +version = "0.6.6" + [[DelimitedFiles]] deps = ["Mmap"] uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" @@ -132,12 +143,6 @@ git-tree-sha1 = "50ddf44c53698f5e784bbebb3f4b21c5807401b1" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" version = "0.8.3" -[[Documenter]] -deps = ["Base64", "Dates", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] -git-tree-sha1 = "fb1ff838470573adc15c71ba79f8d31328f035da" -uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -version = "0.25.2" - [[ExprTools]] git-tree-sha1 = "7fce513fcda766962ff67c5596cb16c463dfd371" uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04" @@ -191,6 +196,12 @@ git-tree-sha1 = "f4435ce0055d4da938f3bab0c0e523826735c96a" uuid = "a2cc645c-3eea-5389-862e-a155d0052231" version = "0.3.1" +[[Highlights]] +deps = ["DocStringExtensions", "InteractiveUtils", "REPL"] +git-tree-sha1 = "f823a2d04fb233d52812c8024a6d46d9581904a4" +uuid = "eafb193a-b7ab-5a9e-9068-77385905fa72" +version = "0.4.5" + [[Inflate]] git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c" uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" @@ -294,12 +305,6 @@ git-tree-sha1 = "9af25a91bda16307caff2a50f9c744c432b8bc1b" uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" version = "1.2.6" -[[MKL]] -deps = ["Libdl", "MKL_jll", "PackageCompiler"] -git-tree-sha1 = "e01175ff53c062c52b6cbe441a4382e132f7c82e" -uuid = "33e6dc65-8f57-5167-99aa-e5a354878fb2" -version = "0.3.0" - [[MKL_jll]] deps = ["IntelOpenMP_jll", "Libdl", "Pkg"] git-tree-sha1 = "eb540ede3aabb8284cb482aa41d00d6ca850b1f8" @@ -363,12 +368,6 @@ git-tree-sha1 = "16c08bf5dba06609fe45e30860092d6fa41fde7b" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" version = "1.3.1" -[[PackageCompiler]] -deps = ["Libdl", "Pkg", "UUIDs"] -git-tree-sha1 = "3eee77c94646163f15bd8626acf494360897f890" -uuid = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d" -version = "1.2.3" - [[Parsers]] deps = ["Dates"] git-tree-sha1 = "6fa4202675c05ba0f8268a6ddf07606350eda3ce" diff --git a/Project.toml b/Project.toml index e152872f..7f66c24b 100644 --- a/Project.toml +++ b/Project.toml @@ -6,27 +6,27 @@ version = "0.0.1" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +Debugger = "31a5f54b-26ea-5ae9-a837-f05ce5417438" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231" LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" LowRankApprox = "898213cb-b102-5a47-900c-97e73b919f73" MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Requires = "ae029012-a4dd-5104-9daa-d747884805df" Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b" TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" -Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - [compat] TensorOperations = "3.0.1" julia = "1.4, 1.5" [extras] -NPZ = "15e1cf62-19b3-5cfa-8e77-841668bca605" +NPZ = "15e1cf62-19b3-5cfa-8e77-841668bca605" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] diff --git a/src/PEPS.jl b/src/PEPS.jl index 6842355a..73af9b73 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -64,6 +64,7 @@ mutable struct PepsTensor println(size(pc.right)) println(size(pc.up)) println(size(pc.down)) + @cast pc.tensor[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] pc diff --git a/src/SpinGlassPEPS.jl b/src/SpinGlassPEPS.jl index 46427e1d..a99cde77 100644 --- a/src/SpinGlassPEPS.jl +++ b/src/SpinGlassPEPS.jl @@ -6,6 +6,7 @@ module SpinGlassPEPS using LightGraphs using MetaGraphs using CSV + using Debugger using DocStringExtensions const product = Iterators.product diff --git a/src/graph.jl b/src/graph.jl index 114f4840..7f18be75 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -5,6 +5,7 @@ export rank_reveal const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter, Array} +const Graph = Union{MetaDiGraph, MetaGraph} mutable struct Cluster tag::Int @@ -14,7 +15,7 @@ mutable struct Cluster J::Matrix{<:Number} h::Vector{<:Number} - function Cluster(ig::MetaDiGraph, v::Int, vertices::Dict, edges::EdgeIter) + function Cluster(ig::Graph, v::Int, vertices::Dict, edges::EdgeIter) cl = new(v, vertices, edges) L = length(cl.vertices) @@ -72,7 +73,7 @@ mutable struct Edge end function factor_graph(m::Int, n::Int, hdir=:LR, vdir=:BT) - dg = MetaDiGraph(SimpleDiGraph(m * n)) + dg = MetaDiGraph(m * n) set_prop!(dg, :order, (hdir, vdir)) linear = LinearIndices((1:m, 1:n)) diff --git a/test/PEPS.jl b/test/PEPS.jl index 0a18175f..01787d5f 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -1,4 +1,3 @@ - @testset "PepsTensor correctly builds PEPS tensor" begin m = 4 n = 4 diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 2ee73f47..81458bab 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -67,11 +67,12 @@ end Mq = ones(4,4) fullM2grid!(Mq, (2,2)) +if false @testset "tensor construction" begin g = M2graph(Mq) - β = -2. + β = 2. #smaller tensors g1 = graph4peps(g, (1,1)) @@ -89,13 +90,13 @@ fullM2grid!(Mq, (2,2)) @test size(t1) == (1, 1, 2, 2) - @test t1[1,1,:,:] ≈ [exp(-1*β) 0.; 0. exp(1*β)] + @test t1[1,1,:,:] ≈ [exp(1*β) 0.; 0. exp(-1*β)] @test size(t2) == (2,1,1,2) - @test t2[:,1,1,:] ≈ [exp(1*β) exp(-1*β); exp(-3*β) exp(3*β)] + @test t2[:,1,1,:] ≈ [exp(-1*β) exp(1*β); exp(3*β) exp(-3*β)] @test size(t3) == (1,2,2,1) - @test t3[1,:,:,1] ≈ [exp(1*β) exp(-1*β); exp(-3*β) exp(3*β)] + @test t3[1,:,:,1] ≈ [exp(-1*β) exp(1*β); exp(3*β) exp(-3*β)] t = compute_single_tensor(g1, 1, β) @@ -112,6 +113,7 @@ fullM2grid!(Mq, (2,2)) @test vec(T1) ≈ vec(T2) end +end Mq = zeros(9,9) Mq[1,1] = 1. @@ -252,4 +254,4 @@ end @test objective[i] ≈ objective_l[i] atol=1e-5 @test spins[i] == spins_l[i] end -end +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 444eeac5..f6d8d836 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -37,12 +37,12 @@ push!(my_tests, #"ising.jl", #"spectrum.jl", #"graph.jl", - "PEPS.jl" - #"notation_tests.jl", - #"peps_tests.jl", - #"mps_tests.jl", - #"tests_full_graph.jl", - #"tests_on_data.jl" + #"PEPS.jl" + "notation_tests.jl", + "peps_tests.jl", + "mps_tests.jl", + "tests_full_graph.jl", + "tests_on_data.jl" ) for my_test in my_tests From e54c577aaf37ae3f3dc8acde0a8dd662b0e3afbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Sat, 19 Dec 2020 19:39:19 +0100 Subject: [PATCH 039/137] change Meta na DiMeta --- Manifest.toml | 21 +++++---------------- Project.toml | 2 +- src/PEPS.jl | 20 ++++---------------- src/SpinGlassPEPS.jl | 2 +- src/graph.jl | 9 ++++++--- test/PEPS.jl | 1 - test/runtests.jl | 13 +++++++------ 7 files changed, 24 insertions(+), 44 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 3938ae97..bdc4a069 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -92,11 +92,6 @@ git-tree-sha1 = "a2b4df8e2dc688f2d63b5cfcc00c773218fa9e7f" uuid = "a81c6b42-2e10-5240-aca2-a61377ecd94b" version = "0.9.1" -[[Crayons]] -git-tree-sha1 = "3f71217b538d7aaee0b69ab47d9b7724ca8afa0d" -uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" -version = "4.0.4" - [[DataAPI]] git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" @@ -123,12 +118,6 @@ version = "1.0.0" deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" -[[Debugger]] -deps = ["CodeTracking", "Crayons", "Highlights", "InteractiveUtils", "JuliaInterpreter", "Markdown", "REPL"] -git-tree-sha1 = "c37eca3eff2657c700f32e05500215feac886dcf" -uuid = "31a5f54b-26ea-5ae9-a837-f05ce5417438" -version = "0.6.6" - [[DelimitedFiles]] deps = ["Mmap"] uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" @@ -196,11 +185,11 @@ git-tree-sha1 = "f4435ce0055d4da938f3bab0c0e523826735c96a" uuid = "a2cc645c-3eea-5389-862e-a155d0052231" version = "0.3.1" -[[Highlights]] -deps = ["DocStringExtensions", "InteractiveUtils", "REPL"] -git-tree-sha1 = "f823a2d04fb233d52812c8024a6d46d9581904a4" -uuid = "eafb193a-b7ab-5a9e-9068-77385905fa72" -version = "0.4.5" +[[Infiltrator]] +deps = ["REPL"] +git-tree-sha1 = "2be5c3e8adddf062c3903a6d7618f233fa4d2874" +uuid = "5903a43b-9cc3-4c30-8d17-598619ec4e9b" +version = "0.3.0" [[Inflate]] git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c" diff --git a/Project.toml b/Project.toml index 7f66c24b..7355473d 100644 --- a/Project.toml +++ b/Project.toml @@ -6,9 +6,9 @@ version = "0.0.1" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" -Debugger = "31a5f54b-26ea-5ae9-a837-f05ce5417438" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231" +Infiltrator = "5903a43b-9cc3-4c30-8d17-598619ec4e9b" LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" diff --git a/src/PEPS.jl b/src/PEPS.jl index 73af9b73..4f3136da 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -7,64 +7,52 @@ mutable struct PepsTensor down::AbstractArray tensor::AbstractArray - function PepsTensor(fg::MetaGraph, v::Int) + function PepsTensor(fg::MetaDiGraph, v::Int) pc = new() outgoing = outneighbors(fg, v) incoming = inneighbors(fg, v) - - + for u ∈ outgoing e = SimpleEdge(v, u) - println(e) - println(get_prop(fg, e, :orientation)) if get_prop(fg, e, :orientation) == "horizontal" - println("Setting right") pc.right = last(get_prop(fg, e, :decomposition)) else - println("Setting down") pc.down = last(get_prop(fg, e, :decomposition)) end end for u ∈ incoming e = SimpleEdge(u, v) - println(e) - println(get_prop(fg, e, :orientation)) if get_prop(fg, e, :orientation) == "horizontal" - println("Setting left") pc.left = first(get_prop(fg, e, :decomposition)) else - println("Setting up") pc.up = first(get_prop(fg, e, :decomposition)) end end # open boundary conditions if !isdefined(pc, :left) - println("left was undefined") pc.left = ones(1, size(pc.right, 1)) end if !isdefined(pc, :right) - println("right was undefined") pc.right = ones(size(pc.left, 2), 1) end if !isdefined(pc, :up) - println("up was undefined") pc.up = ones(1, size(pc.down, 1)) end if !isdefined(pc, :down) - println("down was undefined") pc.down = ones(size(pc.up, 2), 1) end + + #@infiltrate println(v) println(size(pc.left)) println(size(pc.right)) println(size(pc.up)) println(size(pc.down)) - @cast pc.tensor[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] pc diff --git a/src/SpinGlassPEPS.jl b/src/SpinGlassPEPS.jl index a99cde77..3ea86bf5 100644 --- a/src/SpinGlassPEPS.jl +++ b/src/SpinGlassPEPS.jl @@ -6,7 +6,7 @@ module SpinGlassPEPS using LightGraphs using MetaGraphs using CSV - using Debugger + using Infiltrator using DocStringExtensions const product = Iterators.product diff --git a/src/graph.jl b/src/graph.jl index 7f18be75..e8a5ba1d 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -55,7 +55,7 @@ mutable struct Edge edges::EdgeIter J::Matrix{<:Number} - function Edge(ig::MetaDiGraph, v::Cluster, w::Cluster) + function Edge(ig::MetaGraph, v::Cluster, w::Cluster) ed = new((v.tag, w.tag)) ed.edges = filter_edges(ig, v, w) @@ -128,8 +128,11 @@ function decompose_edges!(fg::MetaDiGraph, order=:PE, beta::Float64=1.0) set_prop!(fg, :tensorsOrder, order) for edge ∈ edges(fg) - energies = get_prop(fg, edge, :energy) - en, p = rank_reveal(energies) + energy = get_prop(fg, edge, :energy) + en, p = rank_reveal(energy) + + println(edge) + println(size(energy), size(en), " ", size(p)) if order == :PE dec = (p, exp.(-beta .* en)) diff --git a/test/PEPS.jl b/test/PEPS.jl index 01787d5f..1b8e7328 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -11,7 +11,6 @@ cg = Chimera((m, n, t), ig) fg = factor_graph(cg) decompose_edges!(fg) - peps = PepsTensor(fg, 5) end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index f6d8d836..9a7b6a08 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -37,12 +37,13 @@ push!(my_tests, #"ising.jl", #"spectrum.jl", #"graph.jl", - #"PEPS.jl" - "notation_tests.jl", - "peps_tests.jl", - "mps_tests.jl", - "tests_full_graph.jl", - "tests_on_data.jl" + "PEPS.jl" + #"notation_tests.jl", + # do NOT pass: + #"peps_tests.jl", + #"mps_tests.jl", + #"tests_full_graph.jl", + #"tests_on_data.jl" ) for my_test in my_tests From ab52013799380a490ee853cbc67846728dbff8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Sat, 19 Dec 2020 21:00:47 +0100 Subject: [PATCH 040/137] add local energy --- src/PEPS.jl | 6 +++++- src/graph.jl | 16 +++++++++------- src/spectrum.jl | 32 +++++++++----------------------- test/PEPS.jl | 3 ++- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 4f3136da..36ca9f2e 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -5,10 +5,13 @@ mutable struct PepsTensor right::AbstractArray up::AbstractArray down::AbstractArray + loc::AbstractArray tensor::AbstractArray function PepsTensor(fg::MetaDiGraph, v::Int) pc = new() + pc.loc = get_prop(fg, v, :local_exp) + outgoing = outneighbors(fg, v) incoming = inneighbors(fg, v) @@ -53,7 +56,8 @@ mutable struct PepsTensor println(size(pc.right)) println(size(pc.up)) println(size(pc.down)) - @cast pc.tensor[l, r, u, d, σ] |= pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] + + @cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] pc end diff --git a/src/graph.jl b/src/graph.jl index e8a5ba1d..e6c03213 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -100,7 +100,7 @@ end function factor_graph( g::Model, energy::Function=energy, - spectrum::Function=brute_force, + spectrum::Function=full_spectrum, cluster::Function=unit_cell, ) m, n, _ = g.size @@ -124,23 +124,25 @@ function factor_graph( end -function decompose_edges!(fg::MetaDiGraph, order=:PE, beta::Float64=1.0) +function decompose_edges!(fg::MetaDiGraph, order=:PE, β::Float64=1.0) set_prop!(fg, :tensorsOrder, order) for edge ∈ edges(fg) energy = get_prop(fg, edge, :energy) en, p = rank_reveal(energy) - println(edge) - println(size(energy), size(en), " ", size(p)) - if order == :PE - dec = (p, exp.(-beta .* en)) + dec = (p, exp.(-β .* en)) else - dec = (exp.(-beta .* en), p) + dec = (exp.(-β .* en), p) end set_prop!(fg, edge, :decomposition, dec) end + + for v ∈ vertices(fg) + en = get_prop(fg, v, :spectrum).energies + set_prop!(fg, v, :local_exp, exp.(-β .* en)) + end end diff --git a/src/spectrum.jl b/src/spectrum.jl index cf1da530..e17c2518 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -1,4 +1,4 @@ -export brute_force +export full_spectrum, brute_force export MPS_from_gates, unique_neighbors export MPSControl export spectrum @@ -16,15 +16,6 @@ struct MPSControl β::Vector end - -#Spectrum(cl::Cluster) = brute_force(cl, num_states=256) -function Spectrum(cl::Cluster) - σ = collect.(all_states(cl.rank)) - energies = energy.(σ, Ref(cl)) - Spectrum(energies, σ) -end - - # ρ needs to be in the right canonical form function spectrum(ψ::MPS, keep::Int) @assert keep > 0 "Number of states has to be > 0" @@ -252,18 +243,13 @@ end function brute_force(cl::Cluster; num_states::Int=1) σ = collect.(all_states(cl.rank)) - states = reshape(σ, prod(cl.rank)) - energies = energy.(states, Ref(cl)) - perm = partialsortperm(energies, 1:num_states) - Spectrum(energies[perm], states[perm]) + energies = energy.(σ, Ref(cl)) + perm = partialsortperm(vec(energies), 1:num_states) + Spectrum(energies[perm], σ[perm]) end -_ising(σ::State) = 2 .* σ .- 1 - -function _brute_force(ig::MetaGraph, k::Int=1) - L = nv(ig) - states = _ising.(digits.(0:2^L-1, base=2, pad=L)) - energies = energy.(states, Ref(ig)) - perm = partialsortperm(energies, 1:k) - states[perm], energies[perm] -end +function full_spectrum(cl::Cluster) + σ = collect.(all_states(cl.rank)) + energies = energy.(σ, Ref(cl)) + Spectrum(energies, σ) +end diff --git a/test/PEPS.jl b/test/PEPS.jl index 1b8e7328..73bce019 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -11,6 +11,7 @@ cg = Chimera((m, n, t), ig) fg = factor_graph(cg) decompose_edges!(fg) -peps = PepsTensor(fg, 5) + +#peps = PepsTensor(fg, 6) end \ No newline at end of file From 9376c01e025dcba123971c6d14dab3b8651524c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sat, 19 Dec 2020 22:39:27 +0100 Subject: [PATCH 041/137] add inline --- src/base.jl | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/base.jl b/src/base.jl index 3da95f72..e56e767f 100644 --- a/src/base.jl +++ b/src/base.jl @@ -17,33 +17,33 @@ for (T, N) in ((:MPO, 4), (:MPS, 3)) $T(::Type{T}, L::Int) where {T} = $T(Vector{Array{T, $N}}(undef, L)) $T(L::Int) = $T(Float64, L) - Base.setindex!(a::$AT, A::AbstractArray{<:Number, $N}, i::Int) = a.tensors[i] = A - bond_dimension(a::$AT) = maximum(size.(a.tensors, $N)) + @inline Base.setindex!(a::$AT, A::AbstractArray{<:Number, $N}, i::Int) = a.tensors[i] = A + @inline bond_dimension(a::$AT) = maximum(size.(a.tensors, $N)) Base.copy(a::$T) = $T(copy(a.tensors)) - Base.eltype(::$AT{T}) where {T} = T + @inline Base.eltype(::$AT{T}) where {T} = T end end const AbstractMPSorMPO = Union{AbstractMPS, AbstractMPO} const MPSorMPO = Union{MPS, MPO} -Base.:(==)(a::AbstractMPSorMPO, b::AbstractMPSorMPO) = a.tensors == b.tensors -Base.:(≈)(a::AbstractMPSorMPO, b::AbstractMPSorMPO) = a.tensors ≈ b.tensors +@inline Base.:(==)(a::AbstractMPSorMPO, b::AbstractMPSorMPO) = a.tensors == b.tensors +@inline Base.:(≈)(a::AbstractMPSorMPO, b::AbstractMPSorMPO) = a.tensors ≈ b.tensors -Base.getindex(a::AbstractMPSorMPO, i) = getindex(a.tensors, i) -Base.iterate(a::AbstractMPSorMPO) = iterate(a.tensors) -Base.iterate(a::AbstractMPSorMPO, state) = iterate(a.tensors, state) -Base.lastindex(a::AbstractMPSorMPO) = lastindex(a.tensors) -Base.length(a::AbstractMPSorMPO) = length(a.tensors) -Base.size(a::AbstractMPSorMPO) = (length(a.tensors), ) +@inline Base.getindex(a::AbstractMPSorMPO, i) = getindex(a.tensors, i) +@inline Base.iterate(a::AbstractMPSorMPO) = iterate(a.tensors) +@inline Base.iterate(a::AbstractMPSorMPO, state) = iterate(a.tensors, state) +@inline Base.lastindex(a::AbstractMPSorMPO) = lastindex(a.tensors) +@inline Base.length(a::AbstractMPSorMPO) = length(a.tensors) +@inline Base.size(a::AbstractMPSorMPO) = (length(a.tensors), ) -LinearAlgebra.rank(ψ::MPS) = Tuple(size(A, 2) for A ∈ ψ) +@inline LinearAlgebra.rank(ψ::MPS) = Tuple(size(A, 2) for A ∈ ψ) -MPS(A::AbstractArray) = MPS(A, :right) -MPS(A::AbstractArray, s::Symbol, args...) = MPS(A, Val(s), typemax(Int), args...) -MPS(A::AbstractArray, s::Symbol, Dcut::Int, args...) = MPS(A, Val(s), Dcut, args...) -MPS(A::AbstractArray, ::Val{:right}, Dcut::Int, args...) = _left_sweep_SVD(A, Dcut, args...) -MPS(A::AbstractArray, ::Val{:left}, Dcut::Int, args...) = _right_sweep_SVD(A, Dcut, args...) +@inline MPS(A::AbstractArray) = MPS(A, :right) +@inline MPS(A::AbstractArray, s::Symbol, args...) = MPS(A, Val(s), typemax(Int), args...) +@inline MPS(A::AbstractArray, s::Symbol, Dcut::Int, args...) = MPS(A, Val(s), Dcut, args...) +@inline MPS(A::AbstractArray, ::Val{:right}, Dcut::Int, args...) = _left_sweep_SVD(A, Dcut, args...) +@inline MPS(A::AbstractArray, ::Val{:left}, Dcut::Int, args...) = _right_sweep_SVD(A, Dcut, args...) function _right_sweep_SVD(Θ::AbstractArray{T}, Dcut::Int=typemax(Int), args...) where {T} rank = ndims(Θ) From 25a690b17443e63dbbb32a1b81c77dd2490b543d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sat, 19 Dec 2020 22:39:35 +0100 Subject: [PATCH 042/137] add unique rows --- src/utils.jl | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index a87d2288..feeed4aa 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -3,6 +3,9 @@ export HadamardMPS, rq export all_states, local_basis export enum +using Base.Cartesian +import Base.Prehashed + idx(σ::Int) = (σ == -1) ? 1 : σ + 1 _σ(idx::Int) = (idx == 1) ? -1 : idx - 1 @@ -63,3 +66,73 @@ function LinearAlgebra.svd(A::AbstractMatrix, Dcut::Int, args...) ph = d ./ abs.(d) return U * Diagonal(ph), Σ, V * Diagonal(ph) end + +@generated function _unique_dims(A::AbstractArray{T,N}, dim::Integer) where {T,N} + quote + 1 <= dim <= $N || return copy(A) + hashes = zeros(UInt, axes(A, dim)) + + # Compute hash for each row + k = 0 + @nloops $N i A d->(if d == dim; k = i_d; end) begin + @inbounds hashes[k] = hash(hashes[k], hash((@nref $N A i))) + end + + # Collect index of first row for each hash + uniquerow = similar(Array{Int}, axes(A, dim)) + firstrow = Dict{Prehashed,Int}() + for k = axes(A, dim) + uniquerow[k] = get!(firstrow, Prehashed(hashes[k]), k) + end + uniquerows = collect(values(firstrow)) + + # Check for collisions + collided = falses(axes(A, dim)) + @inbounds begin + @nloops $N i A d->(if d == dim + k = i_d + j_d = uniquerow[k] + else + j_d = i_d + end) begin + if (@nref $N A j) != (@nref $N A i) + collided[k] = true + end + end + end + + if any(collided) + nowcollided = similar(BitArray, axes(A, dim)) + while any(collided) + # Collect index of first row for each collided hash + empty!(firstrow) + for j = axes(A, dim) + collided[j] || continue + uniquerow[j] = get!(firstrow, Prehashed(hashes[j]), j) + end + for v in values(firstrow) + push!(uniquerows, v) + end + + # Check for collisions + fill!(nowcollided, false) + @nloops $N i A d->begin + if d == dim + k = i_d + j_d = uniquerow[k] + (!collided[k] || j_d == k) && continue + else + j_d = i_d + end + end begin + if (@nref $N A j) != (@nref $N A i) + nowcollided[k] = true + end + end + (collided, nowcollided) = (nowcollided, collided) + end + end + + (@nref $N A d->d == dim ? sort!(uniquerows) : (axes(A, d))) + end +end \ No newline at end of file From 903052e3ad72afcdc2749725efb1a3768cf740e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sat, 19 Dec 2020 22:39:43 +0100 Subject: [PATCH 043/137] refactor graph --- src/graph.jl | 57 +++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index e8a5ba1d..c7e4b99a 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -23,7 +23,7 @@ mutable struct Cluster for e ∈ cl.edges i = cl.vertices[src(e)] j = cl.vertices[dst(e)] - cl.J[i, j] = get_prop(ig, e, :J) + @inbounds cl.J[i, j] = get_prop(ig, e, :J) end rank = get_prop(ig, :rank) @@ -31,27 +31,23 @@ mutable struct Cluster cl.h = zeros(L) for (w, i) ∈ cl.vertices - cl.h[i] = get_prop(ig, w, :h) - cl.rank[i] = rank[w] + @inbounds cl.h[i] = get_prop(ig, w, :h) + @inbounds cl.rank[i] = rank[w] end cl end end function MetaGraphs.filter_edges(ig::MetaGraph, v::Cluster, w::Cluster) - edges = [] - for i ∈ keys(v.vertices) - for j ∈ unique_neighbors(ig, i) - if j ∈ keys(w.vertices) - push!(edges, SimpleEdge(i, j)) - end - end + edges = SimpleEdge[] + for i ∈ keys(v.vertices), j ∈ unique_neighbors(ig, i) + if j ∈ keys(w.vertices) push!(edges, SimpleEdge(i, j)) end end edges end mutable struct Edge - tag::NTuple + tag::NTuple{2, Int} edges::EdgeIter J::Matrix{<:Number} @@ -66,33 +62,32 @@ mutable struct Edge for e ∈ ed.edges i = v.vertices[src(e)] j = w.vertices[dst(e)] - ed.J[i, j] = get_prop(ig, e, :J) + @inbounds ed.J[i, j] = get_prop(ig, e, :J) end ed end end function factor_graph(m::Int, n::Int, hdir=:LR, vdir=:BT) + @assert hdir ∈ (:LR, :RL) + @assert vdir ∈ (:BT, :TB) + dg = MetaDiGraph(m * n) set_prop!(dg, :order, (hdir, vdir)) linear = LinearIndices((1:m, 1:n)) - for i ∈ 1:m - for j ∈ 1:n-1 - v, w = linear[i, j], linear[i, j+1] - hdir == :LR ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) - add_edge!(dg, e) - set_prop!(dg, e, :orientation, "horizontal") - end + for i ∈ 1:m, j ∈ 1:n-1 + v, w = linear[i, j], linear[i, j+1] + hdir == :LR ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) + add_edge!(dg, e) + set_prop!(dg, e, :orientation, "horizontal") end - for i ∈ 1:n - for j ∈ 1:m-1 - v, w = linear[j, i], linear[j+1, i] - vdir == :BT ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) - add_edge!(dg, e) - set_prop!(dg, e, :orientation, "vertical") - end + for i ∈ 1:n, j ∈ 1:m-1 + v, w = linear[j, i], linear[j+1, i] + vdir == :BT ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) + add_edge!(dg, e) + set_prop!(dg, e, :orientation, "vertical") end dg end @@ -125,15 +120,12 @@ end function decompose_edges!(fg::MetaDiGraph, order=:PE, beta::Float64=1.0) - set_prop!(fg, :tensorsOrder, order) + set_prop!(fg, :tensors_order, order) for edge ∈ edges(fg) energy = get_prop(fg, edge, :energy) en, p = rank_reveal(energy) - println(edge) - println(size(energy), size(en), " ", size(p)) - if order == :PE dec = (p, exp.(-beta .* en)) else @@ -144,14 +136,15 @@ function decompose_edges!(fg::MetaDiGraph, order=:PE, beta::Float64=1.0) end -function rank_reveal(energy, order=:PE) # or E_then_P +function rank_reveal(energy, order=:PE) + @assert order ∈ (:PE, :EP) dim = order == :PE ? 1 : 2 E = unique(energy, dims=dim) idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) P = order == :PE ? zeros(size(energy, 1), size(E, 1)) : zeros(size(E, 2), size(energy, 2)) - + for (i, elements) ∈ enumerate(eachslice(P, dims=dim)) elements[idx[i]] = 1 end From 4d39585bc750ca12c3f4642d9b89593f711f18e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sat, 19 Dec 2020 22:52:11 +0100 Subject: [PATCH 044/137] refactor graphs --- src/graphs/chimera.jl | 6 +++--- src/graphs/lattice.jl | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/graphs/chimera.jl b/src/graphs/chimera.jl index 23b4a3de..67480518 100644 --- a/src/graphs/chimera.jl +++ b/src/graphs/chimera.jl @@ -1,7 +1,7 @@ export Chimera export unit_cell -mutable struct Chimera <: Model +struct Chimera <: Model size::NTuple{3, Int} graph::MetaGraph @@ -48,12 +48,12 @@ function Chimera(m::Int, n::Int=m, t::Int=4) Chimera((m, n, t), g) end -function Base.getindex(c::Chimera, i::Int, j::Int, u::Int, k::Int) +@inline function Base.getindex(c::Chimera, i::Int, j::Int, u::Int, k::Int) _, n, t = size(c) t * (2 * (n * (i - 1) + j - 1) + u - 1) + k end -function Base.getindex(c::Chimera, i::Int, j::Int) +@inline function Base.getindex(c::Chimera, i::Int, j::Int) t = size(c, 3) idx = vec([c[i, j, u, k] for u=1:2, k=1:t]) c.graph[idx] diff --git a/src/graphs/lattice.jl b/src/graphs/lattice.jl index a9e956eb..354bb7de 100644 --- a/src/graphs/lattice.jl +++ b/src/graphs/lattice.jl @@ -1,19 +1,18 @@ export Lattice export unit_cell -mutable struct Lattice <: Model +struct Lattice <: Model size::NTuple{2, Int} graph::MetaGraph function Lattice(m::Int, n::Int) - lt = new() - lt.size = (m, n) + lt = new((m, n)) lt.graph = MetaGraph(grid([m, n])) lt end end -function Base.getindex(l::Lattice, i::Int, j::Int) +@inline function Base.getindex(l::Lattice, i::Int, j::Int) m, n = size(l) LinearIndices((1:m, 1:n))[i, j] end From 3fced477a2cb76af31c70b3ec43b93c23a382599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sat, 19 Dec 2020 23:08:20 +0100 Subject: [PATCH 045/137] spectrum->solve --- src/spectrum.jl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/spectrum.jl b/src/spectrum.jl index cf1da530..7445f294 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -1,8 +1,7 @@ export brute_force -export MPS_from_gates, unique_neighbors +export unique_neighbors export MPSControl -export spectrum -export spectrum_new +export solve, solve_new struct Spectrum energies::Array{<:Number} @@ -26,7 +25,7 @@ end # ρ needs to be in the right canonical form -function spectrum(ψ::MPS, keep::Int) +function solve(ψ::MPS, keep::Int) @assert keep > 0 "Number of states has to be > 0" T = eltype(ψ) @@ -79,7 +78,7 @@ function spectrum(ψ::MPS, keep::Int) end # ρ needs to be in the right canonical form -function spectrum_new(ψ::MPS, keep::Int) +function solve_new(ψ::MPS, keep::Int) @assert keep > 0 "Number of states has to be > 0" T = eltype(ψ) From 28b686b43ac91a4ceb8ad89667683131cc54deb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sat, 19 Dec 2020 23:08:33 +0100 Subject: [PATCH 046/137] set energy array type --- src/ising.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ising.jl b/src/ising.jl index fcceb93d..66224df1 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -50,7 +50,7 @@ function energy(fg::MetaDiGraph, edge::Edge) vSp = get_prop(fg, v, :spectrum).states wSp = get_prop(fg, w, :spectrum).states - [ energy.(vec(vSp), Ref(edge.J), Ref(η)) for η ∈ vec(wSp)] + Vector{Float64}[energy.(vec(vSp), Ref(edge.J), Ref(η)) for η ∈ vec(wSp)] end """ From 86e0edea85f8a7e874bd4f3705b37079b7847ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sat, 19 Dec 2020 23:08:42 +0100 Subject: [PATCH 047/137] spectrum->solve --- test/spectrum.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spectrum.jl b/test/spectrum.jl index 8960dc5f..7444ab02 100644 --- a/test/spectrum.jl +++ b/test/spectrum.jl @@ -141,7 +141,7 @@ end @info "Verifying low energy spectrum" max_states @info "Testing spectrum" - states, prob, pCut = spectrum(rψ, max_states) + states, prob, pCut = solve(rψ, max_states) sp = brute_force(ig, num_states = max_states) @info "The largest discarded probability" pCut @@ -155,7 +155,7 @@ end end @info "Testing spectrum_new" - states_new, prob_new, pCut_new = spectrum_new(rψ, max_states) + states_new, prob_new, pCut_new = solve_new(rψ, max_states) eng_new = zeros(length(prob_new)) for (j, p) ∈ enumerate(prob_new) From 84ef85b48ce9f1f121ffe1c699ff242f634d7db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sat, 19 Dec 2020 23:08:47 +0100 Subject: [PATCH 048/137] enable tests --- test/runtests.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 9a7b6a08..f5f07c71 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,7 +22,7 @@ function reshape_row(A::AbstractArray{T}, dims::Tuple) where {T <: Number} end my_tests = [] -if CUDA.functional() && CUDA.has_cutensor() +if CUDA.functional() && CUDA.has_cutensor() && false push!(my_tests, "cuda/base.jl", "cuda/contractions.jl", @@ -31,13 +31,13 @@ if CUDA.functional() && CUDA.has_cutensor() end push!(my_tests, - #"base.jl", - #"contractions.jl", - #"compressions.jl", - #"ising.jl", - #"spectrum.jl", - #"graph.jl", - "PEPS.jl" + "base.jl", + "contractions.jl", + "compressions.jl", + "ising.jl", + "spectrum.jl", + "graph.jl", + # "PEPS.jl" #"notation_tests.jl", # do NOT pass: #"peps_tests.jl", From 3dd739a8062d993e86848b35ef7b41915f005628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sun, 20 Dec 2020 12:17:23 +0100 Subject: [PATCH 049/137] return do coveralls --- .github/workflows/CI.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7cbf2f48..791ca71a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -27,6 +27,9 @@ jobs: env: JULIA_NUM_THREADS: 4 - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v1 + # - uses: codecov/codecov-action@v1 + # with: + # file: lcov.info + - uses: coverallsapp/github-action@master with: - file: lcov.info \ No newline at end of file + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 872b6f0588ba1181323512c4faf09f7c0e3cb67e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Sun, 20 Dec 2020 12:27:23 +0100 Subject: [PATCH 050/137] fix lcov path --- .github/workflows/CI.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 791ca71a..777dc982 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -32,4 +32,5 @@ jobs: # file: lcov.info - uses: coverallsapp/github-action@master with: - github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: lcov.info \ No newline at end of file From 86109ab27a76ef578a294257f4dc9308ef1069c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Sun, 20 Dec 2020 18:41:07 +0100 Subject: [PATCH 051/137] add Dict enumerating nbrs --- src/PEPS.jl | 6 ++++++ src/graph.jl | 2 +- test/PEPS.jl | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 36ca9f2e..c329c07d 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,6 +1,7 @@ export PepsTensor mutable struct PepsTensor + nbrs::Dict{String, Int} left::AbstractArray right::AbstractArray up::AbstractArray @@ -10,6 +11,7 @@ mutable struct PepsTensor function PepsTensor(fg::MetaDiGraph, v::Int) pc = new() + pc.nbrs = Dict() pc.loc = get_prop(fg, v, :local_exp) outgoing = outneighbors(fg, v) @@ -19,8 +21,10 @@ mutable struct PepsTensor e = SimpleEdge(v, u) if get_prop(fg, e, :orientation) == "horizontal" pc.right = last(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "r" => u) else pc.down = last(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "d" => u) end end @@ -28,8 +32,10 @@ mutable struct PepsTensor e = SimpleEdge(u, v) if get_prop(fg, e, :orientation) == "horizontal" pc.left = first(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "l" => u) else pc.up = first(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "u" => u) end end diff --git a/src/graph.jl b/src/graph.jl index e6c03213..522e8e04 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -129,7 +129,7 @@ function decompose_edges!(fg::MetaDiGraph, order=:PE, β::Float64=1.0) for edge ∈ edges(fg) energy = get_prop(fg, edge, :energy) - en, p = rank_reveal(energy) + en, p = rank_reveal(energy, order) if order == :PE dec = (p, exp.(-β .* en)) diff --git a/test/PEPS.jl b/test/PEPS.jl index 73bce019..d25d04a7 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -12,6 +12,6 @@ cg = Chimera((m, n, t), ig) fg = factor_graph(cg) decompose_edges!(fg) -#peps = PepsTensor(fg, 6) +peps = PepsTensor(fg, 6) end \ No newline at end of file From ef4f06be7bac5c5322111ba17af9fc267677fec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 21 Dec 2020 11:39:33 +0100 Subject: [PATCH 052/137] add more test --- src/PEPS.jl | 1 + src/graph.jl | 4 ++-- src/ising.jl | 9 ++++++++- test/PEPS.jl | 27 ++++++++++++++++++++++++--- test/runtests.jl | 14 +++++++------- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index c329c07d..a8c37930 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -58,6 +58,7 @@ mutable struct PepsTensor #@infiltrate println(v) + println(pc.nbrs) println(size(pc.left)) println(size(pc.right)) println(size(pc.up)) diff --git a/src/graph.jl b/src/graph.jl index a09afd58..ccfadf7f 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -118,13 +118,13 @@ function factor_graph( fg end -function decompose_edges!(fg::MetaDiGraph, order=:PE, beta::Float64=1.0) +function decompose_edges!(fg::MetaDiGraph, order=:PE, β::Float64=1.0) set_prop!(fg, :tensors_order, order) for edge ∈ edges(fg) energy = get_prop(fg, edge, :energy) en, p = rank_reveal(energy, order) - + if order == :PE dec = (p, exp.(-β .* en)) else diff --git a/src/ising.jl b/src/ising.jl index 66224df1..fb2f2d59 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -50,7 +50,14 @@ function energy(fg::MetaDiGraph, edge::Edge) vSp = get_prop(fg, v, :spectrum).states wSp = get_prop(fg, w, :spectrum).states - Vector{Float64}[energy.(vec(vSp), Ref(edge.J), Ref(η)) for η ∈ vec(wSp)] + m = prod(size(vSp)) + n = prod(size(wSp)) + + en = zeros(m, n) + for (j, η) ∈ enumerate(wSp) + en[:, j] = energy.(vec(vSp), Ref(edge.J), Ref(η)) + end + en end """ diff --git a/test/PEPS.jl b/test/PEPS.jl index d25d04a7..ecc906b5 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -8,10 +8,31 @@ instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" ig = ising_graph(instance, L) cg = Chimera((m, n, t), ig) - fg = factor_graph(cg) -decompose_edges!(fg) -peps = PepsTensor(fg, 6) +order = :PE +decompose_edges!(fg, order) + +@testset "decompose_edges! workds correctly" begin + order = get_prop(fg, :tensors_order) + println("order ->", order) + + for e ∈ edges(fg) + dec = get_prop(fg, e, :decomposition) + en = get_prop(fg, e, :energy) + + println(size(en)) + println(size(first(dec)), size(last(dec))) + + if order == :PE + @test en ≈ prod(dec) + else + @test en ≈ prod(reverse(dec)) + end + break + end +end + +#peps = PepsTensor(fg, 6) end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index f5f07c71..b14f9a9c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,13 +31,13 @@ if CUDA.functional() && CUDA.has_cutensor() && false end push!(my_tests, - "base.jl", - "contractions.jl", - "compressions.jl", - "ising.jl", - "spectrum.jl", - "graph.jl", - # "PEPS.jl" + #"base.jl", + #"contractions.jl", + #"compressions.jl", + #"ising.jl", + #"spectrum.jl", + #"graph.jl", + "PEPS.jl" #"notation_tests.jl", # do NOT pass: #"peps_tests.jl", From 4f34bcddc0a6eed4932f2c35808d7dc52fa2c14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 21 Dec 2020 12:28:16 +0100 Subject: [PATCH 053/137] fix bug in rank_reveal --- src/graph.jl | 5 +++-- src/ising.jl | 2 +- test/PEPS.jl | 15 +++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index ccfadf7f..565b9c06 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -118,16 +118,17 @@ function factor_graph( fg end -function decompose_edges!(fg::MetaDiGraph, order=:PE, β::Float64=1.0) +function decompose_edges!(fg::MetaDiGraph, order=:PE; β::Float64=1.0) set_prop!(fg, :tensors_order, order) for edge ∈ edges(fg) energy = get_prop(fg, edge, :energy) - en, p = rank_reveal(energy, order) if order == :PE + p, en = rank_reveal(energy, order) dec = (p, exp.(-β .* en)) else + en, p = rank_reveal(energy, order) dec = (exp.(-β .* en), p) end set_prop!(fg, edge, :decomposition, dec) diff --git a/src/ising.jl b/src/ising.jl index fb2f2d59..7f504001 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -69,7 +69,7 @@ Create the Ising spin glass model. Store extra information """ -function ising_graph(instance::Instance, L::Int, β::Number=1, sgn::Number=-1) +function ising_graph(instance::Instance, L::Int, β::Number=1.0, sgn::Number=-1.0) # load the Ising instance if typeof(instance) == String diff --git a/test/PEPS.jl b/test/PEPS.jl index ecc906b5..4e126e3b 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -8,26 +8,25 @@ instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" ig = ising_graph(instance, L) cg = Chimera((m, n, t), ig) -fg = factor_graph(cg) + +β = get_prop(ig, :β) order = :PE -decompose_edges!(fg, order) +fg = factor_graph(cg) +decompose_edges!(fg, order, β=β) @testset "decompose_edges! workds correctly" begin order = get_prop(fg, :tensors_order) - println("order ->", order) for e ∈ edges(fg) dec = get_prop(fg, e, :decomposition) en = get_prop(fg, e, :energy) - println(size(en)) - println(size(first(dec)), size(last(dec))) - + ρ = exp.(-β .* en) if order == :PE - @test en ≈ prod(dec) + @test ρ ≈ prod(dec) else - @test en ≈ prod(reverse(dec)) + @test ρ ≈ prod(reverse(dec)) end break end From c2649744ac9a72d23fda2e619d7ec77a99f2b66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 21 Dec 2020 14:30:01 +0100 Subject: [PATCH 054/137] fix bugs in PEPS --- src/PEPS.jl | 17 +++++++++-------- src/graph.jl | 2 +- test/PEPS.jl | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index a8c37930..941e6b48 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -20,22 +20,22 @@ mutable struct PepsTensor for u ∈ outgoing e = SimpleEdge(v, u) if get_prop(fg, e, :orientation) == "horizontal" - pc.right = last(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "r" => u) - else - pc.down = last(get_prop(fg, e, :decomposition)) + pc.down = first(get_prop(fg, e, :decomposition)) push!(pc.nbrs, "d" => u) + else + pc.right = first(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "r" => u) end end for u ∈ incoming e = SimpleEdge(u, v) if get_prop(fg, e, :orientation) == "horizontal" - pc.left = first(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "l" => u) - else - pc.up = first(get_prop(fg, e, :decomposition)) + pc.up = last(get_prop(fg, e, :decomposition)) push!(pc.nbrs, "u" => u) + else + pc.left = last(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "l" => u) end end @@ -59,6 +59,7 @@ mutable struct PepsTensor #@infiltrate println(v) println(pc.nbrs) + println(size(pc.loc)) println(size(pc.left)) println(size(pc.right)) println(size(pc.up)) diff --git a/src/graph.jl b/src/graph.jl index 565b9c06..8291ea9f 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -136,7 +136,7 @@ function decompose_edges!(fg::MetaDiGraph, order=:PE; β::Float64=1.0) for v ∈ vertices(fg) en = get_prop(fg, v, :spectrum).energies - set_prop!(fg, v, :local_exp, exp.(-β .* en)) + set_prop!(fg, v, :local_exp, vec(exp.(-β .* en))) end end diff --git a/test/PEPS.jl b/test/PEPS.jl index 4e126e3b..3b5f3354 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -32,6 +32,6 @@ decompose_edges!(fg, order, β=β) end end -#peps = PepsTensor(fg, 6) +peps = PepsTensor(fg, 6) end \ No newline at end of file From 930585ffff10ce804dd34569b0c8939c038d865d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 21 Dec 2020 16:44:45 +0100 Subject: [PATCH 055/137] add PEPS tests --- src/PEPS.jl | 9 --------- src/graph.jl | 8 +++++--- src/spectrum.jl | 2 +- test/PEPS.jl | 42 +++++++++++++++++++++++------------------- test/spectrum.jl | 3 ++- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 941e6b48..0c058e92 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -56,15 +56,6 @@ mutable struct PepsTensor pc.down = ones(size(pc.up, 2), 1) end - #@infiltrate - println(v) - println(pc.nbrs) - println(size(pc.loc)) - println(size(pc.left)) - println(size(pc.right)) - println(size(pc.up)) - println(size(pc.down)) - @cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] pc diff --git a/src/graph.jl b/src/graph.jl index 8291ea9f..0881745a 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -68,7 +68,7 @@ mutable struct Edge end end -function factor_graph(m::Int, n::Int, hdir=:LR, vdir=:BT) +function factor_graph(m::Int, n::Int, hdir::Symbol=:LR, vdir::Symbol=:BT) @assert hdir ∈ (:LR, :RL) @assert vdir ∈ (:BT, :TB) @@ -96,10 +96,12 @@ function factor_graph( g::Model, energy::Function=energy, spectrum::Function=full_spectrum, - cluster::Function=unit_cell, + cluster::Function=unit_cell; + hdir::Symbol=:LR, + vdir::Symbol=:BT, ) m, n, _ = g.size - fg = factor_graph(m, n) + fg = factor_graph(m, n, hdir, vdir) for v ∈ vertices(fg) cl = cluster(g, v) diff --git a/src/spectrum.jl b/src/spectrum.jl index e52d65ac..0611a11a 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -204,7 +204,7 @@ function MPS(ig::MetaGraph, control::MPSControl) end for l ∈ _holes(nbrs) - _apply_nothing!(χ, l, i) + _apply_nothing!(ρ, l, i) end end diff --git a/test/PEPS.jl b/test/PEPS.jl index 3b5f3354..3e591fd0 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -11,27 +11,31 @@ cg = Chimera((m, n, t), ig) β = get_prop(ig, :β) -order = :PE -fg = factor_graph(cg) -decompose_edges!(fg, order, β=β) - -@testset "decompose_edges! workds correctly" begin - order = get_prop(fg, :tensors_order) - - for e ∈ edges(fg) - dec = get_prop(fg, e, :decomposition) - en = get_prop(fg, e, :energy) - - ρ = exp.(-β .* en) - if order == :PE - @test ρ ≈ prod(dec) - else - @test ρ ≈ prod(reverse(dec)) +for order ∈ (:EP, :PE) + for hd ∈ (:LR, :RL), vd ∈ (:BT, :TB) + + @info "Testing factor graph" order hd vd + + fg = factor_graph(cg, hdir=hd, vdir=vd) + decompose_edges!(fg, order, β=β) + + @test order == get_prop(fg, :tensors_order) + @test (hd, vd) == get_prop(fg, :order) + + for e ∈ edges(fg) + dec = get_prop(fg, e, :decomposition) + en = get_prop(fg, e, :energy) + + @test exp.(-β .* en) ≈ prod(dec) + end + + @info "Testing PEPS" + + net = [] + for v ∈ vertices(fg) + push!(net, PepsTensor(fg, v)) end - break end end -peps = PepsTensor(fg, 6) - end \ No newline at end of file diff --git a/test/spectrum.jl b/test/spectrum.jl index 7444ab02..270c1e01 100644 --- a/test/spectrum.jl +++ b/test/spectrum.jl @@ -9,7 +9,8 @@ instance = "$(@__DIR__)/instances/$(N)_001.txt" ig = ising_graph(instance, N) set_prop!(ig, :β, 1.) #rand(Float64)) -r = [3, 2, 5, 4] +#r = [3, 2, 5, 4] +r = fill(2, N) set_prop!(ig, :rank, r) sgn = -1. From 05041b3df4b03261e8d98fb1b980a6a3c9a085a3 Mon Sep 17 00:00:00 2001 From: kdomino Date: Mon, 21 Dec 2020 17:11:56 +0100 Subject: [PATCH 056/137] some tests fixed --- src/mps_implementation.jl | 4 +- src/notation.jl | 2 +- src/spectrum.jl | 74 ++++++++++++++++++------------------ test/notation_tests.jl | 8 ++-- test/peps_tests.jl | 42 ++++++++++++++++---- test/test_helpers.jl | 67 ++++++++++++++++---------------- test/tests_grid_from_file.jl | 2 +- test/tests_on_chimera.jl | 2 +- 8 files changed, 115 insertions(+), 86 deletions(-) diff --git a/src/mps_implementation.jl b/src/mps_implementation.jl index 0120c61e..10e273a2 100644 --- a/src/mps_implementation.jl +++ b/src/mps_implementation.jl @@ -69,7 +69,7 @@ function add_MPO!(mpo::AbstractMPO{T}, vec_edges::VE, g::MetaGraph, β::T) where for e in vec_edges j = dst(e) # minus for convention 1/2 since each is taken doubled in the product - J = -1/2*props(g, e)[:J] + J = 1/2*props(g, e)[:J] # minus for probability mpo[j] = Ctensor(T, -J*β, d, j==l) end @@ -81,7 +81,7 @@ function add_phase!(mps::AbstractMPS{T}, g::MetaGraph, β::T) where T<: Real for i in 1:length(mps) internal_e = props(g, i)[:energy] for j in 1:length(internal_e) - mps[i][:,j,:] = mps[i][:,j,:]*exp(-β/2*internal_e[j]) + mps[i][:,j,:] = mps[i][:,j,:]*exp(β/2*internal_e[j]) end end end diff --git a/src/notation.jl b/src/notation.jl index 8c78946a..035b5dc4 100644 --- a/src/notation.jl +++ b/src/notation.jl @@ -418,7 +418,7 @@ function M_of_interaction(g::EE, g1::EE, ig::MetaGraph) σ_cluster = ind2spin(i, no_spins) for j in 1:2^subset_size σ = ind2spin(j, subset_size) - @inbounds energy[j,i] = -sum(J.*σ.*σ_cluster[spin_subset]) + @inbounds energy[j,i] = sum(J.*σ.*σ_cluster[spin_subset]) end end energy diff --git a/src/spectrum.jl b/src/spectrum.jl index cf1da530..b1359cf3 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -9,7 +9,7 @@ struct Spectrum states::Array{Vector{<:Number}} end -struct MPSControl +struct MPSControl max_bond::Int var_ϵ::Number max_sweeps::Int @@ -21,15 +21,15 @@ end function Spectrum(cl::Cluster) σ = collect.(all_states(cl.rank)) energies = energy.(σ, Ref(cl)) - Spectrum(energies, σ) + Spectrum(energies, σ) end # ρ needs to be in the right canonical form -function spectrum(ψ::MPS, keep::Int) +function spectrum(ψ::MPS, keep::Int) @assert keep > 0 "Number of states has to be > 0" T = eltype(ψ) - + keep_extra = keep pCut = prob = 0. k = 1 @@ -48,7 +48,7 @@ function spectrum(ψ::MPS, keep::Int) LL = zeros(T, b, b, k, d) config = zeros(Int, i, k, d) - for j ∈ 1:k + for j ∈ 1:k L = left_env[:, :, j] for σ ∈ local_basis(d) @@ -57,19 +57,19 @@ function spectrum(ψ::MPS, keep::Int) LL[:, :, j, m] = M[:, m, :]' * (L * M[:, m, :]) pdo[j, m] = tr(LL[:, :, j, m]) config[:, j, m] = vcat(states[:, j]..., σ) - end + end end perm = collect(1: k * d) k = min(k * d, keep_extra) if k >= keep_extra - partialsortperm!(perm, vec(pdo), 1:k, rev=true) + partialsortperm!(perm, vec(pdo), 1:k, rev=true) prob = vec(pdo)[perm] pCut < last(prob) ? pCut = last(prob) : () end - @cast A[α, β, (l, d)] |= LL[α, β, l, d] + @cast A[α, β, (l, d)] |= LL[α, β, l, d] left_env = A[:, :, perm] @cast B[α, (l, d)] |= config[α, l, d] @@ -79,10 +79,10 @@ function spectrum(ψ::MPS, keep::Int) end # ρ needs to be in the right canonical form -function spectrum_new(ψ::MPS, keep::Int) +function spectrum_new(ψ::MPS, keep::Int) @assert keep > 0 "Number of states has to be > 0" T = eltype(ψ) - + keep_extra = keep lpCut = -1000 k = 1 @@ -102,7 +102,7 @@ function spectrum_new(ψ::MPS, keep::Int) LL = zeros(T, b, k, d) config = zeros(Int, i, k, d) - for j ∈ 1:k + for j ∈ 1:k L = left_env[:, j] for σ ∈ local_basis(d) @@ -121,9 +121,9 @@ function spectrum_new(ψ::MPS, keep::Int) if k > keep_extra k = keep_extra - partialsortperm!(perm, vec(lpdo), 1:k, rev=true) + partialsortperm!(perm, vec(lpdo), 1:k, rev=true) lprob = vec(lpdo)[perm] - lpCut < last(lprob) ? lpCut = last(lprob) : () + lpCut < last(lprob) ? lpCut = last(lprob) : () end lprob = vec(lpdo)[perm] @@ -134,7 +134,7 @@ function spectrum_new(ψ::MPS, keep::Int) end states = states' states, lprob, lpCut -end +end function _apply_bias!(ψ::AbstractMPS, ig::MetaGraph, dβ::Number, i::Int) M = ψ[i] @@ -143,22 +143,22 @@ function _apply_bias!(ψ::AbstractMPS, ig::MetaGraph, dβ::Number, i::Int) h = get_prop(ig, i, :h) v = [exp(-0.5 * dβ * h * σ) for σ ∈ local_basis(d)] - @cast M[x, σ, y] = M[x, σ, y] * v[σ] + @cast M[x, σ, y] = M[x, σ, y] * v[σ] ψ[i] = M end function _apply_exponent!(ψ::AbstractMPS, ig::MetaGraph, dβ::Number, i::Int, j::Int, last::Int) M = ψ[j] D = I(ψ, i) - - J = get_prop(ig, i, j, :J) + + J = get_prop(ig, i, j, :J) C = [ exp(-0.5 * dβ * k * J * l) for k ∈ local_basis(ψ, i), l ∈ local_basis(ψ, j) ] if j == last - @cast M̃[(x, a), σ, b] := C[x, σ] * M[a, σ, b] + @cast M̃[(x, a), σ, b] := C[x, σ] * M[a, σ, b] else - @cast M̃[(x, a), σ, (y, b)] := C[x, σ] * D[x, y] * M[a, σ, b] - end + @cast M̃[(x, a), σ, (y, b)] := C[x, σ] * D[x, y] * M[a, σ, b] + end ψ[j] = M̃ end @@ -171,12 +171,12 @@ function _apply_projector!(ψ::AbstractMPS, i::Int) ψ[i] = M̃ end -function _apply_nothing!(ψ::AbstractMPS, l::Int, i::Int) - M = ψ[l] +function _apply_nothing!(ψ::AbstractMPS, l::Int, i::Int) + M = ψ[l] D = I(ψ, i) - @cast M̃[(x, a), σ, (y, b)] := D[x, y] * M[a, σ, b] - ψ[l] = M̃ + @cast M̃[(x, a), σ, (y, b)] := D[x, y] * M[a, σ, b] + ψ[l] = M̃ end _holes(nbrs::Vector) = setdiff(first(nbrs) : last(nbrs), nbrs) @@ -202,25 +202,25 @@ function MPS(ig::MetaGraph, control::MPSControl) @info "Sweeping through β and σ" schedule for dβ ∈ schedule, i ∈ 1:L - _apply_bias!(ρ, ig, dβ, i) + _apply_bias!(ρ, ig, dβ, i) is_right = false nbrs = unique_neighbors(ig, i) if !isempty(nbrs) _apply_projector!(ρ, i) - for j ∈ nbrs - _apply_exponent!(ρ, ig, dβ, i, j, last(nbrs)) + for j ∈ nbrs + _apply_exponent!(ρ, ig, dβ, i, j, last(nbrs)) end - for l ∈ _holes(nbrs) - _apply_nothing!(χ, l, i) + for l ∈ _holes(nbrs) + _apply_nothing!(χ, l, i) end end if bond_dimension(ρ) > Dcut @info "Compresing MPS" bond_dimension(ρ), Dcut - ρ = compress(ρ, Dcut, tol, max_sweeps) + ρ = compress(ρ, Dcut, tol, max_sweeps) is_right = true end end @@ -240,23 +240,23 @@ Return the low energy spectrum # Details -Calculates \$k\$ lowest energy states -together with the coresponding energies +Calculates \$k\$ lowest energy states +together with the coresponding energies of a classical Ising Hamiltonian """ function brute_force(ig::MetaGraph; num_states::Int=1) cl = Cluster(ig, 0, enum(vertices(ig)), edges(ig)) brute_force(cl, num_states=num_states) -end +end function brute_force(cl::Cluster; num_states::Int=1) σ = collect.(all_states(cl.rank)) states = reshape(σ, prod(cl.rank)) energies = energy.(states, Ref(cl)) - perm = partialsortperm(energies, 1:num_states) + perm = partialsortperm(energies, 1:num_states) Spectrum(energies[perm], states[perm]) -end +end _ising(σ::State) = 2 .* σ .- 1 @@ -264,6 +264,6 @@ function _brute_force(ig::MetaGraph, k::Int=1) L = nv(ig) states = _ising.(digits.(0:2^L-1, base=2, pad=L)) energies = energy.(states, Ref(ig)) - perm = partialsortperm(energies, 1:k) + perm = partialsortperm(energies, 1:k) states[perm], energies[perm] -end +end diff --git a/test/notation_tests.jl b/test/notation_tests.jl index 5151a359..97ededc7 100644 --- a/test/notation_tests.jl +++ b/test/notation_tests.jl @@ -141,8 +141,8 @@ end ig = M2graph(M) g1 = graph4peps(ig, (1,1)) - @test props(g1, 1,2)[:M] == [-2.0 2.0; 2.0 -2.0] - @test props(g1, 2,4)[:M] == [-2.0 2.0; 2.0 -2.0] + @test props(g1, 1,2)[:M] == [2.0 -2.0; -2.0 2.0] + @test props(g1, 2,4)[:M] == [2.0 -2.0; -2.0 2.0] @test props(g1, 1)[:energy] == [-1., 1.] @test props(g1, 2)[:energy] == [-1., 1.] @test props(g1, 1,2)[:inds] == [1] @@ -154,7 +154,7 @@ end M = props(g1, 1,2)[:M] @test size(M) == (4,16) - @test M[:,1] == [-4.0, 0.0, 0.0, 4.0] + @test M[:,1] == [4.0, 0.0, 0.0, -4.0] e = [-4.0, 2.0, 2.0, 0.0, 2.0, 0.0, 8.0, -2.0, 2.0, 8.0, 0.0, -2.0, 0.0, -2.0, -2.0, -12.0] @test props(g1, 1)[:energy] == -e @test props(g1, 1,2)[:inds] == [3, 4] @@ -181,7 +181,7 @@ end @test get_Js(v2, v1, ig) == [2.0, 2.0] M = M_of_interaction(v2, v1, ig) @test size(M) == (4, 16) - @test M[:,1] == [-4.0, 0.0, 0.0, 4.0] + @test M[:,1] == [4.0, 0.0, 0.0, -4.0] end @testset "operations on spins" begin diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 59272c0c..28b06133 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -4,7 +4,7 @@ import SpinGlassPEPS: compute_single_tensor, conditional_probabs, get_parameters import SpinGlassPEPS: make_lower_mps import SpinGlassPEPS: set_spin_from_letf, spin_index_from_left, spin_indices_from_above import SpinGlassPEPS: energy, solve - +if true @testset "PEPS - axiliary functions" begin @testset "partial solution type" begin @@ -138,11 +138,37 @@ Mq[6,9] = Mq[9,6] = -0.52 Mq[7,8] = Mq[8,7] = 0.5 Mq[8,9] = Mq[9,8] = -0.05 +f = -1. +f1 = -1. + +Mq1 = zeros(9,9) +Mq1[1,1] = f*1.0 +Mq1[2,2] = 1.4*f +Mq1[3,3] = -0.2*f +Mq1[4,4] = -1.0*f +Mq1[5,5] = 0.2*f +Mq1[6,6] = -2.2*f +Mq1[7,7] = 0.2*f +Mq1[8,8] = -0.2*f +Mq1[9,9] = -0.8*f +Mq1[1,2] = Mq1[2,1] = 2.0*f1 +Mq1[1,4] = Mq1[4,1] = -1.0*f1 +Mq1[2,3] = Mq1[3,2] = 1.1*f1 +Mq1[4,5] = Mq1[5,4] = 0.5*f1 +Mq1[4,7] = Mq1[7,4] = -1.0*f1 +Mq1[2,5] = Mq1[5,2] = -0.75*f1 +Mq1[3,6] = Mq1[6,3] = 1.5*f1 +Mq1[5,6] = Mq1[6,5] = 2.1*f1 +Mq1[5,8] = Mq1[8,5] = 0.12*f1 +Mq1[6,9] = Mq1[9,6] = -0.52*f1 +Mq1[7,8] = Mq1[8,7] = 0.5*f1 +Mq1[8,9] = Mq1[9,8] = -0.05*f1 @testset "whole peps tensor" begin - g = M2graph(Mq) - gg = graph4peps(g, (1,1)) + #g = M2graph(Mq, -1) + g1 = M2graph(Mq1) + gg = graph4peps(g1, (1,1)) ### forms a peps network @@ -153,13 +179,13 @@ Mq[8,9] = Mq[9,8] = -0.05 v = [-1 for _ in 1:9] - @test exp.(-β*energy(v, g)) ≈ cc[1,1,1,1,1,1,1,1,1] + @test exp.(β*energy(v, g)) ≈ cc[1,1,1,1,1,1,1,1,1] v[1] = 1 - @test exp.(-β*energy(v, g)) ≈ cc[2,1,1,1,1,1,1,1,1] + @test exp.(β*energy(v, g)) ≈ cc[2,1,1,1,1,1,1,1,1] v = [1, -1, 1, -1, 1, -1, 1, -1, 1] - @test exp.(-β*energy(v, g)) ≈ cc[2,1,2,1,2,1,2,1,2] + @test exp.(β*energy(v, g)) ≈ cc[2,1,2,1,2,1,2,1,2] end # TODO this will be the ilustative step by step how does the probability computation work @@ -175,7 +201,7 @@ end @test mps[2] == 2*ones(2,2,2) β = 3. - g = M2graph(Mq) + g = M2graph(Mq1) gg = graph4peps(g, (1,1)) M = form_peps(gg, β) @@ -226,7 +252,7 @@ end @test objective ≈ [p1, p2] end - +end @testset "test an exemple instance" begin diff --git a/test/test_helpers.jl b/test/test_helpers.jl index 0a80f1ef..35002f7f 100644 --- a/test/test_helpers.jl +++ b/test/test_helpers.jl @@ -50,43 +50,46 @@ end function make_interactions_case1() L = 9 - + f = 1 + f1 = 1 D = Dict{Tuple{Int64,Int64},Float64}() - push!(D, (1, 1) => 1.) - push!(D, (1, 2) => -1.) - push!(D, (1, 4) => -3) - push!(D, (2, 2) => -2.) - push!(D, (2, 3) => -3.) - push!(D, (2,5) => -2.) - push!(D, (3,3) => 4.) - push!(D, (3,6) => 3.) - push!(D, (5,6) => -0.5) - push!(D, (4,5) => 1.0) - push!(D, (6,6) => .1) - push!(D, (6,9) => -1.04) - push!(D, (5,5) => 1.5) - push!(D, (5,8) => 1.0) - push!(D, (4,4) => 0.) - push!(D, (4,7) => -0.02) - push!(D, (7,7) => 0.7) - push!(D, (7,8) => 1.7) - push!(D, (8,8) => -0.16) - push!(D, (8,9) => -0.1) - push!(D, (9,9) => 0.66) - - ising_graph(D, L, 1, -1) + push!(D, (1, 1) => 1.0*f) + push!(D, (1, 2) => -1.0*f1) + push!(D, (1, 4) => -3*f1) + push!(D, (2, 2) => -2.0*f) + push!(D, (2, 3) => -3.0*f1) + push!(D, (2,5) => -2.0*f1) + push!(D, (3,3) => 4.0*f) + push!(D, (3,6) => 3.0*f1) + push!(D, (5,6) => -0.5*f1) + push!(D, (4,5) => 1.0*f1) + push!(D, (6,6) => 0.1*f) + push!(D, (6,9) => -1.04*f1) + push!(D, (5,5) => 1.5*f) + push!(D, (5,8) => 1.0*f1) + push!(D, (4,4) => 0.0*f) + push!(D, (4,7) => -0.02*f1) + push!(D, (7,7) => 0.7*f) + push!(D, (7,8) => 1.7*f1) + push!(D, (8,8) => -0.16*f) + push!(D, (8,9) => -0.1*f1) + push!(D, (9,9) => 0.66*f) + + ising_graph(D, L, 1, 1) end function make_interactions_case2() + f = 1 + f1 = 1 L = 16 - D1 = Dict((1, 1) => -2.8, (1, 2) => 0.3, (1, 5) => 0.2, (2, 2) => 2.7, (2, 3) => 0.255, (2, 6) => 0.21, (3, 3) => -2.6) - D12 = Dict((3, 4) => 0.222, (3, 7) => 0.213, (4, 4) => 2.5, (4, 8) => 0.2) - D2 = Dict((5, 5) => -2.4, (5, 6) => 0.15, (5, 9) => 0.211, (6, 6) => 2.3, (6, 7) => 0.2) - D22 = Dict((6, 10) => 0.15, (7, 7) => -2.2, (7, 8) => 0.11, (7, 11) => 0.35, (8, 8) => 2.1, (8, 12) => 0.19) - D3 = Dict((9, 9) => -2., (9, 10) => 0.222, (9, 13) => 0.15, (10, 10) => 1.9, (10, 11) => 0.28) - D32 = Dict((10, 14) => 0.21, (11, 11) => -1.8, (11, 12) => 0.19, (11, 15) => 0.18, (12, 12) => 1.7, (12, 16) => 0.27) - D4 = Dict((13, 13) => -1.6, (13, 14) => 0.32, (14, 14) => 1.5, (14, 15) => 0.19, (15, 15) => -1.4, (15, 16) => 0.21, (16, 16) => 1.3) + D1 = Dict((1, 1) => -2.8*f, (1, 2) => 0.3*f1, (1, 5) => 0.2*f1, (2, 2) => 2.7*f, (2, 3) => 0.255*f1, (2, 6) => 0.21*f1, (3, 3) => -2.6*f) + D12 = Dict((3, 4) => 0.222*f1, (3, 7) => 0.213*f1, (4, 4) => 2.5*f, (4, 8) => 0.2*f1) + D2 = Dict((5, 5) => -2.4*f, (5, 6) => 0.15*f1, (5, 9) => 0.211*f1, (6, 6) => 2.3*f, (6, 7) => 0.2*f1) + D22 = Dict((6, 10) => 0.15*f1, (7, 7) => -2.2*f, (7, 8) => 0.11*f1, (7, 11) => 0.35*f1, (8, 8) => 2.1*f, (8, 12) => 0.19*f1) + D3 = Dict((9, 9) => -2.0*f, (9, 10) => 0.222*f1, (9, 13) => 0.15*f1, (10, 10) => 1.9*f, (10, 11) => 0.28*f1) + D32 = Dict((10, 14) => 0.21*f1, (11, 11) => -1.8*f, (11, 12) => 0.19*f1, (11, 15) => 0.18*f1, (12, 12) => 1.7*f, (12, 16) => 0.27*f1) + D4 = Dict((13, 13) => -1.6*f, (13, 14) => 0.32*f1, (14, 14) => 1.5*f, (14, 15) => 0.19*f1, (15, 15) => -1.4*f, (15, 16) => 0.21*f1, (16, 16) => 1.3*f) D = merge!(+, D1, D12, D2, D22, D3, D32, D4) - ising_graph(D, L, 1, -1) + ising_graph(D, L, 1, 1) end diff --git a/test/tests_grid_from_file.jl b/test/tests_grid_from_file.jl index b9b00e57..cbaa834b 100644 --- a/test/tests_grid_from_file.jl +++ b/test/tests_grid_from_file.jl @@ -63,7 +63,7 @@ for k in 1:examples energies_given = data["energies"][k,:,:] - g = M2graph(Mat_of_interactions) + g = M2graph(Mat_of_interactions, -1) ################ exact method ################### diff --git a/test/tests_on_chimera.jl b/test/tests_on_chimera.jl index dab9b0a3..3404fac4 100644 --- a/test/tests_on_chimera.jl +++ b/test/tests_on_chimera.jl @@ -67,7 +67,7 @@ problem_size = parse_args(s)["size"] χ = parse_args(s)["chi"] si = parse_args(s)["size"] -ig = ising_graph(fi, si, 1, -1) +ig = ising_graph(fi, si, 1, 1) n_sols = parse_args(s)["n_sols"] node_size = (parse_args(s)["node_size1"], parse_args(s)["node_size2"]) From 8cc0bea2eadb144a5d96bbc2f389761be20e7f71 Mon Sep 17 00:00:00 2001 From: kdomino Date: Mon, 21 Dec 2020 17:32:09 +0100 Subject: [PATCH 057/137] tests are passing --- test/mps_tests.jl | 8 +++--- test/peps_tests.jl | 40 ++++----------------------- test/test_helpers.jl | 59 ++++++++++++++++++++-------------------- test/tests_full_graph.jl | 4 +-- test/tests_on_data.jl | 2 +- 5 files changed, 42 insertions(+), 71 deletions(-) diff --git a/test/mps_tests.jl b/test/mps_tests.jl index 622429ea..6a7b5d3a 100644 --- a/test/mps_tests.jl +++ b/test/mps_tests.jl @@ -30,12 +30,12 @@ end @test length(mps1) == 3 # this is B type tensor, only internal energy (± h/2) - @test mps1[1][1,:,:] ≈ [exp(-1/2) 0.0; 0.0 exp(1/2)] + @test mps1[1][1,:,:] ≈ [exp(1/2) 0.0; 0.0 exp(-1/2)] # type C tensor input from internale enegy and interaction #±(h/2 + J) -- J is twice due to the symmetry of M - @test mps1[2][1,:,:] ≈ [exp(1/2) 0.0; exp(-1/2) 0.0] - @test mps1[2][2,:,:] ≈ [0. exp(-1)*exp(-1/2); 0. exp(1)*exp(1/2)] - @test mps1[3][:,:,1] ≈ [exp(1/2) exp(-1/2); exp(-1)*exp(-1/2) exp(1)*exp(1/2)] + @test mps1[2][1,:,:] ≈ [exp(-1/2) 0.0; exp(1/2) 0.0] + @test mps1[2][2,:,:] ≈ [0. exp(1)*exp(1/2); 0. exp(-1)*exp(-1/2)] + @test mps1[3][:,:,1] ≈ [exp(-1/2) exp(1/2); exp(1)*exp(1/2) exp(-1)*exp(-1/2)] ####### compute probability ###### diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 28b06133..17dbd3ea 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -67,7 +67,6 @@ end Mq = ones(4,4) fullM2grid!(Mq, (2,2)) -if false @testset "tensor construction" begin @@ -113,7 +112,6 @@ if false @test vec(T1) ≈ vec(T2) end -end Mq = zeros(9,9) Mq[1,1] = 1. @@ -138,37 +136,11 @@ Mq[6,9] = Mq[9,6] = -0.52 Mq[7,8] = Mq[8,7] = 0.5 Mq[8,9] = Mq[9,8] = -0.05 -f = -1. -f1 = -1. - -Mq1 = zeros(9,9) -Mq1[1,1] = f*1.0 -Mq1[2,2] = 1.4*f -Mq1[3,3] = -0.2*f -Mq1[4,4] = -1.0*f -Mq1[5,5] = 0.2*f -Mq1[6,6] = -2.2*f -Mq1[7,7] = 0.2*f -Mq1[8,8] = -0.2*f -Mq1[9,9] = -0.8*f -Mq1[1,2] = Mq1[2,1] = 2.0*f1 -Mq1[1,4] = Mq1[4,1] = -1.0*f1 -Mq1[2,3] = Mq1[3,2] = 1.1*f1 -Mq1[4,5] = Mq1[5,4] = 0.5*f1 -Mq1[4,7] = Mq1[7,4] = -1.0*f1 -Mq1[2,5] = Mq1[5,2] = -0.75*f1 -Mq1[3,6] = Mq1[6,3] = 1.5*f1 -Mq1[5,6] = Mq1[6,5] = 2.1*f1 -Mq1[5,8] = Mq1[8,5] = 0.12*f1 -Mq1[6,9] = Mq1[9,6] = -0.52*f1 -Mq1[7,8] = Mq1[8,7] = 0.5*f1 -Mq1[8,9] = Mq1[9,8] = -0.05*f1 @testset "whole peps tensor" begin - #g = M2graph(Mq, -1) - g1 = M2graph(Mq1) - gg = graph4peps(g1, (1,1)) + g = M2graph(Mq, -1) + gg = graph4peps(g, (1,1)) ### forms a peps network @@ -179,13 +151,13 @@ Mq1[8,9] = Mq1[9,8] = -0.05*f1 v = [-1 for _ in 1:9] - @test exp.(β*energy(v, g)) ≈ cc[1,1,1,1,1,1,1,1,1] + @test exp.(-β*energy(v, g)) ≈ cc[1,1,1,1,1,1,1,1,1] v[1] = 1 - @test exp.(β*energy(v, g)) ≈ cc[2,1,1,1,1,1,1,1,1] + @test exp.(-β*energy(v, g)) ≈ cc[2,1,1,1,1,1,1,1,1] v = [1, -1, 1, -1, 1, -1, 1, -1, 1] - @test exp.(β*energy(v, g)) ≈ cc[2,1,2,1,2,1,2,1,2] + @test exp.(-β*energy(v, g)) ≈ cc[2,1,2,1,2,1,2,1,2] end # TODO this will be the ilustative step by step how does the probability computation work @@ -201,7 +173,7 @@ end @test mps[2] == 2*ones(2,2,2) β = 3. - g = M2graph(Mq1) + g = M2graph(Mq, -1) gg = graph4peps(g, (1,1)) M = form_peps(gg, β) diff --git a/test/test_helpers.jl b/test/test_helpers.jl index 35002f7f..d303e73a 100644 --- a/test/test_helpers.jl +++ b/test/test_helpers.jl @@ -50,30 +50,29 @@ end function make_interactions_case1() L = 9 - f = 1 - f1 = 1 + D = Dict{Tuple{Int64,Int64},Float64}() - push!(D, (1, 1) => 1.0*f) - push!(D, (1, 2) => -1.0*f1) - push!(D, (1, 4) => -3*f1) - push!(D, (2, 2) => -2.0*f) - push!(D, (2, 3) => -3.0*f1) - push!(D, (2,5) => -2.0*f1) - push!(D, (3,3) => 4.0*f) - push!(D, (3,6) => 3.0*f1) - push!(D, (5,6) => -0.5*f1) - push!(D, (4,5) => 1.0*f1) - push!(D, (6,6) => 0.1*f) - push!(D, (6,9) => -1.04*f1) - push!(D, (5,5) => 1.5*f) - push!(D, (5,8) => 1.0*f1) - push!(D, (4,4) => 0.0*f) - push!(D, (4,7) => -0.02*f1) - push!(D, (7,7) => 0.7*f) - push!(D, (7,8) => 1.7*f1) - push!(D, (8,8) => -0.16*f) - push!(D, (8,9) => -0.1*f1) - push!(D, (9,9) => 0.66*f) + push!(D, (1, 1) => 1.0) + push!(D, (1, 2) => -1.0) + push!(D, (1, 4) => -3) + push!(D, (2, 2) => -2.0) + push!(D, (2, 3) => -3.0) + push!(D, (2,5) => -2.0) + push!(D, (3,3) => 4.0) + push!(D, (3,6) => 3.0) + push!(D, (5,6) => -0.5) + push!(D, (4,5) => 1.0) + push!(D, (6,6) => 0.1) + push!(D, (6,9) => -1.04) + push!(D, (5,5) => 1.5) + push!(D, (5,8) => 1.0) + push!(D, (4,4) => 0.0) + push!(D, (4,7) => -0.02) + push!(D, (7,7) => 0.7) + push!(D, (7,8) => 1.7) + push!(D, (8,8) => -0.16) + push!(D, (8,9) => -0.1) + push!(D, (9,9) => 0.66) ising_graph(D, L, 1, 1) end @@ -83,13 +82,13 @@ function make_interactions_case2() f = 1 f1 = 1 L = 16 - D1 = Dict((1, 1) => -2.8*f, (1, 2) => 0.3*f1, (1, 5) => 0.2*f1, (2, 2) => 2.7*f, (2, 3) => 0.255*f1, (2, 6) => 0.21*f1, (3, 3) => -2.6*f) - D12 = Dict((3, 4) => 0.222*f1, (3, 7) => 0.213*f1, (4, 4) => 2.5*f, (4, 8) => 0.2*f1) - D2 = Dict((5, 5) => -2.4*f, (5, 6) => 0.15*f1, (5, 9) => 0.211*f1, (6, 6) => 2.3*f, (6, 7) => 0.2*f1) - D22 = Dict((6, 10) => 0.15*f1, (7, 7) => -2.2*f, (7, 8) => 0.11*f1, (7, 11) => 0.35*f1, (8, 8) => 2.1*f, (8, 12) => 0.19*f1) - D3 = Dict((9, 9) => -2.0*f, (9, 10) => 0.222*f1, (9, 13) => 0.15*f1, (10, 10) => 1.9*f, (10, 11) => 0.28*f1) - D32 = Dict((10, 14) => 0.21*f1, (11, 11) => -1.8*f, (11, 12) => 0.19*f1, (11, 15) => 0.18*f1, (12, 12) => 1.7*f, (12, 16) => 0.27*f1) - D4 = Dict((13, 13) => -1.6*f, (13, 14) => 0.32*f1, (14, 14) => 1.5*f, (14, 15) => 0.19*f1, (15, 15) => -1.4*f, (15, 16) => 0.21*f1, (16, 16) => 1.3*f) + D1 = Dict((1, 1) => -2.8, (1, 2) => 0.3, (1, 5) => 0.2, (2, 2) => 2.7, (2, 3) => 0.255, (2, 6) => 0.21, (3, 3) => -2.6) + D12 = Dict((3, 4) => 0.222, (3, 7) => 0.213, (4, 4) => 2.5, (4, 8) => 0.2) + D2 = Dict((5, 5) => -2.4, (5, 6) => 0.15, (5, 9) => 0.211, (6, 6) => 2.3, (6, 7) => 0.2) + D22 = Dict((6, 10) => 0.15, (7, 7) => -2.2, (7, 8) => 0.11, (7, 11) => 0.35, (8, 8) => 2.1, (8, 12) => 0.19) + D3 = Dict((9, 9) => -2.0, (9, 10) => 0.222, (9, 13) => 0.15, (10, 10) => 1.9, (10, 11) => 0.28) + D32 = Dict((10, 14) => 0.21, (11, 11) => -1.8, (11, 12) => 0.19, (11, 15) => 0.18, (12, 12) => 1.7, (12, 16) => 0.27) + D4 = Dict((13, 13) => -1.6, (13, 14) => 0.32, (14, 14) => 1.5, (14, 15) => 0.19, (15, 15) => -1.4, (15, 16) => 0.21, (16, 16) => 1.3) D = merge!(+, D1, D12, D2, D22, D3, D32, D4) ising_graph(D, L, 1, 1) end diff --git a/test/tests_full_graph.jl b/test/tests_full_graph.jl index 6e0ec103..0159f7f9 100644 --- a/test/tests_full_graph.jl +++ b/test/tests_full_graph.jl @@ -14,7 +14,7 @@ β_step = 2 β = 2. - g = M2graph(M) + g = M2graph(M, -1) spectrum = brute_force(g; num_states=sols) @@ -51,7 +51,7 @@ β = 0.1 β_step = 1 - g = M2graph(M) + g = M2graph(M, -1) spins_mps, objectives_mps = solve_mps(g, 20; β=β, β_step=β_step, χ=χ, threshold = 1.e-12) diff --git a/test/tests_on_data.jl b/test/tests_on_data.jl index a2e04761..b576d820 100644 --- a/test/tests_on_data.jl +++ b/test/tests_on_data.jl @@ -11,7 +11,7 @@ 0.0 0.0 0.0 -0.4375 -0.4375 -0.4375 -0.4375 -3.125] - g = M2graph(JJ) + g = M2graph(JJ, -1) # parameters of the solver χ = 10 From 451138d737d234af6ef6ab45c78890c82d71e865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 21 Dec 2020 20:39:07 +0100 Subject: [PATCH 058/137] add filtering edges when readin instances, fix PEPS construction --- src/PEPS.jl | 20 +++++++++++--------- src/graph.jl | 6 +++--- src/graphs/model.jl | 2 +- src/ising.jl | 5 ++++- test/PEPS.jl | 14 +++++++++----- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 0c058e92..f5bb1bbc 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -20,22 +20,22 @@ mutable struct PepsTensor for u ∈ outgoing e = SimpleEdge(v, u) if get_prop(fg, e, :orientation) == "horizontal" - pc.down = first(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "d" => u) - else pc.right = first(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "r" => u) + push!(pc.nbrs, "h_out" => u) + else + pc.down = first(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "v_out" => u) end end for u ∈ incoming e = SimpleEdge(u, v) if get_prop(fg, e, :orientation) == "horizontal" - pc.up = last(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "u" => u) - else pc.left = last(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "l" => u) + push!(pc.nbrs, "h_in" => u) + else + pc.up = last(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "v_in" => u) end end @@ -60,4 +60,6 @@ mutable struct PepsTensor pc end -end \ No newline at end of file +end + +Base.size(A::PepsTensor) = size(A.tensor) \ No newline at end of file diff --git a/src/graph.jl b/src/graph.jl index 0881745a..15cec2bc 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -40,7 +40,7 @@ end function MetaGraphs.filter_edges(ig::MetaGraph, v::Cluster, w::Cluster) edges = SimpleEdge[] - for i ∈ keys(v.vertices), j ∈ unique_neighbors(ig, i) + for i ∈ keys(v.vertices), j ∈ neighbors(ig, i) if j ∈ keys(w.vertices) push!(edges, SimpleEdge(i, j)) end end edges @@ -133,6 +133,7 @@ function decompose_edges!(fg::MetaDiGraph, order=:PE; β::Float64=1.0) en, p = rank_reveal(energy, order) dec = (exp.(-β .* en), p) end + set_prop!(fg, edge, :decomposition, dec) end @@ -142,11 +143,10 @@ function decompose_edges!(fg::MetaDiGraph, order=:PE; β::Float64=1.0) end end - function rank_reveal(energy, order=:PE) @assert order ∈ (:PE, :EP) dim = order == :PE ? 1 : 2 - + E = unique(energy, dims=dim) idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) diff --git a/src/graphs/model.jl b/src/graphs/model.jl index b0e26ed9..086fa8fc 100644 --- a/src/graphs/model.jl +++ b/src/graphs/model.jl @@ -25,7 +25,7 @@ for op in [ @eval MetaGraphs.$op(m::Model, args...) = $op(m.graph, args...) end -@inline has_edge(m::Model, x...) = has_edge(m.graph, x...) +#has_edge(m::Model, x...) = has_edge(m.graph, x...) Base.size(m::Model) = m.size Base.size(m::Model, i::Int) = m.size[i] \ No newline at end of file diff --git a/src/ising.jl b/src/ising.jl index 7f504001..39d4eeed 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -54,7 +54,7 @@ function energy(fg::MetaDiGraph, edge::Edge) n = prod(size(wSp)) en = zeros(m, n) - for (j, η) ∈ enumerate(wSp) + for (j, η) ∈ enumerate(vec(wSp)) en[:, j] = energy.(vec(vSp), Ref(edge.J), Ref(η)) end en @@ -87,6 +87,9 @@ function ising_graph(instance::Instance, L::Int, β::Number=1.0, sgn::Number=-1. if i == j set_prop!(ig, i, :h, v) || error("Node $i missing!") else + if has_edge(ig, j, i) + error("Cannot add ($i, $j) as ($j, $i) already exists!") + end add_edge!(ig, i, j) && set_prop!(ig, i, j, :J, v) || error("Cannot add Egde ($i, $j)") end diff --git a/test/PEPS.jl b/test/PEPS.jl index 3e591fd0..1e1dfc83 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -30,11 +30,15 @@ for order ∈ (:EP, :PE) end @info "Testing PEPS" - - net = [] - for v ∈ vertices(fg) - push!(net, PepsTensor(fg, v)) - end + + @time begin + net = [] + for v ∈ vertices(fg) + peps = PepsTensor(fg, v) + push!(net, peps) + println(size(peps)) + end + end end end From e307eea520cf13389f74bdc4941a9a4c1c69fa9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 21 Dec 2020 23:03:50 +0100 Subject: [PATCH 059/137] add more test for PEPS generation --- src/graph.jl | 4 ++-- test/PEPS.jl | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 15cec2bc..2e5a6305 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -93,10 +93,10 @@ function factor_graph(m::Int, n::Int, hdir::Symbol=:LR, vdir::Symbol=:BT) end function factor_graph( - g::Model, + g::Model; energy::Function=energy, spectrum::Function=full_spectrum, - cluster::Function=unit_cell; + cluster::Function=unit_cell, hdir::Symbol=:LR, vdir::Symbol=:BT, ) diff --git a/test/PEPS.jl b/test/PEPS.jl index 1e1dfc83..7420bd2f 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -1,4 +1,4 @@ -@testset "PepsTensor correctly builds PEPS tensor" begin +@testset "PepsTensor correctly builds PEPS network for Chimera" begin m = 4 n = 4 t = 4 @@ -10,13 +10,21 @@ ig = ising_graph(instance, L) cg = Chimera((m, n, t), ig) β = get_prop(ig, :β) +k = 64 for order ∈ (:EP, :PE) for hd ∈ (:LR, :RL), vd ∈ (:BT, :TB) @info "Testing factor graph" order hd vd - fg = factor_graph(cg, hdir=hd, vdir=vd) + fg = factor_graph(cg, + #spectrum=full_spectrum, + spectrum = cl -> brute_force(cl, num_states=k), + energy=energy, + cluster=unit_cell, + hdir=hd, + vdir=vd, + ) decompose_edges!(fg, order, β=β) @test order == get_prop(fg, :tensors_order) @@ -36,10 +44,22 @@ for order ∈ (:EP, :PE) for v ∈ vertices(fg) peps = PepsTensor(fg, v) push!(net, peps) + println(peps.nbrs) println(size(peps)) end end end end +@testset "PepsTensor correctly builds PEPS network for Lattice" begin + +L = 9 +instance = "$(@__DIR__)/instances/$(L)_001.txt" + +ig = ising_graph(instance, L) + + +end + + end \ No newline at end of file From f67238681da258fbd800386f6544b2638dcf2e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 22 Dec 2020 09:35:37 +0100 Subject: [PATCH 060/137] modify lattice struct --- src/graph.jl | 7 ++++++- src/graphs/lattice.jl | 10 ++++------ test/PEPS.jl | 26 +++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 2e5a6305..d4e85e9e 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -100,7 +100,12 @@ function factor_graph( hdir::Symbol=:LR, vdir::Symbol=:BT, ) - m, n, _ = g.size + if typeof(g) == Chimera + m, n, _ = g.size + elseif typeof(g) == Lattice + m, n = g.size + end + fg = factor_graph(m, n, hdir, vdir) for v ∈ vertices(fg) diff --git a/src/graphs/lattice.jl b/src/graphs/lattice.jl index 354bb7de..f8e6b92c 100644 --- a/src/graphs/lattice.jl +++ b/src/graphs/lattice.jl @@ -4,15 +4,13 @@ export unit_cell struct Lattice <: Model size::NTuple{2, Int} graph::MetaGraph - - function Lattice(m::Int, n::Int) - lt = new((m, n)) - lt.graph = MetaGraph(grid([m, n])) - lt - end end @inline function Base.getindex(l::Lattice, i::Int, j::Int) m, n = size(l) LinearIndices((1:m, 1:n))[i, j] end + +function unit_cell(c::Lattice, v::Int) + Cluster(c.graph, v, enum([v]), []) +end diff --git a/test/PEPS.jl b/test/PEPS.jl index 7420bd2f..f5fd4f5a 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -12,6 +12,7 @@ cg = Chimera((m, n, t), ig) β = get_prop(ig, :β) k = 64 +#= for order ∈ (:EP, :PE) for hd ∈ (:LR, :RL), vd ∈ (:BT, :TB) @@ -50,14 +51,33 @@ for order ∈ (:EP, :PE) end end end +=# @testset "PepsTensor correctly builds PEPS network for Lattice" begin -L = 9 -instance = "$(@__DIR__)/instances/$(L)_001.txt" +L = 3 +N = L^2 +instance = "$(@__DIR__)/instances/$(N)_001.txt" -ig = ising_graph(instance, L) +ig = ising_graph(instance, N) +lt = Lattice((L, L), ig) + +for order ∈ (:EP, :PE) + for hd ∈ (:LR, :RL), vd ∈ (:BT, :TB) + @info "Testing factor graph" order hd vd + + fg = factor_graph(lt, + spectrum=full_spectrum, + energy=energy, + cluster=unit_cell, + hdir=hd, + vdir=vd, + ) + + decompose_edges!(fg, order, β=β) + end +end end From c367e65e1d7919c687e17a624f505e08a9cb42fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 22 Dec 2020 09:52:09 +0100 Subject: [PATCH 061/137] add peps for lattice --- test/PEPS.jl | 10 ++++++++++ test/runtests.jl | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/test/PEPS.jl b/test/PEPS.jl index f5fd4f5a..f82e4ceb 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -76,6 +76,16 @@ for order ∈ (:EP, :PE) ) decompose_edges!(fg, order, β=β) + + @time begin + net = [] + for v ∈ vertices(fg) + peps = PepsTensor(fg, v) + push!(net, peps) + println(peps.nbrs) + println(size(peps)) + end + end end end diff --git a/test/runtests.jl b/test/runtests.jl index 4fb7c7ff..79830c78 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,18 +31,18 @@ if CUDA.functional() && CUDA.has_cutensor() && false end push!(my_tests, - "base.jl", - "contractions.jl", - "compressions.jl", - "ising.jl", - "spectrum.jl", - "graph.jl", + #"base.jl", + #"contractions.jl", + #"compressions.jl", + #"ising.jl", + #"spectrum.jl", + #"graph.jl", "PEPS.jl", - "notation_tests.jl", - "peps_tests.jl", - "mps_tests.jl", - "tests_full_graph.jl", - "tests_on_data.jl" + #"notation_tests.jl", + #"peps_tests.jl", + #"mps_tests.jl", + #"tests_full_graph.jl", + #"tests_on_data.jl" ) for my_test in my_tests From 097ba16f015912a509b78f49141a5f3c9b29258f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 22 Dec 2020 11:23:11 +0100 Subject: [PATCH 062/137] add some comments regarding futher changes --- src/graph.jl | 4 ++++ test/PEPS.jl | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/graph.jl b/src/graph.jl index d4e85e9e..e2c88597 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -100,6 +100,9 @@ function factor_graph( hdir::Symbol=:LR, vdir::Symbol=:BT, ) + + #---------------------------------- + # this will not work in general if typeof(g) == Chimera m, n, _ = g.size elseif typeof(g) == Lattice @@ -107,6 +110,7 @@ function factor_graph( end fg = factor_graph(m, n, hdir, vdir) + #---------------------------------- for v ∈ vertices(fg) cl = cluster(g, v) diff --git a/test/PEPS.jl b/test/PEPS.jl index f82e4ceb..d07411c2 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -86,6 +86,8 @@ for order ∈ (:EP, :PE) println(size(peps)) end end + + end end From 8a1c25e7b7ff7b7987abfd77d1c926b5145427ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 22 Dec 2020 17:27:03 +0100 Subject: [PATCH 063/137] fix _holes fuction --- src/PEPS.jl | 17 +++++++++++------ src/spectrum.jl | 5 ++--- test/PEPS.jl | 13 +++++-------- test/runtests.jl | 4 ++-- test/spectrum.jl | 11 +++++------ 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index f5bb1bbc..846b5886 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,6 +1,7 @@ export PepsTensor mutable struct PepsTensor + tag::Int nbrs::Dict{String, Int} left::AbstractArray right::AbstractArray @@ -10,7 +11,7 @@ mutable struct PepsTensor tensor::AbstractArray function PepsTensor(fg::MetaDiGraph, v::Int) - pc = new() + pc = new(v) pc.nbrs = Dict() pc.loc = get_prop(fg, v, :local_exp) @@ -41,22 +42,26 @@ mutable struct PepsTensor # open boundary conditions if !isdefined(pc, :left) - pc.left = ones(1, size(pc.right, 1)) + #pc.left = ones(1, size(pc.right, 1)) + @cast pc.tensor[r, u, d, σ] |= pc.loc[σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] end if !isdefined(pc, :right) - pc.right = ones(size(pc.left, 2), 1) + #pc.right = ones(size(pc.left, 2), 1) + @cast pc.tensor[l, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.up[u, σ] * pc.down[σ, d] end if !isdefined(pc, :up) - pc.up = ones(1, size(pc.down, 1)) + #pc.up = ones(1, size(pc.down, 1)) + @cast pc.tensor[l, r, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.down[σ, d] end if !isdefined(pc, :down) - pc.down = ones(size(pc.up, 2), 1) + #pc.down = ones(size(pc.up, 2), 1) + @cast pc.tensor[l, r, u, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] end - @cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] + #@cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] pc end diff --git a/src/spectrum.jl b/src/spectrum.jl index 91bb1019..dcb4b2a4 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -169,8 +169,7 @@ function _apply_nothing!(ψ::AbstractMPS, l::Int, i::Int) ψ[l] = M̃ end -_holes(nbrs::Vector) = setdiff(first(nbrs) : last(nbrs), nbrs) - +_holes(nbrs::Vector, i::Int) = setdiff(i + 1 : last(nbrs), nbrs) function MPS(ig::MetaGraph, control::MPSControl) L = nv(ig) @@ -203,7 +202,7 @@ function MPS(ig::MetaGraph, control::MPSControl) _apply_exponent!(ρ, ig, dβ, i, j, last(nbrs)) end - for l ∈ _holes(nbrs) + for l ∈ _holes(nbrs, i) _apply_nothing!(ρ, l, i) end end diff --git a/test/PEPS.jl b/test/PEPS.jl index d07411c2..5d5fd062 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -12,7 +12,6 @@ cg = Chimera((m, n, t), ig) β = get_prop(ig, :β) k = 64 -#= for order ∈ (:EP, :PE) for hd ∈ (:LR, :RL), vd ∈ (:BT, :TB) @@ -44,6 +43,7 @@ for order ∈ (:EP, :PE) net = [] for v ∈ vertices(fg) peps = PepsTensor(fg, v) + @test v == peps.tag push!(net, peps) println(peps.nbrs) println(size(peps)) @@ -51,7 +51,6 @@ for order ∈ (:EP, :PE) end end end -=# @testset "PepsTensor correctly builds PEPS network for Lattice" begin @@ -77,17 +76,15 @@ for order ∈ (:EP, :PE) decompose_edges!(fg, order, β=β) - @time begin + #@time begin net = [] for v ∈ vertices(fg) peps = PepsTensor(fg, v) + @test v == peps.tag push!(net, peps) - println(peps.nbrs) - println(size(peps)) + @info "lt peps" peps.nbrs size(peps) end - end - - + #end end end diff --git a/test/runtests.jl b/test/runtests.jl index 79830c78..90c92d05 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -35,9 +35,9 @@ push!(my_tests, #"contractions.jl", #"compressions.jl", #"ising.jl", - #"spectrum.jl", + "spectrum.jl", #"graph.jl", - "PEPS.jl", + # "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", diff --git a/test/spectrum.jl b/test/spectrum.jl index 270c1e01..f6c14394 100644 --- a/test/spectrum.jl +++ b/test/spectrum.jl @@ -2,19 +2,19 @@ using MetaGraphs using LightGraphs using GraphPlot -L = 2 +L = 4 N = L^2 instance = "$(@__DIR__)/instances/$(N)_001.txt" ig = ising_graph(instance, N) -set_prop!(ig, :β, 1.) #rand(Float64)) +set_prop!(ig, :β, 5.) #rand(Float64)) #r = [3, 2, 5, 4] r = fill(2, N) set_prop!(ig, :rank, r) sgn = -1. -ϵ = 1E-8 +ϵ = 1E-7 D = prod(r) + 1 var_ϵ = 1E-8 sweeps = 4 @@ -57,7 +57,7 @@ states = all_states(get_prop(ig, :rank)) end end - for l ∈ SpinGlassPEPS._holes(nbrs) + for l ∈ SpinGlassPEPS._holes(nbrs, i) SpinGlassPEPS._apply_nothing!(χ, l, i) end end @@ -68,7 +68,6 @@ states = all_states(get_prop(ig, :rank)) @test abs(dot(χ, χ) - sum(T)) < ϵ end - x = T ./ sum(T) @test T ./ sum(T) ≈ ϱ end @@ -138,7 +137,7 @@ end @test ϱ[idx.(σ)...] ≈ p end - for max_states ∈ [1, N, 2*N, N^2] + for max_states ∈ [N, 2*N, N^2] @info "Verifying low energy spectrum" max_states @info "Testing spectrum" From 8c8f53d2e0952feba0e9ad4fc4c04e0759c66454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Wed, 23 Dec 2020 10:33:18 +0100 Subject: [PATCH 064/137] add more tests --- src/PEPS.jl | 14 +++++--------- test/PEPS.jl | 3 +++ test/runtests.jl | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 846b5886..f7f4e4be 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -42,26 +42,22 @@ mutable struct PepsTensor # open boundary conditions if !isdefined(pc, :left) - #pc.left = ones(1, size(pc.right, 1)) - @cast pc.tensor[r, u, d, σ] |= pc.loc[σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] + pc.left = ones(1, size(pc.right, 1)) end if !isdefined(pc, :right) - #pc.right = ones(size(pc.left, 2), 1) - @cast pc.tensor[l, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.up[u, σ] * pc.down[σ, d] + pc.right = ones(size(pc.left, 2), 1) end if !isdefined(pc, :up) - #pc.up = ones(1, size(pc.down, 1)) - @cast pc.tensor[l, r, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.down[σ, d] + pc.up = ones(1, size(pc.down, 1)) end if !isdefined(pc, :down) - #pc.down = ones(size(pc.up, 2), 1) - @cast pc.tensor[l, r, u, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] + pc.down = ones(size(pc.up, 2), 1) end - #@cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] + @cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] pc end diff --git a/test/PEPS.jl b/test/PEPS.jl index 5d5fd062..93e1622e 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -12,6 +12,7 @@ cg = Chimera((m, n, t), ig) β = get_prop(ig, :β) k = 64 +#= for order ∈ (:EP, :PE) for hd ∈ (:LR, :RL), vd ∈ (:BT, :TB) @@ -51,6 +52,7 @@ for order ∈ (:EP, :PE) end end end +=# @testset "PepsTensor correctly builds PEPS network for Lattice" begin @@ -85,6 +87,7 @@ for order ∈ (:EP, :PE) @info "lt peps" peps.nbrs size(peps) end #end + end end diff --git a/test/runtests.jl b/test/runtests.jl index 90c92d05..79830c78 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -35,9 +35,9 @@ push!(my_tests, #"contractions.jl", #"compressions.jl", #"ising.jl", - "spectrum.jl", + #"spectrum.jl", #"graph.jl", - # "PEPS.jl", + "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", From 3909bfd3e6430d9e224755609f22596bd4927f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 28 Dec 2020 12:37:34 +0100 Subject: [PATCH 065/137] add MPO from factor graph --- src/PEPS.jl | 33 +++++++++++++++++++++++++++++++-- test/PEPS.jl | 2 ++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index f7f4e4be..7b17ffc8 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,4 +1,4 @@ -export PepsTensor +export PepsTensor, MPO mutable struct PepsTensor tag::Int @@ -63,4 +63,33 @@ mutable struct PepsTensor end end -Base.size(A::PepsTensor) = size(A.tensor) \ No newline at end of file +Base.size(A::PepsTensor) = size(A.tensor) + +function MPO(fg::MetaDiGraph, dim::Symbol=:r, i::Int; T::DataType=Float64) + @assert dir ∈ (:r, :c) + + m, n = size(fg) + idx = LinearIndices((1:m, 1:n)) + chain = dim == :r ? fg[idx[:, i]] : fg[idx[i, :]] + + ψ = MPO(T, length(chain)) + + for (j, v) ∈ enumerate(chain) + ψ[j] = PepsTensor(fg, v).tensor + end + ψ +end + +function MPS(fg::MetaDiGraph, which::Symbol=:d; T::DataType=Float64) + @assert which ∈ (:l, :r, :u, :d) + + #ϕ = MPO() + + for (j, v) ∈ enumerate(_row(fg, 1)) + ψ[j] = dropdims(PepsTensor(fg, v).tensor, dims=4) + end + + # TBW + + ψ +end \ No newline at end of file diff --git a/test/PEPS.jl b/test/PEPS.jl index 93e1622e..eb8fd35b 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -78,6 +78,8 @@ for order ∈ (:EP, :PE) decompose_edges!(fg, order, β=β) + #ψ = MPO(fg, :r, 1) + #@time begin net = [] for v ∈ vertices(fg) From 49d7b9c73124b6bccef9265c4d68e8f87bf034cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 28 Dec 2020 13:29:48 +0100 Subject: [PATCH 066/137] add Mareks ideas --- src/graph.jl | 13 ++++++++++--- src/graphs/chimera.jl | 3 ++- src/graphs/model.jl | 8 +++++++- src/ising.jl | 4 +++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index e2c88597..171e1af6 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -9,16 +9,23 @@ const Graph = Union{MetaDiGraph, MetaGraph} mutable struct Cluster tag::Int - vertices::Dict{Int,Int} + vertices::Dict{Int, Int} edges::EdgeIter rank::Vector J::Matrix{<:Number} h::Vector{<:Number} - function Cluster(ig::Graph, v::Int, vertices::Dict, edges::EdgeIter) - cl = new(v, vertices, edges) + function Cluster(ig::Graph, v::Int, vertices::Dict) + cl = new(v, vertices) L = length(cl.vertices) + cl.edges = [] + for e ∈ edges(ig) + if src(e) ∈ keys(cl.vertices) && dst(e) ∈ keys(cl.vertices) + push!(cl.edges, e) + end + end + cl.J = zeros(L, L) for e ∈ cl.edges i = cl.vertices[src(e)] diff --git a/src/graphs/chimera.jl b/src/graphs/chimera.jl index 67480518..bc96f22c 100644 --- a/src/graphs/chimera.jl +++ b/src/graphs/chimera.jl @@ -62,5 +62,6 @@ end function unit_cell(c::Chimera, v::Int) elist = filter_edges(c.graph, :cells, (v, v)) vlist = filter_vertices(c.graph, :cell, v) - Cluster(c.graph, v, enum(vlist), elist) + Cluster(c.graph, v, enum(vlist)) end + diff --git a/src/graphs/model.jl b/src/graphs/model.jl index 086fa8fc..9c79da2c 100644 --- a/src/graphs/model.jl +++ b/src/graphs/model.jl @@ -28,4 +28,10 @@ end #has_edge(m::Model, x...) = has_edge(m.graph, x...) Base.size(m::Model) = m.size -Base.size(m::Model, i::Int) = m.size[i] \ No newline at end of file +Base.size(m::Model, i::Int) = m.size[i] + +function cluster_graph(ig::MetaGraph, vertices::Dict) + + + Cluster(ig, v, vertices) +end diff --git a/src/ising.jl b/src/ising.jl index 39d4eeed..400893d9 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -41,7 +41,7 @@ energy(σ::Vector, h::Vector) = dot(h, σ) energy(σ::Vector, cl::Cluster, η::Vector=σ) = energy(σ, cl.J, η) + energy(cl.h, σ) function energy(σ::Vector, ig::MetaGraph) - cl = Cluster(ig, 0, enum(vertices(ig)), edges(ig)) + cl = Cluster(ig, 0, enum(vertices(ig))) energy(σ, cl) end @@ -69,6 +69,8 @@ Create the Ising spin glass model. Store extra information """ + +# ADD CONCEPT OF MISSING SPINS !!! function ising_graph(instance::Instance, L::Int, β::Number=1.0, sgn::Number=-1.0) # load the Ising instance From 1e5bc2f976ffdbc206e9b90ebf1b924f9d226d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 28 Dec 2020 20:49:15 +0100 Subject: [PATCH 067/137] add ideas for different clustering --- src/graph.jl | 2 +- src/graphs/chimera.jl | 67 ------------------------------------------- src/graphs/lattice.jl | 34 ++++++++++++++++------ 3 files changed, 26 insertions(+), 77 deletions(-) delete mode 100644 src/graphs/chimera.jl diff --git a/src/graph.jl b/src/graph.jl index 171e1af6..c1d9e667 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -19,7 +19,7 @@ mutable struct Cluster cl = new(v, vertices) L = length(cl.vertices) - cl.edges = [] + cl.edges = SimpleEdge[] for e ∈ edges(ig) if src(e) ∈ keys(cl.vertices) && dst(e) ∈ keys(cl.vertices) push!(cl.edges, e) diff --git a/src/graphs/chimera.jl b/src/graphs/chimera.jl deleted file mode 100644 index bc96f22c..00000000 --- a/src/graphs/chimera.jl +++ /dev/null @@ -1,67 +0,0 @@ -export Chimera -export unit_cell - -struct Chimera <: Model - size::NTuple{3, Int} - graph::MetaGraph - - function Chimera(size::NTuple{3, Int}, graph::MetaGraph) - cg = new(size, graph) - m, n, t = size - linear = LinearIndices((1:m, 1:n)) - - for i=1:m, j=1:n, u=1:2, k=1:t - v = cg[i, j, u, k] - ij = linear[i, j] - set_prop!(cg, v, :cell, ij) - end - - for e in edges(cg) - v = get_prop(cg, src(e), :cell) - w = get_prop(cg, dst(e), :cell) - set_prop!(cg, e, :cells, (v, w)) - end - cg - end -end - -function Chimera(m::Int, n::Int=m, t::Int=4) - max_size = m * n * 2 * t - g = MetaGraph(max_size) - - hoff = 2t - voff = n * hoff - mi = m * voff - ni = n * hoff - - for i=1:hoff:ni, j=i:voff:mi, k0=j:j+t-1, k1=j+t:j+2t-1 - add_edge!(g, k0, k1) - end - - for i=t:2t-1, j=i:hoff:ni-hoff-1, k=j+1:voff:mi-1 - add_edge!(g, k, k+hoff-1) - end - - for i=1:t, j=i:hoff:ni-1, k=j:voff:mi-voff-1 - add_edge!(g, k, k+voff) - end - Chimera((m, n, t), g) -end - -@inline function Base.getindex(c::Chimera, i::Int, j::Int, u::Int, k::Int) - _, n, t = size(c) - t * (2 * (n * (i - 1) + j - 1) + u - 1) + k -end - -@inline function Base.getindex(c::Chimera, i::Int, j::Int) - t = size(c, 3) - idx = vec([c[i, j, u, k] for u=1:2, k=1:t]) - c.graph[idx] -end - -function unit_cell(c::Chimera, v::Int) - elist = filter_edges(c.graph, :cells, (v, v)) - vlist = filter_vertices(c.graph, :cell, v) - Cluster(c.graph, v, enum(vlist)) -end - diff --git a/src/graphs/lattice.jl b/src/graphs/lattice.jl index f8e6b92c..af047e34 100644 --- a/src/graphs/lattice.jl +++ b/src/graphs/lattice.jl @@ -1,16 +1,32 @@ export Lattice -export unit_cell struct Lattice <: Model - size::NTuple{2, Int} + size::NTuple{5, Int} graph::MetaGraph + + function Lattice(size::NTuple{5, Int}, ig::MetaGraph) + lt = new(size, ig) + m, um, n, un, t = lt.size + + linear_grid = LinearIndices((1:m, 1:n)) + linear_graph = LinearIndices((1:m, 1:um, 1:n, 1:un, 1:t)) + + for i=1:m, ui=1:um, j=1:n, uj=1:un, k=1:t + ijk = linear_graph[i, du, j, uj, k] + set_prop!(lt, ig[ijk], :cell, linear_grid[i, j]) + end + lt + end end -@inline function Base.getindex(l::Lattice, i::Int, j::Int) - m, n = size(l) - LinearIndices((1:m, 1:n))[i, j] -end - -function unit_cell(c::Lattice, v::Int) - Cluster(c.graph, v, enum([v]), []) +function cluster!(ig::MetaGraph, size::NTuple{5, Int}) + m, um, n, un, t = size + + linear_grid = LinearIndices((1:m, 1:n)) + linear_graph = LinearIndices((1:m, 1:um, 1:n, 1:un, 1:t)) + + for i=1:m, ui=1:um, j=1:n, uj=1:un, k=1:t + ijk = linear_graph[i, du, j, uj, k] + set_prop!(ig, ig[ijk], :cell, linear_grid[i, j]) + end end From 8af31ccbff786edf65844cb92387bf6ab206ce94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 29 Dec 2020 10:29:28 +0100 Subject: [PATCH 068/137] add more changes --- src/PEPS.jl | 4 ++- src/SpinGlassPEPS.jl | 1 - src/graph.jl | 64 ++++++++++++++++++------------------------- src/graphs/lattice.jl | 13 +-------- src/ising.jl | 13 ++++----- test/graph.jl | 32 +++------------------- test/runtests.jl | 4 +-- 7 files changed, 42 insertions(+), 89 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 7b17ffc8..e57f8763 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -65,6 +65,7 @@ end Base.size(A::PepsTensor) = size(A.tensor) +#= function MPO(fg::MetaDiGraph, dim::Symbol=:r, i::Int; T::DataType=Float64) @assert dir ∈ (:r, :c) @@ -92,4 +93,5 @@ function MPS(fg::MetaDiGraph, which::Symbol=:d; T::DataType=Float64) # TBW ψ -end \ No newline at end of file +end +=# \ No newline at end of file diff --git a/src/SpinGlassPEPS.jl b/src/SpinGlassPEPS.jl index 3ea86bf5..5635a22e 100644 --- a/src/SpinGlassPEPS.jl +++ b/src/SpinGlassPEPS.jl @@ -15,7 +15,6 @@ module SpinGlassPEPS include("compressions.jl") include("contractions.jl") include("graphs/model.jl") - include("graphs/chimera.jl") include("graphs/lattice.jl") include("graph.jl") include("ising.jl") diff --git a/src/graph.jl b/src/graph.jl index c1d9e667..e575f9e8 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,11 +1,9 @@ -export Chimera, Lattice export factor_graph, decompose_edges! -export Cluster, Spectrum +export Cluster export rank_reveal const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge -const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter, Array} -const Graph = Union{MetaDiGraph, MetaGraph} +const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter} mutable struct Cluster tag::Int @@ -15,32 +13,32 @@ mutable struct Cluster J::Matrix{<:Number} h::Vector{<:Number} - function Cluster(ig::Graph, v::Int, vertices::Dict) - cl = new(v, vertices) - L = length(cl.vertices) + function Cluster(ig::Graph, v::Int) + cl = new(v) + vlist = filter_vertices(ig, :cell, v) - cl.edges = SimpleEdge[] - for e ∈ edges(ig) - if src(e) ∈ keys(cl.vertices) && dst(e) ∈ keys(cl.vertices) - push!(cl.edges, e) - end - end + L = length(vlist) + cl.h = zeros(L) cl.J = zeros(L, L) - for e ∈ cl.edges - i = cl.vertices[src(e)] - j = cl.vertices[dst(e)] - @inbounds cl.J[i, j] = get_prop(ig, e, :J) - end - rank = get_prop(ig, :rank) - cl.rank = rank[1:L] + cl.vertices = Dict() + cl.edges = SimpleEdge[] + cl.rank = get_prop(ig, :rank)[1:L] - cl.h = zeros(L) - for (w, i) ∈ cl.vertices + for (i, w) ∈ enumerate(vlist) + push(cl.vertices, w => i) @inbounds cl.h[i] = get_prop(ig, w, :h) @inbounds cl.rank[i] = rank[w] end + + for e ∈ edges(ig) + if src(e) ∈ vlist && dst(e) ∈ vlist + i, j = cl.vertices[src(e)], cl.vertices[dst(e)] + @inbounds cl.J[i, j] = get_prop(ig, e, :J) + push!(cl.edges, e) + end + end cl end end @@ -75,6 +73,7 @@ mutable struct Edge end end +#= function factor_graph(m::Int, n::Int, hdir::Symbol=:LR, vdir::Symbol=:BT) @assert hdir ∈ (:LR, :RL) @assert vdir ∈ (:BT, :TB) @@ -98,29 +97,18 @@ function factor_graph(m::Int, n::Int, hdir::Symbol=:LR, vdir::Symbol=:BT) end dg end +=# function factor_graph( - g::Model; + lt::Lattice; energy::Function=energy, spectrum::Function=full_spectrum, - cluster::Function=unit_cell, - hdir::Symbol=:LR, - vdir::Symbol=:BT, ) - - #---------------------------------- - # this will not work in general - if typeof(g) == Chimera - m, n, _ = g.size - elseif typeof(g) == Lattice - m, n = g.size - end - - fg = factor_graph(m, n, hdir, vdir) - #---------------------------------- + m, _, n, _, t = lt.size + fg = MetaGraph(m * n) for v ∈ vertices(fg) - cl = cluster(g, v) + cl = Cluster(lt, v) set_prop!(fg, v, :cluster, cl) set_prop!(fg, v, :spectrum, spectrum(cl)) end diff --git a/src/graphs/lattice.jl b/src/graphs/lattice.jl index af047e34..38316024 100644 --- a/src/graphs/lattice.jl +++ b/src/graphs/lattice.jl @@ -12,21 +12,10 @@ struct Lattice <: Model linear_graph = LinearIndices((1:m, 1:um, 1:n, 1:un, 1:t)) for i=1:m, ui=1:um, j=1:n, uj=1:un, k=1:t - ijk = linear_graph[i, du, j, uj, k] + ijk = linear_graph[i, ui, j, uj, k] set_prop!(lt, ig[ijk], :cell, linear_grid[i, j]) end lt end end -function cluster!(ig::MetaGraph, size::NTuple{5, Int}) - m, um, n, un, t = size - - linear_grid = LinearIndices((1:m, 1:n)) - linear_graph = LinearIndices((1:m, 1:um, 1:n, 1:un, 1:t)) - - for i=1:m, ui=1:um, j=1:n, uj=1:un, k=1:t - ijk = linear_graph[i, du, j, uj, k] - set_prop!(ig, ig[ijk], :cell, linear_grid[i, j]) - end -end diff --git a/src/ising.jl b/src/ising.jl index 400893d9..42647377 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -5,7 +5,6 @@ export State const State = Union{Vector, NTuple} const Instance = Union{String, Dict} - """ $(TYPEDSIGNATURES) @@ -40,10 +39,10 @@ energy(σ::Vector, J::Matrix, η::Vector=σ) = dot(σ, J, η) energy(σ::Vector, h::Vector) = dot(h, σ) energy(σ::Vector, cl::Cluster, η::Vector=σ) = energy(σ, cl.J, η) + energy(cl.h, σ) -function energy(σ::Vector, ig::MetaGraph) - cl = Cluster(ig, 0, enum(vertices(ig))) - energy(σ, cl) -end +#function energy(σ::Vector, ig::MetaGraph) +# cl = Cluster(ig, 0, enum(vertices(ig))) +# energy(σ, cl) +#end function energy(fg::MetaDiGraph, edge::Edge) v, w = edge.tag @@ -69,8 +68,6 @@ Create the Ising spin glass model. Store extra information """ - -# ADD CONCEPT OF MISSING SPINS !!! function ising_graph(instance::Instance, L::Int, β::Number=1.0, sgn::Number=-1.0) # load the Ising instance @@ -108,11 +105,13 @@ function ising_graph(instance::Instance, L::Int, β::Number=1.0, sgn::Number=-1. set_prop!(ig, :β, β) set_prop!(ig, :rank, fill(2, L)) + #= # state (random by default) and corresponding energy σ = 2.0 * (rand(L) .< 0.5) .- 1.0 set_prop!(ig, :state, σ) set_prop!(ig, :energy, energy(σ, ig)) || error("Unable to calculate the Ising energy!") + =# ig end diff --git a/test/graph.jl b/test/graph.jl index a90dd77b..87e68c83 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -3,18 +3,8 @@ using LightGraphs using GraphPlot using CSV -m = 6 -n = 7 -t = 4 -@time g = Chimera(m, n, t) -@testset "Chimera creation" begin - @test nv(g) == 2m * n * t - @test ne(g) == t^2 * m * n + m * (n -1) * t + (m - 1) * n * t - @test g[m, n, 2, t] == 2m * n * t - @show g[1, 1] -end -@testset "Chimera graph" begin +@testset "Lattice graph" begin m = 4 n = 4 t = 4 @@ -23,14 +13,14 @@ end instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" ig = ising_graph(instance, L) - cg = Chimera((m, n, t), ig) + lt = Lattice((m, 1, n, 1, t), ig) - @time fg = factor_graph(cg) + @time fg = factor_graph(lt) @test collect(vertices(fg)) == collect(1:m * n) @test nv(fg) == m * n - @info "Verifying cluster properties for Chimera" m, n, t + @info "Verifying cluster properties for Lattice" m, n, t clv = [] cle = [] @@ -50,20 +40,6 @@ end @test isempty(intersect(cle...)) end -@testset "Factor graph" begin - m = 16 - n = 16 - t = 4 - - L = 2 * n * m * t - instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" - - ig = ising_graph(instance, L) - cg = Chimera((m, n, t), ig) - - @time fg = factor_graph(cg) -end - @testset "Rank reveal correctly decomposes energy row-wise" begin energy = [[1 2 3]; [0 -1 0]; [1 2 3]] P, E = rank_reveal(energy, :PE) diff --git a/test/runtests.jl b/test/runtests.jl index 79830c78..17e2cdfc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,8 +36,8 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - #"graph.jl", - "PEPS.jl", + "graph.jl", + # "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", From 725e235687f4dd7f0f43621ff4129ec3fcb25e11 Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Tue, 29 Dec 2020 11:33:15 +0100 Subject: [PATCH 069/137] cleaning up lattice.jl --- src/graphs/lattice.jl | 32 ++++++++++++++++---------------- src/ising.jl | 36 +++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/graphs/lattice.jl b/src/graphs/lattice.jl index 38316024..b1d5cb1c 100644 --- a/src/graphs/lattice.jl +++ b/src/graphs/lattice.jl @@ -1,21 +1,21 @@ -export Lattice +export square_lattice -struct Lattice <: Model - size::NTuple{5, Int} - graph::MetaGraph + function square_lattice(size::NTuple{5, Int}) + m, um, n, un, t = size + rule = Dict() + + linear_new = LinearIndices((1:m, 1:n)) + linear_old = LinearIndices((1:m, 1:um, 1:n, 1:un, 1:t)) - function Lattice(size::NTuple{5, Int}, ig::MetaGraph) - lt = new(size, ig) - m, um, n, un, t = lt.size - - linear_grid = LinearIndices((1:m, 1:n)) - linear_graph = LinearIndices((1:m, 1:um, 1:n, 1:un, 1:t)) - - for i=1:m, ui=1:um, j=1:n, uj=1:un, k=1:t - ijk = linear_graph[i, ui, j, uj, k] - set_prop!(lt, ig[ijk], :cell, linear_grid[i, j]) - end - lt + for i=1:m, ui=1:um, j=1:n, uj=1:un, k=1:t + old = linear_old[i, ui, j, uj, k] + new = linear_new[i, j] + push!(rule, old => new) end + rule end +function square_lattice(size::NTuple{3, Int}) + m, n, t = size + square_lattice((m, 1, n, 1, t)) +end \ No newline at end of file diff --git a/src/ising.jl b/src/ising.jl index 42647377..8490221d 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -68,7 +68,7 @@ Create the Ising spin glass model. Store extra information """ -function ising_graph(instance::Instance, L::Int, β::Number=1.0, sgn::Number=-1.0) +function ising_graph(instance::Instance, L::Int, sgn::Number=1.0) # load the Ising instance if typeof(instance) == String @@ -80,6 +80,13 @@ function ising_graph(instance::Instance, L::Int, β::Number=1.0, sgn::Number=-1. ig = MetaGraph(L, 0.0) set_prop!(ig, :description, "The Ising model.") + + for v ∈ 1:L + set_prop!(ig, v, :active, false) + set_prop!(ig, v, :cell, v) + end + + # setup the model (J_ij, h_i) for (i, j, v) ∈ ising v *= sgn @@ -92,27 +99,13 @@ function ising_graph(instance::Instance, L::Int, β::Number=1.0, sgn::Number=-1. add_edge!(ig, i, j) && set_prop!(ig, i, j, :J, v) || error("Cannot add Egde ($i, $j)") end + set_prop!(ig, i, :active, true) + set_prop!(ig, j, :active, true) end - # by default h should be zero - for i ∈ 1:nv(ig) - if !has_prop(ig, i, :h) - set_prop!(ig, i, :h, 0.) || error("Cannot set bias at node $(i).") - end - end - # store extra information - set_prop!(ig, :β, β) set_prop!(ig, :rank, fill(2, L)) - #= - # state (random by default) and corresponding energy - σ = 2.0 * (rand(L) .< 0.5) .- 1.0 - - set_prop!(ig, :state, σ) - set_prop!(ig, :energy, energy(σ, ig)) || error("Unable to calculate the Ising energy!") - =# - ig end @@ -130,3 +123,12 @@ function unique_neighbors(ig::MetaGraph, i::Int) nbrs = neighbors(ig::MetaGraph, i::Int) filter(j -> j > i, nbrs) end + + + function update_cells!(ig::MetaGraph, rule::Function) + for v ∈ ig + old = get_prop(ig, v, :cell) + new = rule(old) + set_prop!(ig, v, cell, new) + end + end From b8bfeb389ec8e554e15269178a6b052ea31addb4 Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Tue, 29 Dec 2020 12:26:13 +0100 Subject: [PATCH 070/137] cleaning up factor_graph.jl --- src/graph.jl | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index e575f9e8..bdaf9ce2 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -100,50 +100,51 @@ end =# function factor_graph( - lt::Lattice; + ig::MetaGraph; energy::Function=energy, spectrum::Function=full_spectrum, ) - m, _, n, _, t = lt.size - fg = MetaGraph(m * n) + L = 0 + for v ∈ ig + L = maximum(L, get_prop(ig, v, :cell)) + end + + fg = MetaGraph(ig, L) for v ∈ vertices(fg) - cl = Cluster(lt, v) + cl = Cluster(ig, v) set_prop!(fg, v, :cluster, cl) set_prop!(fg, v, :spectrum, spectrum(cl)) end - for e ∈ edges(fg) - v = get_prop(fg, src(e), :cluster) - w = get_prop(fg, dst(e), :cluster) - - edge = Edge(g.graph, v, w) - set_prop!(fg, e, :edge, edge) - set_prop!(fg, e, :energy, energy(fg, edge)) + for i ∈ 1:L, j ∈ i+1:L + v = get_prop(fg, i, :cluster) + w = get_prop(fg, j, :cluster) + + edge = Edge(ig, v, w) + if !isempty(edge.edges) + set_prop!(fg, e, :edge, edge) + set_prop!(fg, e, :energy, energy(fg, edge)) + end end fg end -function decompose_edges!(fg::MetaDiGraph, order=:PE; β::Float64=1.0) +function decompose_edges!(fg::MetaGraph) set_prop!(fg, :tensors_order, order) for edge ∈ edges(fg) energy = get_prop(fg, edge, :energy) - - if order == :PE - p, en = rank_reveal(energy, order) - dec = (p, exp.(-β .* en)) - else - en, p = rank_reveal(energy, order) - dec = (exp.(-β .* en), p) - end + + pl, en = rank_reveal(energy, :PE) + en, pr = rank_reveal(en, :EP) - set_prop!(fg, edge, :decomposition, dec) + set_prop!(fg, edge, :decomposition, (pl, en, pr)) end for v ∈ vertices(fg) en = get_prop(fg, v, :spectrum).energies - set_prop!(fg, v, :local_exp, vec(exp.(-β .* en))) + set_prop!(fg, v, :loc_en, vec(en)) end end From 71ba23232f459dd6afec446f7734e65894b34755 Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Tue, 29 Dec 2020 14:28:52 +0100 Subject: [PATCH 071/137] cleaning up PEPS --- src/PEPS.jl | 100 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/graph.jl | 40 ++++++++------------- src/ising.jl | 12 +++---- 3 files changed, 118 insertions(+), 34 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index e57f8763..0fe1d5ef 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,5 +1,5 @@ export PepsTensor, MPO - +#= mutable struct PepsTensor tag::Int nbrs::Dict{String, Int} @@ -62,7 +62,7 @@ mutable struct PepsTensor pc end end - +=# Base.size(A::PepsTensor) = size(A.tensor) #= @@ -94,4 +94,98 @@ function MPS(fg::MetaDiGraph, which::Symbol=:d; T::DataType=Float64) ψ end -=# \ No newline at end of file +=# + +mutable struct PepsTensor + tag::Int + nbrs::Dict{String, Int} + left::AbstractArray + right::AbstractArray + up::AbstractArray + down::AbstractArray + loc::AbstractArray + tensor::AbstractArray + + function PepsTensor(fg::MetaDiGraph, v::Int) + pc = new(v) + pc.nbrs = Dict() + pc.loc = get_prop(fg, v, :local_exp) + + outgoing = outneighbors(fg, v) + incoming = inneighbors(fg, v) + + for u ∈ outgoing + e = SimpleEdge(v, u) + if get_prop(fg, e, :orientation) == "horizontal" + pc.right = first(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "h_out" => u) + else + pc.down = first(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "v_out" => u) + end + end + + for u ∈ incoming + e = SimpleEdge(u, v) + if get_prop(fg, e, :orientation) == "horizontal" + pc.left = last(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "h_in" => u) + else + pc.up = last(get_prop(fg, e, :decomposition)) + push!(pc.nbrs, "v_in" => u) + end + end + + # open boundary conditions + if !isdefined(pc, :left) + pc.left = ones(1, size(pc.right, 1)) + end + + if !isdefined(pc, :right) + pc.right = ones(size(pc.left, 2), 1) + end + + if !isdefined(pc, :up) + pc.up = ones(1, size(pc.down, 1)) + end + + if !isdefined(pc, :down) + pc.down = ones(size(pc.up, 2), 1) + end + + @cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] + + pc + end +end + +function generate_tensor(ng::NetworkGraph, v::Int) + loc_en = get_prop(ng.graph, v, :loc_en) + tensor = exp.(-ng.β .* loc_en) + for w ∈ ng.nbrs[v] + if has_edge(ng.graph, w, v) + pw, e, pv = get_prop(ng.graph, w, v, :decomposition) + @cast tensor[σ, ..., γ] |= tensor[σ, ...] * pv[γ, σ] + elseif has_edge(ng.graph, v, w) + pv, e, pw = get_prop(ng.graph, v, w, :decomposition) + @cast tensor[σ, ..., γ] |= tensor[σ, ...] * pv[σ, γ] + else + pv = ones(size(loc_en), 1) + @cast tensor[σ, ..., γ] |= tensor[σ, ...] * pv[σ, γ] + end + end + tensor +end + +function generate_tensor(ng::NetworkGraph, v::Int, w::Int) + if has_edge(ng.graph, w, v) + _, e, _ = get_prop(ng.graph, w, v, :decomposition) + tensor = exp.(-ng.β .* e') #?transpose e + elseif has_edge(ng.graph, v, w) + _, e, _ = get_prop(ng.graph, v, w, :decomposition) + tensor = exp.(-ng.β .* e) + else + tensor = ones(1, 1) + end + tensor +end \ No newline at end of file diff --git a/src/graph.jl b/src/graph.jl index bdaf9ce2..184ceff8 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -5,6 +5,21 @@ export rank_reveal const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter} +mutable struct NetworkGraph + geometry::Dict{} + β::Number + graph::MetaGraph + nbrs::Dict{Int, Tuple{Int}} + #gauge + + function NetworkGraph(geometry::Dict{}, β::Number, graph::MetaGraph) + ng = new(geometry, β, graph) + # wygenerować nbrs na podstawie geometry + # sprawdzić czy w factor graphie nie ma edgy wychodzących poza nbrs + end +end + + mutable struct Cluster tag::Int vertices::Dict{Int, Int} @@ -73,31 +88,6 @@ mutable struct Edge end end -#= -function factor_graph(m::Int, n::Int, hdir::Symbol=:LR, vdir::Symbol=:BT) - @assert hdir ∈ (:LR, :RL) - @assert vdir ∈ (:BT, :TB) - - dg = MetaDiGraph(m * n) - set_prop!(dg, :order, (hdir, vdir)) - - linear = LinearIndices((1:m, 1:n)) - for i ∈ 1:m, j ∈ 1:n-1 - v, w = linear[i, j], linear[i, j+1] - hdir == :LR ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) - add_edge!(dg, e) - set_prop!(dg, e, :orientation, "horizontal") - end - - for i ∈ 1:n, j ∈ 1:m-1 - v, w = linear[j, i], linear[j+1, i] - vdir == :BT ? e = SimpleEdge(v, w) : e = SimpleEdge(w, v) - add_edge!(dg, e) - set_prop!(dg, e, :orientation, "vertical") - end - dg -end -=# function factor_graph( ig::MetaGraph; diff --git a/src/ising.jl b/src/ising.jl index 8490221d..eea8a0bd 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -125,10 +125,10 @@ function unique_neighbors(ig::MetaGraph, i::Int) end - function update_cells!(ig::MetaGraph, rule::Function) - for v ∈ ig - old = get_prop(ig, v, :cell) - new = rule(old) - set_prop!(ig, v, cell, new) - end +function update_cells!(ig::MetaGraph, rule::Function) + for v ∈ ig + old = get_prop(ig, v, :cell) + new = rule(old) + set_prop!(ig, v, cell, new) end +end From 3d8bb8b2bffd7598eb7d8710c09fa386b5cc1ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 29 Dec 2020 19:17:11 +0100 Subject: [PATCH 072/137] graph.jl test work --- src/PEPS.jl | 174 +++--------------------------------- src/SpinGlassPEPS.jl | 3 +- src/graph.jl | 43 ++++----- src/graphs/model.jl | 37 -------- src/ising.jl | 21 ++--- src/{graphs => }/lattice.jl | 0 test/PEPS.jl | 94 ++----------------- test/graph.jl | 10 ++- 8 files changed, 57 insertions(+), 325 deletions(-) delete mode 100644 src/graphs/model.jl rename src/{graphs => }/lattice.jl (100%) diff --git a/src/PEPS.jl b/src/PEPS.jl index 0fe1d5ef..766a83ea 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,174 +1,21 @@ -export PepsTensor, MPO -#= -mutable struct PepsTensor - tag::Int - nbrs::Dict{String, Int} - left::AbstractArray - right::AbstractArray - up::AbstractArray - down::AbstractArray - loc::AbstractArray - tensor::AbstractArray - - function PepsTensor(fg::MetaDiGraph, v::Int) - pc = new(v) - pc.nbrs = Dict() - pc.loc = get_prop(fg, v, :local_exp) - - outgoing = outneighbors(fg, v) - incoming = inneighbors(fg, v) - - for u ∈ outgoing - e = SimpleEdge(v, u) - if get_prop(fg, e, :orientation) == "horizontal" - pc.right = first(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "h_out" => u) - else - pc.down = first(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "v_out" => u) - end - end - - for u ∈ incoming - e = SimpleEdge(u, v) - if get_prop(fg, e, :orientation) == "horizontal" - pc.left = last(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "h_in" => u) - else - pc.up = last(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "v_in" => u) - end - end - - # open boundary conditions - if !isdefined(pc, :left) - pc.left = ones(1, size(pc.right, 1)) - end - - if !isdefined(pc, :right) - pc.right = ones(size(pc.left, 2), 1) - end - - if !isdefined(pc, :up) - pc.up = ones(1, size(pc.down, 1)) - end - - if !isdefined(pc, :down) - pc.down = ones(size(pc.up, 2), 1) - end - - @cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] - - pc - end -end -=# -Base.size(A::PepsTensor) = size(A.tensor) +export generate_tensor #= -function MPO(fg::MetaDiGraph, dim::Symbol=:r, i::Int; T::DataType=Float64) - @assert dir ∈ (:r, :c) - - m, n = size(fg) - idx = LinearIndices((1:m, 1:n)) - chain = dim == :r ? fg[idx[:, i]] : fg[idx[i, :]] - - ψ = MPO(T, length(chain)) - - for (j, v) ∈ enumerate(chain) - ψ[j] = PepsTensor(fg, v).tensor - end - ψ -end - -function MPS(fg::MetaDiGraph, which::Symbol=:d; T::DataType=Float64) - @assert which ∈ (:l, :r, :u, :d) - - #ϕ = MPO() - - for (j, v) ∈ enumerate(_row(fg, 1)) - ψ[j] = dropdims(PepsTensor(fg, v).tensor, dims=4) - end - - # TBW - - ψ -end -=# - -mutable struct PepsTensor - tag::Int - nbrs::Dict{String, Int} - left::AbstractArray - right::AbstractArray - up::AbstractArray - down::AbstractArray - loc::AbstractArray - tensor::AbstractArray - - function PepsTensor(fg::MetaDiGraph, v::Int) - pc = new(v) - pc.nbrs = Dict() - pc.loc = get_prop(fg, v, :local_exp) - - outgoing = outneighbors(fg, v) - incoming = inneighbors(fg, v) - - for u ∈ outgoing - e = SimpleEdge(v, u) - if get_prop(fg, e, :orientation) == "horizontal" - pc.right = first(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "h_out" => u) - else - pc.down = first(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "v_out" => u) - end - end - - for u ∈ incoming - e = SimpleEdge(u, v) - if get_prop(fg, e, :orientation) == "horizontal" - pc.left = last(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "h_in" => u) - else - pc.up = last(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "v_in" => u) - end - end - - # open boundary conditions - if !isdefined(pc, :left) - pc.left = ones(1, size(pc.right, 1)) - end - - if !isdefined(pc, :right) - pc.right = ones(size(pc.left, 2), 1) - end - - if !isdefined(pc, :up) - pc.up = ones(1, size(pc.down, 1)) - end - - if !isdefined(pc, :down) - pc.down = ones(size(pc.up, 2), 1) - end - - @cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] - - pc - end -end - function generate_tensor(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.graph, v, :loc_en) tensor = exp.(-ng.β .* loc_en) + for w ∈ ng.nbrs[v] + n = max(1, ndims(tensor)-1) + s = :(@ntuple n i) + if has_edge(ng.graph, w, v) pw, e, pv = get_prop(ng.graph, w, v, :decomposition) - @cast tensor[σ, ..., γ] |= tensor[σ, ...] * pv[γ, σ] + @eval @cast tensor[σ, s..., γ] |= tensor[σ, s...] * pv[γ, σ] + elseif has_edge(ng.graph, v, w) pv, e, pw = get_prop(ng.graph, v, w, :decomposition) - @cast tensor[σ, ..., γ] |= tensor[σ, ...] * pv[σ, γ] + @eval @cast tensor[σ, s..., γ] |= tensor[σ, s...] * pv[σ, γ] else pv = ones(size(loc_en), 1) @cast tensor[σ, ..., γ] |= tensor[σ, ...] * pv[σ, γ] @@ -180,7 +27,7 @@ end function generate_tensor(ng::NetworkGraph, v::Int, w::Int) if has_edge(ng.graph, w, v) _, e, _ = get_prop(ng.graph, w, v, :decomposition) - tensor = exp.(-ng.β .* e') #?transpose e + tensor = exp.(-ng.β .* e') elseif has_edge(ng.graph, v, w) _, e, _ = get_prop(ng.graph, v, w, :decomposition) tensor = exp.(-ng.β .* e) @@ -188,4 +35,5 @@ function generate_tensor(ng::NetworkGraph, v::Int, w::Int) tensor = ones(1, 1) end tensor -end \ No newline at end of file +end +=# \ No newline at end of file diff --git a/src/SpinGlassPEPS.jl b/src/SpinGlassPEPS.jl index 5635a22e..989177d3 100644 --- a/src/SpinGlassPEPS.jl +++ b/src/SpinGlassPEPS.jl @@ -14,8 +14,7 @@ module SpinGlassPEPS include("base.jl") include("compressions.jl") include("contractions.jl") - include("graphs/model.jl") - include("graphs/lattice.jl") + include("lattice.jl") include("graph.jl") include("ising.jl") include("PEPS.jl") diff --git a/src/graph.jl b/src/graph.jl index 184ceff8..ed0d4196 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,9 +1,8 @@ -export factor_graph, decompose_edges! -export Cluster -export rank_reveal +export factor_graph, decompose_edges!, NetworkGraph +export Cluster, rank_reveal const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge -const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter} +const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter, Array} mutable struct NetworkGraph geometry::Dict{} @@ -19,7 +18,6 @@ mutable struct NetworkGraph end end - mutable struct Cluster tag::Int vertices::Dict{Int, Int} @@ -28,21 +26,23 @@ mutable struct Cluster J::Matrix{<:Number} h::Vector{<:Number} - function Cluster(ig::Graph, v::Int) + function Cluster(ig::MetaGraph, v::Int) cl = new(v) vlist = filter_vertices(ig, :cell, v) - L = length(vlist) + L = length(collect(vlist)) cl.h = zeros(L) cl.J = zeros(L, L) cl.vertices = Dict() cl.edges = SimpleEdge[] - cl.rank = get_prop(ig, :rank)[1:L] + + rank = get_prop(ig, :rank) + cl.rank = rank[1:L] for (i, w) ∈ enumerate(vlist) - push(cl.vertices, w => i) + push!(cl.vertices, w => i) @inbounds cl.h[i] = get_prop(ig, w, :h) @inbounds cl.rank[i] = rank[w] end @@ -88,18 +88,21 @@ mutable struct Edge end end +function _mv(ig::MetaGraph) + L = 0 + for v ∈ vertices(ig) + L = max(L, get_prop(ig, v, :cell)) + end + L +end function factor_graph( ig::MetaGraph; energy::Function=energy, spectrum::Function=full_spectrum, ) - L = 0 - for v ∈ ig - L = maximum(L, get_prop(ig, v, :cell)) - end - - fg = MetaGraph(ig, L) + L = _mv(ig) + fg = MetaGraph(L, 0.0) for v ∈ vertices(fg) cl = Cluster(ig, v) @@ -111,17 +114,17 @@ function factor_graph( v = get_prop(fg, i, :cluster) w = get_prop(fg, j, :cluster) - edge = Edge(ig, v, w) - if !isempty(edge.edges) - set_prop!(fg, e, :edge, edge) - set_prop!(fg, e, :energy, energy(fg, edge)) + edg = Edge(ig, v, w) + if !isempty(edg.edges) + e = SimpleEdge(i, j) + set_prop!(fg, e, :edge, edg) + set_prop!(fg, e, :energy, energy(fg, edg)) end end fg end function decompose_edges!(fg::MetaGraph) - set_prop!(fg, :tensors_order, order) for edge ∈ edges(fg) energy = get_prop(fg, edge, :energy) diff --git a/src/graphs/model.jl b/src/graphs/model.jl deleted file mode 100644 index 9c79da2c..00000000 --- a/src/graphs/model.jl +++ /dev/null @@ -1,37 +0,0 @@ -export Model - -abstract type Model end - -for op in [ - :nv, - :ne, - :eltype, - :edgetype, - :vertices, - :edges, - ] - - @eval LightGraphs.$op(c::Model) = $op(c.graph) -end - -for op in [ - :get_prop, - :set_prop!, - :has_vertex, - :inneighbors, - :outneighbors, - :neighbors] - - @eval MetaGraphs.$op(m::Model, args...) = $op(m.graph, args...) -end - -#has_edge(m::Model, x...) = has_edge(m.graph, x...) - -Base.size(m::Model) = m.size -Base.size(m::Model, i::Int) = m.size[i] - -function cluster_graph(ig::MetaGraph, vertices::Dict) - - - Cluster(ig, v, vertices) -end diff --git a/src/ising.jl b/src/ising.jl index eea8a0bd..0c0f79c4 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -1,5 +1,5 @@ -export ising_graph, energy -export gibbs_tensor +export ising_graph, update_cells! +export energy, gibbs_tensor export State const State = Union{Vector, NTuple} @@ -44,7 +44,7 @@ energy(σ::Vector, cl::Cluster, η::Vector=σ) = energy(σ, cl.J, η) + energy(c # energy(σ, cl) #end -function energy(fg::MetaDiGraph, edge::Edge) +function energy(fg::MetaGraph, edge::Edge) v, w = edge.tag vSp = get_prop(fg, v, :spectrum).states wSp = get_prop(fg, w, :spectrum).states @@ -80,13 +80,11 @@ function ising_graph(instance::Instance, L::Int, sgn::Number=1.0) ig = MetaGraph(L, 0.0) set_prop!(ig, :description, "The Ising model.") - for v ∈ 1:L set_prop!(ig, v, :active, false) set_prop!(ig, v, :cell, v) end - # setup the model (J_ij, h_i) for (i, j, v) ∈ ising v *= sgn @@ -99,8 +97,8 @@ function ising_graph(instance::Instance, L::Int, sgn::Number=1.0) add_edge!(ig, i, j) && set_prop!(ig, i, j, :J, v) || error("Cannot add Egde ($i, $j)") end - set_prop!(ig, i, :active, true) - set_prop!(ig, j, :active, true) + set_prop!(ig, i, :active, true) || error("Cannot activate node $(i)!") + set_prop!(ig, j, :active, true) || error("Cannot activate node $(j)!") end # store extra information @@ -125,10 +123,9 @@ function unique_neighbors(ig::MetaGraph, i::Int) end -function update_cells!(ig::MetaGraph, rule::Function) - for v ∈ ig - old = get_prop(ig, v, :cell) - new = rule(old) - set_prop!(ig, v, cell, new) +function update_cells!(ig::MetaGraph; rule::Dict) + for v ∈ vertices(ig) + w = rule[get_prop(ig, v, :cell)] + set_prop!(ig, v, :cell, rule[w]) end end diff --git a/src/graphs/lattice.jl b/src/lattice.jl similarity index 100% rename from src/graphs/lattice.jl rename to src/lattice.jl diff --git a/test/PEPS.jl b/test/PEPS.jl index eb8fd35b..68242383 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -1,58 +1,3 @@ -@testset "PepsTensor correctly builds PEPS network for Chimera" begin -m = 4 -n = 4 -t = 4 - -L = 2 * n * m * t -instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" - -ig = ising_graph(instance, L) -cg = Chimera((m, n, t), ig) - -β = get_prop(ig, :β) -k = 64 - -#= -for order ∈ (:EP, :PE) - for hd ∈ (:LR, :RL), vd ∈ (:BT, :TB) - - @info "Testing factor graph" order hd vd - - fg = factor_graph(cg, - #spectrum=full_spectrum, - spectrum = cl -> brute_force(cl, num_states=k), - energy=energy, - cluster=unit_cell, - hdir=hd, - vdir=vd, - ) - decompose_edges!(fg, order, β=β) - - @test order == get_prop(fg, :tensors_order) - @test (hd, vd) == get_prop(fg, :order) - - for e ∈ edges(fg) - dec = get_prop(fg, e, :decomposition) - en = get_prop(fg, e, :energy) - - @test exp.(-β .* en) ≈ prod(dec) - end - - @info "Testing PEPS" - - @time begin - net = [] - for v ∈ vertices(fg) - peps = PepsTensor(fg, v) - @test v == peps.tag - push!(net, peps) - println(peps.nbrs) - println(size(peps)) - end - end - end -end -=# @testset "PepsTensor correctly builds PEPS network for Lattice" begin @@ -61,39 +6,14 @@ N = L^2 instance = "$(@__DIR__)/instances/$(N)_001.txt" ig = ising_graph(instance, N) -lt = Lattice((L, L), ig) - -for order ∈ (:EP, :PE) - for hd ∈ (:LR, :RL), vd ∈ (:BT, :TB) - - @info "Testing factor graph" order hd vd - - fg = factor_graph(lt, - spectrum=full_spectrum, - energy=energy, - cluster=unit_cell, - hdir=hd, - vdir=vd, - ) - - decompose_edges!(fg, order, β=β) - - #ψ = MPO(fg, :r, 1) +fg = factor_graph(ig, energy=energy, spectrum=full_spectrum) - #@time begin - net = [] - for v ∈ vertices(fg) - peps = PepsTensor(fg, v) - @test v == peps.tag - push!(net, peps) - @info "lt peps" peps.nbrs size(peps) - end - #end - - end -end +#= +decompose_edges!(fg) +ng = NetworkGraph(fg,) +for v ∈ vertices(fg) + peps = PepsTensor(fg, v) end - - +=# end \ No newline at end of file diff --git a/test/graph.jl b/test/graph.jl index 87e68c83..f81943aa 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -3,19 +3,21 @@ using LightGraphs using GraphPlot using CSV - @testset "Lattice graph" begin m = 4 n = 4 t = 4 - L = 2 * n * m * t + L = n * m * (2 * t) instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" ig = ising_graph(instance, L) - lt = Lattice((m, 1, n, 1, t), ig) + update_cells!( + ig, + rule = square_lattice((m, n, 2*t)), + ) - @time fg = factor_graph(lt) + @time fg = factor_graph(ig) @test collect(vertices(fg)) == collect(1:m * n) @test nv(fg) == m * n From 2582e398a34d386c08a1ef562df1f99abab465df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 29 Dec 2020 19:23:24 +0100 Subject: [PATCH 073/137] add Marek's instance, correct peps generation --- src/PEPS.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 766a83ea..e70adad3 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,6 +1,5 @@ export generate_tensor -#= function generate_tensor(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.graph, v, :loc_en) tensor = exp.(-ng.β .* loc_en) @@ -18,7 +17,7 @@ function generate_tensor(ng::NetworkGraph, v::Int) @eval @cast tensor[σ, s..., γ] |= tensor[σ, s...] * pv[σ, γ] else pv = ones(size(loc_en), 1) - @cast tensor[σ, ..., γ] |= tensor[σ, ...] * pv[σ, γ] + @eval @cast tensor[σ, s..., γ] |= tensor[σ, s...] * pv[σ, γ] end end tensor @@ -36,4 +35,3 @@ function generate_tensor(ng::NetworkGraph, v::Int, w::Int) end tensor end -=# \ No newline at end of file From e2ac8f2b9f0996e43c01900cb71a680879b82a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 29 Dec 2020 22:19:39 +0100 Subject: [PATCH 074/137] make sure tests are passing after changing the core structure of key functions --- src/graph.jl | 7 +++- src/ising.jl | 24 +++++++---- src/notation.jl | 2 +- src/spectrum.jl | 6 +-- test/PEPS.jl | 35 ++++++++++++---- test/instances/pathological/test_3_4_3.txt | 48 ++++++++++++++++++++++ test/ising.jl | 11 ++--- test/mps_tests.jl | 4 +- test/peps_tests.jl | 2 +- test/runtests.jl | 22 +++++----- test/spectrum.jl | 10 ++--- test/test_helpers.jl | 4 +- test/tests_full_graph.jl | 2 + test/tests_on_data.jl | 2 + 14 files changed, 129 insertions(+), 50 deletions(-) create mode 100644 test/instances/pathological/test_3_4_3.txt diff --git a/src/graph.jl b/src/graph.jl index ed0d4196..59c06add 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -28,7 +28,12 @@ mutable struct Cluster function Cluster(ig::MetaGraph, v::Int) cl = new(v) - vlist = filter_vertices(ig, :cell, v) + + if cl.tag == 0 + vlist = vertices(ig) + else + vlist = filter_vertices(ig, :cell, v) + end L = length(collect(vlist)) diff --git a/src/ising.jl b/src/ising.jl index 0c0f79c4..7e70bbd0 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -18,8 +18,7 @@ Calculates matrix elements (probabilities) of \$\\rho\$ ``` for all possible configurations \$\\σ\$. """ -function gibbs_tensor(ig::MetaGraph) - β = get_prop(ig, :β) +function gibbs_tensor(ig::MetaGraph, β=Float64=1.0) rank = get_prop(ig, :rank) states = collect.(all_states(rank)) ρ = exp.(-β .* energy.(states, Ref(ig))) @@ -38,11 +37,7 @@ E = -\\sum_ s_i J_{ij} * s_j - \\sum_j h_i s_j. energy(σ::Vector, J::Matrix, η::Vector=σ) = dot(σ, J, η) energy(σ::Vector, h::Vector) = dot(h, σ) energy(σ::Vector, cl::Cluster, η::Vector=σ) = energy(σ, cl.J, η) + energy(cl.h, σ) - -#function energy(σ::Vector, ig::MetaGraph) -# cl = Cluster(ig, 0, enum(vertices(ig))) -# energy(σ, cl) -#end +energy(σ::Vector, ig::MetaGraph) = energy(σ, get_prop(ig, :J)) + energy(σ, get_prop(ig, :h)) function energy(fg::MetaGraph, edge::Edge) v, w = edge.tag @@ -83,20 +78,28 @@ function ising_graph(instance::Instance, L::Int, sgn::Number=1.0) for v ∈ 1:L set_prop!(ig, v, :active, false) set_prop!(ig, v, :cell, v) + set_prop!(ig, v, :h, 0.) end + J = zeros(L, L) + h = zeros(L) + # setup the model (J_ij, h_i) for (i, j, v) ∈ ising v *= sgn + if i == j set_prop!(ig, i, :h, v) || error("Node $i missing!") + h[i] = v else if has_edge(ig, j, i) error("Cannot add ($i, $j) as ($j, $i) already exists!") end add_edge!(ig, i, j) && set_prop!(ig, i, j, :J, v) || error("Cannot add Egde ($i, $j)") + J[i, j] = v end + set_prop!(ig, i, :active, true) || error("Cannot activate node $(i)!") set_prop!(ig, j, :active, true) || error("Cannot activate node $(j)!") end @@ -104,6 +107,13 @@ function ising_graph(instance::Instance, L::Int, sgn::Number=1.0) # store extra information set_prop!(ig, :rank, fill(2, L)) + set_prop!(ig, :J, J) + set_prop!(ig, :h, h) + + σ = 2.0 * (rand(L) .< 0.5) .- 1.0 + + set_prop!(ig, :state, σ) + set_prop!(ig, :energy, energy(σ, ig)) ig end diff --git a/src/notation.jl b/src/notation.jl index 035b5dc4..872ca1bb 100644 --- a/src/notation.jl +++ b/src/notation.jl @@ -248,7 +248,7 @@ function M2graph(M::Matrix{Float64}, sgn::Int = 1) end end end - ising_graph(D, L, 1, sgn) + ising_graph(D, L, sgn) end diff --git a/src/spectrum.jl b/src/spectrum.jl index dcb4b2a4..9daaab04 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -171,7 +171,7 @@ end _holes(nbrs::Vector, i::Int) = setdiff(i + 1 : last(nbrs), nbrs) -function MPS(ig::MetaGraph, control::MPSControl) +function MPS(ig::MetaGraph, control::MPSControl, β::Float64=1.0) L = nv(ig) Dcut = control.max_bond @@ -180,7 +180,6 @@ function MPS(ig::MetaGraph, control::MPSControl) schedule = control.β @info "Set control parameters for MPS" Dcut tol max_sweeps - β = get_prop(ig, :β) rank = get_prop(ig, :rank) @assert β ≈ sum(schedule) "Incorrect β schedule." @@ -234,11 +233,10 @@ together with the coresponding energies of a classical Ising Hamiltonian """ function brute_force(ig::MetaGraph; num_states::Int=1) - cl = Cluster(ig, 0, enum(vertices(ig)), edges(ig)) + cl = Cluster(ig, 0) brute_force(cl, num_states=num_states) end - function brute_force(cl::Cluster; num_states::Int=1) σ = collect.(all_states(cl.rank)) energies = energy.(σ, Ref(cl)) diff --git a/test/PEPS.jl b/test/PEPS.jl index 68242383..9f68e0ed 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -1,19 +1,38 @@ -@testset "PepsTensor correctly builds PEPS network for Lattice" begin +@testset "PepsTensor correctly builds PEPS network" begin -L = 3 -N = L^2 -instance = "$(@__DIR__)/instances/$(N)_001.txt" +m = 3 +n = 4 +t = 3 -ig = ising_graph(instance, N) -fg = factor_graph(ig, energy=energy, spectrum=full_spectrum) +L = m * n * t + +instance = "$(@__DIR__)/instances/pathological/test_$(m)_$(n)_$(t).txt" + +ig = ising_graph(instance, L) +update_cells!( + ig, + rule = square_lattice((m, n, t)), +) + +fg = factor_graph( + ig, + energy=energy, + spectrum=full_spectrum, +) -#= decompose_edges!(fg) + +#= ng = NetworkGraph(fg,) for v ∈ vertices(fg) - peps = PepsTensor(fg, v) + A = generate_tensor(ng, v) + + for w ∈ neighbors(v) + A = generate_tensor(ng, v, w) + end end =# + end \ No newline at end of file diff --git a/test/instances/pathological/test_3_4_3.txt b/test/instances/pathological/test_3_4_3.txt new file mode 100644 index 00000000..1b830021 --- /dev/null +++ b/test/instances/pathological/test_3_4_3.txt @@ -0,0 +1,48 @@ +# SquareLattice((3, 4, 3)) +# 16 spins 32 couplings 2 local fields +# Egs = 16.4 degeneracy = 4 +# low energies: +# -16.4, -16.4, -16.4, -16.4, -16.1, -16.1, -16.1, -16.1, -15.9, +# -15.9, -15.9, -15.9, -15.9, -15.9, -15.6, -15.6, -15.6, -15.6, +# -15.6, -15.6, -15.4, -15.4 +# gs configurations +# 0, 2, 2, 1, 1, 0, 0, 0, 1, 2, 2, 2, 1, 2, 2, 1, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 1, 0, 1, 2, 2, 2 +# 0, 2, 2, 1, 1, 0, 0, 0, 1, 2, 2, 2, 1, 2, 2, 1, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 1, 0, 0, 2, 2, 2 +# 0, 2, 2, 1, 1, 0, 0, 1, 1, 2, 2, 2, 1, 2, 2, 1, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 1, 0, 1, 2, 2, 2 +# 0, 2, 2, 1, 1, 0, 0, 1, 1, 2, 2, 2, 1, 2, 2, 1, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 1, 0, 0, 2, 2, 2 +# +# i j Jij +1 4 1.0 +1 5 0.75 +1 6 -0.5 +4 7 0.5 +5 7 0.25 +6 8 -0.25 +6 9 0.5 +1 13 1.0 +5 16 -1.0 +6 16 1.0 +6 18 -0.5 +13 16 -0.75 +13 18 0.75 +18 28 0.75 +28 31 -0.75 +28 32 0.5 +28 33 0.25 +29 31 -0.25 +29 32 0.5 +29 33 0.25 +30 31 1.0 +30 32 -1.0 +30 33 0.5 +4 5 -0.5 +4 6 0.75 +5 6 0.5 +7 8 0.25 +7 9 -0.25 +16 18 0.5 +28 29 -0.5 +28 30 1.0 +29 30 -0.5 +6 6 0.05 +16 16 -0.1 \ No newline at end of file diff --git a/test/ising.jl b/test/ising.jl index 007919c9..f5744427 100644 --- a/test/ising.jl +++ b/test/ising.jl @@ -60,14 +60,11 @@ using CSV # @test energies ≈ sp.energies # @test states == sp.states - set_prop!(ig, :β, rand(Float64)) - - ρ = gibbs_tensor(ig) + β = rand(Float64) + ρ = gibbs_tensor(ig, β) @test size(ρ) == Tuple(fill(2, N)) - β = get_prop(ig, :β) - r = exp.(-β .* sp.energies) R = r ./ sum(r) @@ -89,11 +86,11 @@ using CSV all = prod(rank) sp = brute_force(ig, num_states=all) - β = get_prop(ig, :β) + β = rand(Float64) ρ = exp.(-β .* sp.energies) ϱ = ρ ./ sum(ρ) - ϱ̃ = gibbs_tensor(ig) + ϱ̃ = gibbs_tensor(ig, β) @test [ ϱ̃[idx.(σ)...] for σ ∈ sp.states ] ≈ ϱ end diff --git a/test/mps_tests.jl b/test/mps_tests.jl index 6a7b5d3a..de6f64ec 100644 --- a/test/mps_tests.jl +++ b/test/mps_tests.jl @@ -1,6 +1,6 @@ import SpinGlassPEPS: connections_for_mps, construct_mps import SpinGlassPEPS: contract4probability, compute_probs -import SpinGlassPEPS: solve_mps +import SpinGlassPEPS: solve_mps, M2graph, graph4mps @testset "grouping of connections" begin M = ones(5,5) @@ -43,7 +43,7 @@ end d = 2 # construct form mpo-mps - g = make_interactions_case1() + g = make_interactions_case2() g2 = graph4mps(g) mps = construct_mps(g2, β, 2, 4, 0.) diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 11ac6dd9..4492cb13 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -1,7 +1,7 @@ include("test_helpers.jl") import SpinGlassPEPS: Partial_sol, update_partial_solution, select_best_solutions, return_solutions import SpinGlassPEPS: compute_single_tensor, conditional_probabs, get_parameters_for_T -import SpinGlassPEPS: make_lower_mps +import SpinGlassPEPS: make_lower_mps, M2graph, graph4peps, fullM2grid! import SpinGlassPEPS: set_spin_from_letf, spin_index_from_left, spin_indices_from_above import SpinGlassPEPS: energy, solve if true diff --git a/test/runtests.jl b/test/runtests.jl index 17e2cdfc..280f638c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,18 +31,18 @@ if CUDA.functional() && CUDA.has_cutensor() && false end push!(my_tests, - #"base.jl", - #"contractions.jl", - #"compressions.jl", - #"ising.jl", - #"spectrum.jl", + "base.jl", + "contractions.jl", + "compressions.jl", + "ising.jl", + "spectrum.jl", "graph.jl", - # "PEPS.jl", - #"notation_tests.jl", - #"peps_tests.jl", - #"mps_tests.jl", - #"tests_full_graph.jl", - #"tests_on_data.jl" + "PEPS.jl", + "notation_tests.jl", + "peps_tests.jl", + #"mps_tests.jl", # problems + "tests_full_graph.jl", + "tests_on_data.jl" ) for my_test in my_tests diff --git a/test/spectrum.jl b/test/spectrum.jl index f6c14394..d1c6b71b 100644 --- a/test/spectrum.jl +++ b/test/spectrum.jl @@ -8,7 +8,7 @@ N = L^2 instance = "$(@__DIR__)/instances/$(N)_001.txt" ig = ising_graph(instance, N) -set_prop!(ig, :β, 5.) #rand(Float64)) +β = 5. #r = [3, 2, 5, 4] r = fill(2, N) set_prop!(ig, :rank, r) @@ -18,15 +18,14 @@ sgn = -1. D = prod(r) + 1 var_ϵ = 1E-8 sweeps = 4 -schedule = [get_prop(ig, :β)] +schedule = [β] control = MPSControl(D, var_ϵ, sweeps, schedule) states = all_states(get_prop(ig, :rank)) -ϱ = gibbs_tensor(ig) +ϱ = gibbs_tensor(ig, β) @test sum(ϱ) ≈ 1 @testset "Verifying gate operations" begin - β = get_prop(ig, :β) rank = get_prop(ig, :rank) χ = HadamardMPS(rank) @@ -75,7 +74,6 @@ end @testset "Exact Gibbs pure state (MPS)" begin L = nv(ig) - β = get_prop(ig, :β) rank = get_prop(ig, :rank) @info "Generating Gibbs state - |ρ>" L rank β ϵ @@ -118,7 +116,7 @@ end @info "Verifying MPS from gates" - Gψ = MPS(ig, control) + Gψ = MPS(ig, control, β) @test_nowarn is_right_normalized(Gψ) @test bond_dimension(Gψ) > 1 diff --git a/test/test_helpers.jl b/test/test_helpers.jl index d303e73a..d5693dbb 100644 --- a/test/test_helpers.jl +++ b/test/test_helpers.jl @@ -74,7 +74,7 @@ function make_interactions_case1() push!(D, (8,9) => -0.1) push!(D, (9,9) => 0.66) - ising_graph(D, L, 1, 1) + ising_graph(D, L, 1) end @@ -90,5 +90,5 @@ function make_interactions_case2() D32 = Dict((10, 14) => 0.21, (11, 11) => -1.8, (11, 12) => 0.19, (11, 15) => 0.18, (12, 12) => 1.7, (12, 16) => 0.27) D4 = Dict((13, 13) => -1.6, (13, 14) => 0.32, (14, 14) => 1.5, (14, 15) => 0.19, (15, 15) => -1.4, (15, 16) => 0.21, (16, 16) => 1.3) D = merge!(+, D1, D12, D2, D22, D3, D32, D4) - ising_graph(D, L, 1, 1) + ising_graph(D, L, 1) end diff --git a/test/tests_full_graph.jl b/test/tests_full_graph.jl index 0159f7f9..8d330334 100644 --- a/test/tests_full_graph.jl +++ b/test/tests_full_graph.jl @@ -1,3 +1,5 @@ +import SpinGlassPEPS: M2graph, brute_force, solve_mps + @testset "mps on full graphs" begin @testset "L = 15 testing with brute force" begin diff --git a/test/tests_on_data.jl b/test/tests_on_data.jl index b576d820..a936a583 100644 --- a/test/tests_on_data.jl +++ b/test/tests_on_data.jl @@ -1,3 +1,5 @@ +import SpinGlassPEPS: M2graph, solve_mps + @testset "mpo-mps small instance of rail dispratching problem" begin # the matrix made from the disparching problem From 147573460fbe12acd63886e06a0a019886964450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 29 Dec 2020 22:21:37 +0100 Subject: [PATCH 075/137] add changes MPS/MPO from graph concept --- src/PEPS.jl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/PEPS.jl b/src/PEPS.jl index e70adad3..f525c0db 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -35,3 +35,34 @@ function generate_tensor(ng::NetworkGraph, v::Int, w::Int) end tensor end + +#= +function MPO(fg::MetaDiGraph, dim::Symbol=:r, i::Int; T::DataType=Float64) + @assert dir ∈ (:r, :c) + + m, n = size(fg) + idx = LinearIndices((1:m, 1:n)) + chain = dim == :r ? fg[idx[:, i]] : fg[idx[i, :]] + + ψ = MPO(T, length(chain)) + + for (j, v) ∈ enumerate(chain) + ψ[j] = PepsTensor(fg, v).tensor + end + ψ +end + +function MPS(fg::MetaDiGraph, which::Symbol=:d; T::DataType=Float64) + @assert which ∈ (:l, :r, :u, :d) + + #ϕ = MPO() + + for (j, v) ∈ enumerate(_row(fg, 1)) + ψ[j] = dropdims(PepsTensor(fg, v).tensor, dims=4) + end + + # TBW + + ψ +end +=# \ No newline at end of file From 81ffc90b77631a54ee65e266b78f437c37cd4eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Wed, 30 Dec 2020 10:41:34 +0100 Subject: [PATCH 076/137] comments some test for now --- test/runtests.jl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 280f638c..adc1c3fc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,18 +31,18 @@ if CUDA.functional() && CUDA.has_cutensor() && false end push!(my_tests, - "base.jl", - "contractions.jl", - "compressions.jl", - "ising.jl", - "spectrum.jl", - "graph.jl", + #"base.jl", + #"contractions.jl", + #"compressions.jl", + #"ising.jl", + #"spectrum.jl", + #"graph.jl", "PEPS.jl", - "notation_tests.jl", - "peps_tests.jl", + #"notation_tests.jl", + #"peps_tests.jl", #"mps_tests.jl", # problems - "tests_full_graph.jl", - "tests_on_data.jl" + #"tests_full_graph.jl", + #"tests_on_data.jl" ) for my_test in my_tests From 8f31c20236d7fcd47613f330077bed101f16dfe4 Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Wed, 30 Dec 2020 11:01:50 +0100 Subject: [PATCH 077/137] remove gauge --- src/graph.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/graph.jl b/src/graph.jl index 59c06add..3f4acd8b 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -9,7 +9,6 @@ mutable struct NetworkGraph β::Number graph::MetaGraph nbrs::Dict{Int, Tuple{Int}} - #gauge function NetworkGraph(geometry::Dict{}, β::Number, graph::MetaGraph) ng = new(geometry, β, graph) From 12291c16b3f0fa35aaff04aeb80cec4990ef8fdb Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Wed, 30 Dec 2020 13:41:55 +0100 Subject: [PATCH 078/137] add NetworkGraph, PepsNetwork, aux functions --- src/PEPS.jl | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/graph.jl | 14 +----------- test/PEPS.jl | 15 +++++-------- 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index f525c0db..8b63dd96 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,4 +1,26 @@ export generate_tensor +export NetworkGraph +export PepsNetwork + +mutable struct NetworkGraph + β::Number + graph::MetaGraph + nbrs::Dict + + function NetworkGraph(graph::MetaGraph, nbrs::Dict, β::Number) + ng = new(graph, nbrs, β) + count = 0 + for v ∈ vertices(ng.graph), w ∈ ng.nbrs[v] + if has_edge(ng.graph, v, w) + count += 1 + end + end + if count < nv(ng.graph) + error("Error!") + end + end +end + function generate_tensor(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.graph, v, :loc_en) @@ -65,4 +87,42 @@ function MPS(fg::MetaDiGraph, which::Symbol=:d; T::DataType=Float64) ψ end -=# \ No newline at end of file +=# + +function _linear(m::Int, n::Int) + map = LinearIndices((1:m, 1:n)) + out = Dict() + for i ∈ 0:m+1, j ∈ 0:n+1 + try + push!(out, (i, j) => map[i, j]) + catch + push!(out, (i, j) => 0) + end + end + out +end + +mutable struct PepsNetwork + m::Int + n::Int + β::Number + map::Dict + network_graph::MetaGraph + orientation::Symbol + + function PepsNetwork(m::Int, n::Int, fg::MetaGraph, β::Number) + pn = new(m, n, β) + pn.map = _linear(m, n) + nbrs = Dict() + + for i ∈ 1:m, j ∈ 1:n + push!(nbrs, pn.map[i, j] => (pn.map[i-1, j], pn.map[i, j+1], pn.map[i+1, j], pn.map[i, j-1])) + end + + pn.network_graph = NetworkGraph(fg, nbrs, pn.β) + pn + end +end + +generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m]) +generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}, n::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m], pn.map[n]) \ No newline at end of file diff --git a/src/graph.jl b/src/graph.jl index 3f4acd8b..6d9e909f 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,21 +1,9 @@ -export factor_graph, decompose_edges!, NetworkGraph +export factor_graph, decompose_edges! export Cluster, rank_reveal const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter, Array} -mutable struct NetworkGraph - geometry::Dict{} - β::Number - graph::MetaGraph - nbrs::Dict{Int, Tuple{Int}} - - function NetworkGraph(geometry::Dict{}, β::Number, graph::MetaGraph) - ng = new(geometry, β, graph) - # wygenerować nbrs na podstawie geometry - # sprawdzić czy w factor graphie nie ma edgy wychodzących poza nbrs - end -end mutable struct Cluster tag::Int diff --git a/test/PEPS.jl b/test/PEPS.jl index 9f68e0ed..d4a6f73c 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -4,6 +4,7 @@ m = 3 n = 4 t = 3 +β = 1 L = m * n * t @@ -23,16 +24,12 @@ fg = factor_graph( decompose_edges!(fg) -#= -ng = NetworkGraph(fg,) +x = m +y = n +peps = PepsNetwork(x, y, fg, β) -for v ∈ vertices(fg) - A = generate_tensor(ng, v) - - for w ∈ neighbors(v) - A = generate_tensor(ng, v, w) - end +for i ∈ 1:x, j ∈ 1:y + @time A = generate_tensor(peps, (i, j)) end -=# end \ No newline at end of file From 46c6486aa7958703cb0bf9c087ee0db9eefd4616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Wed, 30 Dec 2020 15:25:33 +0100 Subject: [PATCH 079/137] partially fix type problems --- src/PEPS.jl | 74 +++++++++++++++++----------------------------------- src/graph.jl | 1 + src/utils.jl | 14 ++++++++++ test/PEPS.jl | 4 ++- 4 files changed, 42 insertions(+), 51 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 8b63dd96..9819ec55 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,41 +1,41 @@ +export NetworkGraph, PepsNetwork export generate_tensor -export NetworkGraph -export PepsNetwork mutable struct NetworkGraph - β::Number - graph::MetaGraph + factor_graph::MetaGraph nbrs::Dict + β::Number + + function NetworkGraph(factor_graph::MetaGraph, nbrs::Dict, β::Number) + ng = new(factor_graph, nbrs, β) - function NetworkGraph(graph::MetaGraph, nbrs::Dict, β::Number) - ng = new(graph, nbrs, β) count = 0 - for v ∈ vertices(ng.graph), w ∈ ng.nbrs[v] - if has_edge(ng.graph, v, w) - count += 1 - end + for v ∈ vertices(ng.factor_graph), w ∈ ng.nbrs[v] + if has_edge(ng.factor_graph, v, w) count += 1 end end - if count < nv(ng.graph) - error("Error!") + + mc = nv(ng.factor_graph) + if count < mc + error("Error: $(count) < $(mc)") end + ng end end - function generate_tensor(ng::NetworkGraph, v::Int) - loc_en = get_prop(ng.graph, v, :loc_en) + loc_en = get_prop(ng.factor_graph, v, :loc_en) tensor = exp.(-ng.β .* loc_en) for w ∈ ng.nbrs[v] n = max(1, ndims(tensor)-1) s = :(@ntuple n i) - if has_edge(ng.graph, w, v) - pw, e, pv = get_prop(ng.graph, w, v, :decomposition) + if has_edge(ng.factor_graph, w, v) + pw, e, pv = get_prop(ng.factor_graph, w, v, :decomposition) @eval @cast tensor[σ, s..., γ] |= tensor[σ, s...] * pv[γ, σ] - elseif has_edge(ng.graph, v, w) - pv, e, pw = get_prop(ng.graph, v, w, :decomposition) + elseif has_edge(ng.factor_graph, v, w) + pv, e, pw = get_prop(ng.factor_graph, v, w, :decomposition) @eval @cast tensor[σ, s..., γ] |= tensor[σ, s...] * pv[σ, γ] else pv = ones(size(loc_en), 1) @@ -73,52 +73,26 @@ function MPO(fg::MetaDiGraph, dim::Symbol=:r, i::Int; T::DataType=Float64) end ψ end - -function MPS(fg::MetaDiGraph, which::Symbol=:d; T::DataType=Float64) - @assert which ∈ (:l, :r, :u, :d) - - #ϕ = MPO() - - for (j, v) ∈ enumerate(_row(fg, 1)) - ψ[j] = dropdims(PepsTensor(fg, v).tensor, dims=4) - end - - # TBW - - ψ -end =# -function _linear(m::Int, n::Int) - map = LinearIndices((1:m, 1:n)) - out = Dict() - for i ∈ 0:m+1, j ∈ 0:n+1 - try - push!(out, (i, j) => map[i, j]) - catch - push!(out, (i, j) => 0) - end - end - out -end - mutable struct PepsNetwork m::Int n::Int β::Number map::Dict - network_graph::MetaGraph + network_graph::NetworkGraph orientation::Symbol function PepsNetwork(m::Int, n::Int, fg::MetaGraph, β::Number) pn = new(m, n, β) - pn.map = _linear(m, n) - nbrs = Dict() + pn.map = LinearIndices(m, n) + nbrs = Dict() for i ∈ 1:m, j ∈ 1:n - push!(nbrs, pn.map[i, j] => (pn.map[i-1, j], pn.map[i, j+1], pn.map[i+1, j], pn.map[i, j-1])) + push!(nbrs, + pn.map[i, j] => (pn.map[i-1, j], pn.map[i, j+1], + pn.map[i+1, j], pn.map[i, j-1])) end - pn.network_graph = NetworkGraph(fg, nbrs, pn.β) pn end diff --git a/src/graph.jl b/src/graph.jl index 6d9e909f..526e7c9b 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -109,6 +109,7 @@ function factor_graph( edg = Edge(ig, v, w) if !isempty(edg.edges) e = SimpleEdge(i, j) + add_edge!(fg, e) set_prop!(fg, e, :edge, edg) set_prop!(fg, e, :energy, energy(fg, edg)) end diff --git a/src/utils.jl b/src/utils.jl index feeed4aa..806fc0d1 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -67,6 +67,20 @@ function LinearAlgebra.svd(A::AbstractMatrix, Dcut::Int, args...) return U * Diagonal(ph), Σ, V * Diagonal(ph) end +function Base.LinearIndices(m::Int, n::Int) + ind = LinearIndices((1:m, 1:n)) + bind = Dict() + + for i ∈ 0:m+1, j ∈ 0:n+1 + try + push!(bind, (i, j) => ind[i, j]) + catch + push!(bind, (i, j) => 0) + end + end + bind +end + @generated function _unique_dims(A::AbstractArray{T,N}, dim::Integer) where {T,N} quote 1 <= dim <= $N || return copy(A) diff --git a/test/PEPS.jl b/test/PEPS.jl index d4a6f73c..3bc06c36 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -4,6 +4,7 @@ m = 3 n = 4 t = 3 + β = 1 L = m * n * t @@ -28,8 +29,9 @@ x = m y = n peps = PepsNetwork(x, y, fg, β) +#= for i ∈ 1:x, j ∈ 1:y @time A = generate_tensor(peps, (i, j)) end - +=# end \ No newline at end of file From 5e001c96cd3b83a25345b39fc2f050db2a97c963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Sun, 3 Jan 2021 18:13:14 +0100 Subject: [PATCH 080/137] add MPO from PepsNetwork (not finished yet) --- src/PEPS.jl | 69 ++++++++++++++++++++++++++++++++-------------------- test/PEPS.jl | 1 + 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 9819ec55..155f1013 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,5 +1,5 @@ export NetworkGraph, PepsNetwork -export generate_tensor +export generate_tensor, MPO mutable struct NetworkGraph factor_graph::MetaGraph @@ -28,18 +28,18 @@ function generate_tensor(ng::NetworkGraph, v::Int) for w ∈ ng.nbrs[v] n = max(1, ndims(tensor)-1) - s = :(@ntuple n i) + s = :(@ntuple $n i) if has_edge(ng.factor_graph, w, v) pw, e, pv = get_prop(ng.factor_graph, w, v, :decomposition) - @eval @cast tensor[σ, s..., γ] |= tensor[σ, s...] * pv[γ, σ] + @eval @cast tensor[σ, s, γ] |= tensor[σ, s] * pv[γ, σ] elseif has_edge(ng.factor_graph, v, w) pv, e, pw = get_prop(ng.factor_graph, v, w, :decomposition) - @eval @cast tensor[σ, s..., γ] |= tensor[σ, s...] * pv[σ, γ] + @eval @cast tensor[σ, s, γ] |= tensor[σ, s] * pv[σ, γ] else - pv = ones(size(loc_en), 1) - @eval @cast tensor[σ, s..., γ] |= tensor[σ, s...] * pv[σ, γ] + pv = ones(size(loc_en)...) + @eval @cast tensor[σ, s, γ] |= tensor[σ, s] * pv[σ, γ] end end tensor @@ -58,33 +58,15 @@ function generate_tensor(ng::NetworkGraph, v::Int, w::Int) tensor end -#= -function MPO(fg::MetaDiGraph, dim::Symbol=:r, i::Int; T::DataType=Float64) - @assert dir ∈ (:r, :c) - - m, n = size(fg) - idx = LinearIndices((1:m, 1:n)) - chain = dim == :r ? fg[idx[:, i]] : fg[idx[i, :]] - - ψ = MPO(T, length(chain)) - - for (j, v) ∈ enumerate(chain) - ψ[j] = PepsTensor(fg, v).tensor - end - ψ -end -=# - mutable struct PepsNetwork - m::Int - n::Int + size::NTuple{2, Int} β::Number map::Dict network_graph::NetworkGraph orientation::Symbol function PepsNetwork(m::Int, n::Int, fg::MetaGraph, β::Number) - pn = new(m, n, β) + pn = new((m, n), β) pn.map = LinearIndices(m, n) nbrs = Dict() @@ -99,4 +81,37 @@ mutable struct PepsNetwork end generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m]) -generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}, n::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m], pn.map[n]) \ No newline at end of file +generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}, n::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m], pn.map[n]) + +function _MPO_row(peps::PepsNetwork, i::Int; type::DataType=Float64) + _, n = peps.size + ψ = MPO(type, n) + + for j ∈ 1:n + A = generate_tensor(peps, (i, j)) + @reduce B[l, r, u ,d] := sum(σ) A[l, r, u, d, σ] + + # multiply by en + ψ[j] = B + end + ψ +end + +function _MPO_column(peps::PepsNetwork, j::Int; type::DataType=Float64) + m, _ = peps.size + ψ = MPO(type, m) + + for i ∈ 1:m + A = generate_tensor(peps, (i, j)) + @reduce B[l, r, u, d] := sum(σ) A[l, r, u, d, σ] + + # multiply by en + ψ[i] = B + end + ψ +end + +MPO(peps::PepsNetwork, dim::Symbol, k::Int; type::DataType=Float64) = MPO(peps, Val(dim), k; type=T) +MPO(peps::PepsNetwork, ::Val{:row}, i::Int; type::DataType=Float64) = _MPO_row(peps, i, type=T) +MPO(peps::PepsNetwork, ::Val{:col}, j::Int; type::DataType=Float64) = _MPO_column(peps, j, type=T) + diff --git a/test/PEPS.jl b/test/PEPS.jl index 3bc06c36..1dee93df 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -34,4 +34,5 @@ for i ∈ 1:x, j ∈ 1:y @time A = generate_tensor(peps, (i, j)) end =# + end \ No newline at end of file From 8078df94c2ad62915216780baa52e471b34097ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Sun, 3 Jan 2021 20:57:00 +0100 Subject: [PATCH 081/137] fix MPO from PepsNetwork --- src/PEPS.jl | 28 ++++++++++++++++++++++++---- test/PEPS.jl | 14 +++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 155f1013..de85ef35 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -90,10 +90,20 @@ function _MPO_row(peps::PepsNetwork, i::Int; type::DataType=Float64) for j ∈ 1:n A = generate_tensor(peps, (i, j)) @reduce B[l, r, u ,d] := sum(σ) A[l, r, u, d, σ] - - # multiply by en ψ[j] = B end + + fg = peps.network_graph.factor_graph + + for j ∈ 1:n-1 + v, w = peps.map[i, j], peps.map[i, j+1] + + _, en, _ = get_prop(fg, v, w, :decomposition) + + A = ψ[j+1] + @tensor B[l, r, u, d] := A[l, r, ũ, d] * en[ũ, u] + ψ[j+1] = B + end ψ end @@ -104,10 +114,20 @@ function _MPO_column(peps::PepsNetwork, j::Int; type::DataType=Float64) for i ∈ 1:m A = generate_tensor(peps, (i, j)) @reduce B[l, r, u, d] := sum(σ) A[l, r, u, d, σ] - - # multiply by en ψ[i] = B end + + fg = peps.network_graph.factor_graph + + for i ∈ 1:m-1 + v, w = peps.map[i, j], peps.map[i+1, j] + + _, en, _ = get_prop(fg, v, w, :decomposition) + + A = ψ[i+1] + @tensor B[l, r, u, d] := en[l, l̃] * A[l̃, r, u, d] + ψ[i+1] = B + end ψ end diff --git a/test/PEPS.jl b/test/PEPS.jl index 1dee93df..b3872d7e 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -31,7 +31,19 @@ peps = PepsNetwork(x, y, fg, β) #= for i ∈ 1:x, j ∈ 1:y - @time A = generate_tensor(peps, (i, j)) + @time peps = generate_tensor(peps, (i, j)) +end +=# + +#= +for i ∈ 1:x + @time mpo = MPO(peps, :row, i) +end +=# + +#= +for j ∈ 1:y + @time mpo = MPO(peps, :col, j) end =# From 33a15b96fd2f3ea27b4573df782ca753138201b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Sun, 3 Jan 2021 22:57:03 +0100 Subject: [PATCH 082/137] fix small bugs in MPO --- src/PEPS.jl | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index de85ef35..711278d8 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -60,13 +60,12 @@ end mutable struct PepsNetwork size::NTuple{2, Int} - β::Number map::Dict network_graph::NetworkGraph orientation::Symbol function PepsNetwork(m::Int, n::Int, fg::MetaGraph, β::Number) - pn = new((m, n), β) + pn = new((m, n)) pn.map = LinearIndices(m, n) nbrs = Dict() @@ -75,7 +74,7 @@ mutable struct PepsNetwork pn.map[i, j] => (pn.map[i-1, j], pn.map[i, j+1], pn.map[i+1, j], pn.map[i, j-1])) end - pn.network_graph = NetworkGraph(fg, nbrs, pn.β) + pn.network_graph = NetworkGraph(fg, nbrs, β) pn end end @@ -89,19 +88,14 @@ function _MPO_row(peps::PepsNetwork, i::Int; type::DataType=Float64) for j ∈ 1:n A = generate_tensor(peps, (i, j)) - @reduce B[l, r, u ,d] := sum(σ) A[l, r, u, d, σ] + @reduce B[l, r, u ,d] |= sum(σ) A[l, r, u, d, σ] ψ[j] = B end - fg = peps.network_graph.factor_graph - for j ∈ 1:n-1 - v, w = peps.map[i, j], peps.map[i, j+1] - - _, en, _ = get_prop(fg, v, w, :decomposition) - + ten = generate_tensor(peps, (i, j), (i, j+1)) A = ψ[j+1] - @tensor B[l, r, u, d] := A[l, r, ũ, d] * en[ũ, u] + @tensor B[l, r, u, d] = A[l, r, ũ, d] * ten[ũ, u] ψ[j+1] = B end ψ @@ -113,19 +107,14 @@ function _MPO_column(peps::PepsNetwork, j::Int; type::DataType=Float64) for i ∈ 1:m A = generate_tensor(peps, (i, j)) - @reduce B[l, r, u, d] := sum(σ) A[l, r, u, d, σ] + @reduce B[l, r, u, d] |= sum(σ) A[l, r, u, d, σ] ψ[i] = B end - fg = peps.network_graph.factor_graph - for i ∈ 1:m-1 - v, w = peps.map[i, j], peps.map[i+1, j] - - _, en, _ = get_prop(fg, v, w, :decomposition) - + ten = generate_tensor(peps, (i, j), (i+1, j)) A = ψ[i+1] - @tensor B[l, r, u, d] := en[l, l̃] * A[l̃, r, u, d] + @tensor B[l, r, u, d] = ten[l, l̃] * A[l̃, r, u, d] ψ[i+1] = B end ψ From 65ba8172a02b6cbcc962e11ad4e2bf58fd4bfab3 Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Mon, 4 Jan 2021 14:43:08 +0100 Subject: [PATCH 083/137] fixed bugs in core functions, add tests for pathological instances --- src/PEPS.jl | 12 ++++++----- src/graph.jl | 13 ++++++++---- src/ising.jl | 4 ++-- src/lattice.jl | 10 +++++---- src/spectrum.jl | 6 ++++++ src/utils.jl | 54 ++++++++++++++++++++++++++++++++++++++++-------- test/PEPS.jl | 2 +- test/graph.jl | 45 +++++++++++++++++++++++++++++++++++++++- test/runtests.jl | 4 ++-- 9 files changed, 122 insertions(+), 28 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 711278d8..63bf3bd3 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -2,11 +2,11 @@ export NetworkGraph, PepsNetwork export generate_tensor, MPO mutable struct NetworkGraph - factor_graph::MetaGraph + factor_graph::MetaDiGraph nbrs::Dict β::Number - function NetworkGraph(factor_graph::MetaGraph, nbrs::Dict, β::Number) + function NetworkGraph(factor_graph::MetaDiGraph, nbrs::Dict, β::Number) ng = new(factor_graph, nbrs, β) count = 0 @@ -14,7 +14,7 @@ mutable struct NetworkGraph if has_edge(ng.factor_graph, v, w) count += 1 end end - mc = nv(ng.factor_graph) + mc = ne(ng.factor_graph) if count < mc error("Error: $(count) < $(mc)") end @@ -63,10 +63,12 @@ mutable struct PepsNetwork map::Dict network_graph::NetworkGraph orientation::Symbol + i_max::Int + j_max::Int - function PepsNetwork(m::Int, n::Int, fg::MetaGraph, β::Number) + function PepsNetwork(m::Int, n::Int, fg::MetaDiGraph, β::Number, orientation::Symbol) pn = new((m, n)) - pn.map = LinearIndices(m, n) + pn.map, pn.i_max, pn.j_max = LinearIndices(m, n, orientation) nbrs = Dict() for i ∈ 1:m, j ∈ 1:n diff --git a/src/graph.jl b/src/graph.jl index 526e7c9b..d99d08f1 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -1,4 +1,4 @@ -export factor_graph, decompose_edges! +export factor_graph #decompose_edges! export Cluster, rank_reveal const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge @@ -15,12 +15,14 @@ mutable struct Cluster function Cluster(ig::MetaGraph, v::Int) cl = new(v) + active = filter_vertices(ig, :active, true) if cl.tag == 0 vlist = vertices(ig) else vlist = filter_vertices(ig, :cell, v) end + vlist = intersect(active, vlist) L = length(collect(vlist)) @@ -94,7 +96,7 @@ function factor_graph( spectrum::Function=full_spectrum, ) L = _mv(ig) - fg = MetaGraph(L, 0.0) + fg = MetaDiGraph(L, 0.0) for v ∈ vertices(fg) cl = Cluster(ig, v) @@ -111,12 +113,14 @@ function factor_graph( e = SimpleEdge(i, j) add_edge!(fg, e) set_prop!(fg, e, :edge, edg) - set_prop!(fg, e, :energy, energy(fg, edg)) + pl, en = rank_reveal(energy(fg, edg), :PE) + en, pr = rank_reveal(en, :EP) + set_prop!(fg, e, :decomposition, (pl, en, pr)) end end fg end - +#= function decompose_edges!(fg::MetaGraph) for edge ∈ edges(fg) @@ -133,6 +137,7 @@ function decompose_edges!(fg::MetaGraph) set_prop!(fg, v, :loc_en, vec(en)) end end +=# function rank_reveal(energy, order=:PE) @assert order ∈ (:PE, :EP) diff --git a/src/ising.jl b/src/ising.jl index 7e70bbd0..f9c8a396 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -39,7 +39,7 @@ energy(σ::Vector, h::Vector) = dot(h, σ) energy(σ::Vector, cl::Cluster, η::Vector=σ) = energy(σ, cl.J, η) + energy(cl.h, σ) energy(σ::Vector, ig::MetaGraph) = energy(σ, get_prop(ig, :J)) + energy(σ, get_prop(ig, :h)) -function energy(fg::MetaGraph, edge::Edge) +function energy(fg::MetaDiGraph, edge::Edge) v, w = edge.tag vSp = get_prop(fg, v, :spectrum).states wSp = get_prop(fg, w, :spectrum).states @@ -135,7 +135,7 @@ end function update_cells!(ig::MetaGraph; rule::Dict) for v ∈ vertices(ig) - w = rule[get_prop(ig, v, :cell)] + w = get_prop(ig, v, :cell) set_prop!(ig, v, :cell, rule[w]) end end diff --git a/src/lattice.jl b/src/lattice.jl index b1d5cb1c..c17f2d58 100644 --- a/src/lattice.jl +++ b/src/lattice.jl @@ -4,12 +4,14 @@ export square_lattice m, um, n, un, t = size rule = Dict() - linear_new = LinearIndices((1:m, 1:n)) - linear_old = LinearIndices((1:m, 1:um, 1:n, 1:un, 1:t)) + linear_new = LinearIndices((1:n, 1:m)) + linear_old = LinearIndices((1:t, 1:un, 1:n, 1:um, 1:m)) for i=1:m, ui=1:um, j=1:n, uj=1:un, k=1:t - old = linear_old[i, ui, j, uj, k] - new = linear_new[i, j] + #old = (i-1) * um * n * un * t + (ui-1) * n * un * t + (j-1) * un * t + (uj-1) * t + k + #new = (i-1) * m + j + old = linear_old[k, uj, j, ui, i] + new = linear_new[j, i] push!(rule, old => new) end rule diff --git a/src/spectrum.jl b/src/spectrum.jl index 9daaab04..a72050f1 100644 --- a/src/spectrum.jl +++ b/src/spectrum.jl @@ -238,6 +238,9 @@ function brute_force(ig::MetaGraph; num_states::Int=1) end function brute_force(cl::Cluster; num_states::Int=1) + if isempty(cl.vertices) + return Spectrum(zeros(1), []) + end σ = collect.(all_states(cl.rank)) energies = energy.(σ, Ref(cl)) perm = partialsortperm(vec(energies), 1:num_states) @@ -245,6 +248,9 @@ function brute_force(cl::Cluster; num_states::Int=1) end function full_spectrum(cl::Cluster) + if isempty(cl.vertices) + return Spectrum(zeros(1), []) + end σ = collect.(all_states(cl.rank)) energies = energy.(σ, Ref(cl)) Spectrum(energies, σ) diff --git a/src/utils.jl b/src/utils.jl index 806fc0d1..fb874d02 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -67,18 +67,54 @@ function LinearAlgebra.svd(A::AbstractMatrix, Dcut::Int, args...) return U * Diagonal(ph), Σ, V * Diagonal(ph) end -function Base.LinearIndices(m::Int, n::Int) - ind = LinearIndices((1:m, 1:n)) +function Base.LinearIndices(m::Int, n::Int, origin::Symbol) + #ind = LinearIndices((1:m, 1:n)) bind = Dict() - - for i ∈ 0:m+1, j ∈ 0:n+1 - try - push!(bind, (i, j) => ind[i, j]) - catch - push!(bind, (i, j) => 0) + if origin == :NW + for i ∈ 1:m, j ∈ 1:n + push!(bind, (i, j) => (i-1)*n+j) end + elseif origin == :WN + for i ∈ 1:n, j ∈ 1:m + push!(bind, (i, j) => (j-1)*n+i) + end + elseif origin == :EN + for i ∈ 1:n, j ∈ 1:m + push!(bind, (i, j) => (j-1)*n+(n+1-i)) + end + elseif origin == :NE + for i ∈ 1:n, j ∈ 1:m + push!(bind, (i, j) => (i-1)*n+(n+1-j)) + end + elseif origin == :SE + for i ∈ 1:n, j ∈ 1:m + push!(bind, (i, j) => (m-i)*n+(n+1-j)) + end + elseif origin == :ES + for i ∈ 1:n, j ∈ 1:m + push!(bind, (i, j) => (m-j)*n+(n+1-i)) + end + end + + if origin == :NW + i_max = m + j_max = n + + else + i_max = n + j_max = m + end + + for i ∈ 0:i_max+1 + push!(bind, (i, 0) => 0) + push!(bind, (i, j_max+1) => 0) + end + for j ∈ 0:j_max+1 + push!(bind, (0, j) => 0) + push!(bind, (i_max+1, j) => 0) end - bind + + bind, i_max, j_max end @generated function _unique_dims(A::AbstractArray{T,N}, dim::Integer) where {T,N} diff --git a/test/PEPS.jl b/test/PEPS.jl index b3872d7e..19c955a5 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -23,7 +23,7 @@ fg = factor_graph( spectrum=full_spectrum, ) -decompose_edges!(fg) +#decompose_edges!(fg) x = m y = n diff --git a/test/graph.jl b/test/graph.jl index f81943aa..6a30f08b 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -2,7 +2,7 @@ using MetaGraphs using LightGraphs using GraphPlot using CSV - +#= @testset "Lattice graph" begin m = 4 n = 4 @@ -41,6 +41,49 @@ using CSV @test isempty(intersect(clv...)) @test isempty(intersect(cle...)) end +=# + +@testset "Testing factor graph" begin +m = 3 +n = 4 +t = 3 +instance = "$(@__DIR__)/instances/pathological/test_$(m)_$(n)_$(t).txt" + + +β = 1 +origin = :NW +m = 4 +L = m * n * t +ig = ising_graph(instance, L) +update_cells!( + ig, + rule = square_lattice((m, n, t)), +) +println("sq_lattice ", square_lattice((m, n, t))) + +for v ∈ filter_vertices(ig, :active, true) + #h = get_prop(ig, v, :h) + #println("h ", v, " ----> ", h) + cell = get_prop(ig, v, :cell) + println("cell ", v, " ----> ", cell) + +end + +fg = factor_graph( + ig, + energy=energy, + spectrum=full_spectrum, +) + +for v ∈ vertices(fg) + eng = get_prop(fg, v, :spectrum).energies + println("rank ", v, " ----> ", vec(eng)) +end +x = m +y = n +peps = PepsNetwork(x, y, fg, β, origin) + +end @testset "Rank reveal correctly decomposes energy row-wise" begin energy = [[1 2 3]; [0 -1 0]; [1 2 3]] diff --git a/test/runtests.jl b/test/runtests.jl index adc1c3fc..59122027 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,8 +36,8 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - #"graph.jl", - "PEPS.jl", + "graph.jl", + # "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", # problems From 3631cd0009aed4598a2f35183bab241c79761bf7 Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Mon, 4 Jan 2021 16:01:48 +0100 Subject: [PATCH 084/137] fix MPO, ordering --- src/PEPS.jl | 72 +++++++++++++++++++++++------------------------- src/graph.jl | 6 ++++ test/PEPS.jl | 30 ++++++++++---------- test/runtests.jl | 4 +-- 4 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 63bf3bd3..04e47c94 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -22,7 +22,7 @@ mutable struct NetworkGraph end end -function generate_tensor(ng::NetworkGraph, v::Int) +function generate_tensor_not_working(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.factor_graph, v, :loc_en) tensor = exp.(-ng.β .* loc_en) @@ -45,12 +45,32 @@ function generate_tensor(ng::NetworkGraph, v::Int) tensor end +function generate_tensor(ng::NetworkGraph, v::Int) + loc_en = get_prop(ng.factor_graph, v, :loc_en) + tensor_local = exp.(-ng.β .* loc_en) + p_list = Dict() + for (i,w) ∈ enumerate(ng.nbrs[v]) + + if has_edge(ng.factor_graph, w, v) + pw, e, pv = get_prop(ng.factor_graph, w, v, :decomposition) + pv = pv' + elseif has_edge(ng.factor_graph, v, w) + pv, e, pw = get_prop(ng.factor_graph, v, w, :decomposition) + else + pv = ones(length(loc_en), 1) + end + push!(p_list, i => pv) + end + @cast tensor[l, u, r, d, σ] |= tensor_local[σ] * p_list[1][σ, l] * p_list[2][σ, u] * p_list[3][σ, r] * p_list[4][σ, d] + tensor +end + function generate_tensor(ng::NetworkGraph, v::Int, w::Int) - if has_edge(ng.graph, w, v) - _, e, _ = get_prop(ng.graph, w, v, :decomposition) + if has_edge(ng.factor_graph, w, v) + _, e, _ = get_prop(ng.factor_graph, w, v, :decomposition) tensor = exp.(-ng.β .* e') - elseif has_edge(ng.graph, v, w) - _, e, _ = get_prop(ng.graph, v, w, :decomposition) + elseif has_edge(ng.factor_graph, v, w) + _, e, _ = get_prop(ng.factor_graph, v, w, :decomposition) tensor = exp.(-ng.β .* e) else tensor = ones(1, 1) @@ -73,8 +93,8 @@ mutable struct PepsNetwork nbrs = Dict() for i ∈ 1:m, j ∈ 1:n push!(nbrs, - pn.map[i, j] => (pn.map[i-1, j], pn.map[i, j+1], - pn.map[i+1, j], pn.map[i, j-1])) + pn.map[i, j] => (pn.map[i, j-1], pn.map[i-1, j], + pn.map[i, j+1], pn.map[i+1, j])) end pn.network_graph = NetworkGraph(fg, nbrs, β) pn @@ -84,45 +104,21 @@ end generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m]) generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}, n::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m], pn.map[n]) -function _MPO_row(peps::PepsNetwork, i::Int; type::DataType=Float64) - _, n = peps.size +function MPO(peps::PepsNetwork, i::Int; type::DataType=Float64) + n = peps.j_max ψ = MPO(type, n) for j ∈ 1:n A = generate_tensor(peps, (i, j)) - @reduce B[l, r, u ,d] |= sum(σ) A[l, r, u, d, σ] + @reduce B[l, u, r ,d] |= sum(σ) A[l, u, r, d, σ] ψ[j] = B end for j ∈ 1:n-1 ten = generate_tensor(peps, (i, j), (i, j+1)) - A = ψ[j+1] - @tensor B[l, r, u, d] = A[l, r, ũ, d] * ten[ũ, u] - ψ[j+1] = B - end - ψ -end - -function _MPO_column(peps::PepsNetwork, j::Int; type::DataType=Float64) - m, _ = peps.size - ψ = MPO(type, m) - - for i ∈ 1:m - A = generate_tensor(peps, (i, j)) - @reduce B[l, r, u, d] |= sum(σ) A[l, r, u, d, σ] - ψ[i] = B - end - - for i ∈ 1:m-1 - ten = generate_tensor(peps, (i, j), (i+1, j)) - A = ψ[i+1] - @tensor B[l, r, u, d] = ten[l, l̃] * A[l̃, r, u, d] - ψ[i+1] = B + A = ψ[j] + @tensor B[l, u, r, d] := A[l, u, r̃, d] * ten[r̃, r] + ψ[j] = B end ψ -end - -MPO(peps::PepsNetwork, dim::Symbol, k::Int; type::DataType=Float64) = MPO(peps, Val(dim), k; type=T) -MPO(peps::PepsNetwork, ::Val{:row}, i::Int; type::DataType=Float64) = _MPO_row(peps, i, type=T) -MPO(peps::PepsNetwork, ::Val{:col}, j::Int; type::DataType=Float64) = _MPO_column(peps, j, type=T) - +end \ No newline at end of file diff --git a/src/graph.jl b/src/graph.jl index d99d08f1..b1428129 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -118,6 +118,12 @@ function factor_graph( set_prop!(fg, e, :decomposition, (pl, en, pr)) end end + + for v ∈ vertices(fg) + en = get_prop(fg, v, :spectrum).energies + set_prop!(fg, v, :loc_en, vec(en)) + end + fg end #= diff --git a/test/PEPS.jl b/test/PEPS.jl index 19c955a5..31f34894 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -23,28 +23,28 @@ fg = factor_graph( spectrum=full_spectrum, ) -#decompose_edges!(fg) - x = m y = n -peps = PepsNetwork(x, y, fg, β) +peps = PepsNetwork(x, y, fg, β, :NW) +println(typeof(peps)) + -#= -for i ∈ 1:x, j ∈ 1:y - @time peps = generate_tensor(peps, (i, j)) +for i ∈ 2:2, j ∈ 1:y + println(i, j) + @time A = generate_tensor(peps, (i, j)) + println(size(A)) end -=# -#= -for i ∈ 1:x - @time mpo = MPO(peps, :row, i) +i=2 +for j ∈ 1:y-1 + A = generate_tensor(peps, (i, j), (i, j+1)) + println(size(A)) end -=# -#= -for j ∈ 1:y - @time mpo = MPO(peps, :col, j) +for i ∈ 1:x + println(i) + @time mpo = MPO(peps, i) + println(size(mpo)) end -=# end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 59122027..8a5074d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,8 +36,8 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - "graph.jl", - # "PEPS.jl", + #"graph.jl", + "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", # problems From bbb14256aedb342f1cf5e34323acf1d0ad88bcb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 4 Jan 2021 18:06:38 +0100 Subject: [PATCH 085/137] fix bug in dot and add test in peps --- src/PEPS.jl | 11 ++++++----- src/contractions.jl | 2 +- test/PEPS.jl | 6 +++++- test/graph.jl | 3 +-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 04e47c94..6881425c 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -22,7 +22,8 @@ mutable struct NetworkGraph end end -function generate_tensor_not_working(ng::NetworkGraph, v::Int) +# This still does not work (mixing @eval and @cast gives unexpected results) +function generate_tensor_general(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.factor_graph, v, :loc_en) tensor = exp.(-ng.β .* loc_en) @@ -47,10 +48,10 @@ end function generate_tensor(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.factor_graph, v, :loc_en) - tensor_local = exp.(-ng.β .* loc_en) + ten_loc = exp.(-ng.β .* loc_en) + p_list = Dict() - for (i,w) ∈ enumerate(ng.nbrs[v]) - + for (i,w) ∈ enumerate(ng.nbrs[v]) if has_edge(ng.factor_graph, w, v) pw, e, pv = get_prop(ng.factor_graph, w, v, :decomposition) pv = pv' @@ -61,7 +62,7 @@ function generate_tensor(ng::NetworkGraph, v::Int) end push!(p_list, i => pv) end - @cast tensor[l, u, r, d, σ] |= tensor_local[σ] * p_list[1][σ, l] * p_list[2][σ, u] * p_list[3][σ, r] * p_list[4][σ, d] + @cast tensor[l, u, r, d, σ] |= ten_loc[σ] * p_list[1][σ, l] * p_list[2][σ, u] * p_list[3][σ, r] * p_list[4][σ, d] tensor end diff --git a/src/contractions.jl b/src/contractions.jl index 04a0c786..478492b7 100644 --- a/src/contractions.jl +++ b/src/contractions.jl @@ -135,7 +135,7 @@ Base.:(*)(O::AbstractMPO, ψ::AbstractMPS) = return dot(O, ψ) function LinearAlgebra.dot(O1::AbstractMPO, O2::AbstractMPO) L = length(O1) - T = promote_type(eltype(ψ), eltype(ϕ)) + T = promote_type(eltype(O1), eltype(O2)) O = MPO(T, L) for i in 1:L diff --git a/test/PEPS.jl b/test/PEPS.jl index 31f34894..33254b10 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -28,7 +28,6 @@ y = n peps = PepsNetwork(x, y, fg, β, :NW) println(typeof(peps)) - for i ∈ 2:2, j ∈ 1:y println(i, j) @time A = generate_tensor(peps, (i, j)) @@ -47,4 +46,9 @@ for i ∈ 1:x println(size(mpo)) end +mpo = MPO(peps, 1) +for i ∈ 2:x + mpo = dot(MPO(peps, i), mpo) +end + end \ No newline at end of file diff --git a/test/graph.jl b/test/graph.jl index 6a30f08b..9bab66e0 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -2,7 +2,7 @@ using MetaGraphs using LightGraphs using GraphPlot using CSV -#= + @testset "Lattice graph" begin m = 4 n = 4 @@ -41,7 +41,6 @@ using CSV @test isempty(intersect(clv...)) @test isempty(intersect(cle...)) end -=# @testset "Testing factor graph" begin m = 3 From 686ec7f317f430064bb8f0f5198cd8512038997c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 4 Jan 2021 18:25:14 +0100 Subject: [PATCH 086/137] improve readability --- src/PEPS.jl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 6881425c..bd392828 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -32,14 +32,14 @@ function generate_tensor_general(ng::NetworkGraph, v::Int) s = :(@ntuple $n i) if has_edge(ng.factor_graph, w, v) - pw, e, pv = get_prop(ng.factor_graph, w, v, :decomposition) + _, _, pv = get_prop(ng.factor_graph, w, v, :decomposition) @eval @cast tensor[σ, s, γ] |= tensor[σ, s] * pv[γ, σ] elseif has_edge(ng.factor_graph, v, w) - pv, e, pw = get_prop(ng.factor_graph, v, w, :decomposition) + pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) @eval @cast tensor[σ, s, γ] |= tensor[σ, s] * pv[σ, γ] else - pv = ones(size(loc_en)...) + pv = ones(length(loc_en), 1) @eval @cast tensor[σ, s, γ] |= tensor[σ, s] * pv[σ, γ] end end @@ -51,18 +51,19 @@ function generate_tensor(ng::NetworkGraph, v::Int) ten_loc = exp.(-ng.β .* loc_en) p_list = Dict() - for (i,w) ∈ enumerate(ng.nbrs[v]) + for (i, w) ∈ enumerate(ng.nbrs[v]) if has_edge(ng.factor_graph, w, v) - pw, e, pv = get_prop(ng.factor_graph, w, v, :decomposition) + _, _, pv = get_prop(ng.factor_graph, w, v, :decomposition) pv = pv' elseif has_edge(ng.factor_graph, v, w) - pv, e, pw = get_prop(ng.factor_graph, v, w, :decomposition) + pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) else pv = ones(length(loc_en), 1) end push!(p_list, i => pv) end - @cast tensor[l, u, r, d, σ] |= ten_loc[σ] * p_list[1][σ, l] * p_list[2][σ, u] * p_list[3][σ, r] * p_list[4][σ, d] + L, R, U, D = p_list[1], p_list[2], p_list[3], p_list[4] + @cast tensor[l, u, r, d, σ] |= ten_loc[σ] * L[σ, l] * R[σ, u] * U[σ, r] * D[σ, d] tensor end From 30a005820dd0549a2633b1cb7f516d5c30606e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 4 Jan 2021 18:30:32 +0100 Subject: [PATCH 087/137] add assertion to linera ind --- src/PEPS.jl | 2 ++ src/utils.jl | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index bd392828..4a3ecb92 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -62,8 +62,10 @@ function generate_tensor(ng::NetworkGraph, v::Int) end push!(p_list, i => pv) end + L, R, U, D = p_list[1], p_list[2], p_list[3], p_list[4] @cast tensor[l, u, r, d, σ] |= ten_loc[σ] * L[σ, l] * R[σ, u] * U[σ, r] * D[σ, d] + tensor end diff --git a/src/utils.jl b/src/utils.jl index fb874d02..be596cb6 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -68,38 +68,38 @@ function LinearAlgebra.svd(A::AbstractMatrix, Dcut::Int, args...) end function Base.LinearIndices(m::Int, n::Int, origin::Symbol) - #ind = LinearIndices((1:m, 1:n)) - bind = Dict() + @asset origin ∈ (:NW, :WN, :EN, :NE, :SE, :ES) + + ind = Dict() if origin == :NW for i ∈ 1:m, j ∈ 1:n - push!(bind, (i, j) => (i-1)*n+j) + push!(ind, (i, j) => (i-1) * n + j) end elseif origin == :WN for i ∈ 1:n, j ∈ 1:m - push!(bind, (i, j) => (j-1)*n+i) + push!(ind, (i, j) => (j-1) * n + i) end elseif origin == :EN for i ∈ 1:n, j ∈ 1:m - push!(bind, (i, j) => (j-1)*n+(n+1-i)) + push!(ind, (i, j) => (j-1) * n + (n + 1 - i)) end elseif origin == :NE for i ∈ 1:n, j ∈ 1:m - push!(bind, (i, j) => (i-1)*n+(n+1-j)) + push!(ind, (i, j) => (i - 1) * n + (n + 1 - j)) end elseif origin == :SE for i ∈ 1:n, j ∈ 1:m - push!(bind, (i, j) => (m-i)*n+(n+1-j)) + push!(ind, (i, j) => (m - i) * n + (n + 1 - j)) end elseif origin == :ES for i ∈ 1:n, j ∈ 1:m - push!(bind, (i, j) => (m-j)*n+(n+1-i)) + push!(ind, (i, j) => (m - j) * n + (n + 1 - i)) end end if origin == :NW i_max = m j_max = n - else i_max = n j_max = m @@ -107,11 +107,11 @@ function Base.LinearIndices(m::Int, n::Int, origin::Symbol) for i ∈ 0:i_max+1 push!(bind, (i, 0) => 0) - push!(bind, (i, j_max+1) => 0) + push!(bind, (i, j_max + 1) => 0) end for j ∈ 0:j_max+1 push!(bind, (0, j) => 0) - push!(bind, (i_max+1, j) => 0) + push!(bind, (i_max + 1, j) => 0) end bind, i_max, j_max From 0c69fc16761189142ff27a2cdd433d861fe785ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 4 Jan 2021 18:46:58 +0100 Subject: [PATCH 088/137] fix further bugs --- src/graph.jl | 1 - src/utils.jl | 12 ++++++------ test/graph.jl | 8 ++++++++ test/runtests.jl | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index b1428129..66f7cf8b 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -25,7 +25,6 @@ mutable struct Cluster vlist = intersect(active, vlist) L = length(collect(vlist)) - cl.h = zeros(L) cl.J = zeros(L, L) diff --git a/src/utils.jl b/src/utils.jl index be596cb6..4eda4f98 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -68,7 +68,7 @@ function LinearAlgebra.svd(A::AbstractMatrix, Dcut::Int, args...) end function Base.LinearIndices(m::Int, n::Int, origin::Symbol) - @asset origin ∈ (:NW, :WN, :EN, :NE, :SE, :ES) + @assert origin ∈ (:NW, :WN, :EN, :NE, :SE, :ES) ind = Dict() if origin == :NW @@ -106,15 +106,15 @@ function Base.LinearIndices(m::Int, n::Int, origin::Symbol) end for i ∈ 0:i_max+1 - push!(bind, (i, 0) => 0) - push!(bind, (i, j_max + 1) => 0) + push!(ind, (i, 0) => 0) + push!(ind, (i, j_max + 1) => 0) end for j ∈ 0:j_max+1 - push!(bind, (0, j) => 0) - push!(bind, (i_max + 1, j) => 0) + push!(ind, (0, j) => 0) + push!(ind, (i_max + 1, j) => 0) end - bind, i_max, j_max + ind, i_max, j_max end @generated function _unique_dims(A::AbstractArray{T,N}, dim::Integer) where {T,N} diff --git a/test/graph.jl b/test/graph.jl index 9bab66e0..adf5d45c 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -8,6 +8,8 @@ using CSV n = 4 t = 4 + β = 1 + L = n * m * (2 * t) instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" @@ -40,6 +42,12 @@ using CSV @test isempty(intersect(clv...)) @test isempty(intersect(cle...)) + + + peps = PepsNetwork(m, n, fg, β, :NW) + for i ∈ 1:m, j ∈ 1:n + @time A = generate_tensor(peps, (i, j)) + end end @testset "Testing factor graph" begin diff --git a/test/runtests.jl b/test/runtests.jl index 8a5074d9..a52542c8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,8 +36,8 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - #"graph.jl", - "PEPS.jl", + "graph.jl", + #"PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", # problems From ab07779b38e16897f9ad496ae2b383c25341cdea Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Mon, 4 Jan 2021 20:27:14 +0100 Subject: [PATCH 089/137] complete LinearIndices --- src/utils.jl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 4eda4f98..7f370f32 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -68,7 +68,7 @@ function LinearAlgebra.svd(A::AbstractMatrix, Dcut::Int, args...) end function Base.LinearIndices(m::Int, n::Int, origin::Symbol) - @assert origin ∈ (:NW, :WN, :EN, :NE, :SE, :ES) + @assert origin ∈ (:NW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) ind = Dict() if origin == :NW @@ -79,25 +79,33 @@ function Base.LinearIndices(m::Int, n::Int, origin::Symbol) for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (j-1) * n + i) end + elseif origin == :NE + for i ∈ 1:m, j ∈ 1:n + push!(ind, (i, j) => (i - 1) * n + (n + 1 - j)) + end elseif origin == :EN for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (j-1) * n + (n + 1 - i)) end - elseif origin == :NE - for i ∈ 1:n, j ∈ 1:m - push!(ind, (i, j) => (i - 1) * n + (n + 1 - j)) - end elseif origin == :SE - for i ∈ 1:n, j ∈ 1:m + for i ∈ 1:m, j ∈ 1:n push!(ind, (i, j) => (m - i) * n + (n + 1 - j)) end elseif origin == :ES for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (m - j) * n + (n + 1 - i)) end + elseif origin == :SW + for i ∈ 1:m, j ∈ 1:n + push!(ind, (i, j) => (m - i) * n + j) + end + elseif origin == :WS + for i ∈ 1:n, j ∈ 1:m + push!(ind, (i, j) => (m - j) * n + i) + end end - if origin == :NW + if origin == :NW || origin == :NE || origin == :SE || origin == :SW i_max = m j_max = n else From e69cf6cff3ed077e411bee10cabc0a2347197fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 4 Jan 2021 23:41:17 +0100 Subject: [PATCH 090/137] fix bug in generate_peps --- src/PEPS.jl | 16 ++++++++-------- src/graph.jl | 32 +++++++------------------------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 4a3ecb92..cf0038d0 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -33,14 +33,14 @@ function generate_tensor_general(ng::NetworkGraph, v::Int) if has_edge(ng.factor_graph, w, v) _, _, pv = get_prop(ng.factor_graph, w, v, :decomposition) - @eval @cast tensor[σ, s, γ] |= tensor[σ, s] * pv[γ, σ] + @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[γ, σ] elseif has_edge(ng.factor_graph, v, w) pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) - @eval @cast tensor[σ, s, γ] |= tensor[σ, s] * pv[σ, γ] + @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[σ, γ] else pv = ones(length(loc_en), 1) - @eval @cast tensor[σ, s, γ] |= tensor[σ, s] * pv[σ, γ] + @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[σ, γ] end end tensor @@ -62,9 +62,9 @@ function generate_tensor(ng::NetworkGraph, v::Int) end push!(p_list, i => pv) end - + L, R, U, D = p_list[1], p_list[2], p_list[3], p_list[4] - @cast tensor[l, u, r, d, σ] |= ten_loc[σ] * L[σ, l] * R[σ, u] * U[σ, r] * D[σ, d] + @cast tensor[l, u, r, d, σ] |= L[σ, l] * U[σ, u] * R[σ, r] * D[σ, d] * ten_loc[σ] tensor end @@ -86,13 +86,13 @@ mutable struct PepsNetwork size::NTuple{2, Int} map::Dict network_graph::NetworkGraph - orientation::Symbol + origin::Symbol i_max::Int j_max::Int - function PepsNetwork(m::Int, n::Int, fg::MetaDiGraph, β::Number, orientation::Symbol) + function PepsNetwork(m::Int, n::Int, fg::MetaDiGraph, β::Number, origin::Symbol) pn = new((m, n)) - pn.map, pn.i_max, pn.j_max = LinearIndices(m, n, orientation) + pn.map, pn.i_max, pn.j_max = LinearIndices(m, n, origin) nbrs = Dict() for i ∈ 1:m, j ∈ 1:n diff --git a/src/graph.jl b/src/graph.jl index 66f7cf8b..8ec1d898 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -100,7 +100,10 @@ function factor_graph( for v ∈ vertices(fg) cl = Cluster(ig, v) set_prop!(fg, v, :cluster, cl) - set_prop!(fg, v, :spectrum, spectrum(cl)) + + sp = spectrum(cl) + set_prop!(fg, v, :spectrum, sp) + set_prop!(fg, v, :loc_en, vec(sp.energies)) end for i ∈ 1:L, j ∈ i+1:L @@ -110,40 +113,19 @@ function factor_graph( edg = Edge(ig, v, w) if !isempty(edg.edges) e = SimpleEdge(i, j) + add_edge!(fg, e) set_prop!(fg, e, :edge, edg) + pl, en = rank_reveal(energy(fg, edg), :PE) en, pr = rank_reveal(en, :EP) set_prop!(fg, e, :decomposition, (pl, en, pr)) end end - - for v ∈ vertices(fg) - en = get_prop(fg, v, :spectrum).energies - set_prop!(fg, v, :loc_en, vec(en)) - end - fg end -#= -function decompose_edges!(fg::MetaGraph) - - for edge ∈ edges(fg) - energy = get_prop(fg, edge, :energy) - - pl, en = rank_reveal(energy, :PE) - en, pr = rank_reveal(en, :EP) - - set_prop!(fg, edge, :decomposition, (pl, en, pr)) - end - for v ∈ vertices(fg) - en = get_prop(fg, v, :spectrum).energies - set_prop!(fg, v, :loc_en, vec(en)) - end -end -=# - +# needs to be rewritten! function rank_reveal(energy, order=:PE) @assert order ∈ (:PE, :EP) dim = order == :PE ? 1 : 2 From 194eae3af02cdf8aedb81480a641cc28c2c25f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 5 Jan 2021 12:01:48 +0100 Subject: [PATCH 091/137] fix bugs in generate_tensor --- src/PEPS.jl | 10 ++++------ test/runtests.jl | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index cf0038d0..fdd7851c 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -33,15 +33,13 @@ function generate_tensor_general(ng::NetworkGraph, v::Int) if has_edge(ng.factor_graph, w, v) _, _, pv = get_prop(ng.factor_graph, w, v, :decomposition) - @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[γ, σ] - + pv = pv' elseif has_edge(ng.factor_graph, v, w) pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) - @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[σ, γ] else pv = ones(length(loc_en), 1) - @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[σ, γ] end + @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[σ, γ] end tensor end @@ -63,8 +61,8 @@ function generate_tensor(ng::NetworkGraph, v::Int) push!(p_list, i => pv) end - L, R, U, D = p_list[1], p_list[2], p_list[3], p_list[4] - @cast tensor[l, u, r, d, σ] |= L[σ, l] * U[σ, u] * R[σ, r] * D[σ, d] * ten_loc[σ] + L, U, R, D = p_list[1], p_list[2], p_list[3], p_list[4] + @cast tensor[l, u, r, d, σ] |= L[σ, l] * U[σ, u] * R[σ, r] * D[σ, d] * ten_loc[σ] tensor end diff --git a/test/runtests.jl b/test/runtests.jl index a52542c8..8a5074d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,8 +36,8 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - "graph.jl", - #"PEPS.jl", + #"graph.jl", + "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", # problems From a10f2495512e09f44bfda4122635b70455887892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 5 Jan 2021 13:50:30 +0100 Subject: [PATCH 092/137] fix peps_tensor in general case --- src/PEPS.jl | 23 ++++++++++++++--------- test/PEPS.jl | 21 ++++++--------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index fdd7851c..352c3989 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,6 +1,6 @@ export NetworkGraph, PepsNetwork export generate_tensor, MPO - + mutable struct NetworkGraph factor_graph::MetaDiGraph nbrs::Dict @@ -22,29 +22,33 @@ mutable struct NetworkGraph end end -# This still does not work (mixing @eval and @cast gives unexpected results) -function generate_tensor_general(ng::NetworkGraph, v::Int) +function generate_tensor(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.factor_graph, v, :loc_en) tensor = exp.(-ng.β .* loc_en) - for w ∈ ng.nbrs[v] - n = max(1, ndims(tensor)-1) - s = :(@ntuple $n i) + dim = [] + @cast tensor[_, i] := tensor[i] + for w ∈ ng.nbrs[v] if has_edge(ng.factor_graph, w, v) _, _, pv = get_prop(ng.factor_graph, w, v, :decomposition) pv = pv' + elseif has_edge(ng.factor_graph, v, w) pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) else pv = ones(length(loc_en), 1) end - @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[σ, γ] + + push!(dim, size(pv, 2)) + @cast tensor[c, γ, σ] := tensor[c, σ] * pv[σ, γ] + @cast tensor[(c, γ), σ] := tensor[c, γ, σ] end - tensor + + reshape(tensor, dim..., :) end -function generate_tensor(ng::NetworkGraph, v::Int) +function _generate_tensor(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.factor_graph, v, :loc_en) ten_loc = exp.(-ng.β .* loc_en) @@ -66,6 +70,7 @@ function generate_tensor(ng::NetworkGraph, v::Int) tensor end +_generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = _generate_tensor(pn.network_graph, pn.map[m]) function generate_tensor(ng::NetworkGraph, v::Int, w::Int) if has_edge(ng.factor_graph, w, v) diff --git a/test/PEPS.jl b/test/PEPS.jl index 33254b10..52268373 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -1,4 +1,3 @@ - @testset "PepsTensor correctly builds PEPS network" begin m = 3 @@ -28,22 +27,14 @@ y = n peps = PepsNetwork(x, y, fg, β, :NW) println(typeof(peps)) -for i ∈ 2:2, j ∈ 1:y - println(i, j) - @time A = generate_tensor(peps, (i, j)) - println(size(A)) +for i ∈ 1:x, j ∈ 1:y + A = SpinGlassPEPS._generate_tensor(peps, (i, j)) + B = generate_tensor(peps, (i, j)) + @test A ≈ B end -i=2 -for j ∈ 1:y-1 - A = generate_tensor(peps, (i, j), (i, j+1)) - println(size(A)) -end - -for i ∈ 1:x - println(i) - @time mpo = MPO(peps, i) - println(size(mpo)) +for i ∈ 1:x, j ∈ 1:y + @time A = generate_tensor(peps, (i, j)) end mpo = MPO(peps, 1) From 2d85cbabdf4bbe8eab0417ddf3d4b791ef3ae9b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 5 Jan 2021 14:33:18 +0100 Subject: [PATCH 093/137] improve casting in generate_tensor --- src/PEPS.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 352c3989..77587800 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -24,10 +24,10 @@ end function generate_tensor(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.factor_graph, v, :loc_en) - tensor = exp.(-ng.β .* loc_en) + loc_exp = exp.(-ng.β .* loc_en) dim = [] - @cast tensor[_, i] := tensor[i] + @cast tensor[_, i] := loc_exp[i] for w ∈ ng.nbrs[v] if has_edge(ng.factor_graph, w, v) @@ -41,8 +41,7 @@ function generate_tensor(ng::NetworkGraph, v::Int) end push!(dim, size(pv, 2)) - @cast tensor[c, γ, σ] := tensor[c, σ] * pv[σ, γ] - @cast tensor[(c, γ), σ] := tensor[c, γ, σ] + @cast tensor[(c, γ), σ] |= tensor[c, σ] * pv[σ, γ] end reshape(tensor, dim..., :) From 1e54c7b5c71e48f68bdfd3ff79aae68c8e9e9037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 5 Jan 2021 14:55:24 +0100 Subject: [PATCH 094/137] modify aux functions --- src/PEPS.jl | 48 ++++++++++++++++++++++++------------------------ src/graph.jl | 2 +- src/utils.jl | 44 ++++++++++++-------------------------------- 3 files changed, 37 insertions(+), 57 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 77587800..2ef9cd48 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -23,60 +23,60 @@ mutable struct NetworkGraph end function generate_tensor(ng::NetworkGraph, v::Int) - loc_en = get_prop(ng.factor_graph, v, :loc_en) - loc_exp = exp.(-ng.β .* loc_en) + fg = ng.factor_graph + loc_exp = exp.(-ng.β .* get_prop(fg, v, :loc_en)) dim = [] @cast tensor[_, i] := loc_exp[i] for w ∈ ng.nbrs[v] - if has_edge(ng.factor_graph, w, v) - _, _, pv = get_prop(ng.factor_graph, w, v, :decomposition) + if has_edge(fg, w, v) + _, _, pv = get_prop(fg, w, v, :split) pv = pv' - - elseif has_edge(ng.factor_graph, v, w) - pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) + elseif has_edge(fg, v, w) + pv, _, _ = get_prop(fg, v, w, :split) else - pv = ones(length(loc_en), 1) + pv = ones(length(loc_exp), 1) end - push!(dim, size(pv, 2)) @cast tensor[(c, γ), σ] |= tensor[c, σ] * pv[σ, γ] + push!(dim, size(pv, 2)) end reshape(tensor, dim..., :) end function _generate_tensor(ng::NetworkGraph, v::Int) - loc_en = get_prop(ng.factor_graph, v, :loc_en) - ten_loc = exp.(-ng.β .* loc_en) + fg = ng.factor_graph + loc_exp = exp.(-ng.β .* get_prop(fg, v, :loc_en)) - p_list = Dict() + projs = Dict() for (i, w) ∈ enumerate(ng.nbrs[v]) - if has_edge(ng.factor_graph, w, v) - _, _, pv = get_prop(ng.factor_graph, w, v, :decomposition) + if has_edge(fg, w, v) + _, _, pv = get_prop(fg, w, v, :split) pv = pv' - elseif has_edge(ng.factor_graph, v, w) - pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) + elseif has_edge(fg, v, w) + pv, _, _ = get_prop(fg, v, w, :split) else - pv = ones(length(loc_en), 1) + pv = ones(length(loc_exp), 1) end - push!(p_list, i => pv) + push!(projs, i => pv) end - L, U, R, D = p_list[1], p_list[2], p_list[3], p_list[4] - @cast tensor[l, u, r, d, σ] |= L[σ, l] * U[σ, u] * R[σ, r] * D[σ, d] * ten_loc[σ] + L, U, R, D = projs[1], projs[2], projs[3], projs[4] + @cast tensor[l, u, r, d, σ] |= L[σ, l] * U[σ, u] * R[σ, r] * D[σ, d] * loc_exp[σ] tensor end _generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = _generate_tensor(pn.network_graph, pn.map[m]) function generate_tensor(ng::NetworkGraph, v::Int, w::Int) - if has_edge(ng.factor_graph, w, v) - _, e, _ = get_prop(ng.factor_graph, w, v, :decomposition) + fg = ng.factor_graph + if has_edge(fg, w, v) + _, e, _ = get_prop(fg, w, v, :split) tensor = exp.(-ng.β .* e') - elseif has_edge(ng.factor_graph, v, w) - _, e, _ = get_prop(ng.factor_graph, v, w, :decomposition) + elseif has_edge(fg, v, w) + _, e, _ = get_prop(fg, v, w, :split) tensor = exp.(-ng.β .* e) else tensor = ones(1, 1) diff --git a/src/graph.jl b/src/graph.jl index 8ec1d898..7e99fd24 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -119,7 +119,7 @@ function factor_graph( pl, en = rank_reveal(energy(fg, edg), :PE) en, pr = rank_reveal(en, :EP) - set_prop!(fg, e, :decomposition, (pl, en, pr)) + set_prop!(fg, e, :split, (pl, en, pr)) end end fg diff --git a/src/utils.jl b/src/utils.jl index 7f370f32..732575f6 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,7 +1,6 @@ export idx, ising, proj export HadamardMPS, rq export all_states, local_basis -export enum using Base.Cartesian import Base.Prehashed @@ -9,8 +8,6 @@ import Base.Prehashed idx(σ::Int) = (σ == -1) ? 1 : σ + 1 _σ(idx::Int) = (idx == 1) ? -1 : idx - 1 -enum(vec) = Dict(v => i for (i, v) ∈ enumerate(vec)) - LinearAlgebra.I(ψ::AbstractMPS, i::Int) = I(size(ψ[i], 2)) local_basis(d::Int) = union(-1, 1:d-1) @@ -72,51 +69,34 @@ function Base.LinearIndices(m::Int, n::Int, origin::Symbol) ind = Dict() if origin == :NW - for i ∈ 1:m, j ∈ 1:n - push!(ind, (i, j) => (i-1) * n + j) - end + for i ∈ 1:m, j ∈ 1:n push!(ind, (i, j) => (i-1) * n + j) end elseif origin == :WN - for i ∈ 1:n, j ∈ 1:m - push!(ind, (i, j) => (j-1) * n + i) - end + for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (j-1) * n + i) end elseif origin == :NE - for i ∈ 1:m, j ∈ 1:n - push!(ind, (i, j) => (i - 1) * n + (n + 1 - j)) - end + for i ∈ 1:m, j ∈ 1:n push!(ind, (i, j) => (i - 1) * n + (n + 1 - j)) end elseif origin == :EN - for i ∈ 1:n, j ∈ 1:m - push!(ind, (i, j) => (j-1) * n + (n + 1 - i)) - end + for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (j-1) * n + (n + 1 - i)) end elseif origin == :SE - for i ∈ 1:m, j ∈ 1:n - push!(ind, (i, j) => (m - i) * n + (n + 1 - j)) - end + for i ∈ 1:m, j ∈ 1:n push!(ind, (i, j) => (m - i) * n + (n + 1 - j)) end elseif origin == :ES - for i ∈ 1:n, j ∈ 1:m - push!(ind, (i, j) => (m - j) * n + (n + 1 - i)) - end + for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (m - j) * n + (n + 1 - i)) end elseif origin == :SW - for i ∈ 1:m, j ∈ 1:n - push!(ind, (i, j) => (m - i) * n + j) - end + for i ∈ 1:m, j ∈ 1:n push!(ind, (i, j) => (m - i) * n + j) end elseif origin == :WS - for i ∈ 1:n, j ∈ 1:m - push!(ind, (i, j) => (m - j) * n + i) - end + for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (m - j) * n + i) end end - if origin == :NW || origin == :NE || origin == :SE || origin == :SW - i_max = m - j_max = n + if origin ∈ (:NW, :NE, :SE, :SW) + i_max, j_max = m, n else - i_max = n - j_max = m + i_max, j_max = n, m end for i ∈ 0:i_max+1 push!(ind, (i, 0) => 0) push!(ind, (i, j_max + 1) => 0) end + for j ∈ 0:j_max+1 push!(ind, (0, j) => 0) push!(ind, (i_max + 1, j) => 0) From 59d68633af4e9d468c6a6e7bd574b1885c2449f2 Mon Sep 17 00:00:00 2001 From: kdomino Date: Tue, 5 Jan 2021 14:59:25 +0100 Subject: [PATCH 095/137] merge and correct testing --- benchmarks/low_energy_approx_chimera.jl | 4 +- {test => benchmarks}/tests_grid_from_file.jl | 0 {test => benchmarks}/tests_on_chimera.jl | 4 +- src/PEPS.jl | 45 ++++-------- src/SpinGlassPEPS.jl | 4 +- src/graph.jl | 75 ++++++-------------- src/ising.jl | 45 ++++++------ test/PEPS.jl | 15 ++-- test/graph.jl | 25 +++---- test/notation_tests.jl | 6 +- test/peps_tests.jl | 4 +- test/runtests.jl | 12 ++-- 12 files changed, 86 insertions(+), 153 deletions(-) rename {test => benchmarks}/tests_grid_from_file.jl (100%) rename {test => benchmarks}/tests_on_chimera.jl (97%) diff --git a/benchmarks/low_energy_approx_chimera.jl b/benchmarks/low_energy_approx_chimera.jl index c1cb761e..dad981af 100644 --- a/benchmarks/low_energy_approx_chimera.jl +++ b/benchmarks/low_energy_approx_chimera.jl @@ -28,7 +28,7 @@ end s = ArgParseSettings("description") @add_arg_table! s begin - "--file", "-f" + "--file", "-i" arg_type = String help = "the file name" "--size", "-s" @@ -72,7 +72,7 @@ problem_size = parse_args(s)["size"] χ = parse_args(s)["chi"] si = parse_args(s)["size"] -ig = ising_graph(fi, si, 1, 1) +ig = ising_graph(fi, si, 1) n_sols = parse_args(s)["n_sols"] node_size = (parse_args(s)["node_size1"], parse_args(s)["node_size2"]) diff --git a/test/tests_grid_from_file.jl b/benchmarks/tests_grid_from_file.jl similarity index 100% rename from test/tests_grid_from_file.jl rename to benchmarks/tests_grid_from_file.jl diff --git a/test/tests_on_chimera.jl b/benchmarks/tests_on_chimera.jl similarity index 97% rename from test/tests_on_chimera.jl rename to benchmarks/tests_on_chimera.jl index 0437502f..e8efa9a5 100644 --- a/test/tests_on_chimera.jl +++ b/benchmarks/tests_on_chimera.jl @@ -27,7 +27,7 @@ end s = ArgParseSettings("description") @add_arg_table! s begin - "--file", "-f" + "--file", "-i" arg_type = String help = "the file name" "--size", "-s" @@ -71,7 +71,7 @@ problem_size = parse_args(s)["size"] χ = parse_args(s)["chi"] si = parse_args(s)["size"] -ig = ising_graph(fi, si, 1, 1) +ig = ising_graph(fi, si, 1) n_sols = parse_args(s)["n_sols"] node_size = (parse_args(s)["node_size1"], parse_args(s)["node_size2"]) diff --git a/src/PEPS.jl b/src/PEPS.jl index b396e030..49e2c400 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -7,30 +7,16 @@ mutable struct NetworkGraph β::Number function NetworkGraph(factor_graph::MetaDiGraph, nbrs::Dict, β::Number) - ng = new(factor_graph, nbrs, β) + ng = new(factor_graph, nbrs, β) count = 0 for v ∈ vertices(ng.factor_graph), w ∈ ng.nbrs[v] if has_edge(ng.factor_graph, v, w) count += 1 end - pc.loc = get_prop(fg, v, :local_exp) - - outgoing = outneighbors(fg, v) - incoming = inneighbors(fg, v) - - for u ∈ outgoing - e = SimpleEdge(v, u) - if get_prop(fg, e, :orientation) == "horizontal" - pc.right = first(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "h_out" => u) - else - pc.down = first(get_prop(fg, e, :decomposition)) - push!(pc.nbrs, "v_out" => u) - end end mc = ne(ng.factor_graph) if count < mc - error("Error: $(count) < $(mc)") + error("Error: $(count) < $(mc)") end ng end @@ -50,7 +36,7 @@ function generate_tensor_general(ng::NetworkGraph, v::Int) pv = pv' elseif has_edge(ng.factor_graph, v, w) pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) - else + else pv = ones(length(loc_en), 1) end @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[σ, γ] @@ -63,13 +49,13 @@ function generate_tensor(ng::NetworkGraph, v::Int) ten_loc = exp.(-ng.β .* loc_en) p_list = Dict() - for (i, w) ∈ enumerate(ng.nbrs[v]) + for (i, w) ∈ enumerate(ng.nbrs[v]) if has_edge(ng.factor_graph, w, v) _, _, pv = get_prop(ng.factor_graph, w, v, :decomposition) pv = pv' elseif has_edge(ng.factor_graph, v, w) pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) - else + else pv = ones(length(loc_en), 1) end push!(p_list, i => pv) @@ -84,11 +70,11 @@ end function generate_tensor(ng::NetworkGraph, v::Int, w::Int) if has_edge(ng.factor_graph, w, v) _, e, _ = get_prop(ng.factor_graph, w, v, :decomposition) - tensor = exp.(-ng.β .* e') + tensor = exp.(-ng.β .* e') elseif has_edge(ng.factor_graph, v, w) _, e, _ = get_prop(ng.factor_graph, v, w, :decomposition) - tensor = exp.(-ng.β .* e) - else + tensor = exp.(-ng.β .* e) + else tensor = ones(1, 1) end tensor @@ -103,13 +89,13 @@ mutable struct PepsNetwork j_max::Int function PepsNetwork(m::Int, n::Int, fg::MetaDiGraph, β::Number, origin::Symbol) - pn = new((m, n)) + pn = new((m, n)) pn.map, pn.i_max, pn.j_max = LinearIndices(m, n, origin) nbrs = Dict() for i ∈ 1:m, j ∈ 1:n - push!(nbrs, - pn.map[i, j] => (pn.map[i, j-1], pn.map[i-1, j], + push!(nbrs, + pn.map[i, j] => (pn.map[i, j-1], pn.map[i-1, j], pn.map[i, j+1], pn.map[i+1, j])) end pn.network_graph = NetworkGraph(fg, nbrs, β) @@ -123,7 +109,7 @@ generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}, n::NTuple{2,Int}) = generate_ function MPO(peps::PepsNetwork, i::Int; type::DataType=Float64) n = peps.j_max ψ = MPO(type, n) - + for j ∈ 1:n A = generate_tensor(peps, (i, j)) @reduce B[l, u, r ,d] |= sum(σ) A[l, u, r, d, σ] @@ -137,11 +123,4 @@ function MPO(peps::PepsNetwork, i::Int; type::DataType=Float64) ψ[j] = B end ψ - end - @cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d] - - pc - end end - -Base.size(A::PepsTensor) = size(A.tensor) \ No newline at end of file diff --git a/src/SpinGlassPEPS.jl b/src/SpinGlassPEPS.jl index 1e2c8d9b..edade237 100644 --- a/src/SpinGlassPEPS.jl +++ b/src/SpinGlassPEPS.jl @@ -15,8 +15,8 @@ module SpinGlassPEPS include("compressions.jl") include("contractions.jl") include("lattice.jl") - include("graphs/chimera.jl") - include("graphs/lattice.jl") + #include("graphs/chimera.jl") + #include("graphs/lattice.jl") include("graph.jl") include("ising.jl") include("PEPS.jl") diff --git a/src/graph.jl b/src/graph.jl index e32fd365..8de16100 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -4,9 +4,6 @@ export Cluster, rank_reveal const SimpleEdge = LightGraphs.SimpleGraphs.SimpleEdge const EdgeIter = Union{LightGraphs.SimpleGraphs.SimpleEdgeIter, Base.Iterators.Filter, Array} - J::Matrix{<:Number} - h::Vector{<:Number} - mutable struct Cluster tag::Int vertices::Dict{Int, Int} @@ -23,25 +20,19 @@ mutable struct Cluster vlist = vertices(ig) else vlist = filter_vertices(ig, :cell, v) - end + end vlist = intersect(active, vlist) L = length(collect(vlist)) cl.h = zeros(L) cl.J = zeros(L, L) - j = cl.vertices[dst(e)] - @inbounds cl.J[i, j] = get_prop(ig, e, :J) - end cl.vertices = Dict() cl.edges = SimpleEdge[] rank = get_prop(ig, :rank) cl.rank = rank[1:L] - @inbounds cl.h[i] = get_prop(ig, w, :h) - @inbounds cl.rank[i] = rank[w] - end - cl + for (i, w) ∈ enumerate(vlist) push!(cl.vertices, w => i) @inbounds cl.h[i] = get_prop(ig, w, :h) @@ -50,19 +41,15 @@ mutable struct Cluster for e ∈ edges(ig) if src(e) ∈ vlist && dst(e) ∈ vlist - i, j = cl.vertices[src(e)], cl.vertices[dst(e)] + i, j = cl.vertices[src(e)], cl.vertices[dst(e)] @inbounds cl.J[i, j] = get_prop(ig, e, :J) push!(cl.edges, e) end end cl end - ed.edges = filter_edges(ig, v, w) - for e ∈ ed.edges - i = v.vertices[src(e)] - j = w.vertices[dst(e)] - @inbounds ed.J[i, j] = get_prop(ig, e, :J) - end +end + function MetaGraphs.filter_edges(ig::MetaGraph, v::Cluster, w::Cluster) edges = SimpleEdge[] for i ∈ keys(v.vertices), j ∈ neighbors(ig, i) @@ -78,91 +65,71 @@ mutable struct Edge function Edge(ig::MetaGraph, v::Cluster, w::Cluster) ed = new((v.tag, w.tag)) - ed.edges = filter_edges(ig, v, w) - + ed.edges = filter_edges(ig, v, w) + m = length(v.vertices) n = length(w.vertices) ed.J = zeros(m, n) for e ∈ ed.edges i = v.vertices[src(e)] - j = w.vertices[dst(e)] + j = w.vertices[dst(e)] @inbounds ed.J[i, j] = get_prop(ig, e, :J) end ed end - end - dg +end + function _mv(ig::MetaGraph) L = 0 for v ∈ vertices(ig) - L = max(L, get_prop(ig, v, :cell)) + L = max(L, get_prop(ig, v, :cell)) end L -end +end function factor_graph( ig::MetaGraph; - energy::Function=energy, - spectrum::Function=full_spectrum, -) + energy::Function=energy, + spectrum::Function=full_spectrum, +) L = _mv(ig) fg = MetaDiGraph(L, 0.0) -) - m, n, _ = g.size - fg = factor_graph(m, n, hdir, vdir) for v ∈ vertices(fg) cl = Cluster(ig, v) set_prop!(fg, v, :cluster, cl) - end sp = spectrum(cl) set_prop!(fg, v, :spectrum, sp) set_prop!(fg, v, :loc_en, vec(sp.energies)) - set_prop!(fg, e, :energy, energy(fg, edge)) end for i ∈ 1:L, j ∈ i+1:L v = get_prop(fg, i, :cluster) w = get_prop(fg, j, :cluster) - + edg = Edge(ig, v, w) if !isempty(edg.edges) e = SimpleEdge(i, j) add_edge!(fg, e) set_prop!(fg, e, :edge, edg) - + pl, en = rank_reveal(energy(fg, edg), :PE) en, pr = rank_reveal(en, :EP) set_prop!(fg, e, :decomposition, (pl, en, pr)) - else - en, p = rank_reveal(energy, order) - dec = (exp.(-β .* en), p) end - - set_prop!(fg, edge, :decomposition, dec) - end - for v ∈ vertices(fg) - en = get_prop(fg, v, :spectrum).energies - set_prop!(fg, v, :local_exp, vec(exp.(-β .* en))) end + fg end - -function rank_reveal(energy, order=:PE) - @assert order ∈ (:PE, :EP) - dim = order == :PE ? 1 : 2 - - E = unique(energy, dims=dim) - idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) - P = order == :PE ? zeros(size(energy, 1), size(E, 1)) : zeros(size(E, 2), size(energy, 2)) + # needs to be rewritten! function rank_reveal(energy, order=:PE) @assert order ∈ (:PE, :EP) dim = order == :PE ? 1 : 2 - + E = unique(energy, dims=dim) idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) @@ -173,4 +140,4 @@ function rank_reveal(energy, order=:PE) end order == :PE ? (P, E) : (E, P) -end \ No newline at end of file +end diff --git a/src/ising.jl b/src/ising.jl index 7565fe85..0c700e5b 100644 --- a/src/ising.jl +++ b/src/ising.jl @@ -12,7 +12,7 @@ Calculates Gibbs state of a classical Ising Hamiltonian # Details -Calculates matrix elements (probabilities) of \$\\rho\$ +Calculates matrix elements (probabilities) of \$\\rho\$ ```math \$\\bra{\\σ}\\rho\\ket{\\sigma}\$ ``` @@ -28,7 +28,7 @@ end """ $(TYPEDSIGNATURES) -Calculate the Ising energy +Calculate the Ising energy ```math E = -\\sum_ s_i J_{ij} * s_j - \\sum_j h_i s_j. ``` @@ -38,24 +38,20 @@ energy(σ::Vector, J::Matrix, η::Vector=σ) = dot(σ, J, η) energy(σ::Vector, h::Vector) = dot(h, σ) energy(σ::Vector, cl::Cluster, η::Vector=σ) = energy(σ, cl.J, η) + energy(cl.h, σ) energy(σ::Vector, ig::MetaGraph) = energy(σ, get_prop(ig, :J)) + energy(σ, get_prop(ig, :h)) - -function energy(fg::MetaDiGraph, edge::Edge) + +function energy(fg::MetaDiGraph, edge::Edge) v, w = edge.tag vSp = get_prop(fg, v, :spectrum).states wSp = get_prop(fg, w, :spectrum).states - + m = prod(size(vSp)) n = prod(size(wSp)) - wSp = get_prop(fg, w, :spectrum).states - en = zeros(m, n) + en = zeros(m, n) for (j, η) ∈ enumerate(vec(wSp)) - en[:, j] = energy.(vec(vSp), Ref(edge.J), Ref(η)) - end - en - en[:, j] = energy.(vec(vSp), Ref(edge.J), Ref(η)) + en[:, j] = energy.(vec(vSp), Ref(edge.J), Ref(η)) end - en + en end """ @@ -73,7 +69,7 @@ function ising_graph(instance::Instance, L::Int, sgn::Number=1.0) if typeof(instance) == String ising = CSV.File(instance, types = [Int, Int, Float64], header=0, comment = "#") else - ising = [ (i, j, J) for ((i, j), J) ∈ instance ] + ising = [ (i, j, J) for ((i, j), J) ∈ instance ] end ig = MetaGraph(L, 0.0) @@ -89,27 +85,26 @@ function ising_graph(instance::Instance, L::Int, sgn::Number=1.0) h = zeros(L) # setup the model (J_ij, h_i) - for (i, j, v) ∈ ising + for (i, j, v) ∈ ising v *= sgn if i == j set_prop!(ig, i, :h, v) || error("Node $i missing!") h[i] = v else - if has_edge(ig, j, i) - error("Cannot add ($i, $j) as ($j, $i) already exists!") + if has_edge(ig, j, i) + error("Cannot add ($i, $j) as ($j, $i) already exists!") end - end - add_edge!(ig, i, j) && - set_prop!(ig, i, j, :J, v) || error("Cannot add Egde ($i, $j)") + add_edge!(ig, i, j) && + set_prop!(ig, i, j, :J, v) || error("Cannot add Egde ($i, $j)") J[i, j] = v - end + end set_prop!(ig, i, :active, true) || error("Cannot activate node $(i)!") set_prop!(ig, j, :active, true) || error("Cannot activate node $(j)!") - end + end - # store extra information + # store extra information set_prop!(ig, :rank, fill(2, L)) set_prop!(ig, :J, J) @@ -129,7 +124,7 @@ Calculate unique neighbors of node \$i\$ # Details -This is equivalent of taking the upper +This is equivalent of taking the upper diagonal of the adjacency matrix """ function unique_neighbors(ig::MetaGraph, i::Int) @@ -137,8 +132,8 @@ function unique_neighbors(ig::MetaGraph, i::Int) filter(j -> j > i, nbrs) end - -function update_cells!(ig::MetaGraph; rule::Dict) + +function update_cells!(ig::MetaGraph; rule::Dict) for v ∈ vertices(ig) w = get_prop(ig, v, :cell) set_prop!(ig, v, :cell, rule[w]) diff --git a/test/PEPS.jl b/test/PEPS.jl index 36542a2e..5b0aee3c 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -9,17 +9,17 @@ t = 3 L = m * n * t -instance = "$(@__DIR__)/instances/pathological/test_$(m)_$(n)_$(t).txt" +instance = "$(@__DIR__)/instances/pathological/test_$(m)_$(n)_$(t).txt" ig = ising_graph(instance, L) update_cells!( - ig, + ig, rule = square_lattice((m, n, t)), -) +) fg = factor_graph( - ig, - energy=energy, + ig, + energy=energy, spectrum=full_spectrum, ) @@ -54,12 +54,9 @@ end end L = 9 -instance = "$(@__DIR__)/instances/$(L)_001.txt" +instance = "$(@__DIR__)/instances/$(L)_001.txt" ig = ising_graph(instance, L) end - - -end \ No newline at end of file diff --git a/test/graph.jl b/test/graph.jl index 22b7fd49..7fbb6f26 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -12,13 +12,13 @@ using CSV t = 4 L = n * m * (2 * t) - instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" + instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" ig = ising_graph(instance, L) update_cells!( - ig, + ig, rule = square_lattice((m, n, 2*t)), - ) + ) @time fg = factor_graph(ig) @@ -45,19 +45,12 @@ using CSV @test isempty(intersect(cle...)) end -@testset "Factor graph" begin - - peps = PepsNetwork(m, n, fg, β, :NW) - for i ∈ 1:m, j ∈ 1:n - @time A = generate_tensor(peps, (i, j)) - end -end @testset "Testing factor graph" begin m = 3 n = 4 t = 3 -instance = "$(@__DIR__)/instances/pathological/test_$(m)_$(n)_$(t).txt" +instance = "$(@__DIR__)/instances/pathological/test_$(m)_$(n)_$(t).txt" β = 1 @@ -66,9 +59,9 @@ m = 4 L = m * n * t ig = ising_graph(instance, L) update_cells!( - ig, + ig, rule = square_lattice((m, n, t)), -) +) println("sq_lattice ", square_lattice((m, n, t))) for v ∈ filter_vertices(ig, :active, true) @@ -79,8 +72,8 @@ for v ∈ filter_vertices(ig, :active, true) end fg = factor_graph( - ig, - energy=energy, + ig, + energy=energy, spectrum=full_spectrum, ) @@ -123,4 +116,4 @@ end @test size(P) == (2, 3) @test size(E) == (3, 2) @test E * P ≈ energy -end \ No newline at end of file +end diff --git a/test/notation_tests.jl b/test/notation_tests.jl index f85f3a95..db80f51d 100644 --- a/test/notation_tests.jl +++ b/test/notation_tests.jl @@ -154,9 +154,9 @@ end M = props(g1, 1,2)[:M] @test size(M) == (4,16) - @test M[:,1] == [4.0, 0.0, 0.0, -4.0] + @test M[:,1] == [0.0, -4.0, 4.0, 0.0] e = [-8.0, -8.0, -2.0, -2.0, -2.0, -2.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 4.0, 12.0] - @test props(g1, 1)[:energy] == -e + @test props(g1, 1)[:energy] == e @test props(g1, 1,2)[:inds] == [3, 4] @test props(g1, 1,3)[:inds] == [2, 4] @@ -181,7 +181,7 @@ end @test get_Js(v2, v1, ig) == [2.0, 2.0] spectrum = brute_force(ig; num_states = 2) - @test M[:,1] == [4.0, 0.0, 0.0, -4.0] + #M = M_of_interaction(v2, v1, ig, spectrum.states) #@test size(M) == (4, 16) #@test M[:,1] == [-4.0, 0.0, 0.0, 4.0] diff --git a/test/peps_tests.jl b/test/peps_tests.jl index ae249bfc..12135ef2 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -4,6 +4,8 @@ import SpinGlassPEPS: compute_single_tensor, conditional_probabs, get_parameters import SpinGlassPEPS: make_lower_mps, M2graph, graph4peps, fullM2grid! import SpinGlassPEPS: set_spin_from_letf, spin_index_from_left, spin_indices_from_above import SpinGlassPEPS: energy, solve +Random.seed!(1234) + if true @testset "PEPS - axiliary functions" begin @@ -263,4 +265,4 @@ end @test objective[i] ≈ objective_l[i] atol=1e-5 @test spins[i] == spins_l[i] end -end \ No newline at end of file +end diff --git a/test/runtests.jl b/test/runtests.jl index 5afd4e2b..a77b4037 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,14 +31,14 @@ if CUDA.functional() && CUDA.has_cutensor() && false end push!(my_tests, - #"base.jl", - #"contractions.jl", - #"compressions.jl", - #"ising.jl", + "base.jl", + "contractions.jl", + "compressions.jl", + "ising.jl", "spectrum.jl", - #"graph.jl", + "graph.jl", "PEPS.jl", - #"notation_tests.jl", + "notation_tests.jl", "peps_tests.jl", "mps_tests.jl", "tests_full_graph.jl", From 92f6d34e8c617c0bc68ed188ef30b5bc1180be0b Mon Sep 17 00:00:00 2001 From: kdomino Date: Tue, 5 Jan 2021 15:15:27 +0100 Subject: [PATCH 096/137] remove old function --- src/PEPS.jl | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 49e2c400..62e77a87 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -22,28 +22,6 @@ mutable struct NetworkGraph end end -# This still does not work (mixing @eval and @cast gives unexpected results) -function generate_tensor_general(ng::NetworkGraph, v::Int) - loc_en = get_prop(ng.factor_graph, v, :loc_en) - tensor = exp.(-ng.β .* loc_en) - - for w ∈ ng.nbrs[v] - n = max(1, ndims(tensor)-1) - s = :(@ntuple $n i) - - if has_edge(ng.factor_graph, w, v) - _, _, pv = get_prop(ng.factor_graph, w, v, :decomposition) - pv = pv' - elseif has_edge(ng.factor_graph, v, w) - pv, _, _ = get_prop(ng.factor_graph, v, w, :decomposition) - else - pv = ones(length(loc_en), 1) - end - @eval @cast tensor[s, γ, σ] |= tensor[s, σ] * pv[σ, γ] - end - tensor -end - function generate_tensor(ng::NetworkGraph, v::Int) loc_en = get_prop(ng.factor_graph, v, :loc_en) ten_loc = exp.(-ng.β .* loc_en) From 1b63a9e2029a4d7c1412dcf4c630a6d63dad5835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 5 Jan 2021 15:47:22 +0100 Subject: [PATCH 097/137] improve square_lattice, and fix busg --- src/PEPS.jl | 2 +- src/lattice.jl | 14 +++++--------- src/utils.jl | 2 +- test/runtests.jl | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 2ef9cd48..63c85898 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -68,7 +68,6 @@ function _generate_tensor(ng::NetworkGraph, v::Int) tensor end -_generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = _generate_tensor(pn.network_graph, pn.map[m]) function generate_tensor(ng::NetworkGraph, v::Int, w::Int) fg = ng.factor_graph @@ -108,6 +107,7 @@ mutable struct PepsNetwork end generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m]) +_generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = _generate_tensor(pn.network_graph, pn.map[m]) generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}, n::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m], pn.map[n]) function MPO(peps::PepsNetwork, i::Int; type::DataType=Float64) diff --git a/src/lattice.jl b/src/lattice.jl index c17f2d58..52f05de3 100644 --- a/src/lattice.jl +++ b/src/lattice.jl @@ -1,18 +1,14 @@ export square_lattice + function square_lattice(size::NTuple{5, Int}) m, um, n, un, t = size - rule = Dict() + new = LinearIndices((1:n, 1:m)) + old = LinearIndices((1:t, 1:un, 1:n, 1:um, 1:m)) - linear_new = LinearIndices((1:n, 1:m)) - linear_old = LinearIndices((1:t, 1:un, 1:n, 1:um, 1:m)) - + rule = Dict() for i=1:m, ui=1:um, j=1:n, uj=1:un, k=1:t - #old = (i-1) * um * n * un * t + (ui-1) * n * un * t + (j-1) * un * t + (uj-1) * t + k - #new = (i-1) * m + j - old = linear_old[k, uj, j, ui, i] - new = linear_new[j, i] - push!(rule, old => new) + push!(rule, old[k, uj, j, ui, i] => new[j, i]) end rule end diff --git a/src/utils.jl b/src/utils.jl index 732575f6..d02489ad 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -64,7 +64,7 @@ function LinearAlgebra.svd(A::AbstractMatrix, Dcut::Int, args...) return U * Diagonal(ph), Σ, V * Diagonal(ph) end -function Base.LinearIndices(m::Int, n::Int, origin::Symbol) +function Base.LinearIndices(m::Int, n::Int, origin::Symbol=:NW) @assert origin ∈ (:NW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) ind = Dict() diff --git a/test/runtests.jl b/test/runtests.jl index 8a5074d9..975c2d93 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,7 +36,7 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - #"graph.jl", + "graph.jl", "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", From 1abcae254a9ee371251fe90c7115da074b3fc3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 5 Jan 2021 21:06:17 +0100 Subject: [PATCH 098/137] add tests involving origin --- src/PEPS.jl | 2 +- src/contractions.jl | 10 ++++++---- src/lattice.jl | 1 - src/utils.jl | 6 +++--- test/PEPS.jl | 48 ++++++++++++++++++++++++++++++--------------- test/runtests.jl | 2 +- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 63c85898..7581a0f0 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -96,7 +96,7 @@ mutable struct PepsNetwork pn.map, pn.i_max, pn.j_max = LinearIndices(m, n, origin) nbrs = Dict() - for i ∈ 1:m, j ∈ 1:n + for i ∈ 1:pn.i_max, j ∈ 1:pn.j_max push!(nbrs, pn.map[i, j] => (pn.map[i, j-1], pn.map[i-1, j], pn.map[i, j+1], pn.map[i+1, j])) diff --git a/src/contractions.jl b/src/contractions.jl index 478492b7..fe38c54d 100644 --- a/src/contractions.jl +++ b/src/contractions.jl @@ -3,9 +3,9 @@ export left_env, right_env, dot! # --------------------------- Conventions ------------------------ # # MPS MPS* MPO left env left env -# 1 1 1 - 0 1 - -# 0 - A - 2 0 - B - 2 0 - W - 2 L R -# 3 - 1 0 - +# 2 2 2 - 1 2 - +# 1 - A - 3 1 - B - 3 1 - W - 3 L R +# 4 - 2 1 - # --------------------------------------------------------------- # @@ -142,7 +142,9 @@ function LinearAlgebra.dot(O1::AbstractMPO, O2::AbstractMPO) W1 = O1[i] W2 = O2[i] - @reduce V[(x, a), σ, (y, b), η] := sum(γ) W1[x, σ, y, γ] * W2[a, γ, b, η] + #@reduce V[(x, a), η, (y, b), σ] := sum(γ) W1[x, γ, y, σ] * W2[a, η, b, γ] + @reduce V[(x, a), σ, (y, b), η] := sum(γ) W1[x, σ, y, γ] * W2[a, γ, b, η] + O[i] = V end O diff --git a/src/lattice.jl b/src/lattice.jl index 52f05de3..3c744b2b 100644 --- a/src/lattice.jl +++ b/src/lattice.jl @@ -1,6 +1,5 @@ export square_lattice - function square_lattice(size::NTuple{5, Int}) m, um, n, un, t = size new = LinearIndices((1:n, 1:m)) diff --git a/src/utils.jl b/src/utils.jl index d02489ad..a852c50b 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -69,13 +69,13 @@ function Base.LinearIndices(m::Int, n::Int, origin::Symbol=:NW) ind = Dict() if origin == :NW - for i ∈ 1:m, j ∈ 1:n push!(ind, (i, j) => (i-1) * n + j) end + for i ∈ 1:m, j ∈ 1:n push!(ind, (i, j) => (i - 1) * n + j) end elseif origin == :WN - for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (j-1) * n + i) end + for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (j - 1) * n + i) end elseif origin == :NE for i ∈ 1:m, j ∈ 1:n push!(ind, (i, j) => (i - 1) * n + (n + 1 - j)) end elseif origin == :EN - for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (j-1) * n + (n + 1 - i)) end + for i ∈ 1:n, j ∈ 1:m push!(ind, (i, j) => (j - 1) * n + (n + 1 - i)) end elseif origin == :SE for i ∈ 1:m, j ∈ 1:n push!(ind, (i, j) => (m - i) * n + (n + 1 - j)) end elseif origin == :ES diff --git a/test/PEPS.jl b/test/PEPS.jl index 52268373..775dffe8 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -22,24 +22,40 @@ fg = factor_graph( spectrum=full_spectrum, ) -x = m -y = n -peps = PepsNetwork(x, y, fg, β, :NW) -println(typeof(peps)) - -for i ∈ 1:x, j ∈ 1:y - A = SpinGlassPEPS._generate_tensor(peps, (i, j)) - B = generate_tensor(peps, (i, j)) - @test A ≈ B -end +x, y = m, n -for i ∈ 1:x, j ∈ 1:y - @time A = generate_tensor(peps, (i, j)) -end +#for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) +for origin ∈ (:NW, :SW, :NE, :SE, :SW) + + @info "testing peps" origin + println(origin) + + peps = PepsNetwork(x, y, fg, β, origin) + @test typeof(peps) == PepsNetwork + + for i ∈ 1:peps.i_max, j ∈ 1:peps.j_max + A = SpinGlassPEPS._generate_tensor(peps, (i, j)) + B = generate_tensor(peps, (i, j)) + @test A ≈ B + end + + @info "contracting MPOs" + + mpo = MPO(peps, 1) + for ψ ∈ mpo + println(size(ψ)) + @test size(ψ, 2) == 1 + end + + for i ∈ 2:peps.i_max + mpo *= MPO(peps, i) + end -mpo = MPO(peps, 1) -for i ∈ 2:x - mpo = dot(MPO(peps, i), mpo) + for ψ ∈ mpo + #println(size(ψ)) + @test size(ψ, 2) == 1 + @test size(ψ, 4) == 1 + end end end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 975c2d93..8a5074d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,7 +36,7 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - "graph.jl", + #"graph.jl", "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", From db8bf04e588905196aeaf48e46ae7fd91ad97d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Wed, 6 Jan 2021 12:34:31 +0100 Subject: [PATCH 099/137] add tests od mpo/peps --- src/contractions.jl | 2 +- test/PEPS.jl | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/contractions.jl b/src/contractions.jl index fe38c54d..dbde0ac2 100644 --- a/src/contractions.jl +++ b/src/contractions.jl @@ -144,7 +144,7 @@ function LinearAlgebra.dot(O1::AbstractMPO, O2::AbstractMPO) #@reduce V[(x, a), η, (y, b), σ] := sum(γ) W1[x, γ, y, σ] * W2[a, η, b, γ] @reduce V[(x, a), σ, (y, b), η] := sum(γ) W1[x, σ, y, γ] * W2[a, γ, b, η] - + O[i] = V end O diff --git a/test/PEPS.jl b/test/PEPS.jl index 775dffe8..0a391a2f 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -25,7 +25,9 @@ fg = factor_graph( x, y = m, n #for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) -for origin ∈ (:NW, :SW, :NE, :SE, :SW) + +for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK +#for origin ∈ (:WN, :EN, :ES, :WS) # NO @info "testing peps" origin println(origin) @@ -41,21 +43,18 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) @info "contracting MPOs" - mpo = MPO(peps, 1) - for ψ ∈ mpo - println(size(ψ)) - @test size(ψ, 2) == 1 - end + ψ = MPO(peps, 1) + for A ∈ ψ @test size(A, 2) == 1 end for i ∈ 2:peps.i_max - mpo *= MPO(peps, i) + W = MPO(peps, i) + ψ = ψ * W + for A ∈ ψ println(size(A)) end + println("===================") + for A ∈ ψ @test size(A, 2) == 1 end end - for ψ ∈ mpo - #println(size(ψ)) - @test size(ψ, 2) == 1 - @test size(ψ, 4) == 1 - end + for A ∈ ψ @test size(A, 4) == 1 end end end \ No newline at end of file From e1c149dbc78573e62e27c78e9acdc8318a023b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Wed, 6 Jan 2021 13:16:20 +0100 Subject: [PATCH 100/137] add more test befor meeting --- test/PEPS.jl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/PEPS.jl b/test/PEPS.jl index 0a391a2f..b5538e73 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -41,7 +41,7 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK @test A ≈ B end - @info "contracting MPOs" + @info "contracting MPOs (up --> down)" ψ = MPO(peps, 1) for A ∈ ψ @test size(A, 2) == 1 end @@ -49,12 +49,23 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK for i ∈ 2:peps.i_max W = MPO(peps, i) ψ = ψ * W - for A ∈ ψ println(size(A)) end - println("===================") for A ∈ ψ @test size(A, 2) == 1 end end for A ∈ ψ @test size(A, 4) == 1 end + + @info "contracting MPOs (down --> up)" + + ψ = MPO(peps, peps.i_max) + for A ∈ ψ @test size(A, 4) == 1 end + + for i ∈ peps.i_max:2 + W = MPO(peps, i) + ψ = W * ψ + for A ∈ ψ @test size(A, 4) == 1 end + end + + for A ∈ ψ @test size(A, 4) == 1 end end end \ No newline at end of file From 64f7ffb4f73c1795eb6309d71a59d7c533b2b204 Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:00:09 +0100 Subject: [PATCH 101/137] add tests --- src/graph.jl | 5 +++++ test/PEPS.jl | 10 +++++++++- test/graph.jl | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/graph.jl b/src/graph.jl index 7e99fd24..c439132d 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -118,7 +118,12 @@ function factor_graph( set_prop!(fg, e, :edge, edg) pl, en = rank_reveal(energy(fg, edg), :PE) + display(energy(fg, edg)) en, pr = rank_reveal(en, :EP) + display(pl) + display(en) + display(pr) + println("--------------------------") set_prop!(fg, e, :split, (pl, en, pr)) end end diff --git a/test/PEPS.jl b/test/PEPS.jl index b5538e73..0f01087c 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -22,6 +22,14 @@ fg = factor_graph( spectrum=full_spectrum, ) + +for e in edges(fg) + pl, en, pr = get_prop(fg, e, :split) + println("edge ", e) + println(size(pl), " ", size(en), " ", size(pr)) + #display(en) +end + x, y = m, n #for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) @@ -59,7 +67,7 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK ψ = MPO(peps, peps.i_max) for A ∈ ψ @test size(A, 4) == 1 end - for i ∈ peps.i_max:2 + for i ∈ peps.i_max-1:1 W = MPO(peps, i) ψ = W * ψ for A ∈ ψ @test size(A, 4) == 1 end diff --git a/test/graph.jl b/test/graph.jl index adf5d45c..bd8256e2 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -13,6 +13,7 @@ using CSV L = n * m * (2 * t) instance = "$(@__DIR__)/instances/chimera_droplets/$(L)power/001.txt" + ig = ising_graph(instance, L) update_cells!( ig, From 0699d0aeabff4549393fd2dd8a32b19983e44c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Wed, 6 Jan 2021 17:31:23 +0100 Subject: [PATCH 102/137] add MPO on links --- src/PEPS.jl | 23 +++++++++++++++++++++++ src/graph.jl | 4 +++- test/PEPS.jl | 9 ++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 7581a0f0..1bb5894c 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -127,4 +127,27 @@ function MPO(peps::PepsNetwork, i::Int; type::DataType=Float64) ψ[j] = B end ψ +end + +function MPO(peps::PepsNetwork, i::Int, k::Int; type::DataType=Float64) + n = peps.j_max + + ψ = MPO(type, n) + fg = peps.network_graph.factor_graph + + for j ∈ 1:n + v, w = peps.map[i, j], peps.map[k, j] + + if has_edge(fg, v, w) + _, en, _ = get_prop(fg, v, w, :split) + elseif has_edge(fg, w, v) + _, en, _ = get_prop(fg, w, v, :split) + else + en = ones(1, 1) + end + + @cast A[_, σ, _, η] := en[σ, η] + ψ[j] = A + end + ψ end \ No newline at end of file diff --git a/src/graph.jl b/src/graph.jl index c439132d..a924b46a 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -118,12 +118,14 @@ function factor_graph( set_prop!(fg, e, :edge, edg) pl, en = rank_reveal(energy(fg, edg), :PE) - display(energy(fg, edg)) en, pr = rank_reveal(en, :EP) + #= + display(energy(fg, edg)) display(pl) display(en) display(pr) println("--------------------------") + =# set_prop!(fg, e, :split, (pl, en, pr)) end end diff --git a/test/PEPS.jl b/test/PEPS.jl index 0f01087c..60114d4f 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -22,13 +22,14 @@ fg = factor_graph( spectrum=full_spectrum, ) - +#= for e in edges(fg) pl, en, pr = get_prop(fg, e, :split) println("edge ", e) println(size(pl), " ", size(en), " ", size(pr)) #display(en) end +=# x, y = m, n @@ -56,7 +57,8 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK for i ∈ 2:peps.i_max W = MPO(peps, i) - ψ = ψ * W + M = MPO(peps, i-1, i) + ψ = (ψ * M) * W for A ∈ ψ @test size(A, 2) == 1 end end @@ -69,7 +71,8 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK for i ∈ peps.i_max-1:1 W = MPO(peps, i) - ψ = W * ψ + M = eMPO(peps, i, i+1) + ψ = W * (M * ψ) for A ∈ ψ @test size(A, 4) == 1 end end From 2a4cf25806fc9d7b025def494c1513a46fe8546d Mon Sep 17 00:00:00 2001 From: kdomino Date: Thu, 7 Jan 2021 09:02:52 +0100 Subject: [PATCH 103/137] corrections --- src/PEPS.jl | 12 ++++++++++-- test/PEPS.jl | 20 ++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 0dc4d7e3..430ed783 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -1,6 +1,6 @@ export NetworkGraph, PepsNetwork export generate_tensor, MPO - + mutable struct NetworkGraph factor_graph::MetaDiGraph nbrs::Dict @@ -25,19 +25,27 @@ end function generate_tensor(ng::NetworkGraph, v::Int) fg = ng.factor_graph loc_exp = exp.(-ng.β .* get_prop(fg, v, :loc_en)) + dim = [] @cast tensor[_, i] := loc_exp[i] + for w ∈ ng.nbrs[v] if has_edge(fg, w, v) _, _, pv = get_prop(fg, w, v, :split) + pv = pv' elseif has_edge(fg, v, w) pv, _, _ = get_prop(fg, v, w, :split) + else pv = ones(length(loc_exp), 1) + end @cast tensor[(c, γ), σ] |= tensor[c, σ] * pv[σ, γ] push!(dim, size(pv, 2)) + end reshape(tensor, dim..., :) +end + function _generate_tensor(ng::NetworkGraph, v::Int) fg = ng.factor_graph loc_exp = exp.(-ng.β .* get_prop(fg, v, :loc_en)) @@ -129,7 +137,7 @@ function MPO(peps::PepsNetwork, i::Int, k::Int; type::DataType=Float64) for j ∈ 1:n v, w = peps.map[i, j], peps.map[k, j] - + if has_edge(fg, v, w) _, en, _ = get_prop(fg, v, w, :split) elseif has_edge(fg, w, v) diff --git a/test/PEPS.jl b/test/PEPS.jl index 3ef22102..31212bfe 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -45,7 +45,7 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK @test typeof(peps) == PepsNetwork for i ∈ 1:peps.i_max, j ∈ 1:peps.j_max - A = SpinGlassPEPS._generate_tensor(peps, (i, j)) + A = SpinGlassPEPS._generate_tensor(peps, (i, j)) B = generate_tensor(peps, (i, j)) @test A ≈ B end @@ -56,8 +56,8 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK for A ∈ ψ @test size(A, 2) == 1 end for i ∈ 2:peps.i_max - W = MPO(peps, i) - M = MPO(peps, i-1, i) + W = MPO(peps, i) + M = MPO(peps, i-1, i) ψ = (ψ * M) * W for A ∈ ψ @test size(A, 2) == 1 end end @@ -70,21 +70,13 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK for A ∈ ψ @test size(A, 4) == 1 end for i ∈ peps.i_max-1:1 - W = MPO(peps, i) - M = eMPO(peps, i, i+1) - ψ = W * (M * ψ) + W = MPO(peps, i) + M = eMPO(peps, i, i+1) + ψ = W * (M * ψ) for A ∈ ψ @test size(A, 4) == 1 end end for A ∈ ψ @test size(A, 4) == 1 end end -end - -L = 9 -instance = "$(@__DIR__)/instances/$(L)_001.txt" - -ig = ising_graph(instance, L) - - end From af6cb434fd0e1de3fa9c4d0d5882e5050b180e8d Mon Sep 17 00:00:00 2001 From: kdomino Date: Thu, 7 Jan 2021 11:17:19 +0100 Subject: [PATCH 104/137] forst attempt to implement new form of tensor calculation --- test/peps_tests.jl | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 12135ef2..e64672e0 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -69,12 +69,35 @@ end Mq = ones(4,4) fullM2grid!(Mq, (2,2)) -if false +if true @testset "tensor construction" begin g = M2graph(Mq) + + g_ising = M2graph(Mq) + m = 2 + n = 2 + t = 1 + + update_cells!( + g_ising, + rule = square_lattice((m, n, t)), + ) + + fg = factor_graph( + g_ising, + energy=energy, + spectrum=full_spectrum, + ) + + origin = :NW β = 2. + x, y = m, n + + peps = PepsNetwork(x, y, fg, β, origin) + + #smaller tensors g1 = graph4peps(g, (1,1)) @@ -85,19 +108,30 @@ if false @test M_left == [0.0 0.0] @test M_up == [0.0 0.0] + t11 = compute_single_tensor(g1, 1, β, sum_over_last = false) t1 = compute_single_tensor(g1, 1, β, sum_over_last = true) t2 = compute_single_tensor(g1, 2, β, sum_over_last = true) t3 = compute_single_tensor(g1, 3, β, sum_over_last = true) + B = generate_tensor(peps, (1,1)) + println(B == t11) + + + B1 = generate_tensor(peps, (1,1)) + println(B1) + println("......") + println(t2) + println("......") + println(t3) @test size(t1) == (1, 1, 2, 2) @test t1[1,1,:,:] ≈ [exp(1*β) 0.; 0. exp(-1*β)] @test size(t2) == (2,1,1,2) - @test t2[:,1,1,:] ≈ [exp(3*β) exp(-3*β); exp(-1*β) exp(1*β)] + @test t2[:,1,1,:] ≈ [exp(-1*β) exp(1*β); exp(3*β) exp(-3*β)] @test size(t3) == (1,2,2,1) - @test t3[1,:,:,1] ≈ [exp(3*β) exp(-3*β); exp(-1*β) exp(1*β)] + @test t3[1,:,:,1] ≈ [exp(-1*β) exp(1*β); exp(3*β) exp(-3*β)] t = compute_single_tensor(g1, 1, β) @@ -111,7 +145,7 @@ if false gg = graph4peps(g, (2,1)) T1 = compute_single_tensor(gg, 1, β, sum_over_last = true) - p = [1,4,2,3] + p = [2,3,1,4] @test vec(T1) ≈ vec(T2)[p] end From f7647cabbb042cc4320c8953b45c670b43d47ce6 Mon Sep 17 00:00:00 2001 From: kdomino Date: Thu, 7 Jan 2021 16:04:17 +0100 Subject: [PATCH 105/137] some corrections --- test/peps_tests.jl | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/test/peps_tests.jl b/test/peps_tests.jl index e64672e0..fd6afe91 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -80,10 +80,10 @@ if true n = 2 t = 1 - update_cells!( - g_ising, - rule = square_lattice((m, n, t)), - ) + #update_cells!( + # g_ising, + # rule = square_lattice((m, 1, n, 1, t)), + #) fg = factor_graph( g_ising, @@ -113,16 +113,25 @@ if true t2 = compute_single_tensor(g1, 2, β, sum_over_last = true) t3 = compute_single_tensor(g1, 3, β, sum_over_last = true) + t12 = compute_single_tensor(g1, 2, β, sum_over_last = false) + t13 = compute_single_tensor(g1, 3, β, sum_over_last = false) + B = generate_tensor(peps, (1,1)) println(B == t11) - B1 = generate_tensor(peps, (1,1)) + B1 = generate_tensor(peps, (1,2)) println(B1) + println(t12) println("......") - println(t2) + + B1 = generate_tensor(peps, (2,1)) + println(B1) + println(t13) + println("......") - println(t3) + B1 = generate_tensor(peps, (2,2)) + println(B1) @test size(t1) == (1, 1, 2, 2) @test t1[1,1,:,:] ≈ [exp(1*β) 0.; 0. exp(-1*β)] From a1a8d79939d530bf5b9aa91fb1863d9f35cc8698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Thu, 7 Jan 2021 21:37:55 +0100 Subject: [PATCH 106/137] modify MPO function --- src/PEPS.jl | 8 ++++++-- src/SpinGlassPEPS.jl | 1 + test/PEPS.jl | 13 +++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 1bb5894c..ca15fd6c 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -110,13 +110,17 @@ generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = generate_tensor(pn.network_ _generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = _generate_tensor(pn.network_graph, pn.map[m]) generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}, n::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m], pn.map[n]) -function MPO(peps::PepsNetwork, i::Int; type::DataType=Float64) +function MPO(peps::PepsNetwork, i::Int, trace::Bool=true; type::DataType=Float64) n = peps.j_max ψ = MPO(type, n) for j ∈ 1:n A = generate_tensor(peps, (i, j)) - @reduce B[l, u, r ,d] |= sum(σ) A[l, u, r, d, σ] + if trace + @reduce B[l, u, r ,d] |= sum(σ) A[l, u, r, d, σ] + else + B = A + end ψ[j] = B end diff --git a/src/SpinGlassPEPS.jl b/src/SpinGlassPEPS.jl index 989177d3..a200ea8a 100644 --- a/src/SpinGlassPEPS.jl +++ b/src/SpinGlassPEPS.jl @@ -7,6 +7,7 @@ module SpinGlassPEPS using MetaGraphs using CSV using Infiltrator + using Logging using DocStringExtensions const product = Iterators.product diff --git a/test/PEPS.jl b/test/PEPS.jl index 60114d4f..2a36637f 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -22,19 +22,16 @@ fg = factor_graph( spectrum=full_spectrum, ) -#= for e in edges(fg) pl, en, pr = get_prop(fg, e, :split) - println("edge ", e) + println(e) println(size(pl), " ", size(en), " ", size(pr)) - #display(en) + println("------------------------") end -=# x, y = m, n #for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) - for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK #for origin ∈ (:WN, :EN, :ES, :WS) # NO @@ -50,7 +47,7 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK @test A ≈ B end - @info "contracting MPOs (up --> down)" + @info "contracting MPOs (up -> down)" ψ = MPO(peps, 1) for A ∈ ψ @test size(A, 2) == 1 end @@ -64,14 +61,14 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK for A ∈ ψ @test size(A, 4) == 1 end - @info "contracting MPOs (down --> up)" + @info "contracting MPOs (down -> up)" ψ = MPO(peps, peps.i_max) for A ∈ ψ @test size(A, 4) == 1 end for i ∈ peps.i_max-1:1 W = MPO(peps, i) - M = eMPO(peps, i, i+1) + M = MPO(peps, i, i+1) ψ = W * (M * ψ) for A ∈ ψ @test size(A, 4) == 1 end end From d76a751ae7fdf277c67090814457d5c9d99db2f2 Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Thu, 7 Jan 2021 22:40:52 +0100 Subject: [PATCH 107/137] testing bond dimesions --- test/PEPS.jl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/PEPS.jl b/test/PEPS.jl index 60114d4f..f38242b0 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -22,20 +22,22 @@ fg = factor_graph( spectrum=full_spectrum, ) -#= -for e in edges(fg) +bd = [2, 2, 4, 4, 2, 2, 8] + +for (i, e) in enumerate(edges(fg)) pl, en, pr = get_prop(fg, e, :split) - println("edge ", e) + println(e) println(size(pl), " ", size(en), " ", size(pr)) #display(en) + #@test min(size(en)[1], size(en)[2]) == bd[i] + println("------------------------") end -=# x, y = m, n #for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) -for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK +for origin ∈ (:NW, :SW, :NE, :SE) # OK #for origin ∈ (:WN, :EN, :ES, :WS) # NO @info "testing peps" origin @@ -53,6 +55,8 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK @info "contracting MPOs (up --> down)" ψ = MPO(peps, 1) + #println("bd ", bond_dimension(ψ)) + for A ∈ ψ @test size(A, 2) == 1 end for i ∈ 2:peps.i_max @@ -60,20 +64,25 @@ for origin ∈ (:NW, :SW, :NE, :SE, :SW) # OK M = MPO(peps, i-1, i) ψ = (ψ * M) * W for A ∈ ψ @test size(A, 2) == 1 end + #println("bd ", bond_dimension(ψ)) end for A ∈ ψ @test size(A, 4) == 1 end + @info "contracting MPOs (down --> up)" ψ = MPO(peps, peps.i_max) + #println("bd ", bond_dimension(ψ)) + for A ∈ ψ @test size(A, 4) == 1 end for i ∈ peps.i_max-1:1 W = MPO(peps, i) - M = eMPO(peps, i, i+1) + M = MPO(peps, i, i+1) ψ = W * (M * ψ) for A ∈ ψ @test size(A, 4) == 1 end + #println("bd ", bond_dimension(ψ)) end for A ∈ ψ @test size(A, 4) == 1 end From 084d6c4d52d8e328ce71639dba86c76cf7de7e36 Mon Sep 17 00:00:00 2001 From: kdomino Date: Fri, 8 Jan 2021 12:36:37 +0100 Subject: [PATCH 108/137] some tests --- test/peps_tests.jl | 117 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 104 insertions(+), 13 deletions(-) diff --git a/test/peps_tests.jl b/test/peps_tests.jl index fd6afe91..3a768e0d 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -120,18 +120,29 @@ if true println(B == t11) - B1 = generate_tensor(peps, (1,2)) - println(B1) - println(t12) - println("......") - - B1 = generate_tensor(peps, (2,1)) - println(B1) - println(t13) - - println("......") - B1 = generate_tensor(peps, (2,2)) - println(B1) + update_cells!( + g_ising, + rule = square_lattice((m, 2, n, 2, 4)), + ) + + fg = factor_graph( + g_ising, + energy=energy, + spectrum=full_spectrum, + ) + + origin = :NW + β = 2. + x, y = m, n + + peps = PepsNetwork(x, y, fg, β, origin) + B = generate_tensor(peps, (1,1)) + + gg = graph4peps(g, (2,2)) + T1 = compute_single_tensor(gg, 1, β, sum_over_last = true) + + @test sum(B)== T1[1] + @test size(t1) == (1, 1, 2, 2) @test t1[1,1,:,:] ≈ [exp(1*β) 0.; 0. exp(-1*β)] @@ -191,7 +202,7 @@ Mq[8,9] = Mq[9,8] = -0.05 ps =[sortperm(props(gg, i)[:spectrum]) for i in 1:9] ### forms a peps network - β = 3. + β = 2. M = form_peps(gg, β) cc = contract3x3by_ncon(M) # testing peps creation @@ -208,6 +219,62 @@ Mq[8,9] = Mq[9,8] = -0.05 v = [1 for _ in 1:9] ii = [p[2] for p in ps] @test exp.(-β*energy(v, g)) ≈ cc[ii...] + + m, n = 3, 3 + fg = factor_graph( + g, + energy=energy, + spectrum=full_spectrum, + ) + + origin = :NW + x, y = m, n + + peps = PepsNetwork(x, y, fg, β, origin) + B = generate_tensor(peps, (1,1)) + + mpo1 = MPO(peps, 1, true) + + println(size(mpo1[1])) + println(size(mpo1[2])) + println(size(mpo1[3])) + + MPO(peps, 2, false) + + mpo2 = MPO(peps, 2, true) + + mpo12 = mpo1*mpo2 + + mpsu = MPS([permutedims(e[:,1,:,:], [1,3,2]) for e in mpo12]) + + mpo3 = MPO(peps, 3, true) + + mpsl = MPS([e[:,:,:,1] for e in mpo3]) + + println(right_env(mpsu, mpsl)[end] ≈ [1.]) + g1 = copy(g) + + update_cells!( + g1, + rule = square_lattice((m, 3, n, 3, 9)), + ) + + fg = factor_graph( + g1, + energy=energy, + spectrum=full_spectrum, + ) + + origin = :NW + x, y = m, n + + peps = PepsNetwork(x, y, fg, β, origin) + B = generate_tensor(peps, (1,1)) + println(size(B)) + println(size(vec(cc))) + println(sum(cc) ≈ sum(B)) + + end # TODO this will be the ilustative step by step how does the probability computation work @@ -226,6 +293,18 @@ end g = M2graph(Mq, -1) gg = graph4peps(g, (1,1)) + fg = factor_graph( + g, + energy=energy, + spectrum=full_spectrum, + ) + + origin = :NW + + peps = PepsNetwork(3, 3, fg, β, origin) + mpo2 = MPO(peps, 2, true) + mpo3 = MPO(peps, 3, true) + M = form_peps(gg, β) #TODO make something with dimensionality @@ -240,10 +319,22 @@ end row = 1 lower_mps = make_lower_mps(gg, row+1, β, 0, 0.) + l_mps = MPS([e[:,:,:,1] for e in mpo2*mpo3]) + + AA = MPO(peps, 1, false) + + println(size(A[1])) + println(size(AA[1])) + # marginal prob sol = Partial_sol{Float64}(Int[], 0.) j = 1 objective = conditional_probabs(gg, sol, j, lower_mps, A) + println(objective) + + objective1 = conditional_probabs(gg, sol, j, l_mps, AA) + println(objective1) + sol = Partial_sol{Float64}([1], objective[1]) p1 = sum(cc[1,:,:,:,:,:,:,:,:])/su From 6e30ad1199391ab12c695f441e0dddc78e42cf9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Mon, 11 Jan 2021 17:47:14 +0100 Subject: [PATCH 109/137] add PEPSRow type - for vectors of 5-dim tensors --- src/PEPS.jl | 32 ++++++++++++++++++++------------ src/base.jl | 25 +++++++++++++------------ test/PEPS.jl | 4 ++-- test/runtests.jl | 2 +- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index ca15fd6c..140a6fd8 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -110,18 +110,24 @@ generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = generate_tensor(pn.network_ _generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = _generate_tensor(pn.network_graph, pn.map[m]) generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}, n::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m], pn.map[n]) -function MPO(peps::PepsNetwork, i::Int, trace::Bool=true; type::DataType=Float64) +function MPO(::Type{T}, ψ::PEPSRow) where {T <: Number} n = peps.j_max - ψ = MPO(type, n) + ϕ = MPO(T, n) + for i=1:n + A = ψ[i] + @reduce B[l, u, r, d] |= sum(σ) A[l, u, r, d, σ] + ϕ[i] = B + end + ϕ +end +MPO(ψ::PEPSRow) = MPO(Float64, ψ) + +function PEPSRow(::Type{T}, peps::PepsNetwork, i::Int) where {T <: Number} + n = peps.j_max + ψ = PEPSRow(T, n) for j ∈ 1:n - A = generate_tensor(peps, (i, j)) - if trace - @reduce B[l, u, r ,d] |= sum(σ) A[l, u, r, d, σ] - else - B = A - end - ψ[j] = B + ψ[j] = generate_tensor(peps, (i, j)) end for j ∈ 1:n-1 @@ -132,11 +138,12 @@ function MPO(peps::PepsNetwork, i::Int, trace::Bool=true; type::DataType=Float64 end ψ end +PEPSRow(peps::PepsNetwork, i::Int) = PEPSRow(Float64, peps, i) -function MPO(peps::PepsNetwork, i::Int, k::Int; type::DataType=Float64) +function MPO(::Type{T}, peps::PepsNetwork, i::Int, k::Int) where {T <: Number} n = peps.j_max - ψ = MPO(type, n) + ψ = MPO(T, n) fg = peps.network_graph.factor_graph for j ∈ 1:n @@ -154,4 +161,5 @@ function MPO(peps::PepsNetwork, i::Int, k::Int; type::DataType=Float64) ψ[j] = A end ψ -end \ No newline at end of file +end +MPO(peps::PepsNetwork, i::Int, k::Int) = MPO(Float64, peps, i, k) \ No newline at end of file diff --git a/src/base.jl b/src/base.jl index e56e767f..e8f8c5cf 100644 --- a/src/base.jl +++ b/src/base.jl @@ -1,13 +1,15 @@ export bond_dimension, is_left_normalized, is_right_normalized export verify_bonds, verify_physical_dims, tensor, rank -for (T, N) in ((:MPO, 4), (:MPS, 3)) +abstract type AbstractTensorNetwork{T} end + +for (T, N) in ((:PEPSRow, 5), (:MPO, 4), (:MPS, 3)) AT = Symbol(:Abstract, T) @eval begin export $AT export $T - abstract type $AT{T} end + abstract type $AT{T} <: AbstractTensorNetwork{T} end struct $T{T <: Number} <: $AT{T} tensors::Vector{Array{T, $N}} @@ -24,18 +26,17 @@ for (T, N) in ((:MPO, 4), (:MPS, 3)) end end -const AbstractMPSorMPO = Union{AbstractMPS, AbstractMPO} -const MPSorMPO = Union{MPS, MPO} +# const MPSorMPO = Union{MPS, MPO} -@inline Base.:(==)(a::AbstractMPSorMPO, b::AbstractMPSorMPO) = a.tensors == b.tensors -@inline Base.:(≈)(a::AbstractMPSorMPO, b::AbstractMPSorMPO) = a.tensors ≈ b.tensors +@inline Base.:(==)(a::AbstractTensorNetwork, b::AbstractTensorNetwork) = a.tensors == b.tensors +@inline Base.:(≈)(a::AbstractTensorNetwork, b::AbstractTensorNetwork) = a.tensors ≈ b.tensors -@inline Base.getindex(a::AbstractMPSorMPO, i) = getindex(a.tensors, i) -@inline Base.iterate(a::AbstractMPSorMPO) = iterate(a.tensors) -@inline Base.iterate(a::AbstractMPSorMPO, state) = iterate(a.tensors, state) -@inline Base.lastindex(a::AbstractMPSorMPO) = lastindex(a.tensors) -@inline Base.length(a::AbstractMPSorMPO) = length(a.tensors) -@inline Base.size(a::AbstractMPSorMPO) = (length(a.tensors), ) +@inline Base.getindex(a::AbstractTensorNetwork, i) = getindex(a.tensors, i) +@inline Base.iterate(a::AbstractTensorNetwork) = iterate(a.tensors) +@inline Base.iterate(a::AbstractTensorNetwork, state) = iterate(a.tensors, state) +@inline Base.lastindex(a::AbstractTensorNetwork) = lastindex(a.tensors) +@inline Base.length(a::AbstractTensorNetwork) = length(a.tensors) +@inline Base.size(a::AbstractTensorNetwork) = (length(a.tensors), ) @inline LinearAlgebra.rank(ψ::MPS) = Tuple(size(A, 2) for A ∈ ψ) diff --git a/test/PEPS.jl b/test/PEPS.jl index 7bb9ebc4..9c5795b6 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -54,13 +54,13 @@ for origin ∈ (:NW, :SW, :NE, :SE) # OK @info "contracting MPOs (up -> down)" - ψ = MPO(peps, 1) + ψ = PEPSRow(peps, 1) #println("bd ", bond_dimension(ψ)) for A ∈ ψ @test size(A, 2) == 1 end for i ∈ 2:peps.i_max - W = MPO(peps, i) + W = MPO(PEPSRow(eps, i)) M = MPO(peps, i-1, i) ψ = (ψ * M) * W for A ∈ ψ @test size(A, 2) == 1 end diff --git a/test/runtests.jl b/test/runtests.jl index 8a5074d9..cfbd2d3b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,7 +31,7 @@ if CUDA.functional() && CUDA.has_cutensor() && false end push!(my_tests, - #"base.jl", + "base.jl", #"contractions.jl", #"compressions.jl", #"ising.jl", From 36416cc272823f7c4abf3147400734788ebb7c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 11 Jan 2021 18:08:33 +0100 Subject: [PATCH 110/137] change tensor construction in PEPSRow --- src/PEPS.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 140a6fd8..bba3136c 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -133,7 +133,7 @@ function PEPSRow(::Type{T}, peps::PepsNetwork, i::Int) where {T <: Number} for j ∈ 1:n-1 ten = generate_tensor(peps, (i, j), (i, j+1)) A = ψ[j] - @tensor B[l, u, r, d] := A[l, u, r̃, d] * ten[r̃, r] + @tensor B[l, u, r, d, σ] := A[l, u, r̃, d, σ] * ten[r̃, r] ψ[j] = B end ψ From 448beb9d430fa725c0fde7cddd0a6ea4bbf68a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Mon, 11 Jan 2021 18:26:57 +0100 Subject: [PATCH 111/137] correct typos in test - now it works --- src/PEPS.jl | 2 +- test/PEPS.jl | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index bba3136c..56f0fd21 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -111,7 +111,7 @@ _generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}) = _generate_tensor(pn.networ generate_tensor(pn::PepsNetwork, m::NTuple{2,Int}, n::NTuple{2,Int}) = generate_tensor(pn.network_graph, pn.map[m], pn.map[n]) function MPO(::Type{T}, ψ::PEPSRow) where {T <: Number} - n = peps.j_max + n = length(ψ) ϕ = MPO(T, n) for i=1:n A = ψ[i] diff --git a/test/PEPS.jl b/test/PEPS.jl index 9c5795b6..834b7000 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -54,13 +54,13 @@ for origin ∈ (:NW, :SW, :NE, :SE) # OK @info "contracting MPOs (up -> down)" - ψ = PEPSRow(peps, 1) + ψ = MPO(PEPSRow(peps, 1)) #println("bd ", bond_dimension(ψ)) for A ∈ ψ @test size(A, 2) == 1 end for i ∈ 2:peps.i_max - W = MPO(PEPSRow(eps, i)) + W = MPO(PEPSRow(peps, i)) M = MPO(peps, i-1, i) ψ = (ψ * M) * W for A ∈ ψ @test size(A, 2) == 1 end @@ -71,13 +71,13 @@ for origin ∈ (:NW, :SW, :NE, :SE) # OK @info "contracting MPOs (down -> up)" - ψ = MPO(peps, peps.i_max) + ψ = MPO(PEPSRow(peps, peps.i_max)) #println("bd ", bond_dimension(ψ)) for A ∈ ψ @test size(A, 4) == 1 end for i ∈ peps.i_max-1:1 - W = MPO(peps, i) + W = MPO(PEPSRow(peps, i)) M = MPO(peps, i, i+1) ψ = W * (M * ψ) for A ∈ ψ @test size(A, 4) == 1 end From 3bb8a464e73fe9746219f12cfd92f75a1af0d965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Tue, 12 Jan 2021 02:05:03 +0100 Subject: [PATCH 112/137] fix rank reveal --- src/graph.jl | 4 ++-- src/utils.jl | 4 ++-- test/graph.jl | 32 ++++++++++++++++---------------- test/runtests.jl | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index a924b46a..76728c62 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -137,8 +137,8 @@ function rank_reveal(energy, order=:PE) @assert order ∈ (:PE, :EP) dim = order == :PE ? 1 : 2 - E = unique(energy, dims=dim) - idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) + E, idx = unique_dims(energy, dim) + # idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) P = order == :PE ? zeros(size(energy, 1), size(E, 1)) : zeros(size(E, 2), size(energy, 2)) diff --git a/src/utils.jl b/src/utils.jl index a852c50b..720d42d4 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -105,7 +105,7 @@ function Base.LinearIndices(m::Int, n::Int, origin::Symbol=:NW) ind, i_max, j_max end -@generated function _unique_dims(A::AbstractArray{T,N}, dim::Integer) where {T,N} +@generated function unique_dims(A::AbstractArray{T,N}, dim::Integer) where {T,N} quote 1 <= dim <= $N || return copy(A) hashes = zeros(UInt, axes(A, dim)) @@ -171,6 +171,6 @@ end end end - (@nref $N A d->d == dim ? sort!(uniquerows) : (axes(A, d))) + (@nref $N A d->d == dim ? sort!(uniquerows) : (axes(A, d))), uniquerow end end \ No newline at end of file diff --git a/test/graph.jl b/test/graph.jl index bd8256e2..a3c2c158 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -3,6 +3,22 @@ using LightGraphs using GraphPlot using CSV +@testset "Rank reveal correctly decomposes energy row-wise" begin + energy = [[1 2 3]; [0 -1 0]; [1 2 3]] + P, E = rank_reveal(energy, :PE) + @test size(P) == (3, 2) + @test size(E) == (2, 3) + @test P * E ≈ energy +end + +@testset "Rank reveal correctly decomposes energy column-wise" begin + energy = [[1, 2, 3] [0, -1, 1] [1, 2, 3]] + E, P = rank_reveal(energy, :EP) + @test size(P) == (2, 3) + @test size(E) == (3, 2) + @test E * P ≈ energy +end + @testset "Lattice graph" begin m = 4 n = 4 @@ -91,20 +107,4 @@ x = m y = n peps = PepsNetwork(x, y, fg, β, origin) -end - -@testset "Rank reveal correctly decomposes energy row-wise" begin - energy = [[1 2 3]; [0 -1 0]; [1 2 3]] - P, E = rank_reveal(energy, :PE) - @test size(P) == (3, 2) - @test size(E) == (2, 3) - @test P * E ≈ energy -end - -@testset "Rank reveal correctly decomposes energy column-wise" begin - energy = [[1, 2, 3] [0, -1, 1] [1, 2, 3]] - E, P = rank_reveal(energy, :EP) - @test size(P) == (2, 3) - @test size(E) == (3, 2) - @test E * P ≈ energy end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index cfbd2d3b..045e1a7f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,7 +36,7 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - #"graph.jl", + "graph.jl", "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", From 32ea89abd15689bf4859c5ca612b61ccc69cc176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 12 Jan 2021 10:07:22 +0100 Subject: [PATCH 113/137] add some tests --- src/PEPS.jl | 1 + src/contractions.jl | 1 - test/PEPS.jl | 30 +++++++++++++++++++++--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 56f0fd21..61135ada 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -158,6 +158,7 @@ function MPO(::Type{T}, peps::PepsNetwork, i::Int, k::Int) where {T <: Number} end @cast A[_, σ, _, η] := en[σ, η] +# @cast A[_, σ, _, η] := en[η, σ] ψ[j] = A end ψ diff --git a/src/contractions.jl b/src/contractions.jl index dbde0ac2..5f17db13 100644 --- a/src/contractions.jl +++ b/src/contractions.jl @@ -141,7 +141,6 @@ function LinearAlgebra.dot(O1::AbstractMPO, O2::AbstractMPO) for i in 1:L W1 = O1[i] W2 = O2[i] - #@reduce V[(x, a), η, (y, b), σ] := sum(γ) W1[x, γ, y, σ] * W2[a, η, b, γ] @reduce V[(x, a), σ, (y, b), η] := sum(γ) W1[x, σ, y, γ] * W2[a, γ, b, η] diff --git a/test/PEPS.jl b/test/PEPS.jl index 834b7000..b307eac5 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -26,19 +26,28 @@ bd = [2, 2, 4, 4, 2, 2, 8] for (i, e) in enumerate(edges(fg)) pl, en, pr = get_prop(fg, e, :split) + println(e) println(size(pl), " ", size(en), " ", size(pr)) - #display(en) - #@test min(size(en)[1], size(en)[2]) == bd[i] - println("------------------------") + + isOK = min(size(en)[1], size(en)[2]) == bd[i] + + @test isOK + if !isOK + println(min(size(en)[1], size(en)[2]), " ", bd[i]) + #display(pl) + display(en) + #display(pr) + println("--") + end end x, y = m, n #for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) -for origin ∈ (:NW, :SW, :NE, :SE) # OK -#for origin ∈ (:WN, :EN, :ES, :WS) # NO +for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK +#for origin ∈ (:EN, :ES, :WS) # NO @info "testing peps" origin println(origin) @@ -57,18 +66,21 @@ for origin ∈ (:NW, :SW, :NE, :SE) # OK ψ = MPO(PEPSRow(peps, 1)) #println("bd ", bond_dimension(ψ)) + #= for A ∈ ψ @test size(A, 2) == 1 end for i ∈ 2:peps.i_max - W = MPO(PEPSRow(peps, i)) + println(i) + R = PEPSRow(peps, i) + W = MPO(R) M = MPO(peps, i-1, i) ψ = (ψ * M) * W for A ∈ ψ @test size(A, 2) == 1 end - #println("bd ", bond_dimension(ψ)) end for A ∈ ψ @test size(A, 4) == 1 end - +=# +#= @info "contracting MPOs (down -> up)" ψ = MPO(PEPSRow(peps, peps.i_max)) @@ -83,7 +95,7 @@ for origin ∈ (:NW, :SW, :NE, :SE) # OK for A ∈ ψ @test size(A, 4) == 1 end #println("bd ", bond_dimension(ψ)) end - +=# for A ∈ ψ @test size(A, 4) == 1 end end From 75a40e273c4e4a7dba4d179f2b195b1b01e66a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 12 Jan 2021 14:41:08 +0100 Subject: [PATCH 114/137] add more test, some ideas still do not work --- src/graph.jl | 18 +++++++++++++++ test/PEPS.jl | 31 +++++++++++-------------- test/graph.jl | 59 +++++++++++++++++++++++++++++++++++------------- test/runtests.jl | 4 ++-- 4 files changed, 76 insertions(+), 36 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 76728c62..cf4b91e2 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -132,6 +132,7 @@ function factor_graph( fg end +#= # needs to be rewritten! function rank_reveal(energy, order=:PE) @assert order ∈ (:PE, :EP) @@ -146,5 +147,22 @@ function rank_reveal(energy, order=:PE) elements[idx[i]] = 1 end + order == :PE ? (P, E) : (E, P) +end +=# + +function rank_reveal(energy, order=:PE) + @assert order ∈ (:PE, :EP) + dim = order == :PE ? 1 : 2 + + E = unique(energy, dims=dim) + idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) + + P = order == :PE ? zeros(size(energy, 1), size(E, 1)) : zeros(size(E, 2), size(energy, 2)) + + for (i, elements) ∈ enumerate(eachslice(P, dims=dim)) + elements[idx[i]] = 1 + end + order == :PE ? (P, E) : (E, P) end \ No newline at end of file diff --git a/test/PEPS.jl b/test/PEPS.jl index b307eac5..f4f4a4fe 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -1,3 +1,4 @@ + @testset "PepsTensor correctly builds PEPS network" begin m = 3 @@ -8,6 +9,8 @@ t = 3 L = m * n * t +bond_dimensions = [2, 2, 4, 4, 2, 2, 8] + instance = "$(@__DIR__)/instances/pathological/test_$(m)_$(n)_$(t).txt" ig = ising_graph(instance, L) @@ -22,32 +25,28 @@ fg = factor_graph( spectrum=full_spectrum, ) -bd = [2, 2, 4, 4, 2, 2, 8] - -for (i, e) in enumerate(edges(fg)) +#= +for (bd, e) in zip(bond_dimensions, edges(fg)) pl, en, pr = get_prop(fg, e, :split) println(e) println(size(pl), " ", size(en), " ", size(pr)) - isOK = min(size(en)[1], size(en)[2]) == bd[i] + isOK = min(size(en)...) == bd @test isOK if !isOK - println(min(size(en)[1], size(en)[2]), " ", bd[i]) - #display(pl) + println(min(size(en)...), " ", bd) display(en) - #display(pr) - println("--") end end +=# x, y = m, n #for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) - -for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK -#for origin ∈ (:EN, :ES, :WS) # NO +#for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK +for origin ∈ (:EN, :ES, :WS) # NO @info "testing peps" origin println(origin) @@ -66,7 +65,7 @@ for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK ψ = MPO(PEPSRow(peps, 1)) #println("bd ", bond_dimension(ψ)) - #= + for A ∈ ψ @test size(A, 2) == 1 end for i ∈ 2:peps.i_max @@ -79,12 +78,10 @@ for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK end for A ∈ ψ @test size(A, 4) == 1 end -=# -#= + @info "contracting MPOs (down -> up)" ψ = MPO(PEPSRow(peps, peps.i_max)) - #println("bd ", bond_dimension(ψ)) for A ∈ ψ @test size(A, 4) == 1 end @@ -93,10 +90,8 @@ for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK M = MPO(peps, i, i+1) ψ = W * (M * ψ) for A ∈ ψ @test size(A, 4) == 1 end - #println("bd ", bond_dimension(ψ)) end -=# + for A ∈ ψ @test size(A, 4) == 1 end end - end \ No newline at end of file diff --git a/test/graph.jl b/test/graph.jl index a3c2c158..a2d5da33 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -49,6 +49,7 @@ end for v ∈ vertices(fg) cl = get_prop(fg, v, :cluster) + push!(clv, keys(cl.vertices)) push!(cle, collect(cl.edges)) @@ -60,7 +61,6 @@ end @test isempty(intersect(clv...)) @test isempty(intersect(cle...)) - peps = PepsNetwork(m, n, fg, β, :NW) for i ∈ 1:m, j ∈ 1:n @time A = generate_tensor(peps, (i, j)) @@ -71,27 +71,43 @@ end m = 3 n = 4 t = 3 + +β = 1 +L = n * m * t + instance = "$(@__DIR__)/instances/pathological/test_$(m)_$(n)_$(t).txt" +edges = Dict() +push!(edges, (1, 2) => [(1, 4), (1, 5), (1, 6)]) +push!(edges, (1, 5) => [(1, 13)]) + +push!(edges, (2, 3) => [(4, 7), (5, 7), (6, 8), (6, 9)]) +push!(edges, (2, 6) => [(6, 16), (6, 18), (5, 16)]) + +push!(edges, (5, 6) => [(13, 16), (13, 18)]) + +push!(edges, (6, 10) => [(18, 28)]) +push!(edges, (10, 11) => [(28, 31), (28, 32), (28, 33), (29, 31), (29, 32), (29, 33), (30, 31), (30, 32), (30, 33)]) + +cells = Dict() +push!(cells, 1 => [1]) +push!(cells, 2 => [4, 5, 6]) +push!(cells, 3 => [7, 8, 9]) +push!(cells, 4 => []) +push!(cells, 5 => [13]) +push!(cells, 6 => [16, 18]) +push!(cells, 7 => []) +push!(cells, 8 => []) +push!(cells, 9 => []) +push!(cells, 10 => [28, 29, 30]) +push!(cells, 11 => [31, 32, 33]) +push!(cells, 12 => []) -β = 1 -origin = :NW -m = 4 -L = m * n * t ig = ising_graph(instance, L) update_cells!( ig, rule = square_lattice((m, n, t)), ) -println("sq_lattice ", square_lattice((m, n, t))) - -for v ∈ filter_vertices(ig, :active, true) - #h = get_prop(ig, v, :h) - #println("h ", v, " ----> ", h) - cell = get_prop(ig, v, :cell) - println("cell ", v, " ----> ", cell) - -end fg = factor_graph( ig, @@ -100,11 +116,22 @@ fg = factor_graph( ) for v ∈ vertices(fg) - eng = get_prop(fg, v, :spectrum).energies - println("rank ", v, " ----> ", vec(eng)) + cl = get_prop(fg, v, :cluster) + + @test issetequal(keys(cl.vertices), cells[v]) + + for w ∈ neighbors(fg, v) + ed = get_prop(fg, v, w, :edge) + for e in edges[(v, w)] @test e ∈ Tuple.(ed.edges) end + for e in ed.edges @test Tuple(e) ∈ edges[(v, w)] end + end end + + x = m y = n +origin = :NW + peps = PepsNetwork(x, y, fg, β, origin) end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 045e1a7f..a52542c8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,13 +31,13 @@ if CUDA.functional() && CUDA.has_cutensor() && false end push!(my_tests, - "base.jl", + #"base.jl", #"contractions.jl", #"compressions.jl", #"ising.jl", #"spectrum.jl", "graph.jl", - "PEPS.jl", + #"PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", # problems From f42ce16c6ef7377a33c11ae4c714c53bfd376602 Mon Sep 17 00:00:00 2001 From: kdomino Date: Tue, 12 Jan 2021 14:46:20 +0100 Subject: [PATCH 115/137] first implementation of the droplet --- Project.toml | 1 + benchmarks/low_energy_approx_chimera.jl | 4 +- benchmarks/tests_grid_from_file.jl | 9 ++-- benchmarks/tests_on_chimera.jl | 4 +- src/SpinGlassPEPS.jl | 1 + src/peps_no_types.jl | 53 +++++++++++++++++++++-- test/peps_tests.jl | 57 +++++++++++++++---------- 7 files changed, 95 insertions(+), 34 deletions(-) diff --git a/Project.toml b/Project.toml index a26bdc2a..6a8db1b3 100644 --- a/Project.toml +++ b/Project.toml @@ -19,6 +19,7 @@ Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b" TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" +StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" [compat] MetaGraphs = "0.6" diff --git a/benchmarks/low_energy_approx_chimera.jl b/benchmarks/low_energy_approx_chimera.jl index dad981af..85132f68 100644 --- a/benchmarks/low_energy_approx_chimera.jl +++ b/benchmarks/low_energy_approx_chimera.jl @@ -14,7 +14,7 @@ using Test import SpinGlassPEPS: solve, solve_mps, M2graph, energy, binary2spins, ising_graph disable_logging(LogLevel(0)) - +δ = 0.9 # this is axiliary function for npz write function vecvec2matrix(v::Vector{Vector{Int}}) @@ -101,7 +101,7 @@ function proceed() i = 1 for s in ses - @time spins, _ = solve(ig, n_sol; β=β, χ = χ, threshold = 1e-8, node_size = node_size, spectrum_cutoff = s) + @time spins, _ = solve(ig, n_sol; β=β, χ = χ, threshold = 1e-8, node_size = node_size, spectrum_cutoff = s, δ=δ) en = minimum([energy(s, ig) for s in spins]) diff --git a/benchmarks/tests_grid_from_file.jl b/benchmarks/tests_grid_from_file.jl index 7bfa6003..1cc241d9 100644 --- a/benchmarks/tests_grid_from_file.jl +++ b/benchmarks/tests_grid_from_file.jl @@ -31,6 +31,7 @@ println("examples = ", examples) β = 3. +δ = 0. number_of_states = 10 @@ -71,7 +72,7 @@ for k in 1:examples number = number_of_states + more_states_for_peps - @time spins, objective = solve(g, number ; β = T(β), threshold = 0.) + @time spins, objective = solve(g, number ; β = T(β), threshold = 0., δ = δ) for i in 1:number_of_states @@ -87,7 +88,7 @@ for k in 1:examples print("approx peps ") number = number_of_states + more_states_for_peps - @time spins_approx, objective_approx = solve(g, number; β = T(β), χ = χ, threshold = 1e-12) + @time spins_approx, objective_approx = solve(g, number; β = T(β), χ = χ, threshold = 1e-12, δ = δ) for i in 1:number_of_states @@ -102,7 +103,7 @@ for k in 1:examples print("peps larger T") number = number_of_states + more_states_for_peps - @time spins_larger_nodes, objective_larger_nodes = solve(g, number; node_size = (2,2), β = T(β), χ = χ, threshold = 1e-12) + @time spins_larger_nodes, objective_larger_nodes = solve(g, number; node_size = (2,2), β = T(β), χ = χ, threshold = 1e-12, δ = δ) for i in 1:number_of_states @@ -117,7 +118,7 @@ for k in 1:examples print("peps larger T, limited spectrum") number = number_of_states + more_states_for_peps - @time spins_spec, objective_spec = solve(g, number; node_size = (2,2), β = T(β), χ = χ, threshold = 1e-12, spectrum_cutoff = 15) + @time spins_spec, objective_spec = solve(g, number; node_size = (2,2), β = T(β), χ = χ, threshold = 1e-12, spectrum_cutoff = 15, δ = δ) for i in 1:minimum([number_of_states, 60]) @test energy(spins_spec[i], g) ≈ energies_given[i] diff --git a/benchmarks/tests_on_chimera.jl b/benchmarks/tests_on_chimera.jl index e8efa9a5..1b46dd1c 100644 --- a/benchmarks/tests_on_chimera.jl +++ b/benchmarks/tests_on_chimera.jl @@ -23,7 +23,7 @@ function vecvec2matrix(v::Vector{Vector{Int}}) end M end - +δ = 0.1 s = ArgParseSettings("description") @add_arg_table! s begin @@ -78,7 +78,7 @@ node_size = (parse_args(s)["node_size1"], parse_args(s)["node_size2"]) println(node_size) spectrum_cutoff = parse_args(s)["spectrum_cutoff"] -@time spins, objective = solve(ig, n_sols; β=β, χ = χ, threshold = 1e-8, node_size = node_size, spectrum_cutoff = spectrum_cutoff) +@time spins, objective = solve(ig, n_sols; β=β, χ = χ, threshold = 1e-8, node_size = node_size, spectrum_cutoff = spectrum_cutoff, δ=δ) energies = [energy(s, ig) for s in spins] println("energies from peps") diff --git a/src/SpinGlassPEPS.jl b/src/SpinGlassPEPS.jl index 3bd2f7a2..c32f1f63 100644 --- a/src/SpinGlassPEPS.jl +++ b/src/SpinGlassPEPS.jl @@ -8,6 +8,7 @@ module SpinGlassPEPS using CSV using Infiltrator using Logging + using StatsBase using DocStringExtensions const product = Iterators.product diff --git a/src/peps_no_types.jl b/src/peps_no_types.jl index c78f2490..4275a243 100644 --- a/src/peps_no_types.jl +++ b/src/peps_no_types.jl @@ -173,11 +173,15 @@ structure of the partial solution mutable struct Partial_sol{T <: Real} spins::Vector{Int} objective::T + boundary::Vector{Int} function(::Type{Partial_sol{T}})(spins::Vector{Int}, objective::T) where T <:Real - new{T}(spins, objective) + new{T}(spins, objective, Int[]) + end + function(::Type{Partial_sol{T}})(spins::Vector{Int}, objective::T, boundary::Vector{Int}) where T <:Real + new{T}(spins, objective, boundary) end function(::Type{Partial_sol{T}})() where T <:Real - new{T}(Int[], 1.) + new{T}(Int[], 1., Int[]) end end @@ -192,6 +196,10 @@ function update_partial_solution(ps::Partial_sol{T}, s::Int, objective::T) where Partial_sol{T}(vcat(ps.spins, [s]), objective) end +function update_partial_solution(ps::Partial_sol{T}, s::Int, objective::T, boundary::Vector{Int}) where T <: Real + Partial_sol{T}(vcat(ps.spins, [s]), objective, ps.spins[boundary]) +end + """ spin_indices_from_above(gg::MetaGraph, ps::Partial_sol, j::Int) @@ -292,10 +300,17 @@ function conditional_probabs(gg::MetaGraph, ps::Partial_sol{T}, j::Int, lower_mp end +function indices_on_boundary(grid::Matrix{Int}, j::Int) + smax = j-1 + smin = maximum([1, j - size(grid, 2)]) + collect(smin: smax) +end + function solve(g::MetaGraph, no_sols::Int = 2; node_size::Tuple{Int, Int} = (1,1), β::T, χ::Int = 2^prod(node_size), threshold::Float64 = 0., - spectrum_cutoff::Int = 1000) where T <: Real + spectrum_cutoff::Int = 1000, + δ::Float64 = 0.1) where T <: Real gg = graph4peps(g, node_size, spectrum_cutoff = spectrum_cutoff) @@ -311,13 +326,19 @@ function solve(g::MetaGraph, no_sols::Int = 2; node_size::Tuple{Int, Int} = (1,1 for j in grid[row,:] + ie = indices_on_boundary(grid, j) + partial_s_temp = Partial_sol{T}[] + + partial_s = merge_boundaries(partial_s, δ) for ps in partial_s objectives = conditional_probabs(gg, ps, j, lower_mps, vec_of_T) for l in 1:length(objectives) - push!(partial_s_temp, update_partial_solution(ps, l, ps.objective*objectives[l])) + new_objectives = ps.objective*objectives[l] + ps1 = update_partial_solution(ps, l, new_objectives, ie) + push!(partial_s_temp, ps1) end end @@ -364,6 +385,29 @@ function return_solutions(partial_s::Vector{Partial_sol{T}}, ns:: MetaGraph) wh return spins, objective end +function merge_boundaries(partial_s::Vector{Partial_sol{T}}, δ) where T <:Real + if (length(partial_s) > 1) || δ == .0 + leave = [true for _ in partial_s] + boundaries = [ps.boundary for ps in partial_s] + unique_bondaries = unique(boundaries) + if boundaries != unique_bondaries + b = countmap(boundaries) + for el in unique_bondaries + if b[el] > 1 + i = findall(x -> x == el, boundaries) + objectives = [partial_s[el].objective for el in i] + objectives = objectives./maximum(objectives) + for ind in i[objectives .< δ] + leave[ind] = false + end + end + end + return partial_s[leave] + end + end + partial_s +end + """ select_best_solutions(partial_s_temp::Vector{Partial_sol{T}}, no_sols::Int) where T <:Real @@ -373,5 +417,6 @@ function select_best_solutions(partial_s_temp::Vector{Partial_sol{T}}, no_sols:: obj = [ps.objective for ps in partial_s_temp] perm = sortperm(obj) p = last_m_els(perm, no_sols) + return partial_s_temp[p] end diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 3a768e0d..af0d7635 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -4,6 +4,7 @@ import SpinGlassPEPS: compute_single_tensor, conditional_probabs, get_parameters import SpinGlassPEPS: make_lower_mps, M2graph, graph4peps, fullM2grid! import SpinGlassPEPS: set_spin_from_letf, spin_index_from_left, spin_indices_from_above import SpinGlassPEPS: energy, solve +import SpinGlassPEPS: indices_on_boundary Random.seed!(1234) if true @@ -14,15 +15,16 @@ if true @test ps.spins == [] @test ps.objective == 1. - ps1 = Partial_sol{Float64}([1,1], 1.) + ps1 = Partial_sol{Float64}([1,1], 1., [1]) @test ps1.spins == [1,1] @test ps1.objective == 1. - ps2 = update_partial_solution(ps1, 2, 1.) + ps2 = update_partial_solution(ps1, 2, 1., [2]) @test ps2.spins == [1,1,2] @test ps2.objective == 1. + @test ps2.boundary == [1.] - ps3 = Partial_sol{Float64}([1,1,1], .2) + ps3 = Partial_sol{Float64}([1,1,1], .2, [1,2]) b = select_best_solutions([ps3, ps2], 1) @test b[1].spins == [1, 1, 2] @@ -31,8 +33,8 @@ if true @testset "functions of graph" begin - a = Partial_sol{Float64}([1,1,1,2], 0.2) - b = Partial_sol{Float64}([1,1,2,2], 1.) + a = Partial_sol{Float64}([1,1,1,2], 0.2, [1,2,3]) + b = Partial_sol{Float64}([1,1,2,2], 1., [1,2,3]) M = [1. 1. 1. 0.; 1. 1. 0. 1.; 1. 0. 1. 1.; 0. 1. 1. 1.] @@ -48,14 +50,14 @@ if true g = M2graph(M) gg = graph4peps(g, (2,2)) - ps = Partial_sol{Float64}([6], .2) + ps = Partial_sol{Float64}([6], .2, Int[]) ul,ur = spin_indices_from_above(gg, ps, 2) l = spin_index_from_left(gg, ps, 2) @test ul == [2] @test ur == [1] @test l == 2 - ps = Partial_sol{Float64}([4,6], .2) + ps = Partial_sol{Float64}([4,6], .2, [1]) ul,ur = spin_indices_from_above(gg, ps, 3) l = spin_index_from_left(gg, ps, 3) @test ul == Int[] @@ -63,6 +65,17 @@ if true @test l == 1 end + + @testset "droplet hepers" begin + grid = [1 2 3 4; 5 6 7 8; 9 10 11 12] + i = indices_on_boundary(grid, 2) + println(i == [1]) + i = indices_on_boundary(grid, 1) + println(i == Int[]) + + i = indices_on_boundary(grid, 7) + println(i == [3, 4, 5, 6]) + end end ### creation a matrix of interactions step by step as an example @@ -239,7 +252,7 @@ Mq[8,9] = Mq[9,8] = -0.05 println(size(mpo1[2])) println(size(mpo1[3])) - MPO(peps, 2, false) + #MPO(peps, 2, false) mpo2 = MPO(peps, 2, true) @@ -321,21 +334,21 @@ end l_mps = MPS([e[:,:,:,1] for e in mpo2*mpo3]) - AA = MPO(peps, 1, false) + #AA = MPO(peps, 1, false) println(size(A[1])) - println(size(AA[1])) + #println(size(AA[1])) # marginal prob - sol = Partial_sol{Float64}(Int[], 0.) + sol = Partial_sol{Float64}(Int[], 0., Int[]) j = 1 objective = conditional_probabs(gg, sol, j, lower_mps, A) println(objective) - objective1 = conditional_probabs(gg, sol, j, l_mps, AA) - println(objective1) + #objective1 = conditional_probabs(gg, sol, j, l_mps, AA) + #println(objective1) - sol = Partial_sol{Float64}([1], objective[1]) + sol = Partial_sol{Float64}([1], objective[1], Int[]) p1 = sum(cc[1,:,:,:,:,:,:,:,:])/su p2 = sum(cc[2,:,:,:,:,:,:,:,:])/su @@ -356,7 +369,7 @@ end A = M[2,:] # objective value from the previous step is set artificially - sol = Partial_sol{Float64}(Int[1,1,1,1], 1.) + sol = Partial_sol{Float64}(Int[1,1,1,1], 1., [1,2,3]) objective = conditional_probabs(gg, sol, j, lower_mps, A) #conditional prob p1 = sum(cc[1,1,1,1,1,:,:,:,:])/sum(cc[1,1,1,1,:,:,:,:,:]) @@ -368,18 +381,18 @@ end end @testset "test an exemple instance" begin - + δ = 1e-7 g = make_interactions_case2() - spins, objective = solve(g, 10; β = 3., χ = 2, threshold = 1e-11) + spins, objective = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, δ = δ) @test spins[1] == [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1] - spins_l, objective_l = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2)) + spins_l, objective_l = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), δ = δ) for i in 1:10 @test objective[i] ≈ objective_l[i] atol=1e-8 @test spins[i] == spins_l[i] end # low energy spectrum - spins_s, objective_s = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), spectrum_cutoff = 15) + spins_s, objective_s = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), spectrum_cutoff = 15, δ = δ) for i in 1:10 @test objective[i] ≈ objective_s[i] atol=1e-8 @test spins[i] == spins_s[i] @@ -388,13 +401,13 @@ end @testset "test an exemple instance on Float32" begin - + δ = 1e-7 g = make_interactions_case2() T = Float32 - spins, objective = solve(g, 10; β = T(3.), χ = 2, threshold = 1e-11) + spins, objective = solve(g, 10; β = T(3.), χ = 2, threshold = 1e-11, δ = δ) @test spins[1] == [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1] - spins_l, objective_l = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2)) + spins_l, objective_l = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), δ = δ) for i in 1:10 @test objective[i] ≈ objective_l[i] atol=1e-5 @test spins[i] == spins_l[i] From 037ff12d0a5a0bbcb68124098335663c0e232810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 12 Jan 2021 15:27:09 +0100 Subject: [PATCH 116/137] add small changes in test, some origins still do not work --- test/PEPS.jl | 4 ++-- test/graph.jl | 1 - test/runtests.jl | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/PEPS.jl b/test/PEPS.jl index f4f4a4fe..9b40f183 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -45,8 +45,8 @@ end x, y = m, n #for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) -#for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK -for origin ∈ (:EN, :ES, :WS) # NO +for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK +#for origin ∈ (:EN, :ES, :WS) # NO @info "testing peps" origin println(origin) diff --git a/test/graph.jl b/test/graph.jl index a2d5da33..7b5f0db1 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -127,7 +127,6 @@ for v ∈ vertices(fg) end end - x = m y = n origin = :NW diff --git a/test/runtests.jl b/test/runtests.jl index a52542c8..8a5074d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,8 +36,8 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - "graph.jl", - #"PEPS.jl", + #"graph.jl", + "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", # problems From cee9d07b6e3466763f6819bb5025caab5775655b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Tue, 12 Jan 2021 17:58:31 +0100 Subject: [PATCH 117/137] rm some tests --- src/PEPS.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 61135ada..72e980d9 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -134,7 +134,7 @@ function PEPSRow(::Type{T}, peps::PepsNetwork, i::Int) where {T <: Number} ten = generate_tensor(peps, (i, j), (i, j+1)) A = ψ[j] @tensor B[l, u, r, d, σ] := A[l, u, r̃, d, σ] * ten[r̃, r] - ψ[j] = B + ψ[j] = B end ψ end From 48b101573e6bad1114418aa6699feedfe53e9c30 Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Tue, 12 Jan 2021 23:15:05 +0100 Subject: [PATCH 118/137] change bond dim --- test/PEPS.jl | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/test/PEPS.jl b/test/PEPS.jl index 9b40f183..ffe83ac8 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -9,7 +9,7 @@ t = 3 L = m * n * t -bond_dimensions = [2, 2, 4, 4, 2, 2, 8] +bond_dimensions = [2, 2, 8, 4, 2, 2, 8] instance = "$(@__DIR__)/instances/pathological/test_$(m)_$(n)_$(t).txt" @@ -25,22 +25,34 @@ fg = factor_graph( spectrum=full_spectrum, ) -#= for (bd, e) in zip(bond_dimensions, edges(fg)) pl, en, pr = get_prop(fg, e, :split) - println(e) println(size(pl), " ", size(en), " ", size(pr)) - + #= + display(en) + println("-------------------") + println("-------------------") + display(pl) + println("-------------------") + println("-------------------") + display(pr) + println("-------------------") + println("-------------------") + println("-------------------") + =# isOK = min(size(en)...) == bd - + @test isOK if !isOK println(min(size(en)...), " ", bd) display(en) + display(pl) + display(pr) end + end -=# + x, y = m, n From 76ce54907dab24f91f1e1ab4e946e56906e086d0 Mon Sep 17 00:00:00 2001 From: kdomino Date: Wed, 13 Jan 2021 08:36:22 +0100 Subject: [PATCH 119/137] Update Project.toml --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 6a8db1b3..086ee184 100644 --- a/Project.toml +++ b/Project.toml @@ -31,6 +31,7 @@ LowRankApprox = "0.4" Requires = "1.1" TensorCast = "0.3" TensorOperations = "3.0.1" +StatsBase = "0.33" julia = "1.5" [extras] From dc0a9eac6e169adf6fac7dc79abf0b06d7829f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Wed, 13 Jan 2021 10:09:34 +0100 Subject: [PATCH 120/137] resotre old version of rank_reveal --- src/graph.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 76728c62..a924b46a 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -137,8 +137,8 @@ function rank_reveal(energy, order=:PE) @assert order ∈ (:PE, :EP) dim = order == :PE ? 1 : 2 - E, idx = unique_dims(energy, dim) - # idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) + E = unique(energy, dims=dim) + idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) P = order == :PE ? zeros(size(energy, 1), size(E, 1)) : zeros(size(E, 2), size(energy, 2)) From e2c136545f1d0db6c7324c3b0bb486f5d705a40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Wed, 13 Jan 2021 10:09:49 +0100 Subject: [PATCH 121/137] return unique rows from unique_dims --- src/utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index 720d42d4..d65632c5 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -171,6 +171,6 @@ end end end - (@nref $N A d->d == dim ? sort!(uniquerows) : (axes(A, d))), uniquerow + (@nref $N A d->d == dim ? sort!(uniquerows) : (axes(A, d))), uniquerow, uniquerows end end \ No newline at end of file From bd83a9645110fb2c97b5d1fb16dd7c969650a515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= <3093117+lpawela@users.noreply.github.com> Date: Wed, 13 Jan 2021 10:13:30 +0100 Subject: [PATCH 122/137] Delete Manifest.toml --- Manifest.toml | 525 -------------------------------------------------- 1 file changed, 525 deletions(-) delete mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index bdc4a069..00000000 --- a/Manifest.toml +++ /dev/null @@ -1,525 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -[[AbstractFFTs]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "051c95d6836228d120f5f4b984dd5aba1624f716" -uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" -version = "0.5.0" - -[[Adapt]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "42c42f2221906892ceb765dbcb1a51deeffd86d7" -uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -version = "2.3.0" - -[[ArnoldiMethod]] -deps = ["DelimitedFiles", "LinearAlgebra", "Random", "SparseArrays", "StaticArrays", "Test"] -git-tree-sha1 = "2b6845cea546604fb4dca4e31414a6a59d39ddcd" -uuid = "ec485272-7323-5ecc-a04f-4719b315124d" -version = "0.0.4" - -[[Artifacts]] -deps = ["Pkg"] -git-tree-sha1 = "c30985d8821e0cd73870b17b0ed0ce6dc44cb744" -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" -version = "1.3.0" - -[[Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[BinaryProvider]] -deps = ["Libdl", "Logging", "SHA"] -git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058" -uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" -version = "0.5.10" - -[[CEnum]] -git-tree-sha1 = "215a9aa4a1f23fbd05b92769fdd62559488d70e9" -uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82" -version = "0.4.1" - -[[CSV]] -deps = ["CategoricalArrays", "DataFrames", "Dates", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode"] -git-tree-sha1 = "a390152e6850405a48ca51bd7ca33d11a21d6230" -uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" -version = "0.7.7" - -[[CUDA]] -deps = ["AbstractFFTs", "Adapt", "BinaryProvider", "CEnum", "DataStructures", "ExprTools", "GPUArrays", "GPUCompiler", "LLVM", "Libdl", "LinearAlgebra", "Logging", "MacroTools", "NNlib", "Pkg", "Printf", "Random", "Reexport", "Requires", "SparseArrays", "Statistics", "TimerOutputs"] -git-tree-sha1 = "83bfd180e2f842f6d4ee315a6db8665e9aa0c19b" -uuid = "052768ef-5323-5732-b1bb-66c8b64840ba" -version = "1.3.3" - -[[CategoricalArrays]] -deps = ["DataAPI", "Future", "JSON", "Missings", "Printf", "Statistics", "StructTypes", "Unicode"] -git-tree-sha1 = "2ac27f59196a68070e132b25713f9a5bbc5fa0d2" -uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597" -version = "0.8.3" - -[[CodeTracking]] -deps = ["InteractiveUtils", "UUIDs"] -git-tree-sha1 = "8ad457cfeb0bca98732c97958ef81000a543e73e" -uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" -version = "1.0.5" - -[[CodecZlib]] -deps = ["TranscodingStreams", "Zlib_jll"] -git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da" -uuid = "944b1d66-785c-5afd-91f1-9de20f533193" -version = "0.7.0" - -[[ColorTypes]] -deps = ["FixedPointNumbers", "Random"] -git-tree-sha1 = "b9de8dc6106e09c79f3f776c27c62360d30e5eb8" -uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" -version = "0.9.1" - -[[Colors]] -deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport"] -git-tree-sha1 = "177d8b959d3c103a6d57574c38ee79c81059c31b" -uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" -version = "0.11.2" - -[[Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "f76e41cf110de7176a657c72409e722cfc86fbb6" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.20.0" - -[[Compose]] -deps = ["Base64", "Colors", "DataStructures", "Dates", "IterTools", "JSON", "LinearAlgebra", "Measures", "Printf", "Random", "Requires", "Statistics", "UUIDs"] -git-tree-sha1 = "a2b4df8e2dc688f2d63b5cfcc00c773218fa9e7f" -uuid = "a81c6b42-2e10-5240-aca2-a61377ecd94b" -version = "0.9.1" - -[[DataAPI]] -git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32" -uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.3.0" - -[[DataFrames]] -deps = ["CategoricalArrays", "Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "Missings", "PooledArrays", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] -git-tree-sha1 = "ecd850f3d2b815431104252575e7307256121548" -uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -version = "0.21.8" - -[[DataStructures]] -deps = ["Compat", "InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "db07bb22795762895b60e44d62b34b16c982a687" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.18.7" - -[[DataValueInterfaces]] -git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" -uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" -version = "1.0.0" - -[[Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - -[[Distributed]] -deps = ["Random", "Serialization", "Sockets"] -uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" - -[[DocStringExtensions]] -deps = ["LibGit2", "Markdown", "Pkg", "Test"] -git-tree-sha1 = "50ddf44c53698f5e784bbebb3f4b21c5807401b1" -uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.8.3" - -[[ExprTools]] -git-tree-sha1 = "7fce513fcda766962ff67c5596cb16c463dfd371" -uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04" -version = "0.1.2" - -[[FFTW]] -deps = ["AbstractFFTs", "FFTW_jll", "IntelOpenMP_jll", "Libdl", "LinearAlgebra", "MKL_jll", "Reexport"] -git-tree-sha1 = "8b7c16b56936047ca41bf25effa137ae0b381ae8" -uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" -version = "1.2.4" - -[[FFTW_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "f10c3009373a2d5c4349b8a2932d8accb892892d" -uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a" -version = "3.3.9+6" - -[[FileWatching]] -uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" - -[[FillArrays]] -deps = ["LinearAlgebra", "Random", "SparseArrays"] -git-tree-sha1 = "b955c227b0d1413a1a97e2ca0635a5de019d7337" -uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.9.6" - -[[FixedPointNumbers]] -git-tree-sha1 = "4aaea64dd0c30ad79037084f8ca2b94348e65eaa" -uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" -version = "0.7.1" - -[[Future]] -deps = ["Random"] -uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" - -[[GPUArrays]] -deps = ["AbstractFFTs", "Adapt", "LinearAlgebra", "Printf", "Random", "Serialization"] -git-tree-sha1 = "da6398282abd2a8c0dc3e55b49d984fcc2c582e5" -uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" -version = "5.2.1" - -[[GPUCompiler]] -deps = ["DataStructures", "InteractiveUtils", "LLVM", "Libdl", "TimerOutputs", "UUIDs"] -git-tree-sha1 = "05097d81898c527e3bf218bb083ad0ead4378e5f" -uuid = "61eb1bfa-7361-4325-ad38-22787b887f55" -version = "0.6.1" - -[[GraphPlot]] -deps = ["ArnoldiMethod", "ColorTypes", "Colors", "Compose", "DelimitedFiles", "LightGraphs", "LinearAlgebra", "Random", "SparseArrays", "Test"] -git-tree-sha1 = "f4435ce0055d4da938f3bab0c0e523826735c96a" -uuid = "a2cc645c-3eea-5389-862e-a155d0052231" -version = "0.3.1" - -[[Infiltrator]] -deps = ["REPL"] -git-tree-sha1 = "2be5c3e8adddf062c3903a6d7618f233fa4d2874" -uuid = "5903a43b-9cc3-4c30-8d17-598619ec4e9b" -version = "0.3.0" - -[[Inflate]] -git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c" -uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" -version = "0.1.2" - -[[IntelOpenMP_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "fb8e1c7a5594ba56f9011310790e03b5384998d6" -uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0" -version = "2018.0.3+0" - -[[InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[InvertedIndices]] -deps = ["Test"] -git-tree-sha1 = "15732c475062348b0165684ffe28e85ea8396afc" -uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" -version = "1.0.0" - -[[IterTools]] -git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18" -uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" -version = "1.3.0" - -[[IteratorInterfaceExtensions]] -git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" -uuid = "82899510-4779-5014-852e-03e436cf321d" -version = "1.0.0" - -[[JLD2]] -deps = ["CodecZlib", "DataStructures", "MacroTools", "Mmap", "Pkg", "Printf", "Requires", "UUIDs"] -git-tree-sha1 = "1b8168c14939e43c7c4d2c9e8f0ddd8718965430" -uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819" -version = "0.2.4" - -[[JLLWrappers]] -git-tree-sha1 = "7cec881362e5b4e367ff0279dd99a06526d51a55" -uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" -version = "1.1.2" - -[[JSON]] -deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.1" - -[[JuliaInterpreter]] -deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"] -git-tree-sha1 = "d4cbb4ccecfbcf2c475c28d186fd1b02479661eb" -uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a" -version = "0.8.6" - -[[LLVM]] -deps = ["CEnum", "Libdl", "Printf", "Unicode"] -git-tree-sha1 = "a662366a5d485dee882077e8da3e1a95a86d097f" -uuid = "929cbde3-209d-540e-8aea-75f648917ca0" -version = "2.0.0" - -[[LRUCache]] -git-tree-sha1 = "788ab2f8a434a63f065ad962368a8cd0f8660a21" -uuid = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637" -version = "1.1.0" - -[[LazyStack]] -deps = ["LinearAlgebra", "NamedDims", "OffsetArrays", "Test", "ZygoteRules"] -git-tree-sha1 = "a8bf67afad3f1ee59d367267adb7c44ccac7fdee" -uuid = "1fad7336-0346-5a1a-a56f-a06ba010965b" -version = "0.0.7" - -[[LibGit2]] -deps = ["Printf"] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[LightGraphs]] -deps = ["ArnoldiMethod", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"] -git-tree-sha1 = "a0d4bcea4b9c056da143a5ded3c2b7f7740c2d41" -uuid = "093fc24a-ae57-5d10-9952-331d41423f4d" -version = "1.3.0" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[LowRankApprox]] -deps = ["FFTW", "FillArrays", "LinearAlgebra", "Nullables", "Random", "SparseArrays", "Test"] -git-tree-sha1 = "945c7da49e1c999956b21b106b238f9bd7ab1a63" -uuid = "898213cb-b102-5a47-900c-97e73b919f73" -version = "0.4.1" - -[[LoweredCodeUtils]] -deps = ["JuliaInterpreter"] -git-tree-sha1 = "9af25a91bda16307caff2a50f9c744c432b8bc1b" -uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" -version = "1.2.6" - -[[MKL_jll]] -deps = ["IntelOpenMP_jll", "Libdl", "Pkg"] -git-tree-sha1 = "eb540ede3aabb8284cb482aa41d00d6ca850b1f8" -uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7" -version = "2020.2.254+0" - -[[MacroTools]] -deps = ["Markdown", "Random"] -git-tree-sha1 = "f7d2e3f654af75f01ec49be82c231c382214223a" -uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.5" - -[[Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[Measures]] -git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f" -uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" -version = "0.3.1" - -[[MetaGraphs]] -deps = ["JLD2", "LightGraphs", "Random"] -git-tree-sha1 = "df1706b656e11e7bcf5997a51501e40fab84f567" -uuid = "626554b9-1ddb-594c-aa3c-2596fe9399a5" -version = "0.6.6" - -[[Missings]] -deps = ["DataAPI"] -git-tree-sha1 = "ed61674a0864832495ffe0a7e889c0da76b0f4c8" -uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" -version = "0.4.4" - -[[Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[NNlib]] -deps = ["Libdl", "LinearAlgebra", "Pkg", "Requires", "Statistics"] -git-tree-sha1 = "1ef04283efe283be08e2d0de842f5e5286dd0b7a" -uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" -version = "0.7.5" - -[[NamedDims]] -deps = ["LinearAlgebra", "Pkg", "Requires", "Statistics"] -git-tree-sha1 = "263f7305bfa5b8b69cd3239ec6a4c037ff96b3df" -uuid = "356022a1-0364-5f58-8944-0da4b18d706f" -version = "0.2.28" - -[[Nullables]] -git-tree-sha1 = "8f87854cc8f3685a60689d8edecaa29d2251979b" -uuid = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd" -version = "1.0.0" - -[[OffsetArrays]] -git-tree-sha1 = "a416e2f267e2c8729f25bcaf1ce19d2893faf393" -uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "1.3.1" - -[[OrderedCollections]] -git-tree-sha1 = "16c08bf5dba06609fe45e30860092d6fa41fde7b" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.3.1" - -[[Parsers]] -deps = ["Dates"] -git-tree-sha1 = "6fa4202675c05ba0f8268a6ddf07606350eda3ce" -uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "1.0.11" - -[[Pkg]] -deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[PooledArrays]] -deps = ["DataAPI"] -git-tree-sha1 = "b1333d4eced1826e15adbdf01a4ecaccca9d353c" -uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" -version = "0.5.3" - -[[Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[Reexport]] -deps = ["Pkg"] -git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" -uuid = "189a3867-3050-52da-a836-e630ba90ab69" -version = "0.2.0" - -[[Requires]] -deps = ["UUIDs"] -git-tree-sha1 = "28faf1c963ca1dc3ec87f166d92982e3c4a1f66d" -uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "1.1.0" - -[[Revise]] -deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "UUIDs", "Unicode"] -git-tree-sha1 = "b520a7f1a34326c8b5dd23947a71f24f5bb3657b" -uuid = "295af30f-e4ad-537b-8983-00126c2a3abe" -version = "3.1.3" - -[[SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[SentinelArrays]] -deps = ["Dates", "Random"] -git-tree-sha1 = "6ccde405cf0759eba835eb613130723cb8f10ff9" -uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c" -version = "1.2.16" - -[[Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - -[[SimpleTraits]] -deps = ["InteractiveUtils", "MacroTools"] -git-tree-sha1 = "daf7aec3fe3acb2131388f93a4c409b8c7f62226" -uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" -version = "0.9.3" - -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[SortingAlgorithms]] -deps = ["DataStructures", "Random", "Test"] -git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" -uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" -version = "0.3.1" - -[[SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[StaticArrays]] -deps = ["LinearAlgebra", "Random", "Statistics"] -git-tree-sha1 = "016d1e1a00fabc556473b07161da3d39726ded35" -uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "0.12.4" - -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[Strided]] -deps = ["LinearAlgebra", "TupleTools"] -git-tree-sha1 = "82111d3fe7982756d98e8b6606394efc6bb8df40" -uuid = "5e0ebb24-38b0-5f93-81fe-25c709ecae67" -version = "1.1.1" - -[[StructTypes]] -deps = ["Dates", "UUIDs"] -git-tree-sha1 = "1ed04f622a39d2e5a6747c3a70be040c00333933" -uuid = "856f2bd8-1eba-4b0a-8007-ebc267875bd4" -version = "1.1.0" - -[[TableTraits]] -deps = ["IteratorInterfaceExtensions"] -git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e" -uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" -version = "1.0.0" - -[[Tables]] -deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] -git-tree-sha1 = "24a584cf65e2cfabdadc21694fb69d2e74c82b44" -uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -version = "1.1.0" - -[[TensorCast]] -deps = ["Compat", "LazyStack", "LinearAlgebra", "MacroTools", "OffsetArrays", "Random", "Requires", "StaticArrays", "ZygoteRules"] -git-tree-sha1 = "33d8c8e3b5d37e9f98af3f5ae49ec22200d2d277" -uuid = "02d47bb6-7ce6-556a-be16-bb1710789e2b" -version = "0.3.2" - -[[TensorOperations]] -deps = ["CUDA", "LRUCache", "LinearAlgebra", "Requires", "Strided", "TupleTools"] -git-tree-sha1 = "70c0991d6cbed7d80a0c8c0d96153eff34d8a562" -uuid = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" -version = "3.0.1" - -[[Test]] -deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[TimerOutputs]] -deps = ["Printf"] -git-tree-sha1 = "f458ca23ff80e46a630922c555d838303e4b9603" -uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" -version = "0.5.6" - -[[TranscodingStreams]] -deps = ["Random", "Test"] -git-tree-sha1 = "7c53c35547de1c5b9d46a4797cf6d8253807108c" -uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -version = "0.9.5" - -[[TupleTools]] -git-tree-sha1 = "62a7a6cd5a608ff71cecfdb612e67a0897836069" -uuid = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6" -version = "1.2.0" - -[[UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[Zlib_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "320228915c8debb12cb434c59057290f0834dbf6" -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.11+18" - -[[ZygoteRules]] -deps = ["MacroTools"] -git-tree-sha1 = "b3b4882cc9accf6731a08cc39543fbc6b669dca8" -uuid = "700de1a5-db45-46bc-99cf-38207098b444" -version = "0.2.0" From 5644b589c5f5a1652ca119675731e7f85d799d45 Mon Sep 17 00:00:00 2001 From: kdomino Date: Wed, 13 Jan 2021 11:20:59 +0100 Subject: [PATCH 123/137] remove locally Manifest --- Manifest.toml | 525 --------------------------------------------- test/peps_tests.jl | 2 +- 2 files changed, 1 insertion(+), 526 deletions(-) delete mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index bdc4a069..00000000 --- a/Manifest.toml +++ /dev/null @@ -1,525 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -[[AbstractFFTs]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "051c95d6836228d120f5f4b984dd5aba1624f716" -uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" -version = "0.5.0" - -[[Adapt]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "42c42f2221906892ceb765dbcb1a51deeffd86d7" -uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -version = "2.3.0" - -[[ArnoldiMethod]] -deps = ["DelimitedFiles", "LinearAlgebra", "Random", "SparseArrays", "StaticArrays", "Test"] -git-tree-sha1 = "2b6845cea546604fb4dca4e31414a6a59d39ddcd" -uuid = "ec485272-7323-5ecc-a04f-4719b315124d" -version = "0.0.4" - -[[Artifacts]] -deps = ["Pkg"] -git-tree-sha1 = "c30985d8821e0cd73870b17b0ed0ce6dc44cb744" -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" -version = "1.3.0" - -[[Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[BinaryProvider]] -deps = ["Libdl", "Logging", "SHA"] -git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058" -uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" -version = "0.5.10" - -[[CEnum]] -git-tree-sha1 = "215a9aa4a1f23fbd05b92769fdd62559488d70e9" -uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82" -version = "0.4.1" - -[[CSV]] -deps = ["CategoricalArrays", "DataFrames", "Dates", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode"] -git-tree-sha1 = "a390152e6850405a48ca51bd7ca33d11a21d6230" -uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" -version = "0.7.7" - -[[CUDA]] -deps = ["AbstractFFTs", "Adapt", "BinaryProvider", "CEnum", "DataStructures", "ExprTools", "GPUArrays", "GPUCompiler", "LLVM", "Libdl", "LinearAlgebra", "Logging", "MacroTools", "NNlib", "Pkg", "Printf", "Random", "Reexport", "Requires", "SparseArrays", "Statistics", "TimerOutputs"] -git-tree-sha1 = "83bfd180e2f842f6d4ee315a6db8665e9aa0c19b" -uuid = "052768ef-5323-5732-b1bb-66c8b64840ba" -version = "1.3.3" - -[[CategoricalArrays]] -deps = ["DataAPI", "Future", "JSON", "Missings", "Printf", "Statistics", "StructTypes", "Unicode"] -git-tree-sha1 = "2ac27f59196a68070e132b25713f9a5bbc5fa0d2" -uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597" -version = "0.8.3" - -[[CodeTracking]] -deps = ["InteractiveUtils", "UUIDs"] -git-tree-sha1 = "8ad457cfeb0bca98732c97958ef81000a543e73e" -uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" -version = "1.0.5" - -[[CodecZlib]] -deps = ["TranscodingStreams", "Zlib_jll"] -git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da" -uuid = "944b1d66-785c-5afd-91f1-9de20f533193" -version = "0.7.0" - -[[ColorTypes]] -deps = ["FixedPointNumbers", "Random"] -git-tree-sha1 = "b9de8dc6106e09c79f3f776c27c62360d30e5eb8" -uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" -version = "0.9.1" - -[[Colors]] -deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport"] -git-tree-sha1 = "177d8b959d3c103a6d57574c38ee79c81059c31b" -uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" -version = "0.11.2" - -[[Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "f76e41cf110de7176a657c72409e722cfc86fbb6" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.20.0" - -[[Compose]] -deps = ["Base64", "Colors", "DataStructures", "Dates", "IterTools", "JSON", "LinearAlgebra", "Measures", "Printf", "Random", "Requires", "Statistics", "UUIDs"] -git-tree-sha1 = "a2b4df8e2dc688f2d63b5cfcc00c773218fa9e7f" -uuid = "a81c6b42-2e10-5240-aca2-a61377ecd94b" -version = "0.9.1" - -[[DataAPI]] -git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32" -uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.3.0" - -[[DataFrames]] -deps = ["CategoricalArrays", "Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "Missings", "PooledArrays", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] -git-tree-sha1 = "ecd850f3d2b815431104252575e7307256121548" -uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -version = "0.21.8" - -[[DataStructures]] -deps = ["Compat", "InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "db07bb22795762895b60e44d62b34b16c982a687" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.18.7" - -[[DataValueInterfaces]] -git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" -uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" -version = "1.0.0" - -[[Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - -[[Distributed]] -deps = ["Random", "Serialization", "Sockets"] -uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" - -[[DocStringExtensions]] -deps = ["LibGit2", "Markdown", "Pkg", "Test"] -git-tree-sha1 = "50ddf44c53698f5e784bbebb3f4b21c5807401b1" -uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.8.3" - -[[ExprTools]] -git-tree-sha1 = "7fce513fcda766962ff67c5596cb16c463dfd371" -uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04" -version = "0.1.2" - -[[FFTW]] -deps = ["AbstractFFTs", "FFTW_jll", "IntelOpenMP_jll", "Libdl", "LinearAlgebra", "MKL_jll", "Reexport"] -git-tree-sha1 = "8b7c16b56936047ca41bf25effa137ae0b381ae8" -uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" -version = "1.2.4" - -[[FFTW_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "f10c3009373a2d5c4349b8a2932d8accb892892d" -uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a" -version = "3.3.9+6" - -[[FileWatching]] -uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" - -[[FillArrays]] -deps = ["LinearAlgebra", "Random", "SparseArrays"] -git-tree-sha1 = "b955c227b0d1413a1a97e2ca0635a5de019d7337" -uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.9.6" - -[[FixedPointNumbers]] -git-tree-sha1 = "4aaea64dd0c30ad79037084f8ca2b94348e65eaa" -uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" -version = "0.7.1" - -[[Future]] -deps = ["Random"] -uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" - -[[GPUArrays]] -deps = ["AbstractFFTs", "Adapt", "LinearAlgebra", "Printf", "Random", "Serialization"] -git-tree-sha1 = "da6398282abd2a8c0dc3e55b49d984fcc2c582e5" -uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" -version = "5.2.1" - -[[GPUCompiler]] -deps = ["DataStructures", "InteractiveUtils", "LLVM", "Libdl", "TimerOutputs", "UUIDs"] -git-tree-sha1 = "05097d81898c527e3bf218bb083ad0ead4378e5f" -uuid = "61eb1bfa-7361-4325-ad38-22787b887f55" -version = "0.6.1" - -[[GraphPlot]] -deps = ["ArnoldiMethod", "ColorTypes", "Colors", "Compose", "DelimitedFiles", "LightGraphs", "LinearAlgebra", "Random", "SparseArrays", "Test"] -git-tree-sha1 = "f4435ce0055d4da938f3bab0c0e523826735c96a" -uuid = "a2cc645c-3eea-5389-862e-a155d0052231" -version = "0.3.1" - -[[Infiltrator]] -deps = ["REPL"] -git-tree-sha1 = "2be5c3e8adddf062c3903a6d7618f233fa4d2874" -uuid = "5903a43b-9cc3-4c30-8d17-598619ec4e9b" -version = "0.3.0" - -[[Inflate]] -git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c" -uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" -version = "0.1.2" - -[[IntelOpenMP_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "fb8e1c7a5594ba56f9011310790e03b5384998d6" -uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0" -version = "2018.0.3+0" - -[[InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[InvertedIndices]] -deps = ["Test"] -git-tree-sha1 = "15732c475062348b0165684ffe28e85ea8396afc" -uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" -version = "1.0.0" - -[[IterTools]] -git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18" -uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" -version = "1.3.0" - -[[IteratorInterfaceExtensions]] -git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" -uuid = "82899510-4779-5014-852e-03e436cf321d" -version = "1.0.0" - -[[JLD2]] -deps = ["CodecZlib", "DataStructures", "MacroTools", "Mmap", "Pkg", "Printf", "Requires", "UUIDs"] -git-tree-sha1 = "1b8168c14939e43c7c4d2c9e8f0ddd8718965430" -uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819" -version = "0.2.4" - -[[JLLWrappers]] -git-tree-sha1 = "7cec881362e5b4e367ff0279dd99a06526d51a55" -uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" -version = "1.1.2" - -[[JSON]] -deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.1" - -[[JuliaInterpreter]] -deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"] -git-tree-sha1 = "d4cbb4ccecfbcf2c475c28d186fd1b02479661eb" -uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a" -version = "0.8.6" - -[[LLVM]] -deps = ["CEnum", "Libdl", "Printf", "Unicode"] -git-tree-sha1 = "a662366a5d485dee882077e8da3e1a95a86d097f" -uuid = "929cbde3-209d-540e-8aea-75f648917ca0" -version = "2.0.0" - -[[LRUCache]] -git-tree-sha1 = "788ab2f8a434a63f065ad962368a8cd0f8660a21" -uuid = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637" -version = "1.1.0" - -[[LazyStack]] -deps = ["LinearAlgebra", "NamedDims", "OffsetArrays", "Test", "ZygoteRules"] -git-tree-sha1 = "a8bf67afad3f1ee59d367267adb7c44ccac7fdee" -uuid = "1fad7336-0346-5a1a-a56f-a06ba010965b" -version = "0.0.7" - -[[LibGit2]] -deps = ["Printf"] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[LightGraphs]] -deps = ["ArnoldiMethod", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"] -git-tree-sha1 = "a0d4bcea4b9c056da143a5ded3c2b7f7740c2d41" -uuid = "093fc24a-ae57-5d10-9952-331d41423f4d" -version = "1.3.0" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[LowRankApprox]] -deps = ["FFTW", "FillArrays", "LinearAlgebra", "Nullables", "Random", "SparseArrays", "Test"] -git-tree-sha1 = "945c7da49e1c999956b21b106b238f9bd7ab1a63" -uuid = "898213cb-b102-5a47-900c-97e73b919f73" -version = "0.4.1" - -[[LoweredCodeUtils]] -deps = ["JuliaInterpreter"] -git-tree-sha1 = "9af25a91bda16307caff2a50f9c744c432b8bc1b" -uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" -version = "1.2.6" - -[[MKL_jll]] -deps = ["IntelOpenMP_jll", "Libdl", "Pkg"] -git-tree-sha1 = "eb540ede3aabb8284cb482aa41d00d6ca850b1f8" -uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7" -version = "2020.2.254+0" - -[[MacroTools]] -deps = ["Markdown", "Random"] -git-tree-sha1 = "f7d2e3f654af75f01ec49be82c231c382214223a" -uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.5" - -[[Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[Measures]] -git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f" -uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" -version = "0.3.1" - -[[MetaGraphs]] -deps = ["JLD2", "LightGraphs", "Random"] -git-tree-sha1 = "df1706b656e11e7bcf5997a51501e40fab84f567" -uuid = "626554b9-1ddb-594c-aa3c-2596fe9399a5" -version = "0.6.6" - -[[Missings]] -deps = ["DataAPI"] -git-tree-sha1 = "ed61674a0864832495ffe0a7e889c0da76b0f4c8" -uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" -version = "0.4.4" - -[[Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[NNlib]] -deps = ["Libdl", "LinearAlgebra", "Pkg", "Requires", "Statistics"] -git-tree-sha1 = "1ef04283efe283be08e2d0de842f5e5286dd0b7a" -uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" -version = "0.7.5" - -[[NamedDims]] -deps = ["LinearAlgebra", "Pkg", "Requires", "Statistics"] -git-tree-sha1 = "263f7305bfa5b8b69cd3239ec6a4c037ff96b3df" -uuid = "356022a1-0364-5f58-8944-0da4b18d706f" -version = "0.2.28" - -[[Nullables]] -git-tree-sha1 = "8f87854cc8f3685a60689d8edecaa29d2251979b" -uuid = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd" -version = "1.0.0" - -[[OffsetArrays]] -git-tree-sha1 = "a416e2f267e2c8729f25bcaf1ce19d2893faf393" -uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "1.3.1" - -[[OrderedCollections]] -git-tree-sha1 = "16c08bf5dba06609fe45e30860092d6fa41fde7b" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.3.1" - -[[Parsers]] -deps = ["Dates"] -git-tree-sha1 = "6fa4202675c05ba0f8268a6ddf07606350eda3ce" -uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "1.0.11" - -[[Pkg]] -deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[PooledArrays]] -deps = ["DataAPI"] -git-tree-sha1 = "b1333d4eced1826e15adbdf01a4ecaccca9d353c" -uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" -version = "0.5.3" - -[[Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[Reexport]] -deps = ["Pkg"] -git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" -uuid = "189a3867-3050-52da-a836-e630ba90ab69" -version = "0.2.0" - -[[Requires]] -deps = ["UUIDs"] -git-tree-sha1 = "28faf1c963ca1dc3ec87f166d92982e3c4a1f66d" -uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "1.1.0" - -[[Revise]] -deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "UUIDs", "Unicode"] -git-tree-sha1 = "b520a7f1a34326c8b5dd23947a71f24f5bb3657b" -uuid = "295af30f-e4ad-537b-8983-00126c2a3abe" -version = "3.1.3" - -[[SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[SentinelArrays]] -deps = ["Dates", "Random"] -git-tree-sha1 = "6ccde405cf0759eba835eb613130723cb8f10ff9" -uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c" -version = "1.2.16" - -[[Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - -[[SimpleTraits]] -deps = ["InteractiveUtils", "MacroTools"] -git-tree-sha1 = "daf7aec3fe3acb2131388f93a4c409b8c7f62226" -uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" -version = "0.9.3" - -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[SortingAlgorithms]] -deps = ["DataStructures", "Random", "Test"] -git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" -uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" -version = "0.3.1" - -[[SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[StaticArrays]] -deps = ["LinearAlgebra", "Random", "Statistics"] -git-tree-sha1 = "016d1e1a00fabc556473b07161da3d39726ded35" -uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "0.12.4" - -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[Strided]] -deps = ["LinearAlgebra", "TupleTools"] -git-tree-sha1 = "82111d3fe7982756d98e8b6606394efc6bb8df40" -uuid = "5e0ebb24-38b0-5f93-81fe-25c709ecae67" -version = "1.1.1" - -[[StructTypes]] -deps = ["Dates", "UUIDs"] -git-tree-sha1 = "1ed04f622a39d2e5a6747c3a70be040c00333933" -uuid = "856f2bd8-1eba-4b0a-8007-ebc267875bd4" -version = "1.1.0" - -[[TableTraits]] -deps = ["IteratorInterfaceExtensions"] -git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e" -uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" -version = "1.0.0" - -[[Tables]] -deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] -git-tree-sha1 = "24a584cf65e2cfabdadc21694fb69d2e74c82b44" -uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -version = "1.1.0" - -[[TensorCast]] -deps = ["Compat", "LazyStack", "LinearAlgebra", "MacroTools", "OffsetArrays", "Random", "Requires", "StaticArrays", "ZygoteRules"] -git-tree-sha1 = "33d8c8e3b5d37e9f98af3f5ae49ec22200d2d277" -uuid = "02d47bb6-7ce6-556a-be16-bb1710789e2b" -version = "0.3.2" - -[[TensorOperations]] -deps = ["CUDA", "LRUCache", "LinearAlgebra", "Requires", "Strided", "TupleTools"] -git-tree-sha1 = "70c0991d6cbed7d80a0c8c0d96153eff34d8a562" -uuid = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" -version = "3.0.1" - -[[Test]] -deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[TimerOutputs]] -deps = ["Printf"] -git-tree-sha1 = "f458ca23ff80e46a630922c555d838303e4b9603" -uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" -version = "0.5.6" - -[[TranscodingStreams]] -deps = ["Random", "Test"] -git-tree-sha1 = "7c53c35547de1c5b9d46a4797cf6d8253807108c" -uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -version = "0.9.5" - -[[TupleTools]] -git-tree-sha1 = "62a7a6cd5a608ff71cecfdb612e67a0897836069" -uuid = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6" -version = "1.2.0" - -[[UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[Zlib_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "320228915c8debb12cb434c59057290f0834dbf6" -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.11+18" - -[[ZygoteRules]] -deps = ["MacroTools"] -git-tree-sha1 = "b3b4882cc9accf6731a08cc39543fbc6b669dca8" -uuid = "700de1a5-db45-46bc-99cf-38207098b444" -version = "0.2.0" diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 8b5fd0a7..f401f241 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -246,7 +246,7 @@ Mq[8,9] = Mq[9,8] = -0.05 peps = PepsNetwork(x, y, fg, β, origin) B = generate_tensor(peps, (1,1)) - mpo1 = MPO(peps, 1, 3) + mpo1 = MPO(peps, 1) println(size(mpo1[1])) println(size(mpo1[2])) From b6f1615ce782efdb33725c3d082915e5ffe63358 Mon Sep 17 00:00:00 2001 From: kdomino Date: Wed, 13 Jan 2021 11:44:47 +0100 Subject: [PATCH 124/137] all tests are passing --- test/peps_tests.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/peps_tests.jl b/test/peps_tests.jl index f401f241..6ddc51b0 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -246,7 +246,7 @@ Mq[8,9] = Mq[9,8] = -0.05 peps = PepsNetwork(x, y, fg, β, origin) B = generate_tensor(peps, (1,1)) - mpo1 = MPO(peps, 1) + mpo1 = MPO(PEPSRow(peps, 1)) println(size(mpo1[1])) println(size(mpo1[2])) @@ -254,13 +254,13 @@ Mq[8,9] = Mq[9,8] = -0.05 #MPO(peps, 2, false) - mpo2 = MPO(peps, 2, true) + mpo2 = MPO(PEPSRow(peps, 2)) mpo12 = mpo1*mpo2 mpsu = MPS([permutedims(e[:,1,:,:], [1,3,2]) for e in mpo12]) - mpo3 = MPO(peps, 3, true) + mpo3 = MPO(PEPSRow(peps, 3)) mpsl = MPS([e[:,:,:,1] for e in mpo3]) @@ -315,8 +315,8 @@ end origin = :NW peps = PepsNetwork(3, 3, fg, β, origin) - mpo2 = MPO(peps, 2, true) - mpo3 = MPO(peps, 3, true) + mpo2 = MPO(PEPSRow(peps, 2)) + mpo3 = MPO(PEPSRow(peps, 3)) M = form_peps(gg, β) From 596460aee18fc7a41228650e322ef7b4d966e911 Mon Sep 17 00:00:00 2001 From: kdomino Date: Wed, 13 Jan 2021 13:19:16 +0100 Subject: [PATCH 125/137] some tests on the droplet specifics --- test/peps_tests.jl | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 6ddc51b0..611b1029 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -4,7 +4,7 @@ import SpinGlassPEPS: compute_single_tensor, conditional_probabs, get_parameters import SpinGlassPEPS: make_lower_mps, M2graph, graph4peps, fullM2grid! import SpinGlassPEPS: set_spin_from_letf, spin_index_from_left, spin_indices_from_above import SpinGlassPEPS: energy, solve -import SpinGlassPEPS: indices_on_boundary +import SpinGlassPEPS: indices_on_boundary, merge_boundaries Random.seed!(1234) if true @@ -33,7 +33,7 @@ if true @testset "functions of graph" begin - a = Partial_sol{Float64}([1,1,1,2], 0.2, [1,2,3]) + a = Partial_sol{Float64}([1,1,1,2], 0.2, [1,2,3]) b = Partial_sol{Float64}([1,1,2,2], 1., [1,2,3]) M = [1. 1. 1. 0.; 1. 1. 0. 1.; 1. 0. 1. 1.; 0. 1. 1. 1.] @@ -69,12 +69,38 @@ if true @testset "droplet hepers" begin grid = [1 2 3 4; 5 6 7 8; 9 10 11 12] i = indices_on_boundary(grid, 2) - println(i == [1]) + @test i == [1] i = indices_on_boundary(grid, 1) - println(i == Int[]) + @test i == Int[] i = indices_on_boundary(grid, 7) - println(i == [3, 4, 5, 6]) + @test i == [3, 4, 5, 6] + + boundary = [2,3] + a = Partial_sol{Float64}([1,1,1], 0.2, boundary) + b = Partial_sol{Float64}([2,1,1], 0.18, boundary) + c = Partial_sol{Float64}([1,1,2], 1., boundary) + d = Partial_sol{Float64}([2,1,2], .1, boundary) + + vps = [a,b,c,d] + + thershold = 0.15 + # 0.18/0.2 = 0.9 + # 0.1/1. = 0.1 + + ps1 = merge_boundaries(vps, thershold) + println(ps1 == [a,b,c]) + + thershold = 0.95 + + ps1 = merge_boundaries(vps, thershold) + println(ps1) + println(ps1 == [a,c]) + + thershold = 0. + + ps1 = merge_boundaries(vps, thershold) + println(ps1 == [a,b,c,d]) end end From ed7d5fe9ddaa8be5f81955d146365952318c09e7 Mon Sep 17 00:00:00 2001 From: kdomino Date: Wed, 13 Jan 2021 13:27:46 +0100 Subject: [PATCH 126/137] some testing --- src/peps_no_types.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/peps_no_types.jl b/src/peps_no_types.jl index 4275a243..3b828537 100644 --- a/src/peps_no_types.jl +++ b/src/peps_no_types.jl @@ -395,8 +395,11 @@ function merge_boundaries(partial_s::Vector{Partial_sol{T}}, δ) where T <:Real for el in unique_bondaries if b[el] > 1 i = findall(x -> x == el, boundaries) - objectives = [partial_s[el].objective for el in i] + objectives = [partial_s[j].objective for j in i] + println(objectives) + println(maximum(objectives)) objectives = objectives./maximum(objectives) + println(objectives) for ind in i[objectives .< δ] leave[ind] = false end From 914816add57b04c33529cfcab15c1a1359c60670 Mon Sep 17 00:00:00 2001 From: Krzysztof Domino Date: Wed, 13 Jan 2021 14:23:08 +0100 Subject: [PATCH 127/137] correct droplet --- src/peps_no_types.jl | 7 +++---- test/peps_tests.jl | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/peps_no_types.jl b/src/peps_no_types.jl index 3b828537..80b7bdfe 100644 --- a/src/peps_no_types.jl +++ b/src/peps_no_types.jl @@ -388,7 +388,8 @@ end function merge_boundaries(partial_s::Vector{Partial_sol{T}}, δ) where T <:Real if (length(partial_s) > 1) || δ == .0 leave = [true for _ in partial_s] - boundaries = [ps.boundary for ps in partial_s] + boundaries = [ps.spins[ps.boundary] for ps in partial_s] + unique_bondaries = unique(boundaries) if boundaries != unique_bondaries b = countmap(boundaries) @@ -396,10 +397,8 @@ function merge_boundaries(partial_s::Vector{Partial_sol{T}}, δ) where T <:Real if b[el] > 1 i = findall(x -> x == el, boundaries) objectives = [partial_s[j].objective for j in i] - println(objectives) - println(maximum(objectives)) + objectives = objectives./maximum(objectives) - println(objectives) for ind in i[objectives .< δ] leave[ind] = false end diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 611b1029..45ff0327 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -407,7 +407,7 @@ end end @testset "test an exemple instance" begin - δ = 1e-7 + δ = 0. g = make_interactions_case2() spins, objective = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, δ = δ) @test spins[1] == [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1] @@ -427,7 +427,7 @@ end @testset "test an exemple instance on Float32" begin - δ = 1e-7 + δ = 0. g = make_interactions_case2() T = Float32 spins, objective = solve(g, 10; β = T(3.), χ = 2, threshold = 1e-11, δ = δ) From c9736ff50278ac71719c2aac1b58f739f2894ade Mon Sep 17 00:00:00 2001 From: Krzysztof Domino Date: Wed, 13 Jan 2021 15:24:59 +0100 Subject: [PATCH 128/137] correction --- test/peps_tests.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 45ff0327..32c9e432 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -278,7 +278,8 @@ Mq[8,9] = Mq[9,8] = -0.05 println(size(mpo1[2])) println(size(mpo1[3])) - #MPO(peps, 2, false) + pp = PEPSRow(peps, 2) + println(pp) mpo2 = MPO(PEPSRow(peps, 2)) From cd1019008699e900c8eea2161e5e41096a785681 Mon Sep 17 00:00:00 2001 From: kdomino Date: Wed, 13 Jan 2021 16:23:43 +0100 Subject: [PATCH 129/137] correct droplet --- benchmarks/tests_grid_from_file.jl | 2 +- src/peps_no_types.jl | 27 ++++++++---------- test/peps_tests.jl | 45 +++++++++++++++--------------- 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/benchmarks/tests_grid_from_file.jl b/benchmarks/tests_grid_from_file.jl index 1cc241d9..a03a57ee 100644 --- a/benchmarks/tests_grid_from_file.jl +++ b/benchmarks/tests_grid_from_file.jl @@ -31,7 +31,7 @@ println("examples = ", examples) β = 3. -δ = 0. +δ = 1e-8 number_of_states = 10 diff --git a/src/peps_no_types.jl b/src/peps_no_types.jl index 80b7bdfe..dc5f59d1 100644 --- a/src/peps_no_types.jl +++ b/src/peps_no_types.jl @@ -173,15 +173,12 @@ structure of the partial solution mutable struct Partial_sol{T <: Real} spins::Vector{Int} objective::T - boundary::Vector{Int} + function(::Type{Partial_sol{T}})(spins::Vector{Int}, objective::T) where T <:Real - new{T}(spins, objective, Int[]) - end - function(::Type{Partial_sol{T}})(spins::Vector{Int}, objective::T, boundary::Vector{Int}) where T <:Real - new{T}(spins, objective, boundary) + new{T}(spins, objective) end function(::Type{Partial_sol{T}})() where T <:Real - new{T}(Int[], 1., Int[]) + new{T}(Int[], 1.) end end @@ -196,10 +193,6 @@ function update_partial_solution(ps::Partial_sol{T}, s::Int, objective::T) where Partial_sol{T}(vcat(ps.spins, [s]), objective) end -function update_partial_solution(ps::Partial_sol{T}, s::Int, objective::T, boundary::Vector{Int}) where T <: Real - Partial_sol{T}(vcat(ps.spins, [s]), objective, ps.spins[boundary]) -end - """ spin_indices_from_above(gg::MetaGraph, ps::Partial_sol, j::Int) @@ -326,18 +319,18 @@ function solve(g::MetaGraph, no_sols::Int = 2; node_size::Tuple{Int, Int} = (1,1 for j in grid[row,:] - ie = indices_on_boundary(grid, j) + dX = indices_on_boundary(grid, j) partial_s_temp = Partial_sol{T}[] - partial_s = merge_boundaries(partial_s, δ) + partial_s = merge_boundaries(partial_s, dX, δ) for ps in partial_s objectives = conditional_probabs(gg, ps, j, lower_mps, vec_of_T) for l in 1:length(objectives) new_objectives = ps.objective*objectives[l] - ps1 = update_partial_solution(ps, l, new_objectives, ie) + ps1 = update_partial_solution(ps, l, new_objectives) push!(partial_s_temp, ps1) end @@ -385,10 +378,11 @@ function return_solutions(partial_s::Vector{Partial_sol{T}}, ns:: MetaGraph) wh return spins, objective end -function merge_boundaries(partial_s::Vector{Partial_sol{T}}, δ) where T <:Real - if (length(partial_s) > 1) || δ == .0 +function merge_boundaries(partial_s::Vector{Partial_sol{T}}, dX::Vector{Int}, δ) where T <:Real + if (length(partial_s) > 1) & (δ != .0) leave = [true for _ in partial_s] - boundaries = [ps.spins[ps.boundary] for ps in partial_s] + + boundaries = [ps.spins[dX] for ps in partial_s] unique_bondaries = unique(boundaries) if boundaries != unique_bondaries @@ -401,6 +395,7 @@ function merge_boundaries(partial_s::Vector{Partial_sol{T}}, δ) where T <:Real objectives = objectives./maximum(objectives) for ind in i[objectives .< δ] leave[ind] = false + println(leave) end end end diff --git a/test/peps_tests.jl b/test/peps_tests.jl index 32c9e432..a346d964 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -15,16 +15,15 @@ if true @test ps.spins == [] @test ps.objective == 1. - ps1 = Partial_sol{Float64}([1,1], 1., [1]) + ps1 = Partial_sol{Float64}([1,1], 1.) @test ps1.spins == [1,1] @test ps1.objective == 1. - ps2 = update_partial_solution(ps1, 2, 1., [2]) + ps2 = update_partial_solution(ps1, 2, 1.) @test ps2.spins == [1,1,2] @test ps2.objective == 1. - @test ps2.boundary == [1.] - ps3 = Partial_sol{Float64}([1,1,1], .2, [1,2]) + ps3 = Partial_sol{Float64}([1,1,1], .2) b = select_best_solutions([ps3, ps2], 1) @test b[1].spins == [1, 1, 2] @@ -33,8 +32,8 @@ if true @testset "functions of graph" begin - a = Partial_sol{Float64}([1,1,1,2], 0.2, [1,2,3]) - b = Partial_sol{Float64}([1,1,2,2], 1., [1,2,3]) + a = Partial_sol{Float64}([1,1,1,2], 0.2) + b = Partial_sol{Float64}([1,1,2,2], 1.) M = [1. 1. 1. 0.; 1. 1. 0. 1.; 1. 0. 1. 1.; 0. 1. 1. 1.] @@ -50,14 +49,14 @@ if true g = M2graph(M) gg = graph4peps(g, (2,2)) - ps = Partial_sol{Float64}([6], .2, Int[]) + ps = Partial_sol{Float64}([6], .2) ul,ur = spin_indices_from_above(gg, ps, 2) l = spin_index_from_left(gg, ps, 2) @test ul == [2] @test ur == [1] @test l == 2 - ps = Partial_sol{Float64}([4,6], .2, [1]) + ps = Partial_sol{Float64}([4,6], .2) ul,ur = spin_indices_from_above(gg, ps, 3) l = spin_index_from_left(gg, ps, 3) @test ul == Int[] @@ -77,10 +76,10 @@ if true @test i == [3, 4, 5, 6] boundary = [2,3] - a = Partial_sol{Float64}([1,1,1], 0.2, boundary) - b = Partial_sol{Float64}([2,1,1], 0.18, boundary) - c = Partial_sol{Float64}([1,1,2], 1., boundary) - d = Partial_sol{Float64}([2,1,2], .1, boundary) + a = Partial_sol{Float64}([1,1,1], 0.2) + b = Partial_sol{Float64}([2,1,1], 0.18) + c = Partial_sol{Float64}([1,1,2], 1.) + d = Partial_sol{Float64}([2,1,2], .1) vps = [a,b,c,d] @@ -88,18 +87,18 @@ if true # 0.18/0.2 = 0.9 # 0.1/1. = 0.1 - ps1 = merge_boundaries(vps, thershold) + ps1 = merge_boundaries(vps, boundary, thershold) println(ps1 == [a,b,c]) thershold = 0.95 - ps1 = merge_boundaries(vps, thershold) - println(ps1) + ps1 = merge_boundaries(vps, boundary, thershold) + println(ps1 == [a,c]) thershold = 0. - ps1 = merge_boundaries(vps, thershold) + ps1 = merge_boundaries(vps, boundary, thershold) println(ps1 == [a,b,c,d]) end end @@ -279,7 +278,7 @@ Mq[8,9] = Mq[9,8] = -0.05 println(size(mpo1[3])) pp = PEPSRow(peps, 2) - println(pp) + #println(pp) mpo2 = MPO(PEPSRow(peps, 2)) @@ -312,7 +311,7 @@ Mq[8,9] = Mq[9,8] = -0.05 B = generate_tensor(peps, (1,1)) println(size(B)) println(size(vec(cc))) - println(sum(cc) ≈ sum(B)) + @test sum(cc) ≈ sum(B) end @@ -367,7 +366,7 @@ end #println(size(AA[1])) # marginal prob - sol = Partial_sol{Float64}(Int[], 0., Int[]) + sol = Partial_sol{Float64}(Int[], 0.) j = 1 objective = conditional_probabs(gg, sol, j, lower_mps, A) println(objective) @@ -375,7 +374,7 @@ end #objective1 = conditional_probabs(gg, sol, j, l_mps, AA) #println(objective1) - sol = Partial_sol{Float64}([1], objective[1], Int[]) + sol = Partial_sol{Float64}([1], objective[1]) p1 = sum(cc[1,:,:,:,:,:,:,:,:])/su p2 = sum(cc[2,:,:,:,:,:,:,:,:])/su @@ -396,7 +395,7 @@ end A = M[2,:] # objective value from the previous step is set artificially - sol = Partial_sol{Float64}(Int[1,1,1,1], 1., [1,2,3]) + sol = Partial_sol{Float64}(Int[1,1,1,1], 1.) objective = conditional_probabs(gg, sol, j, lower_mps, A) #conditional prob p1 = sum(cc[1,1,1,1,1,:,:,:,:])/sum(cc[1,1,1,1,:,:,:,:,:]) @@ -408,7 +407,7 @@ end end @testset "test an exemple instance" begin - δ = 0. + δ = 1e-6 g = make_interactions_case2() spins, objective = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, δ = δ) @test spins[1] == [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1] @@ -428,7 +427,7 @@ end @testset "test an exemple instance on Float32" begin - δ = 0. + δ = 1e-6 g = make_interactions_case2() T = Float32 spins, objective = solve(g, 10; β = T(3.), χ = 2, threshold = 1e-11, δ = δ) From 07cff3e1c70bcec2f0f9568aad54d3717c8a1b36 Mon Sep 17 00:00:00 2001 From: kdomino Date: Wed, 13 Jan 2021 16:27:16 +0100 Subject: [PATCH 130/137] correction --- benchmarks/tests_grid_from_file.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/tests_grid_from_file.jl b/benchmarks/tests_grid_from_file.jl index a03a57ee..1cc241d9 100644 --- a/benchmarks/tests_grid_from_file.jl +++ b/benchmarks/tests_grid_from_file.jl @@ -31,7 +31,7 @@ println("examples = ", examples) β = 3. -δ = 1e-8 +δ = 0. number_of_states = 10 From f565af785229f15b3facd48a91fdc7125c85f657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= Date: Wed, 13 Jan 2021 18:04:44 +0100 Subject: [PATCH 131/137] use unique_dims in rank_reveal --- src/graph.jl | 5 +++-- src/utils.jl | 2 +- test/runtests.jl | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 09465a0b..3660cce0 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -155,8 +155,9 @@ function rank_reveal(energy, order=:PE) @assert order ∈ (:PE, :EP) dim = order == :PE ? 1 : 2 - E = unique(energy, dims=dim) - idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) + # E = unique(energy, dims=dim) + # idx = indexin(eachslice(energy, dims=dim), collect(eachslice(E, dims=dim))) + E, idx = unique_dims(energy, dim) P = order == :PE ? zeros(size(energy, 1), size(E, 1)) : zeros(size(E, 2), size(energy, 2)) diff --git a/src/utils.jl b/src/utils.jl index d65632c5..0bab4754 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -171,6 +171,6 @@ end end end - (@nref $N A d->d == dim ? sort!(uniquerows) : (axes(A, d))), uniquerow, uniquerows + (@nref $N A d->d == dim ? sort!(uniquerows) : (axes(A, d))), indexin(uniquerow, uniquerows) end end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 8a5074d9..975c2d93 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,7 +36,7 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - #"graph.jl", + "graph.jl", "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", From ba40761128f397b598afe6f6379dc3d1d350a84a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Wed, 13 Jan 2021 22:23:34 +0100 Subject: [PATCH 132/137] play with MPO --- src/PEPS.jl | 1 - src/base.jl | 2 +- test/PEPS.jl | 15 +++++++++++---- test/runtests.jl | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 61135ada..56f0fd21 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -158,7 +158,6 @@ function MPO(::Type{T}, peps::PepsNetwork, i::Int, k::Int) where {T <: Number} end @cast A[_, σ, _, η] := en[σ, η] -# @cast A[_, σ, _, η] := en[η, σ] ψ[j] = A end ψ diff --git a/src/base.jl b/src/base.jl index e8f8c5cf..9766914a 100644 --- a/src/base.jl +++ b/src/base.jl @@ -217,7 +217,7 @@ function verify_bonds(ψ::AbstractMPS) end end -function Base.show(::IO, ψ::AbstractMPS) +function Base.show(::IO, ψ::AbstractTensorNetwork) L = length(ψ) dims = [size(A) for A in ψ] diff --git a/test/PEPS.jl b/test/PEPS.jl index f4f4a4fe..2b76c735 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -46,7 +46,7 @@ x, y = m, n #for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) #for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK -for origin ∈ (:EN, :ES, :WS) # NO +for origin ∈ (:EN, :ES, :WS) # NO @info "testing peps" origin println(origin) @@ -63,22 +63,28 @@ for origin ∈ (:EN, :ES, :WS) # NO @info "contracting MPOs (up -> down)" ψ = MPO(PEPSRow(peps, 1)) - #println("bd ", bond_dimension(ψ)) - for A ∈ ψ @test size(A, 2) == 1 end for i ∈ 2:peps.i_max println(i) + R = PEPSRow(peps, i) W = MPO(R) M = MPO(peps, i-1, i) + + println(ψ) + println(M) + println(W) + ψ = (ψ * M) * W + for A ∈ ψ @test size(A, 2) == 1 end end - for A ∈ ψ @test size(A, 4) == 1 end + #for A ∈ ψ @test size(A, 4) == 1 end + #= @info "contracting MPOs (down -> up)" ψ = MPO(PEPSRow(peps, peps.i_max)) @@ -93,5 +99,6 @@ for origin ∈ (:EN, :ES, :WS) # NO end for A ∈ ψ @test size(A, 4) == 1 end + =# end end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index a52542c8..8a5074d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,8 +36,8 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - "graph.jl", - #"PEPS.jl", + #"graph.jl", + "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", #"mps_tests.jl", # problems From 722fa1b9dd3f23dfbd3cc0e1f102aca88616e279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Thu, 14 Jan 2021 08:36:37 +0100 Subject: [PATCH 133/137] add further tests --- src/graph.jl | 8 +------- test/PEPS.jl | 18 +++++++++++++----- test/runtests.jl | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 3660cce0..54b88b4c 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -119,13 +119,7 @@ function factor_graph( pl, en = rank_reveal(energy(fg, edg), :PE) en, pr = rank_reveal(en, :EP) - #= - display(energy(fg, edg)) - display(pl) - display(en) - display(pr) - println("--------------------------") - =# + set_prop!(fg, e, :split, (pl, en, pr)) end end diff --git a/test/PEPS.jl b/test/PEPS.jl index 06bee1e4..188e7427 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -58,7 +58,7 @@ x, y = m, n #for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) #for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK -for origin ∈ (:EN, :ES, :WS) # NO +for origin ∈ (:EN, ) #(:EN, :ES, :WS) # NO @info "testing peps" origin println(origin) @@ -72,6 +72,7 @@ for origin ∈ (:EN, :ES, :WS) # NO @test A ≈ B end +#= @info "contracting MPOs (up -> down)" ψ = MPO(PEPSRow(peps, 1)) @@ -93,10 +94,9 @@ for origin ∈ (:EN, :ES, :WS) # NO for A ∈ ψ @test size(A, 2) == 1 end end - +=# #for A ∈ ψ @test size(A, 4) == 1 end - #= @info "contracting MPOs (down -> up)" ψ = MPO(PEPSRow(peps, peps.i_max)) @@ -104,13 +104,21 @@ for origin ∈ (:EN, :ES, :WS) # NO for A ∈ ψ @test size(A, 4) == 1 end for i ∈ peps.i_max-1:1 - W = MPO(PEPSRow(peps, i)) + println(i) + R = PEPSRow(peps, i) + W = MPO(R) M = MPO(peps, i, i+1) + + println(W) + println(M) + println(ψ) + ψ = W * (M * ψ) + for A ∈ ψ @test size(A, 4) == 1 end end for A ∈ ψ @test size(A, 4) == 1 end - =# + end end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 975c2d93..8a5074d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,7 +36,7 @@ push!(my_tests, #"compressions.jl", #"ising.jl", #"spectrum.jl", - "graph.jl", + #"graph.jl", "PEPS.jl", #"notation_tests.jl", #"peps_tests.jl", From ff17f1b043c7e3fed3ae2086a7ea897c1566d3eb Mon Sep 17 00:00:00 2001 From: kdomino Date: Thu, 14 Jan 2021 10:50:53 +0100 Subject: [PATCH 134/137] some corrections in merging solutions --- benchmarks/low_energy_approx_chimera.jl | 4 +- benchmarks/tests_grid_from_file.jl | 10 +-- benchmarks/tests_on_chimera.jl | 8 ++- src/peps_no_types.jl | 94 ++++++++++++++++--------- test/mps_tests.jl | 2 +- test/peps_tests.jl | 78 ++++++++++++++------ 6 files changed, 129 insertions(+), 67 deletions(-) diff --git a/benchmarks/low_energy_approx_chimera.jl b/benchmarks/low_energy_approx_chimera.jl index 85132f68..84f5aa06 100644 --- a/benchmarks/low_energy_approx_chimera.jl +++ b/benchmarks/low_energy_approx_chimera.jl @@ -14,7 +14,7 @@ using Test import SpinGlassPEPS: solve, solve_mps, M2graph, energy, binary2spins, ising_graph disable_logging(LogLevel(0)) -δ = 0.9 +δH = 0.9 # this is axiliary function for npz write function vecvec2matrix(v::Vector{Vector{Int}}) @@ -101,7 +101,7 @@ function proceed() i = 1 for s in ses - @time spins, _ = solve(ig, n_sol; β=β, χ = χ, threshold = 1e-8, node_size = node_size, spectrum_cutoff = s, δ=δ) + @time spins, _ = solve(ig, n_sol; β=β, χ = χ, threshold = 1e-8, node_size = node_size, spectrum_cutoff = s, δH=δH) en = minimum([energy(s, ig) for s in spins]) diff --git a/benchmarks/tests_grid_from_file.jl b/benchmarks/tests_grid_from_file.jl index 1cc241d9..5233a5c3 100644 --- a/benchmarks/tests_grid_from_file.jl +++ b/benchmarks/tests_grid_from_file.jl @@ -31,7 +31,7 @@ println("examples = ", examples) β = 3. -δ = 0. +δH = 0. number_of_states = 10 @@ -72,7 +72,7 @@ for k in 1:examples number = number_of_states + more_states_for_peps - @time spins, objective = solve(g, number ; β = T(β), threshold = 0., δ = δ) + @time spins, objective = solve(g, number ; β = T(β), threshold = 0., δH = δH) for i in 1:number_of_states @@ -88,7 +88,7 @@ for k in 1:examples print("approx peps ") number = number_of_states + more_states_for_peps - @time spins_approx, objective_approx = solve(g, number; β = T(β), χ = χ, threshold = 1e-12, δ = δ) + @time spins_approx, objective_approx = solve(g, number; β = T(β), χ = χ, threshold = 1e-12, δH = δH) for i in 1:number_of_states @@ -103,7 +103,7 @@ for k in 1:examples print("peps larger T") number = number_of_states + more_states_for_peps - @time spins_larger_nodes, objective_larger_nodes = solve(g, number; node_size = (2,2), β = T(β), χ = χ, threshold = 1e-12, δ = δ) + @time spins_larger_nodes, objective_larger_nodes = solve(g, number; node_size = (2,2), β = T(β), χ = χ, threshold = 1e-12, δH = δH) for i in 1:number_of_states @@ -118,7 +118,7 @@ for k in 1:examples print("peps larger T, limited spectrum") number = number_of_states + more_states_for_peps - @time spins_spec, objective_spec = solve(g, number; node_size = (2,2), β = T(β), χ = χ, threshold = 1e-12, spectrum_cutoff = 15, δ = δ) + @time spins_spec, objective_spec = solve(g, number; node_size = (2,2), β = T(β), χ = χ, threshold = 1e-12, spectrum_cutoff = 15, δH = δH) for i in 1:minimum([number_of_states, 60]) @test energy(spins_spec[i], g) ≈ energies_given[i] diff --git a/benchmarks/tests_on_chimera.jl b/benchmarks/tests_on_chimera.jl index 1b46dd1c..a35345c9 100644 --- a/benchmarks/tests_on_chimera.jl +++ b/benchmarks/tests_on_chimera.jl @@ -23,7 +23,6 @@ function vecvec2matrix(v::Vector{Vector{Int}}) end M end -δ = 0.1 s = ArgParseSettings("description") @add_arg_table! s begin @@ -58,6 +57,10 @@ s = ArgParseSettings("description") default = 1000 arg_type = Int help = "size of the lower spectrum" + "--deltaH", "-d" + default = 0.1 + arg_type = Float64 + help = "merge parameter on merging dX, the threshold on ratios of objectives" end fi = parse_args(s)["file"] @@ -70,6 +73,7 @@ problem_size = parse_args(s)["size"] β = parse_args(s)["beta"] χ = parse_args(s)["chi"] si = parse_args(s)["size"] +δH = parse_args(s)["deltaH"] ig = ising_graph(fi, si, 1) @@ -78,7 +82,7 @@ node_size = (parse_args(s)["node_size1"], parse_args(s)["node_size2"]) println(node_size) spectrum_cutoff = parse_args(s)["spectrum_cutoff"] -@time spins, objective = solve(ig, n_sols; β=β, χ = χ, threshold = 1e-8, node_size = node_size, spectrum_cutoff = spectrum_cutoff, δ=δ) +@time spins, objective = solve(ig, n_sols; β=β, χ = χ, threshold = 1e-8, node_size = node_size, spectrum_cutoff = spectrum_cutoff, δH=δH) energies = [energy(s, ig) for s in spins] println("energies from peps") diff --git a/src/peps_no_types.jl b/src/peps_no_types.jl index dc5f59d1..296ac963 100644 --- a/src/peps_no_types.jl +++ b/src/peps_no_types.jl @@ -292,18 +292,71 @@ function conditional_probabs(gg::MetaGraph, ps::Partial_sol{T}, j::Int, lower_mp probs_unnormed./sum(probs_unnormed) end +""" + function dX_inds(grid::Matrix{Int}, j::Int; has_diagonals::Bool = false) + +Returns vector{Int} indexing of the boundary region (dX) given a grid. +id has diagonals, diagonal bounds on the grid are taken into account +""" -function indices_on_boundary(grid::Matrix{Int}, j::Int) - smax = j-1 - smin = maximum([1, j - size(grid, 2)]) - collect(smin: smax) +function dX_inds(grid::Matrix{Int}, j::Int; has_diagonals::Bool = false) + last = j-1 + s = size(grid, 2) + first = maximum([1, j - s]) + if (has_diagonals & (j%s != 1)) + first = maximum([1, j - s - 1]) + end + return collect(first: last) end +""" + function merge_dX(partial_s::Vector{Partial_sol{T}}, dX_inds::Vector{Int}, δH::Float64) where T <:Real + +Return a vector of Partial_sol{T}, with merged boundaries. + +Merging rule is such that the retion of the objective function of the merged item +to the maximal is lower than δH +""" + +function merge_dX(partial_s::Vector{Partial_sol{T}}, dX_inds::Vector{Int}, δH::Float64) where T <:Real + if (length(partial_s) > 1) & (δH != .0) + leave = [true for _ in partial_s] + + dXes = [ps.spins[dX_inds] for ps in partial_s] + + unique_dXes = unique(dXes) + if dXes != unique_dXes + dXcount = countmap(dXes) + for dX in unique_dXes + if dXcount[dX] > 1 + i = findall(k -> k == dX, dXes) + objectives = [partial_s[j].objective for j in i] + + objectives = objectives./maximum(objectives) + for ind in i[objectives .< δH] + leave[ind] = false + end + end + end + no_reduced = count(.!(leave)) + # this is just for testing + if no_reduced > 0 + j = length(partial_s[1].spins) + k = length(partial_s) + println(no_reduced, " out of $k partial solutions deleted at j = $j") + end + return partial_s[leave] + end + end + partial_s +end + + function solve(g::MetaGraph, no_sols::Int = 2; node_size::Tuple{Int, Int} = (1,1), β::T, χ::Int = 2^prod(node_size), threshold::Float64 = 0., spectrum_cutoff::Int = 1000, - δ::Float64 = 0.1) where T <: Real + δH::Float64 = 0.) where T <: Real gg = graph4peps(g, node_size, spectrum_cutoff = spectrum_cutoff) @@ -319,11 +372,11 @@ function solve(g::MetaGraph, no_sols::Int = 2; node_size::Tuple{Int, Int} = (1,1 for j in grid[row,:] - dX = indices_on_boundary(grid, j) + dX = dX_inds(grid, j) partial_s_temp = Partial_sol{T}[] - partial_s = merge_boundaries(partial_s, dX, δ) + partial_s = merge_dX(partial_s, dX, δH) for ps in partial_s objectives = conditional_probabs(gg, ps, j, lower_mps, vec_of_T) @@ -378,33 +431,6 @@ function return_solutions(partial_s::Vector{Partial_sol{T}}, ns:: MetaGraph) wh return spins, objective end -function merge_boundaries(partial_s::Vector{Partial_sol{T}}, dX::Vector{Int}, δ) where T <:Real - if (length(partial_s) > 1) & (δ != .0) - leave = [true for _ in partial_s] - - boundaries = [ps.spins[dX] for ps in partial_s] - - unique_bondaries = unique(boundaries) - if boundaries != unique_bondaries - b = countmap(boundaries) - for el in unique_bondaries - if b[el] > 1 - i = findall(x -> x == el, boundaries) - objectives = [partial_s[j].objective for j in i] - - objectives = objectives./maximum(objectives) - for ind in i[objectives .< δ] - leave[ind] = false - println(leave) - end - end - end - return partial_s[leave] - end - end - partial_s -end - """ select_best_solutions(partial_s_temp::Vector{Partial_sol{T}}, no_sols::Int) where T <:Real diff --git a/test/mps_tests.jl b/test/mps_tests.jl index 3eb7fdb2..7b6c1066 100644 --- a/test/mps_tests.jl +++ b/test/mps_tests.jl @@ -91,7 +91,7 @@ end spins_exact, _ = solve_mps(g, 10; β=β, β_step=1, χ=12, threshold = 0.) - spins_peps, _ = solve(g, 10; β = β, χ = 2, threshold = 1e-12) + spins_peps, _ = solve(g, 10; β = β, χ = 2, threshold = 1e-12, δH = 0.1) for k in 1:10 #testing exact diff --git a/test/peps_tests.jl b/test/peps_tests.jl index a346d964..b10840ef 100644 --- a/test/peps_tests.jl +++ b/test/peps_tests.jl @@ -4,7 +4,7 @@ import SpinGlassPEPS: compute_single_tensor, conditional_probabs, get_parameters import SpinGlassPEPS: make_lower_mps, M2graph, graph4peps, fullM2grid! import SpinGlassPEPS: set_spin_from_letf, spin_index_from_left, spin_indices_from_above import SpinGlassPEPS: energy, solve -import SpinGlassPEPS: indices_on_boundary, merge_boundaries +import SpinGlassPEPS: dX_inds, merge_dX Random.seed!(1234) if true @@ -66,16 +66,44 @@ if true end @testset "droplet hepers" begin + grid = [1 2 3 4; 5 6 7 8; 9 10 11 12] - i = indices_on_boundary(grid, 2) + i = dX_inds(grid, 2) @test i == [1] - i = indices_on_boundary(grid, 1) + i = dX_inds(grid, 1) @test i == Int[] - i = indices_on_boundary(grid, 7) + # 1 2 3 4 + # ? | | + # 5 6 <7> 8 + # | | + # 9 10 11 12 + # + + i = dX_inds(grid, 7) @test i == [3, 4, 5, 6] - boundary = [2,3] + i = dX_inds(grid, 7; has_diagonals = true) + @test i == [2, 3, 4, 5, 6] + + + # 5 6 7 8 + # | | | | + # <9> 10 11 12 + # + #both cases the same + i = dX_inds(grid, 9) + @test i == [5,6,7,8] + + i = dX_inds(grid, 9; has_diagonals = true) + @test i == [5,6,7,8] + + # other grid + + grid1 = [1 2; 3 4; 5 6; 7 8] + i = dX_inds(grid1, 5) + @test i == [3,4] + a = Partial_sol{Float64}([1,1,1], 0.2) b = Partial_sol{Float64}([2,1,1], 0.18) c = Partial_sol{Float64}([1,1,2], 1.) @@ -83,23 +111,27 @@ if true vps = [a,b,c,d] - thershold = 0.15 + boundary = [2,3] + + #ratio of objectives + # 0.18/0.2 = 0.9 # 0.1/1. = 0.1 + thershold = 0.15 - ps1 = merge_boundaries(vps, boundary, thershold) - println(ps1 == [a,b,c]) + ps1 = merge_dX(vps, boundary, thershold) + @test ps1 == [a,b,c] thershold = 0.95 - ps1 = merge_boundaries(vps, boundary, thershold) + ps1 = merge_dX(vps, boundary, thershold) - println(ps1 == [a,c]) + @test ps1 == [a,c] thershold = 0. - ps1 = merge_boundaries(vps, boundary, thershold) - println(ps1 == [a,b,c,d]) + ps1 = merge_dX(vps, boundary, thershold) + @test ps1 == [a,b,c,d] end end @@ -107,7 +139,7 @@ end Mq = ones(4,4) fullM2grid!(Mq, (2,2)) -if true + @testset "tensor construction" begin @@ -155,7 +187,7 @@ if true t13 = compute_single_tensor(g1, 3, β, sum_over_last = false) B = generate_tensor(peps, (1,1)) - println(B == t11) + @test B == t11 update_cells!( @@ -207,7 +239,7 @@ if true @test vec(T1) ≈ vec(T2)[p] end -end + Mq = zeros(9,9) Mq[1,1] = 1. Mq[2,2] = 1.4 @@ -290,7 +322,7 @@ Mq[8,9] = Mq[9,8] = -0.05 mpsl = MPS([e[:,:,:,1] for e in mpo3]) - println(right_env(mpsu, mpsl)[end] ≈ [1.]) + @test right_env(mpsu, mpsl)[end] ≈ [1.] g1 = copy(g) update_cells!( @@ -407,18 +439,18 @@ end end @testset "test an exemple instance" begin - δ = 1e-6 + δH = 1e-6 g = make_interactions_case2() - spins, objective = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, δ = δ) + spins, objective = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, δH = δH) @test spins[1] == [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1] - spins_l, objective_l = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), δ = δ) + spins_l, objective_l = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), δH = δH) for i in 1:10 @test objective[i] ≈ objective_l[i] atol=1e-8 @test spins[i] == spins_l[i] end # low energy spectrum - spins_s, objective_s = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), spectrum_cutoff = 15, δ = δ) + spins_s, objective_s = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), spectrum_cutoff = 15, δH = δH) for i in 1:10 @test objective[i] ≈ objective_s[i] atol=1e-8 @test spins[i] == spins_s[i] @@ -427,13 +459,13 @@ end @testset "test an exemple instance on Float32" begin - δ = 1e-6 + δH = 1e-6 g = make_interactions_case2() T = Float32 - spins, objective = solve(g, 10; β = T(3.), χ = 2, threshold = 1e-11, δ = δ) + spins, objective = solve(g, 10; β = T(3.), χ = 2, threshold = 1e-11, δH = δH) @test spins[1] == [1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1] - spins_l, objective_l = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), δ = δ) + spins_l, objective_l = solve(g, 10; β = 3., χ = 2, threshold = 1e-11, node_size = (2,2), δH = δH) for i in 1:10 @test objective[i] ≈ objective_l[i] atol=1e-5 @test spins[i] == spins_l[i] From fddfea603e1f714e6747442e6decbc0831aef677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Thu, 14 Jan 2021 15:38:54 +0100 Subject: [PATCH 135/137] add some tests --- test/PEPS.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/PEPS.jl b/test/PEPS.jl index 188e7427..d7265cb8 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -25,6 +25,7 @@ fg = factor_graph( spectrum=full_spectrum, ) +#= for (bd, e) in zip(bond_dimensions, edges(fg)) pl, en, pr = get_prop(fg, e, :split) println(e) @@ -52,7 +53,7 @@ for (bd, e) in zip(bond_dimensions, edges(fg)) end end - +=# x, y = m, n @@ -103,8 +104,11 @@ for origin ∈ (:EN, ) #(:EN, :ES, :WS) # NO for A ∈ ψ @test size(A, 4) == 1 end - for i ∈ peps.i_max-1:1 + println("imax -> ", peps.i_max) + + for i ∈ peps.i_max-1:-1:1 println(i) + R = PEPSRow(peps, i) W = MPO(R) M = MPO(peps, i, i+1) From 786faae1bb24ab69eb6fe1eeb7109d66cde4af0a Mon Sep 17 00:00:00 2001 From: annamariadziubyna <73058800+annamariadziubyna@users.noreply.github.com> Date: Thu, 14 Jan 2021 16:48:25 +0100 Subject: [PATCH 136/137] test LinearIndices --- test/PEPS.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/PEPS.jl b/test/PEPS.jl index 188e7427..97ef8120 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -1,3 +1,21 @@ +@testset "LinearIndices" begin +m = 3 +n = 4 +origin_l = [:NW, :NE, :SE, :SW] +origin_r = [:WN, :EN, :ES, :WS] +for i ∈ 1:length(origin_l) + o_l = origin_l[i] + o_r = origin_r[i] + println("origin ", o_l, " ", o_r) + ind_l, i_max_l, j_max_l = LinearIndices(m, n, o_l) + ind_r, i_max_r, j_max_r = LinearIndices(m, n, o_r) + @test i_max_l == m == j_max_r + @test j_max_l == n == i_max_r + for i ∈ 0:m+1, j ∈ 0:n+1 + @test ind_l[i,j] == ind_r[j,i] + end +end +end @testset "PepsTensor correctly builds PEPS network" begin From af98442c5d2084918e133aaa84999cbeb6c8c23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Gardas?= Date: Fri, 15 Jan 2021 10:41:16 +0100 Subject: [PATCH 137/137] fix THE issue! --- src/PEPS.jl | 3 ++- src/graph.jl | 2 +- test/PEPS.jl | 7 ++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/PEPS.jl b/src/PEPS.jl index 1914e2ff..5f4a849c 100644 --- a/src/PEPS.jl +++ b/src/PEPS.jl @@ -157,7 +157,8 @@ function MPO(::Type{T}, peps::PepsNetwork, i::Int, k::Int) where {T <: Number} en = ones(1, 1) end - @cast A[_, σ, _, η] := en[σ, η] + #@cast A[_, σ, _, η] := en[σ, η] + @cast A[u, _, d, _] := en[u, d] ψ[j] = A end ψ diff --git a/src/graph.jl b/src/graph.jl index 54b88b4c..8de912ad 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -119,7 +119,7 @@ function factor_graph( pl, en = rank_reveal(energy(fg, edg), :PE) en, pr = rank_reveal(en, :EP) - + set_prop!(fg, e, :split, (pl, en, pr)) end end diff --git a/test/PEPS.jl b/test/PEPS.jl index 184565a7..5387f8b9 100644 --- a/test/PEPS.jl +++ b/test/PEPS.jl @@ -75,9 +75,7 @@ end x, y = m, n -#for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) -#for origin ∈ (:NW, :SW, :NE, :SE, :WN) # OK -for origin ∈ (:EN, ) #(:EN, :ES, :WS) # NO +for origin ∈ (:NW, :SW, :WN, :NE, :EN, :SE, :ES, :SW, :WS) @info "testing peps" origin println(origin) @@ -91,7 +89,6 @@ for origin ∈ (:EN, ) #(:EN, :ES, :WS) # NO @test A ≈ B end -#= @info "contracting MPOs (up -> down)" ψ = MPO(PEPSRow(peps, 1)) @@ -113,7 +110,7 @@ for origin ∈ (:EN, ) #(:EN, :ES, :WS) # NO for A ∈ ψ @test size(A, 2) == 1 end end -=# + #for A ∈ ψ @test size(A, 4) == 1 end @info "contracting MPOs (down -> up)"