Skip to content

Commit

Permalink
rename clustered hamiltonian to potts
Browse files Browse the repository at this point in the history
  • Loading branch information
annamariadziubyna committed Jul 24, 2024
1 parent b9dcb97 commit 5245ece
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 182 deletions.
8 changes: 4 additions & 4 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ couplings
## Clustered Hamiltonian
```@docs
split_into_clusters
decode_clustered_hamiltonian_state
decode_potts_hamiltonian_state
rank_reveal
energy
energy_2site
cluster_size
bond_energy
exact_cond_prob
truncate_clustered_hamiltonian
truncate_potts_hamiltonian
```

## Belief propagation
Expand Down Expand Up @@ -54,8 +54,8 @@ brute_force

## Truncate
```@docs
truncate_clustered_hamiltonian_1site_BP
truncate_clustered_hamiltonian_2site_energy
truncate_potts_hamiltonian_1site_BP
truncate_potts_hamiltonian_2site_energy
select_numstate_best
```

Expand Down
6 changes: 3 additions & 3 deletions docs/src/bp.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## Belief propagation

Local dimensional reduction can be achieved by selectively choosing states in the clustered Hamiltonian that have the lowest local energy in the cluster. This approach aims to reduce the dimensionality of the problem by focusing on the most relevant and energetically favorable states. It can be done by truncation based on energy or truncation based on Loopy Belief Propagation.
Local dimensional reduction can be achieved by selectively choosing states in the Potts Hamiltonian that have the lowest local energy in the cluster. This approach aims to reduce the dimensionality of the problem by focusing on the most relevant and energetically favorable states. It can be done by truncation based on energy or truncation based on Loopy Belief Propagation.

```@docs
clustered_hamiltonian_2site
potts_hamiltonian_2site
belief_propagation
truncate_clustered_hamiltonian_2site_BP
truncate_potts_hamiltonian_2site_BP
```
10 changes: 5 additions & 5 deletions docs/src/clh.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Introduction
A clustered Hamiltonian is a graphical representation that allows for a convenient and intuitive way to describe the structure of a network.
A Potts Hamiltonian is a graphical representation that allows for a convenient and intuitive way to describe the structure of a network.

The concept of a clustered Hamiltonian within `SpinGlassNetworks.jl` introduces a mechanism for organizing spins into desired geometries, facilitating a structured approach to modeling complex spin systems. Analogous to a standard factor graph, the clustered Hamiltonian involves nodes that represent tensors within the underlying network. The edges connecting these nodes in the clustered Hamiltonian correspond to the indices shared between the respective tensors in the tensor network.
The concept of a Potts Hamiltonian within `SpinGlassNetworks.jl` introduces a mechanism for organizing spins into desired geometries, facilitating a structured approach to modeling complex spin systems. Analogous to a standard factor graph, the Potts Hamiltonian involves nodes that represent tensors within the underlying network. The edges connecting these nodes in the Potts Hamiltonian correspond to the indices shared between the respective tensors in the tensor network.

```@docs
clustered_hamiltonian
potts_hamiltonian
```

## Simple example
Expand All @@ -16,8 +16,8 @@ using SpinGlassNetworks
instance = "$(@__DIR__)/../../src/instances/square_diagonal/5x5/diagonal.txt"
ig = ising_graph(instance)
# Create clustered Hamiltonian
cl_h = clustered_hamiltonian(
# Create Potts Hamiltonian
cl_h = potts_hamiltonian(
ig,
cluster_assignment_rule = super_square_lattice((5,5,4))
)
Expand Down
12 changes: 6 additions & 6 deletions docs/src/lattice.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Lattice geometries
The Ising graph allowed for loading instances directly from a file and translating them into a graph. The next step towards constructing the tensor network is to build a lattice, based on which we will transform the Ising graph into a clustered Hamiltonian.
The Ising graph allowed for loading instances directly from a file and translating them into a graph. The next step towards constructing the tensor network is to build a lattice, based on which we will transform the Ising graph into a Potts Hamiltonian.
Within the `SpinGlassNetworks.jl` package, users have the flexibility to construct three types of lattice geometries, each tailored to specific needs.

## Super square lattice
Expand Down Expand Up @@ -27,12 +27,12 @@ m = 5
n = 5
t = 4
cl_h = clustered_hamiltonian(
cl_h = potts_hamiltonian(
ig,
cluster_assignment_rule = super_square_lattice((m, n, t))
)
println("Number of nodes in oryginal instance: ", length(LabelledGraphs.vertices(ig)), "\n", " Number of nodes in clustered Hamiltonian: ", length(LabelledGraphs.vertices(cl_h)))
println("Number of nodes in oryginal instance: ", length(LabelledGraphs.vertices(ig)), "\n", " Number of nodes in Potts Hamiltonian: ", length(LabelledGraphs.vertices(cl_h)))
```

## Pegasus graphs
Expand Down Expand Up @@ -61,12 +61,12 @@ m = 3
n = 3
t = 3
cl_h = clustered_hamiltonian(
cl_h = potts_hamiltonian(
ig,
cluster_assignment_rule = pegasus_lattice((m, n, t))
)
println("Number of nodes in original instance: ", length(LabelledGraphs.vertices(ig)), "\n", " Number of nodes in clustered Hamiltonian: ", length(LabelledGraphs.vertices(cl_h))/2)
println("Number of nodes in original instance: ", length(LabelledGraphs.vertices(ig)), "\n", " Number of nodes in Potts Hamiltonian: ", length(LabelledGraphs.vertices(cl_h))/2)
```


Expand Down Expand Up @@ -96,7 +96,7 @@ m = 6
n = 6
t = 4
cl_h = clustered_hamiltonian(
cl_h = potts_hamiltonian(
ig,
cluster_assignment_rule = zephyr_lattice((m, n, t))
)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/userguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

A [Julia](http://julialang.org) package for building and interacting with Ising spin glass models in context of tensor networks. Part of [SpinGlassPEPS](https://github.com/euro-hpc-pl/SpinGlassPEPS.jl) package.

The contents of our package are illustrated through comprehensive examples, showcasing the practical utilization of key functions. Specifically, the `ising_graph` function is highlighted, demonstrating its capacity to generate Ising model graphs — a fundamental step in modeling spin systems. Additionally, the `clustered_hamiltonian` function is presented as a tool for converting Ising graphs into clustered Hamiltonians. The package delves into various lattice geometries, providing insights into constructing diverse structures such as the `super_square_lattice`, `pegasus_lattice`, and `zephyr_lattice`. Moreover, the documentation outlines methods for local dimensional reduction, shedding light on techniques to streamline computations and enhance the efficiency of spin system simulations.
The contents of our package are illustrated through comprehensive examples, showcasing the practical utilization of key functions. Specifically, the `ising_graph` function is highlighted, demonstrating its capacity to generate Ising model graphs — a fundamental step in modeling spin systems. Additionally, the `potts_hamiltonian` function is presented as a tool for converting Ising graphs into Potts Hamiltonians. The package delves into various lattice geometries, providing insights into constructing diverse structures such as the `super_square_lattice`, `pegasus_lattice`, and `zephyr_lattice`. Moreover, the documentation outlines methods for local dimensional reduction, shedding light on techniques to streamline computations and enhance the efficiency of spin system simulations.
6 changes: 3 additions & 3 deletions examples/bp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Instance below looks like this:
|
7 -- 8 -- 9
"""
function create_larger_example_clustered_hamiltonian_tree()
function create_larger_example_potts_hamiltonian_tree()
instance = Dict(
(1, 1) => 0.5,
(2, 2) => 0.25,
Expand Down Expand Up @@ -48,7 +48,7 @@ function create_larger_example_clustered_hamiltonian_tree()
9 => (3, 3, 1),
)

cl_h = clustered_hamiltonian(
cl_h = potts_hamiltonian(
ig,
Dict{NTuple{3,Int},Int}(),
spectrum = full_spectrum,
Expand All @@ -58,7 +58,7 @@ function create_larger_example_clustered_hamiltonian_tree()
ig, cl_h
end

ig, cl_h = create_larger_example_clustered_hamiltonian_tree()
ig, cl_h = create_larger_example_potts_hamiltonian_tree()
beta = 0.1
iter = 0
beliefs = belief_propagation(cl_h, beta; iter = iter)
Expand Down
4 changes: 2 additions & 2 deletions examples/temp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function load_openGM(fname::String, Nx::Integer, Ny::Integer)
result
end

function clustered_hamiltonian(fname::String, Nx::Integer = 240, Ny::Integer = 320)
function potts_hamiltonian(fname::String, Nx::Integer = 240, Ny::Integer = 320)
loaded_rmf = load_openGM(fname, Nx, Ny)
functions = loaded_rmf["fun"]
factors = loaded_rmf["fac"]
Expand Down Expand Up @@ -135,4 +135,4 @@ x, y = 240, 320
filename = "/home/tsmierzchalski/.julia/dev/SpinGlassNetworks/examples/penguin-small.h5"


cf = clustered_hamiltonian(filename, x, y)
cf = potts_hamiltonian(filename, x, y)
2 changes: 1 addition & 1 deletion src/SpinGlassNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Base.Prehashed
include("ising.jl")
include("spectrum.jl")
include("lattice.jl")
include("clustered_hamiltonian.jl")
include("potts_hamiltonian.jl")
include("bp.jl")
include("truncate.jl")
include("utils.jl")
Expand Down
50 changes: 25 additions & 25 deletions src/bp.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

export belief_propagation,
clustered_hamiltonian_2site,
potts_hamiltonian_2site,
projector,
get_neighbors,
MergedEnergy,
Expand All @@ -12,20 +12,20 @@ export belief_propagation,

"""
$(TYPEDSIGNATURES)
Perform loopy belief propagation on a given clustered Hamiltonian.
Perform loopy belief propagation on a given Potts Hamiltonian.
# Arguments:
- `cl_h::LabelledGraph{S, T}`: The clustered Hamiltonian represented as a labelled graph.
- `cl_h::LabelledGraph{S, T}`: The Potts Hamiltonian represented as a labelled graph.
- `beta::Real`: The inverse temperature parameter for the belief propagation algorithm.
- `tol::Real (optional, default=1e-6)`: The convergence tolerance. The algorithm stops when the message updates between iterations are smaller than this value.
- `iter::Int (optional, default=1)`: The maximum number of iterations to perform.
# Returns:
- `beliefs::Dict`: A dictionary where keys are vertices of clustered hamiltonian, and values are the
- `beliefs::Dict`: A dictionary where keys are vertices of Potts Hamiltonian, and values are the
resulting beliefs after belief propagation.
The function implements loopy belief propagation on the given clustered hamiltonian `cl_h` to calculate beliefs for each vertex.
Belief propagation is an iterative algorithm that computes beliefs by passing messages between vertices and edges of the clustered hamiltonian.
The function implements loopy belief propagation on the given Potts Hamiltonian `cl_h` to calculate beliefs for each vertex.
Belief propagation is an iterative algorithm that computes beliefs by passing messages between vertices and edges of the Potts Hamiltonian.
The algorithm continues until convergence or until the specified maximum number of iterations is reached.
The beliefs are computed based on the inverse temperature parameter `beta`, which controls the influence of energy values on the beliefs.
"""
Expand Down Expand Up @@ -101,10 +101,10 @@ end

"""
$(TYPEDSIGNATURES)
Returns the neighbors of a given vertex in a clustered Hamiltonian.
Returns the neighbors of a given vertex in a Potts Hamiltonian.
# Arguments:
- `cl_h::LabelledGraph{S, T}`: The clustered Hamiltonian represented as a labeled graph.
- `cl_h::LabelledGraph{S, T}`: The Potts Hamiltonian represented as a labeled graph.
- `vertex::NTuple`: The vertex for which neighbors are to be retrieved.
# Returns:
Expand All @@ -114,7 +114,7 @@ Each tuple contains the following information:
- `pv::Matrix`: The projector associated with the edge connecting the vertex and its neighbor.
- `en::Real`: The energy associated with the edge connecting the vertex and its neighbor.
This function retrieves the neighbors of a given vertex in a clustered Hamiltonian graph.
This function retrieves the neighbors of a given vertex in a Potts Hamiltonian graph.
It iterates through the edges of the graph and identifies edges connected to the specified vertex.
For each neighboring edge, it extracts and returns the neighboring vertex, the associated projector, and the energy.
"""
Expand Down Expand Up @@ -255,23 +255,23 @@ end
"""
$(TYPEDSIGNATURES)
Constructs a clustered Hamiltonian for a given clustered Hamiltonian with a 2-site cluster approximation used in Pegasus graph.
Constructs a Potts Hamiltonian for a given Potts Hamiltonian with a 2-site cluster approximation used in Pegasus graph.
# Arguments:
- `cl_h::LabelledGraph{S, T}`: The clustered Hamiltonian represented as a labelled graph.
- `cl_h::LabelledGraph{S, T}`: The Potts Hamiltonian represented as a labelled graph.
- `beta::Real`: The inverse temperature parameter for the 2-site cluster Hamiltonian construction.
# Returns:
- `new_cl_h::LabelledGraph{MetaDiGraph}`: A new labelled graph representing the 2-site cluster Hamiltonian.
This function constructs a clustered Hamiltonian `cl_h` by applying a 2-site cluster approximation.
This function constructs a Potts Hamiltonian `cl_h` by applying a 2-site cluster approximation.
It combines and merges vertices and edges of the original graph to create a simplified representation of the Hamiltonian.
The resulting `new_cl_h` graph represents the 2-site cluster Hamiltonian with simplified interactions between clusters.
The energy values, projectors, and spectra associated with the new vertices and edges are computed based on
the provided temperature parameter `beta`.
"""
function clustered_hamiltonian_2site(cl_h::LabelledGraph{S,T}, beta::Real) where {S,T}
function potts_hamiltonian_2site(cl_h::LabelledGraph{S,T}, beta::Real) where {S,T}

unified_vertices = unique([vertex[1:2] for vertex in vertices(cl_h)])
new_cl_h = LabelledGraph{MetaDiGraph}(unified_vertices)
Expand Down Expand Up @@ -319,10 +319,10 @@ end
"""
$(TYPEDSIGNATURES)
Merge two vertices in a clustered Hamiltonian to create a single merged vertex.
Merge two vertices in a Potts Hamiltonian to create a single merged vertex.
# Arguments:
- `cl_h::LabelledGraph{S, T}`: The clustered Hamiltonian represented as a labeled graph.
- `cl_h::LabelledGraph{S, T}`: The Potts Hamiltonian represented as a labeled graph.
- `β::Real`: The temperature parameter controlling the influence of energy values.
- `node1::NTuple{3, Int64}`: The coordinates of the first vertex to merge.
- `node2::NTuple{3, Int64}`: The coordinates of the second vertex to merge.
Expand All @@ -332,7 +332,7 @@ Merge two vertices in a clustered Hamiltonian to create a single merged vertex.
- `pl::AbstractVector`: The merged left projector.
- `pr::AbstractVector`: The merged right projector.
This function merges two vertices in a clustered Hamiltonian graph `cl_h` to create a single merged vertex.
This function merges two vertices in a Potts Hamiltonian graph `cl_h` to create a single merged vertex.
The merging process combines projectors and energy values associated with the original vertices based on
the provided temperature parameter `β`.
Expand Down Expand Up @@ -383,16 +383,16 @@ end
"""
$(TYPEDSIGNATURES)
Get the local energy associated with a vertex in a clustered Hamiltonian.
Get the local energy associated with a vertex in a Potts Hamiltonian.
# Arguments:
- `cl_h::LabelledGraph{S, T}`: The clustered Hamiltonian represented as a labeled graph.
- `cl_h::LabelledGraph{S, T}`: The Potts Hamiltonian represented as a labeled graph.
- `v::NTuple{3, Int64}`: The coordinates of the vertex for which the local energy is requested.
# Returns:
- `local_energy::AbstractVector`: An abstract vector containing the local energy values associated with the specified vertex.
This function retrieves the local energy values associated with a given vertex `v` in a clustered Hamiltonian graph `cl_h`.
This function retrieves the local energy values associated with a given vertex `v` in a Potts Hamiltonian graph `cl_h`.
If the vertex exists in the graph and has associated energy values, it returns those values; otherwise, it returns a vector of zeros.
The local energy values are typically obtained from the spectrum associated with the vertex.
Expand All @@ -404,17 +404,17 @@ end
"""
$(TYPEDSIGNATURES)
Get the interaction energy between two vertices in a clustered Hamiltonian.
Get the interaction energy between two vertices in a Potts Hamiltonian.
# Arguments:
- `cl_h::LabelledGraph{S, T}`: The clustered Hamiltonian represented as a labeled graph.
- `cl_h::LabelledGraph{S, T}`: The Potts Hamiltonian represented as a labeled graph.
- `v::NTuple{3, Int64}`: The coordinates of the first vertex.
- `w::NTuple{3, Int64}`: The coordinates of the second vertex.
# Returns:
- `interaction_energy::AbstractMatrix`: An abstract matrix containing the interaction energy values between the specified vertices.
This function retrieves the interaction energy values between two vertices, `v` and `w`, in a clustered Hamiltonian graph `cl_h`.
This function retrieves the interaction energy values between two vertices, `v` and `w`, in a Potts Hamiltonian graph `cl_h`.
If there is a directed edge from `w` to `v`, it returns the corresponding energy values;
if there is a directed edge from `v` to `w`, it returns the transpose of the energy values;
otherwise, it returns a matrix of zeros.
Expand All @@ -437,18 +437,18 @@ end
"""
$(TYPEDSIGNATURES)
Get the projector associated with an edge between two vertices in a clustered Hamiltonian.
Get the projector associated with an edge between two vertices in a Potts Hamiltonian.
# Arguments:
- `cl_h::LabelledGraph{S, T}`: The clustered Hamiltonian represented as a labeled graph.
- `cl_h::LabelledGraph{S, T}`: The Potts Hamiltonian represented as a labeled graph.
- `v::NTuple{N, Int64}`: The coordinates of one of the two vertices connected by the edge.
- `w::NTuple{N, Int64}`: The coordinates of the other vertex connected by the edge.
# Returns:
- `p::AbstractVector`: An abstract vector representing the projector associated with the specified edge.
This function retrieves the projector associated with an edge between two vertices, `v` and `w`,
in a clustered Hamiltonian graph `cl_h`.
in a Potts Hamiltonian graph `cl_h`.
If there is a directed edge from `w` to `v`, it returns the index of right projector (`:ipr`);
if there is a directed edge from `v` to `w`, it returns the index of left projector (`:ipl`).
If no edge exists between the vertices, it returns a vector of ones.
Expand Down
Loading

0 comments on commit 5245ece

Please sign in to comment.