Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
lpawela committed Mar 6, 2024
1 parent 11e45d4 commit 3de25f7
Show file tree
Hide file tree
Showing 19 changed files with 1,026 additions and 781 deletions.
4 changes: 2 additions & 2 deletions benchmarks/spectrum.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

using SpinGlassNetworks

function bench(instance::String, size::NTuple{3, Int}, max_states::Int=100)
function bench(instance::String, size::NTuple{3,Int}, max_states::Int = 100)
ig = ising_graph(instance)
cl = split_into_clusters(ig, super_square_lattice(size))
@time sp = brute_force(cl[1, 1], num_states=max_states)
@time sp = brute_force(cl[1, 1], num_states = max_states)
nothing
end

Expand Down
13 changes: 6 additions & 7 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ _pages = [
"Lattice geometries" => "lattice.md",
"Clustered hamiltonian" => "clh.md",
"Local dimensional reduction" => "bp.md",
"API Reference for auxiliary functions" => "api.md"
"API Reference for auxiliary functions" => "api.md",
]

# ============================
format = Documenter.HTML(edit_link = "master",
prettyurls = get(ENV, "CI", nothing) == "true",
)
format =
Documenter.HTML(edit_link = "master", prettyurls = get(ENV, "CI", nothing) == "true")

# format = Documenter.LaTeX(platform="none")

makedocs(
sitename="SpinGlassNetworks.jl",
sitename = "SpinGlassNetworks.jl",
modules = [SpinGlassNetworks],
pages = _pages,
format = format
)
format = format,
)
82 changes: 41 additions & 41 deletions examples/bp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,56 @@ Instance below looks like this:
7 -- 8 -- 9
"""
function create_larger_example_clustered_hamiltonian_tree()
instance = Dict(
(1, 1) => 0.5,
(2, 2) => 0.25,
(3, 3) => 0.3,
(4, 4) => 0.1,
(5, 5) => -0.1,
(6, 6) => 0.1,
(7, 7) => 0.0,
(8, 8) => 0.1,
(9, 9) => 0.01,
(1, 2) => -1.0,
(2, 3) => 1.0,
(1, 4) => 1.0,
(4, 5) => 1.0,
(5, 6) => 1.0,
(4, 7) => 1.0,
(7, 8) => 1.0,
(8, 9) => 1.0
)
instance = Dict(
(1, 1) => 0.5,
(2, 2) => 0.25,
(3, 3) => 0.3,
(4, 4) => 0.1,
(5, 5) => -0.1,
(6, 6) => 0.1,
(7, 7) => 0.0,
(8, 8) => 0.1,
(9, 9) => 0.01,
(1, 2) => -1.0,
(2, 3) => 1.0,
(1, 4) => 1.0,
(4, 5) => 1.0,
(5, 6) => 1.0,
(4, 7) => 1.0,
(7, 8) => 1.0,
(8, 9) => 1.0,
)

ig = ising_graph(instance)
ig = ising_graph(instance)

assignment_rule = Dict(
1 => (1, 1, 1),
2 => (1, 2, 1),
3 => (1, 3, 1),
4 => (2, 1, 1),
5 => (2, 2, 1),
6 => (2, 3, 1),
7 => (3, 1, 1),
8 => (3, 2, 1),
9 => (3, 3, 1)
)
assignment_rule = Dict(
1 => (1, 1, 1),
2 => (1, 2, 1),
3 => (1, 3, 1),
4 => (2, 1, 1),
5 => (2, 2, 1),
6 => (2, 3, 1),
7 => (3, 1, 1),
8 => (3, 2, 1),
9 => (3, 3, 1),
)

cl_h = clustered_hamiltonian(
ig,
Dict{NTuple{3, Int}, Int}(),
spectrum = full_spectrum,
cluster_assignment_rule = assignment_rule,
)
cl_h = clustered_hamiltonian(
ig,
Dict{NTuple{3,Int},Int}(),
spectrum = full_spectrum,
cluster_assignment_rule = assignment_rule,
)

ig, cl_h
ig, cl_h
end

ig, cl_h = create_larger_example_clustered_hamiltonian_tree()
beta = 0.1
iter = 0
beliefs = belief_propagation(cl_h, beta; iter=iter)
beliefs = belief_propagation(cl_h, beta; iter = iter)

for v in vertices(cl_h)
en = get_prop(cl_h, v, :spectrum).energies
println("vertex ", v, " energy = ", en .- minimum(en), " bp = ", beliefs[v])
en = get_prop(cl_h, v, :spectrum).energies
println("vertex ", v, " energy = ", en .- minimum(en), " bp = ", beliefs[v])
end
44 changes: 33 additions & 11 deletions examples/temp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function load_openGM(fname::String, Nx::Integer, Ny::Integer)
nn = pop!(F)
n = []

for _ in 1:nn
for _ = 1:nn
tt = pop!(F)
ny, nx = divrem(tt, Nx)
push!(n, ny, nx)
Expand Down Expand Up @@ -61,17 +61,23 @@ function load_openGM(fname::String, Nx::Integer, Ny::Integer)
nn = pop!(J)
n = []

for _ in 1:nn
for _ = 1:nn
push!(n, pop!(J))
end

upper = lower + prod(n)
functions[ii] = reshape(V[lower + 1:upper], reverse(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 = Dict(
"fun" => functions,
"fac" => factors,
"N" => reshape(N, (Ny, Nx)),
"Nx" => Nx,
"Ny" => Ny,
)
result
end

Expand All @@ -85,22 +91,39 @@ function clustered_hamiltonian(fname::String, Nx::Integer = 240, Ny::Integer = 3
cl_h = LabelledGraph{MetaDiGraph}(sort(collect(values(clusters))))
for v cl_h.labels
x, y = v
sp = Spectrum(Vector{Real}(undef, 1), Array{Vector{Int}}(undef, 1, 1), Vector{Int}(undef, 1))
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))
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))
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))"))
throw(
ErrorException(
"Something is wrong with factor index, it has length $(length(index))",
),
)
end
end

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


cf = clustered_hamiltonian(filename, x, y)

42 changes: 21 additions & 21 deletions src/SpinGlassNetworks.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module SpinGlassNetworks
using LabelledGraphs
using Graphs
using MetaGraphs # TODO: to be replaced by MetaGraphsNext
using CSV
using JLD2
using DocStringExtensions
using LinearAlgebra, MKL
using Base.Cartesian
using SparseArrays
using HDF5
using CUDA, CUDA.CUSPARSE
using SpinGlassTensors
import Base.Prehashed
using LabelledGraphs
using Graphs
using MetaGraphs # TODO: to be replaced by MetaGraphsNext
using CSV
using JLD2
using DocStringExtensions
using LinearAlgebra, MKL
using Base.Cartesian
using SparseArrays
using HDF5
using CUDA, CUDA.CUSPARSE
using SpinGlassTensors
import Base.Prehashed


include("ising.jl")
include("spectrum.jl")
include("lattice.jl")
#include("projectors.jl")
include("clustered_hamiltonian.jl")
include("bp.jl")
include("truncate.jl")
include("utils.jl")
include("ising.jl")
include("spectrum.jl")
include("lattice.jl")
#include("projectors.jl")
include("clustered_hamiltonian.jl")
include("bp.jl")
include("truncate.jl")
include("utils.jl")
end # module
Loading

0 comments on commit 3de25f7

Please sign in to comment.