Skip to content

Commit

Permalink
Ad/rename (#28)
Browse files Browse the repository at this point in the history
* rename clustered Hamiltonian and SquareCrossSingleNode

* rename cl_h to potts_h

* update the dependency

* update version
  • Loading branch information
annamariadziubyna authored Jul 27, 2024
1 parent 38bbdc8 commit 390c53d
Show file tree
Hide file tree
Showing 43 changed files with 233 additions and 233 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SpinGlassEngine"
uuid = "0563570f-ea1b-4080-8a64-041ac6565a4e"
authors = ["Anna Maria Dziubyna <[email protected]>", "Tomasz Śmierzchalski <[email protected]>", "Bartłomiej Gardas <[email protected]>", "Konrad Jałowiecki <[email protected]>", "Łukasz Pawela <[email protected]>", "Marek M. Rams <[email protected]>"]
version = "1.2.0"
version = "1.3.0"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down Expand Up @@ -32,7 +32,7 @@ MKL = "0.4.3"
NNlib = "0.9.14"
ProgressMeter = "1.10"
SpinGlassExhaustive = "1.0.0"
SpinGlassNetworks = "1.1.2"
SpinGlassNetworks = "1.2.0"
SpinGlassTensors = "1.1.3"
Statistics = "1.7.0"
TensorCast = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/guide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Introduction
A [Julia](http://julialang.org) package for finding low energy spectrum of Ising spin systems. Part of [SpinGlassPEPS](https://github.com/euro-hpc-pl/SpinGlassPEPS.jl) package.

This part of the documentation is dedicated to describing the `SpinGlassEngine.jl` package, which serves as the actual solver. First, we will demonstrate how to construct a tensor network using the clustered Hamiltonian obtained with the `SpinGlassNetworks.jl` package. Next, we discuss the parameters necessary for conducting calculations, which the user should provide. Finally, we present functions that enable the discovery of low-energy spectra.
This part of the documentation is dedicated to describing the `SpinGlassEngine.jl` package, which serves as the actual solver. First, we will demonstrate how to construct a tensor network using the Potts Hamiltonian obtained with the `SpinGlassNetworks.jl` package. Next, we discuss the parameters necessary for conducting calculations, which the user should provide. Finally, we present functions that enable the discovery of low-energy spectra.

4 changes: 2 additions & 2 deletions docs/src/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ SquareSingleNode
SquareDoubleNode
```

* `SquareCrossSingleNode`
* `KingSingleNode`
```@raw html
<img src="../images/square_cross_single.png" width="50%" class="center"/>
```
```@docs
SquareCrossSingleNode
KingSingleNode
```

* `SquareCrossDoubleNode`
Expand Down
6 changes: 3 additions & 3 deletions docs/src/peps.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Constructing PEPS tensor network

After creating the clustered Hamiltonian, we can turn it into a PEPS tensor network as shown in the Section [Brief description of the algorithm](../algorithm.md).
After creating the Potts Hamiltonian, we can turn it into a PEPS tensor network as shown in the Section [Brief description of the algorithm](../algorithm.md).

```@docs
PEPSNetwork
Expand All @@ -22,11 +22,11 @@ Layout = GaugesEnergy
Sparsity = Sparse
ig = ising_graph(instance)
cl_h = clustered_hamiltonian(
potts_h = potts_hamiltonian(
ig,
spectrum = full_spectrum,
cluster_assignment_rule=super_square_lattice((m, n, t))
)
net = PEPSNetwork{SquareCrossSingleNode{Layout}, Sparsity}(m, n, cl_h, transform)
net = PEPSNetwork{KingSingleNode{Layout}, Sparsity}(m, n, potts_h, transform)
```
4 changes: 2 additions & 2 deletions examples/pegasus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function bench(instance::String, β::Real, bond_dim::Integer, num_states::Intege
δp = exp(-β * dE)
all_betas =/ 8, β / 4, β / 2, β]

cl_h = clustered_hamiltonian(
potts_h = potts_hamiltonian(
ising_graph(instance),
spectrum = my_brute_force,
cluster_assignment_rule = pegasus_lattice((m, n, t)),
Expand All @@ -32,7 +32,7 @@ function bench(instance::String, β::Real, bond_dim::Integer, num_states::Intege
Layout = GaugesEnergy
transform = rotation(0)
Gauge = NoUpdate
net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparsity,Float64}(m, n, cl_h, transform)
net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparsity,Float64}(m, n, potts_h, transform)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
params;
Expand Down
12 changes: 6 additions & 6 deletions examples/truncation_BP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ for cs ∈ cl_states
println("Transform ", tran)
println("Iter ", iter)

cl_h = clustered_hamiltonian(
potts_h = potts_hamiltonian(
ig,
spectrum = full_spectrum, #rm _gpu to use CPU
cluster_assignment_rule = pegasus_lattice((m, n, t)),
)

@time cl_h = truncate_clustered_hamiltonian(
cl_h,
@time potts_h = truncate_potts_hamiltonian(
potts_h,
β,
cs,
results_folder,
inst;
tol = 1e-6,
iter = iter,
)
# @time cl_h = truncate_clustered_hamiltonian_2site_energy(cl_h, cs)
for v in vertices(cl_h)
println(length(get_prop(cl_h, v, :spectrum).states))
# @time potts_h = truncate_potts_hamiltonian_2site_energy(potts_h, cs)
for v in vertices(potts_h)
println(length(get_prop(potts_h, v, :spectrum).states))
end
end
end
64 changes: 32 additions & 32 deletions src/PEPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ Construct a Projected Entangled Pair States (PEPS) network.
# Arguments
- `m::Int`: Number of rows in the PEPS lattice.
- `n::Int`: Number of columns in the PEPS lattice.
- `clustered_hamiltonian::LabelledGraph`: clustered hamiltonian representing the Hamiltonian.
- `potts_hamiltonian::LabelledGraph`: Potts Hamiltonian representing the Hamiltonian.
- `transformation::LatticeTransformation`: Transformation of the PEPS lattice, as it can be rotated or reflected.
- `gauge_type::Symbol=:id`: Type of gauge to initialize (default is identity).
# Type Parameters
- `T <: AbstractGeometry`: Type of geometry for the PEPS lattice. It can be `SquareSingleNode`, `SquareDoubleNode`, `SquareCrossSingleNode`, `SquareCrossDoubleNode`.
- `T <: AbstractGeometry`: Type of geometry for the PEPS lattice. It can be `SquareSingleNode`, `SquareDoubleNode`, `KingSingleNode`, `SquareCrossDoubleNode`.
- `S <: AbstractSparsity`: Type of sparsity for the PEPS tensors: `Dense` or `Sparse`.
# Returns
An instance of PEPSNetwork{T, S}.
"""
mutable struct PEPSNetwork{T<:AbstractGeometry,S<:AbstractSparsity,R<:Real} <:
AbstractGibbsNetwork{Node,PEPSNode,R}
clustered_hamiltonian::LabelledGraph
potts_hamiltonian::LabelledGraph
vertex_map::Function
lp::PoolOfProjectors
m::Int
Expand All @@ -61,15 +61,15 @@ mutable struct PEPSNetwork{T<:AbstractGeometry,S<:AbstractSparsity,R<:Real} <:
function PEPSNetwork{T,S,R}(
m::Int,
n::Int,
clustered_hamiltonian::LabelledGraph,
potts_hamiltonian::LabelledGraph,
transformation::LatticeTransformation,
gauge_type::Symbol = :id,
) where {T<:AbstractGeometry,S<:AbstractSparsity,R<:Real}
lp = get_prop(clustered_hamiltonian, :pool_of_projectors)
net = new(clustered_hamiltonian, vertex_map(transformation, m, n), lp, m, n)
lp = get_prop(potts_hamiltonian, :pool_of_projectors)
net = new(potts_hamiltonian, vertex_map(transformation, m, n), lp, m, n)
net.nrows, net.ncols = transformation.flips_dimensions ? (n, m) : (m, n)

if !is_compatible(net.clustered_hamiltonian, T.name.wrapper(m, n))
if !is_compatible(net.potts_hamiltonian, T.name.wrapper(m, n))
throw(ArgumentError("Factor graph not compatible with given network."))
end

Expand Down Expand Up @@ -139,8 +139,8 @@ function bond_energy(
v::Node,
σ::Int,
) where {T,S,R}
cl_h_u, cl_h_v = net.vertex_map(u), net.vertex_map(v)
energies = SpinGlassNetworks.bond_energy(net.clustered_hamiltonian, cl_h_u, cl_h_v, σ)
potts_h_u, potts_h_v = net.vertex_map(u), net.vertex_map(v)
energies = SpinGlassNetworks.bond_energy(net.potts_hamiltonian, potts_h_u, potts_h_v, σ)
R.(vec(energies))
end

Expand All @@ -158,9 +158,9 @@ Compute the projector between two nodes `v` and `w` in the Gibbs network `networ
- `projector::Matrix{T}`: Projector matrix between nodes `v` and `w`.
"""
function projector(network::AbstractGibbsNetwork{S,T}, v::S, w::S) where {S,T}
cl_h = network.clustered_hamiltonian
cl_h_v, cl_h_w = network.vertex_map(v), network.vertex_map(w)
SpinGlassNetworks.projector(cl_h, cl_h_v, cl_h_w)
potts_h = network.potts_hamiltonian
potts_h_v, potts_h_w = network.vertex_map(v), network.vertex_map(w)
SpinGlassNetworks.projector(potts_h, potts_h_v, potts_h_w)
end

"""
Expand Down Expand Up @@ -215,22 +215,22 @@ $(TYPEDSIGNATURES)
Retrieve the spectrum associated with a specific vertex in the Gibbs network.
## Arguments
- `network::AbstractGibbsNetwork{S, T}`: Gibbs network containing the clustered Hamiltonian.
- `network::AbstractGibbsNetwork{S, T}`: Gibbs network containing the Potts Hamiltonian.
- `vertex::S`: Vertex for which the spectrum is to be retrieved.
## Returns
- Spectrum associated with the specified vertex.
"""
function spectrum(network::AbstractGibbsNetwork{S,T}, vertex::S) where {S,T}
get_prop(network.clustered_hamiltonian, network.vertex_map(vertex), :spectrum)
get_prop(network.potts_hamiltonian, network.vertex_map(vertex), :spectrum)
end

"""
$(TYPEDSIGNATURES)
Retrieve the local energy spectrum associated with a specific vertex in the Gibbs network.
## Arguments
- `network::AbstractGibbsNetwork{S, T}`: Gibbs network containing the clustered Hamiltonian.
- `network::AbstractGibbsNetwork{S, T}`: Gibbs network containing the Potts Hamiltonian.
- `vertex::S`: Vertex for which the local energy spectrum is to be retrieved.
## Returns
Expand All @@ -246,7 +246,7 @@ $(TYPEDSIGNATURES)
Determine the cluster size associated with a specific vertex in the Gibbs network.
## Arguments
- `net::AbstractGibbsNetwork{S, T}`: Gibbs network containing the clustered Hamiltonian.
- `net::AbstractGibbsNetwork{S, T}`: Gibbs network containing the Potts Hamiltonian.
- `v::S`: Vertex for which the cluster size is to be determined.
## Returns
Expand All @@ -261,40 +261,40 @@ $(TYPEDSIGNATURES)
Compute the interaction energy between two vertices in a Gibbs network.
## Arguments
- `network::AbstractGibbsNetwork{S, T}`: Gibbs network containing the clustered Hamiltonian.
- `network::AbstractGibbsNetwork{S, T}`: Gibbs network containing the Potts Hamiltonian.
- `v::S`: First vertex.
- `w::S`: Second vertex.
## Returns
- `energy::Matrix{T}`: Interaction energy matrix between vertices `v` and `w`.
"""
function interaction_energy(network::AbstractGibbsNetwork{S,T,R}, v::S, w::S) where {S,T,R}
cl_h = network.clustered_hamiltonian
cl_h_v, cl_h_w = network.vertex_map(v), network.vertex_map(w)
if has_edge(cl_h, cl_h_w, cl_h_v)
R.(get_prop(cl_h, cl_h_w, cl_h_v, :en)')
elseif has_edge(cl_h, cl_h_v, cl_h_w)
R.(get_prop(cl_h, cl_h_v, cl_h_w, :en))
potts_h = network.potts_hamiltonian
potts_h_v, potts_h_w = network.vertex_map(v), network.vertex_map(w)
if has_edge(potts_h, potts_h_w, potts_h_v)
R.(get_prop(potts_h, potts_h_w, potts_h_v, :en)')
elseif has_edge(potts_h, potts_h_v, potts_h_w)
R.(get_prop(potts_h, potts_h_v, potts_h_w, :en))
else
zeros(R, 1, 1)
end
end

"""
$(TYPEDSIGNATURES)
Check if a clustered Hamiltonian is compatible with a given network graph.
Check if a Potts Hamiltonian is compatible with a given network graph.
## Arguments
- `clustered_hamiltonian::LabelledGraph`: Graph representing the clustered Hamiltonian.
- `potts_hamiltonian::LabelledGraph`: Graph representing the Potts Hamiltonian.
- `network_graph::LabelledGraph`: Graph representing the network.
## Returns
- `compatibility::Bool`: `true` if the clustered Hamiltonian is compatible with the network graph, `false` otherwise.
- `compatibility::Bool`: `true` if the Potts Hamiltonian is compatible with the network graph, `false` otherwise.
"""
function is_compatible(clustered_hamiltonian::LabelledGraph, network_graph::LabelledGraph)
function is_compatible(potts_hamiltonian::LabelledGraph, network_graph::LabelledGraph)
all(
has_edge(network_graph, src(edge), dst(edge)) for
edge edges(clustered_hamiltonian)
edge edges(potts_hamiltonian)
)
end

Expand Down Expand Up @@ -377,18 +377,18 @@ Decode a state vector into a dictionary representation.
## Arguments
- `peps::AbstractGibbsNetwork{S, T}`: The Gibbs network.
- `σ::Vector{Int}`: State vector to be decoded.
- `cl_h_order::Bool=false`: If true, use the order of nodes in the clustered Hamiltonian.
- `potts_h_order::Bool=false`: If true, use the order of nodes in the Potts Hamiltonian.
## Returns
- `Dict{Symbol, Int}`: A dictionary mapping node symbols to corresponding values in the state vector.
"""
function decode_state(
peps::AbstractGibbsNetwork{S,T},
σ::Vector{Int},
cl_h_order::Bool = false,
potts_h_order::Bool = false,
) where {S,T}
nodes =
cl_h_order ? peps.vertex_map.(nodes_search_order_Mps(peps)) :
vertices(peps.clustered_hamiltonian)
potts_h_order ? peps.vertex_map.(nodes_search_order_Mps(peps)) :
vertices(peps.potts_hamiltonian)
Dict(nodes[1:length(σ)] .=> σ)
end
2 changes: 1 addition & 1 deletion src/SpinGlassEngine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include("geometry.jl")
include("PEPS.jl")
include("contractor.jl")
include("square_single_node.jl")
include("square_cross_single_node.jl")
include("king_single_node.jl")
include("square_double_node.jl")
include("square_cross_double_node.jl")
include("tensors.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/contractor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ function boundary_indices(
states::Vector{Vector{Int}},
) where {T,S,N}
v, w = nodes
if ctr.peps.vertex_map(v) vertices(ctr.peps.clustered_hamiltonian)
if ctr.peps.vertex_map(v) vertices(ctr.peps.potts_hamiltonian)
@inbounds idx = [σ[ctr.node_search_index[v]] for σ states]
return @inbounds projector(ctr.peps, v, w)[idx]
end
Expand Down
2 changes: 1 addition & 1 deletion src/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Node = NTuple{N,Int} where {N}
"""
$(TYPEDSIGNATURES)
Node for the SquareSingleNode and SquareCrossSingleNode.
Node for the SquareSingleNode and KingSingleNode.
"""
struct PEPSNode
i::Site
Expand Down
Loading

2 comments on commit 390c53d

@lpawela
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/111889

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.0 -m "<description of version>" 390c53d7750861980dba7bdfbf15af856cd440e1
git push origin v1.3.0

Please sign in to comment.