Skip to content

Commit

Permalink
rmf clustered hamiltonian v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsmierz committed Nov 17, 2023
1 parent 4008b7b commit caded78
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 18 deletions.
36 changes: 18 additions & 18 deletions examples/temp.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HDF5
using LightGraphs
using LinearAlgebra
using LabelledGraphs
using MetaGraphs
using SpinGlassNetworks
Expand Down Expand Up @@ -74,36 +75,34 @@ function load_openGM(fname::String, Nx::Integer, Ny::Integer)
result
end

function energy_rmf()

end

function clustered_hamiltonian(fname::String, Nx::Integer = 240, Ny::Integer = 320)
loaded_rmf = load_openGM(fname, Nx, Ny)
functions = loaded_rmf["fun"]
factors = loaded_rmf["fac"]
N = loaded_rmf["N"]
println(size(N))
node_factors = Dict()
edge_factors = Dict()

for index in keys(factors)
if length(index) == 4
push!(edge_factors, index=>factors[index])
else
push!(node_factors, index=>factors[index])
end
end
println(length(node_factors))
println((0,0) in collect(keys(node_factors)))
g = grid((Nx,Ny))
clusters = super_square_lattice((Nx, Ny, 1))
cl_h = LabelledGraph{MetaDiGraph}(sort(collect(values(clusters))))
for v cl_h.labels
x, y = v
sp = Spectrum([node_factors[(y-1, x-1)]], Array([collect(1:N[y, x])]), Vector{Int}([]))
sp = Spectrum(Vector{Real}(undef, 1), Array{Vector{Int}}(undef, 1, 1), Vector{Int}(undef, 1))
set_props!(cl_h, v, Dict(:cluster => v, :spectrum => sp))
end
for (index, value) in factors
if length(index) == 2
y, x = index
Eng = sum(functions[value])
set_props!(cl_h, (x+1, y+1), Dict(:eng => Eng))
elseif length(index) == 4
y1, x1, y2, x2 = index
add_edge!(cl_h, (x1 + 1, y1 + 1), (x2 + 1, y2 + 1))
Eng = sum(functions[value], dims=2)
set_props!(cl_h, (x1 + 1, y1 + 1), (x2 + 1, y2 + 1), Dict(:outer_edges=> ((x1 + 1, y1 + 1), (x2 + 1, y2 + 1)),
:eng => Eng, :pl => I, :pr => I))
else
throw(ErrorException("Something is wrong with factor index, it has length $(length(index))"))
end
end

cl_h
end
Expand All @@ -114,3 +113,4 @@ filename = "/home/tsmierzchalski/.julia/dev/SpinGlassNetworks/examples/penguin-s


cf = clustered_hamiltonian(filename, x, y)

37 changes: 37 additions & 0 deletions src/clustered_hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,40 @@ function truncate_clustered_hamiltonian(cl_h::LabelledGraph{S, T}, states::Dict)

new_cl_h
end

function clustered_hamiltonian(fname::String, Nx::Integer = 240, Ny::Integer = 320)
loaded_rmf = load_openGM(fname, Nx, Ny)
functions = loaded_rmf["fun"]
factors = loaded_rmf["fac"]
N = loaded_rmf["N"]

clusters = super_square_lattice((Nx, Ny, 1))
cl_h = LabelledGraph{MetaDiGraph}(sort(collect(values(clusters))))
lp = PoolOfProjectors{Int}()
for v cl_h.labels
x, y = v
sp = Spectrum(Vector{Real}(undef, 1), Array{Vector{Int}}(undef, 1, 1), Vector{Int}(undef, 1))
set_props!(cl_h, v, Dict(:cluster => v, :spectrum => sp))
end
for (index, value) in factors
if length(index) == 2
y, x = index
Eng = sum(functions[value])
set_props!(cl_h, (x+1, y+1), Dict(:en => Eng))
elseif length(index) == 4
y1, x1, y2, x2 = index
add_edge!(cl_h, (x1 + 1, y1 + 1), (x2 + 1, y2 + 1))
Eng = sum(functions[value], dims=2)
n = length(Eng)
ipl = add_projector!(lp, ones(n))
ipr = add_projector!(lp, ones(n))
set_props!(cl_h, (x1 + 1, y1 + 1), (x2 + 1, y2 + 1), Dict(:outer_edges=> ((x1 + 1, y1 + 1), (x2 + 1, y2 + 1)),
:en => Eng, :ipl => ipl, :ipr => ipr))
else
throw(ErrorException("Something is wrong with factor index, it has length $(length(index))"))
end
end

set_props!(cl_h, Dict(:pool_of_projectors => lp))
cl_h
end

0 comments on commit caded78

Please sign in to comment.