Skip to content

Commit

Permalink
added sizes for benchmark instances and
Browse files Browse the repository at this point in the history
allowed diagonal conections
  • Loading branch information
tomsmierz committed Nov 22, 2023
1 parent 5987b75 commit 2ab5ce1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/clustered_hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,18 @@ 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)
function clustered_hamiltonian(fname::String,
Nx::Union{Integer, Nothing}=nothing,
Ny::Union{Integer, Nothing}=nothing)

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))
X, Y = loaded_rmf["Nx"], loaded_rmf["Ny"]

clusters = super_square_lattice((X, Y, 1))
cl_h = LabelledGraph{MetaDiGraph}(sort(collect(values(clusters))))
lp = PoolOfProjectors{Int}()
for v cl_h.labels
Expand All @@ -495,6 +500,6 @@ function clustered_hamiltonian(fname::String, Nx::Integer = 240, Ny::Integer = 3
end
end

set_props!(cl_h, Dict(:pool_of_projectors => lp))
set_props!(cl_h, Dict(:pool_of_projectors => lp, :Nx => X, :Ny => Y))
cl_h
end
25 changes: 21 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Args:
Returns:
dictionary with factors and funcitons defining the energy functional.
"""
function load_openGM(fname::String, Nx::Integer, Ny::Integer)
function load_openGM(fname::String, Nx::Union{Integer, Nothing}=nothing, Ny::Union{Integer, Nothing}=nothing)
file = h5open(fname, "r")

file_keys = collect(keys(read(file)))
Expand All @@ -115,6 +115,11 @@ function load_openGM(fname::String, Nx::Integer, Ny::Integer)
V = Array{Real}(data["function-id-16000"]["values"])
N = Array{Int64}(data["numbers-of-states"])

if isnothing(Nx) || isnothing(Ny)
filename, _ = splitext(basename(fname))
Nx, Ny = benchmark_names[filename]
end

F = reverse(F)
factors = Dict()

Expand All @@ -131,8 +136,8 @@ function load_openGM(fname::String, Nx::Integer, Ny::Integer)
end

if length(n) == 4
if abs(n[1] - n[3]) + abs(n[2] - n[4]) != 1
throw(ErrorException("Not nearest neighbour"))
if abs(n[1] - n[3]) + abs(n[2] - n[4]) [1,2] || (abs(n[1] - n[3]) + abs(n[2] - n[4]) == 2 && (abs(n[1] - n[3]) == 2 || abs(n[2] - n[4])))
throw(ErrorException("Not nearest neighbour or diagonal neighbors"))
end
end

Expand Down Expand Up @@ -171,4 +176,16 @@ function load_openGM(fname::String, Nx::Integer, Ny::Integer)

result = Dict("fun" => functions, "fac" => factors, "N" => reshape(N, (Ny, Nx)), "Nx" => Nx, "Ny" => Ny)
result
end
end

benchmark_names = Dict(
"penguin-small" => (240,320),
"palm-small" => (240,360),
"clownfish-small" => (240,360),
"crops-small" => (240,360),
"pfau-small" => (240,320),
"lake-small" => (240,360),
"snail" => (240,320),
"fourcolors" => (240,320),
"strawberry-glass-2-small" => (320,240)
)

0 comments on commit 2ab5ce1

Please sign in to comment.