Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Kd graphic #45

Merged
merged 158 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
5a95b8f
add Cluster and Edge
bartekGardas Dec 9, 2020
8ac075f
add unit_cell for chimera and the energy decomposition
bartekGardas Dec 9, 2020
e499dd6
add peps tensor
bartekGardas Dec 9, 2020
6eaaa36
remnove sgn
lpawela Dec 9, 2020
cae15b0
something still broken
lpawela Dec 9, 2020
7780010
finish writting factro graph
bartekGardas Dec 9, 2020
dab79bd
add tests
bartekGardas Dec 9, 2020
e75649b
add directed fg
bartekGardas Dec 10, 2020
c53abdd
cleaning instances
bartekGardas Dec 10, 2020
930ee70
cleaning some more
bartekGardas Dec 10, 2020
b4d6cfd
Merge branch 'bg/peps-ideas' of https://github.com/iitis/SpinGlassPEP…
bartekGardas Dec 10, 2020
0166fa6
Merge branch 'bg/peps-ideas' of https://github.com/iitis/SpinGlassPEP…
bartekGardas Dec 10, 2020
657856a
modify factor graph
bartekGardas Dec 10, 2020
6d499be
add working directed factor graph
bartekGardas Dec 11, 2020
1fddb9b
start building peps
bartekGardas Dec 11, 2020
874d5bc
Add draft of decomposition method
dexter2206 Dec 11, 2020
bb890ab
add orientation
bartekGardas Dec 11, 2020
5bd25fb
add comments to kj
bartekGardas Dec 11, 2020
429eed5
fix a minor bug
bartekGardas Dec 12, 2020
1c63260
fix bugs
bartekGardas Dec 14, 2020
a3f70bf
add l, r, u, d extraction
bartekGardas Dec 14, 2020
1b96d96
simplify decompose_edges
bartekGardas Dec 14, 2020
4442359
Add PepsTensor structure
dexter2206 Dec 14, 2020
0c018fb
add bugs in factor_graph
bartekGardas Dec 14, 2020
ff086cd
mer
bartekGardas Dec 14, 2020
02b8c02
move PepsTensor to PEPS.jl
bartekGardas Dec 14, 2020
904c0fb
add Lattice structure
bartekGardas Dec 14, 2020
bfa112f
add more tests in graphs
bartekGardas Dec 15, 2020
cc17fe6
Implement rank_reveal function
dexter2206 Dec 15, 2020
9959ad7
add Revise, add more test in graph
bartekGardas Dec 15, 2020
b1d5f33
Start splitting files
dexter2206 Dec 16, 2020
50c4014
Continue splitting files
dexter2206 Dec 17, 2020
89aee35
Merge branch 'master' of github.com:iitis/SpinGlassPEPS.jl into gnojo…
dexter2206 Dec 17, 2020
ed410f4
Attempt to merge master into bg/peps-ideas
dexter2206 Dec 17, 2020
31663fc
fix broken tests
bartekGardas Dec 18, 2020
d6804a6
rename search.jl to spectrum.jl
bartekGardas Dec 18, 2020
a01edb2
all tests but Krzysiek's passes
bartekGardas Dec 18, 2020
85c2bca
some corrections
kdomino Dec 18, 2020
9b6fba8
add basic test for PEPS generation
bartekGardas Dec 19, 2020
3c02a5b
befor coding with kd
bartekGardas Dec 19, 2020
6ed865a
Debugging problems with PEPS tensor construction
dexter2206 Dec 19, 2020
ef02748
fixing Krzysiek's tests
bartekGardas Dec 19, 2020
e54c577
change Meta na DiMeta
bartekGardas Dec 19, 2020
ab52013
add local energy
bartekGardas Dec 19, 2020
9376c01
add inline
lpawela Dec 19, 2020
25a690b
add unique rows
lpawela Dec 19, 2020
903052e
refactor graph
lpawela Dec 19, 2020
4d39585
refactor graphs
lpawela Dec 19, 2020
3fced47
spectrum->solve
lpawela Dec 19, 2020
28b686b
set energy array type
lpawela Dec 19, 2020
86e0ede
spectrum->solve
lpawela Dec 19, 2020
84ef85b
enable tests
lpawela Dec 19, 2020
8cd7491
Merge branch 'gnojownik' of github.com:iitis/SpinGlassPEPS.jl into gn…
lpawela Dec 19, 2020
7d8b6c8
Merge branch 'master' into gnojownik
lpawela Dec 20, 2020
3dd739a
return do coveralls
lpawela Dec 20, 2020
872b6f0
fix lcov path
lpawela Dec 20, 2020
86109ab
add Dict enumerating nbrs
bartekGardas Dec 20, 2020
754cb37
Merge branch 'gnojownik' of github.com:iitis/SpinGlassPEPS.jl into gn…
bartekGardas Dec 20, 2020
ef4f06b
add more test
bartekGardas Dec 21, 2020
4f34bcd
fix bug in rank_reveal
bartekGardas Dec 21, 2020
c264974
fix bugs in PEPS
bartekGardas Dec 21, 2020
930585f
add PEPS tests
bartekGardas Dec 21, 2020
05041b3
some tests fixed
kdomino Dec 21, 2020
8cc0bea
tests are passing
kdomino Dec 21, 2020
451138d
add filtering edges when readin instances, fix PEPS construction
bartekGardas Dec 21, 2020
e307eea
add more test for PEPS generation
bartekGardas Dec 21, 2020
1495a2a
remove conflicts
kdomino Dec 22, 2020
ed3c47d
Merge pull request #28 from iitis/gnojownik_fix
kdomino Dec 22, 2020
f672386
modify lattice struct
bartekGardas Dec 22, 2020
c367e65
add peps for lattice
bartekGardas Dec 22, 2020
097ba16
add some comments regarding futher changes
bartekGardas Dec 22, 2020
8a1c25e
fix _holes fuction
bartekGardas Dec 22, 2020
8c8f53d
add more tests
bartekGardas Dec 23, 2020
3909bfd
add MPO from factor graph
bartekGardas Dec 28, 2020
49d7b9c
add Mareks ideas
bartekGardas Dec 28, 2020
1e5bc2f
add ideas for different clustering
bartekGardas Dec 28, 2020
8af31cc
add more changes
bartekGardas Dec 29, 2020
725e235
cleaning up lattice.jl
annamariadziubyna Dec 29, 2020
b8bfeb3
cleaning up factor_graph.jl
annamariadziubyna Dec 29, 2020
71ba232
cleaning up PEPS
annamariadziubyna Dec 29, 2020
3d8bb8b
graph.jl test work
bartekGardas Dec 29, 2020
2582e39
add Marek's instance, correct peps generation
bartekGardas Dec 29, 2020
e2ac8f2
make sure tests are passing after changing the core structure of key …
bartekGardas Dec 29, 2020
1475734
add changes MPS/MPO from graph concept
bartekGardas Dec 29, 2020
81ffc90
comments some test for now
bartekGardas Dec 30, 2020
8f31c20
remove gauge
annamariadziubyna Dec 30, 2020
12291c1
add NetworkGraph, PepsNetwork, aux functions
annamariadziubyna Dec 30, 2020
46c6486
partially fix type problems
bartekGardas Dec 30, 2020
5e001c9
add MPO from PepsNetwork (not finished yet)
bartekGardas Jan 3, 2021
8078df9
fix MPO from PepsNetwork
bartekGardas Jan 3, 2021
33a15b9
fix small bugs in MPO
bartekGardas Jan 3, 2021
65ba817
fixed bugs in core functions, add tests for pathological instances
annamariadziubyna Jan 4, 2021
3631cd0
fix MPO, ordering
annamariadziubyna Jan 4, 2021
bbb1425
fix bug in dot and add test in peps
bartekGardas Jan 4, 2021
686ec7f
improve readability
bartekGardas Jan 4, 2021
30a0058
add assertion to linera ind
bartekGardas Jan 4, 2021
0c69fc1
fix further bugs
bartekGardas Jan 4, 2021
ab07779
complete LinearIndices
annamariadziubyna Jan 4, 2021
e69cf6c
fix bug in generate_peps
bartekGardas Jan 4, 2021
194eae3
fix bugs in generate_tensor
bartekGardas Jan 5, 2021
285b13f
merge
kdomino Jan 5, 2021
a10f249
fix peps_tensor in general case
bartekGardas Jan 5, 2021
2d85cba
improve casting in generate_tensor
bartekGardas Jan 5, 2021
1e54c7b
modify aux functions
bartekGardas Jan 5, 2021
59d6863
merge and correct testing
kdomino Jan 5, 2021
92f6d34
remove old function
kdomino Jan 5, 2021
1b63a9e
improve square_lattice, and fix busg
bartekGardas Jan 5, 2021
1abcae2
add tests involving origin
bartekGardas Jan 5, 2021
db8bf04
add tests od mpo/peps
bartekGardas Jan 6, 2021
e1c149d
add more test befor meeting
bartekGardas Jan 6, 2021
64f7ffb
add tests
annamariadziubyna Jan 6, 2021
0699d0a
add MPO on links
bartekGardas Jan 6, 2021
ff4da17
merge with new gowina
kdomino Jan 7, 2021
2a4cf25
corrections
kdomino Jan 7, 2021
af6cb43
forst attempt to implement new form of tensor calculation
kdomino Jan 7, 2021
f7647ca
some corrections
kdomino Jan 7, 2021
a1a8d79
modify MPO function
bartekGardas Jan 7, 2021
d76a751
testing bond dimesions
annamariadziubyna Jan 7, 2021
ee97a6c
Merge branch 'gowina' of https://github.com/iitis/SpinGlassPEPS.jl in…
annamariadziubyna Jan 7, 2021
f527a63
merge with current govina
kdomino Jan 8, 2021
084d6c4
some tests
kdomino Jan 8, 2021
6e30ad1
add PEPSRow type - for vectors of 5-dim tensors
lpawela Jan 11, 2021
36416cc
change tensor construction in PEPSRow
bartekGardas Jan 11, 2021
448beb9
correct typos in test - now it works
bartekGardas Jan 11, 2021
3bb8a46
fix rank reveal
lpawela Jan 12, 2021
32ea89a
add some tests
bartekGardas Jan 12, 2021
7f45fdc
Merge branch 'gowina' of github.com:iitis/SpinGlassPEPS.jl into gowina
bartekGardas Jan 12, 2021
75a40e2
add more test, some ideas still do not work
bartekGardas Jan 12, 2021
f42ce16
first implementation of the droplet
kdomino Jan 12, 2021
037ff12
add small changes in test, some origins still do not work
bartekGardas Jan 12, 2021
cee9d07
rm some tests
bartekGardas Jan 12, 2021
48b1015
change bond dim
annamariadziubyna Jan 12, 2021
0237558
Merge branch 'gowina' of https://github.com/iitis/SpinGlassPEPS.jl in…
annamariadziubyna Jan 12, 2021
76ce549
Update Project.toml
kdomino Jan 13, 2021
dc0a9ea
resotre old version of rank_reveal
lpawela Jan 13, 2021
e2c1365
return unique rows from unique_dims
lpawela Jan 13, 2021
6f07f28
Merge branch 'gowina' of github.com:iitis/SpinGlassPEPS.jl into gowina
lpawela Jan 13, 2021
bd83a96
Delete Manifest.toml
lpawela Jan 13, 2021
84b5ee0
correction
kdomino Jan 13, 2021
5644b58
remove locally Manifest
kdomino Jan 13, 2021
b6f1615
all tests are passing
kdomino Jan 13, 2021
596460a
some tests on the droplet specifics
kdomino Jan 13, 2021
ed7d5fe
some testing
kdomino Jan 13, 2021
914816a
correct droplet
kdomino Jan 13, 2021
c9736ff
correction
kdomino Jan 13, 2021
cd10190
correct droplet
kdomino Jan 13, 2021
07cff3e
correction
kdomino Jan 13, 2021
f565af7
use unique_dims in rank_reveal
lpawela Jan 13, 2021
ba40761
play with MPO
bartekGardas Jan 13, 2021
b2308ce
Merge branch 'gowina' of github.com:iitis/SpinGlassPEPS.jl into gowina
bartekGardas Jan 13, 2021
722fa1b
add further tests
bartekGardas Jan 14, 2021
ff17f1b
some corrections in merging solutions
kdomino Jan 14, 2021
621b694
merge chenges
kdomino Jan 14, 2021
fddfea6
add some tests
bartekGardas Jan 14, 2021
786faae
test LinearIndices
annamariadziubyna Jan 14, 2021
cbc34cc
Merge branch 'gowina' of https://github.com/iitis/SpinGlassPEPS.jl in…
annamariadziubyna Jan 14, 2021
af98442
fix THE issue!
bartekGardas Jan 15, 2021
01f7a86
Merge branch 'gowina' of github.com:iitis/SpinGlassPEPS.jl into kd_gr…
kdomino Jan 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ version = "0.0.1"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Infiltrator = "5903a43b-9cc3-4c30-8d17-598619ec4e9b"
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"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
MetaGraphs = "0.6"
Expand All @@ -25,6 +31,7 @@ LowRankApprox = "0.4"
Requires = "1.1"
TensorCast = "0.3"
TensorOperations = "3.0.1"
StatsBase = "0.33"
julia = "1.5"

[extras]
Expand Down
Empty file added SpinGlassPEPS.jl/Project.toml
Empty file.
13 changes: 6 additions & 7 deletions benchmarks/low_energy_approx_chimera.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using Test
import SpinGlassPEPS: solve, solve_mps, M2graph, energy, binary2spins, ising_graph

disable_logging(LogLevel(0))

δH = 0.9
# this is axiliary function for npz write

function vecvec2matrix(v::Vector{Vector{Int}})
Expand All @@ -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"
Expand Down Expand Up @@ -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"])
Expand All @@ -88,9 +88,8 @@ energy_ref = energy(ground_spins, ig)

spectrum_cutoff = parse_args(s)["spectrum_cutoff"]

ses = collect(spectrum_cutoff:-10:1)
step = 9
step = 100
ses = collect(spectrum_cutoff:-10:40)
step = 10
n_s = collect(n_sols:-step:1)

delta_e = ones(length(ses), length(n_s))
Expand All @@ -102,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])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ println("examples = ", examples)


β = 3.
δH = 0.

number_of_states = 10

Expand Down Expand Up @@ -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., δH = δH)

for i in 1:number_of_states

Expand All @@ -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, δH = δH)

for i in 1:number_of_states

Expand All @@ -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, δH = δH)

for i in 1:number_of_states

Expand All @@ -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, δH = δH)

for i in 1:minimum([number_of_states, 60])
@test energy(spins_spec[i], g) ≈ energies_given[i]
Expand Down
12 changes: 8 additions & 4 deletions test/tests_on_chimera.jl → benchmarks/tests_on_chimera.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ function vecvec2matrix(v::Vector{Vector{Int}})
M
end


s = ArgParseSettings("description")
@add_arg_table! s begin
"--file", "-f"
"--file", "-i"
arg_type = String
help = "the file name"
"--size", "-s"
Expand Down Expand Up @@ -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"]
Expand All @@ -70,15 +73,16 @@ 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, 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"])
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")
Expand Down
203 changes: 152 additions & 51 deletions src/PEPS.jl
Original file line number Diff line number Diff line change
@@ -1,65 +1,166 @@
export PepsTensor

mutable struct PepsTensor
nbrs::Dict{String, Int}
left::AbstractArray
right::AbstractArray
up::AbstractArray
down::AbstractArray
loc::AbstractArray
tensor::AbstractArray

function PepsTensor(fg::MetaDiGraph, v::Int)
pc = new()
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
export NetworkGraph, PepsNetwork
export generate_tensor, MPO

mutable struct NetworkGraph
factor_graph::MetaDiGraph
nbrs::Dict
β::Number

function NetworkGraph(factor_graph::MetaDiGraph, nbrs::Dict, β::Number)
ng = new(factor_graph, nbrs, β)

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
count = 0
for v ∈ vertices(ng.factor_graph), w ∈ ng.nbrs[v]
if has_edge(ng.factor_graph, v, w) count += 1 end
end
# open boundary conditions
if !isdefined(pc, :left)
pc.left = ones(1, size(pc.right, 1))

mc = ne(ng.factor_graph)
if count < mc
error("Error: $(count) < $(mc)")
end
ng
end
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]

if !isdefined(pc, :right)
pc.right = ones(size(pc.left, 2), 1)
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

if !isdefined(pc, :up)
pc.up = ones(1, size(pc.down, 1))
@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))

projs = Dict()
for (i, w) ∈ enumerate(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
push!(projs, i => pv)
end

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[σ]

if !isdefined(pc, :down)
pc.down = ones(size(pc.up, 2), 1)
tensor
end

function generate_tensor(ng::NetworkGraph, v::Int, w::Int)
fg = ng.factor_graph
if has_edge(fg, w, v)
_, e, _ = get_prop(fg, w, v, :split)
tensor = exp.(-ng.β .* e')
elseif has_edge(fg, v, w)
_, e, _ = get_prop(fg, v, w, :split)
tensor = exp.(-ng.β .* e)
else
tensor = ones(1, 1)
end
tensor
end

mutable struct PepsNetwork
size::NTuple{2, Int}
map::Dict
network_graph::NetworkGraph
origin::Symbol
i_max::Int
j_max::Int

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, origin)

nbrs = Dict()
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]))
end
pn.network_graph = NetworkGraph(fg, nbrs, β)
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}) = _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(::Type{T}, ψ::PEPSRow) where {T <: Number}
n = length(ψ)
ϕ = 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, ψ)

@cast pc.tensor[l, r, u, d, σ] |= pc.loc[σ] * pc.left[l, σ] * pc.right[σ, r] * pc.up[u, σ] * pc.down[σ, d]
function PEPSRow(::Type{T}, peps::PepsNetwork, i::Int) where {T <: Number}
n = peps.j_max
ψ = PEPSRow(T, n)

pc
for j ∈ 1:n
ψ[j] = generate_tensor(peps, (i, j))
end

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]
ψ[j] = B
end
ψ
end
PEPSRow(peps::PepsNetwork, i::Int) = PEPSRow(Float64, peps, i)

function MPO(::Type{T}, peps::PepsNetwork, i::Int, k::Int) where {T <: Number}
n = peps.j_max

ψ = MPO(T, n)
fg = peps.network_graph.factor_graph

for j ∈ 1:n
v, w = peps.map[i, j], peps.map[k, j]

Base.size(A::PepsTensor) = size(A.tensor)
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[σ, η]
@cast A[u, _, d, _] := en[u, d]
ψ[j] = A
end
ψ
end
MPO(peps::PepsNetwork, i::Int, k::Int) = MPO(Float64, peps, i, k)
Loading