diff --git a/Project.toml b/Project.toml index 5f411ef..3de7d07 100644 --- a/Project.toml +++ b/Project.toml @@ -7,12 +7,13 @@ version = "0.2.3" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" LabelledGraphs = "605abd48-4d17-4660-b914-d4df33194460" LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MKL = "33e6dc65-8f57-5167-99aa-e5a354878fb2" MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5" -NNlibCUDA = "a00861dc-f156-4864-bf3c-e6376f28a68d" +NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b" @@ -23,7 +24,7 @@ LabelledGraphs = "0.3.2" LightGraphs = "1.3" MKL = "0.4.2" MetaGraphs = "0.6" -julia = "1.5, 1.6, 1.7" +julia = "1.5, 1.6, 1.7, 1.8" [extras] Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" diff --git a/examples/penguin-small.h5 b/examples/penguin-small.h5 new file mode 100644 index 0000000..4b72c88 Binary files /dev/null and b/examples/penguin-small.h5 differ diff --git a/examples/temp.jl b/examples/temp.jl new file mode 100644 index 0000000..689cada --- /dev/null +++ b/examples/temp.jl @@ -0,0 +1,116 @@ +using HDF5 +using LightGraphs +using LabelledGraphs +using MetaGraphs +using SpinGlassNetworks + + +function load_openGM(fname::String, Nx::Integer, Ny::Integer) + file = h5open(fname, "r") + + file_keys = collect(keys(read(file))) + data = read(file[file_keys[1]]) + H = collect(Int64, data["header"]) + F = Array{Int64}(data["factors"]) + J = Array{Int64}(data["function-id-16000"]["indices"]) + V = Array{Real}(data["function-id-16000"]["values"]) + N = Array{Int64}(data["numbers-of-states"]) + + F = reverse(F) + factors = Dict() + + while length(F) > 0 + f1 = pop!(F) + z1 = pop!(F) + nn = pop!(F) + n = [] + + for _ in 1:nn + tt = pop!(F) + ny, nx = divrem(tt, Nx) + push!(n, ny, nx) + end + + if length(n) == 4 + if abs(n[1] - n[3]) + abs(n[2] - n[4]) != 1 + throw(Exception("Not nearest neighbour")) + end + end + + if length(n) == 2 + if (n[1] >= Ny) || (n[2] >= Nx) + throw(Exception("Wrong size")) + end + end + + factors[tuple(n...)] = f1 + + if z1 != 0 + throw(Exception("Something wrong with the expected convention.")) + end + end + + J = reverse(J) + functions = Dict() + ii = -1 + lower = 0 + + while length(J) > 0 + ii += 1 + nn = pop!(J) + n = [] + + for _ in 1:nn + push!(n, pop!(J)) + end + + upper = lower + prod(n) + functions[ii] = reshape(V[lower + 1:upper], reverse(n)...)' + + lower = upper + end + + result = Dict("fun" => functions, "fac" => factors, "N" => reshape(N, (Ny, Nx)), "Nx" => Nx, "Ny" => Ny) + 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}([])) + set_props!(cl_h, v, Dict(:cluster => v, :spectrum => sp)) + end + + cl_h +end + + +x, y = 240, 320 +filename = "/home/tsmierzchalski/.julia/dev/SpinGlassNetworks/examples/penguin-small.h5" + + +cf = clustered_hamiltonian(filename, x, y) diff --git a/src/SpinGlassNetworks.jl b/src/SpinGlassNetworks.jl index b019c09..398fcc9 100644 --- a/src/SpinGlassNetworks.jl +++ b/src/SpinGlassNetworks.jl @@ -7,6 +7,7 @@ module SpinGlassNetworks using LinearAlgebra, MKL using Base.Cartesian using SparseArrays + using HDF5 using CUDA, CUDA.CUSPARSE import Base.Prehashed