diff --git a/src/clustered_hamiltonian.jl b/src/clustered_hamiltonian.jl index 4b8f8a2..eeead8c 100644 --- a/src/clustered_hamiltonian.jl +++ b/src/clustered_hamiltonian.jl @@ -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 @@ -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 \ No newline at end of file diff --git a/src/utils.jl b/src/utils.jl index d043242..83b4d1d 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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))) @@ -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() @@ -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 @@ -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 \ No newline at end of file +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) +) \ No newline at end of file