Skip to content

Commit

Permalink
Allow usage of Float32 (#25)
Browse files Browse the repository at this point in the history
* initial minimal changes to engine

* PRopagate type to params and solution

* update example

* update tests

* bumop version

* update experimental tests

* uncomment tests

* reformat

* remove julia 1.9 support
  • Loading branch information
lpawela authored Jul 4, 2024
1 parent 65579da commit 4ab97c5
Show file tree
Hide file tree
Showing 36 changed files with 354 additions and 206 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.9'
- '1.10'
steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 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.0.1"
version = "1.0.2"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down Expand Up @@ -33,11 +33,11 @@ NNlib = "0.9.14"
ProgressMeter = "1.10"
SpinGlassExhaustive = "1.0.0"
SpinGlassNetworks = "1.1.2"
SpinGlassTensors = "1.1.1"
SpinGlassTensors = "1.1.2"
Statistics = "1.7.0"
TensorCast = "0.4"
TensorOperations = "4"
julia = "1.9, 1.10"
julia = "1.10"

[extras]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand Down
6 changes: 3 additions & 3 deletions examples/pegasus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ function bench(instance::String, β::Real, bond_dim::Integer, num_states::Intege
cluster_assignment_rule = pegasus_lattice((m, n, t)),
)

params = MpsParameters(bond_dim, 1E-8, 10, 1E-16)
params = MpsParameters{Float64}(bond_dim, 1E-8, 10, 1E-16)
search_params = SearchParameters(num_states, δp)
Strategy = Zipper
Sparsity = Sparse
Layout = GaugesEnergy
transform = rotation(0)
Gauge = NoUpdate
net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparsity}(m, n, cl_h, transform)
ctr = MpsContractor{Strategy,Gauge}(
net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparsity,Float64}(m, n, cl_h, transform)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
all_betas,
:graduate_truncate,
Expand Down
40 changes: 24 additions & 16 deletions src/PEPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export AbstractGibbsNetwork,

# T: type of the vertex of network
# S: type of the vertex of underlying factor graph
abstract type AbstractGibbsNetwork{S,T} end
abstract type AbstractGibbsNetwork{S,T,R} end

"""
$(TYPEDSIGNATURES)
Expand All @@ -46,8 +46,8 @@ Construct a Projected Entangled Pair States (PEPS) network.
# Returns
An instance of PEPSNetwork{T, S}.
"""
mutable struct PEPSNetwork{T<:AbstractGeometry,S<:AbstractSparsity} <:
AbstractGibbsNetwork{Node,PEPSNode}
mutable struct PEPSNetwork{T<:AbstractGeometry,S<:AbstractSparsity,R<:Real} <:
AbstractGibbsNetwork{Node,PEPSNode,R}
clustered_hamiltonian::LabelledGraph
vertex_map::Function
lp::PoolOfProjectors
Expand All @@ -58,13 +58,13 @@ mutable struct PEPSNetwork{T<:AbstractGeometry,S<:AbstractSparsity} <:
tensors_map::Dict{PEPSNode,Symbol}
gauges::Gauges{T}

function PEPSNetwork{T,S}(
function PEPSNetwork{T,S,R}(
m::Int,
n::Int,
clustered_hamiltonian::LabelledGraph,
transformation::LatticeTransformation,
gauge_type::Symbol = :id,
) where {T<:AbstractGeometry,S<:AbstractSparsity}
) 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)
net.nrows, net.ncols = transformation.flips_dimensions ? (n, m) : (m, n)
Expand All @@ -74,7 +74,7 @@ mutable struct PEPSNetwork{T<:AbstractGeometry,S<:AbstractSparsity} <:
end

net.tensors_map = tensor_map(T, S, net.nrows, net.ncols)
net.gauges = Gauges{T}(net.nrows, net.ncols)
net.gauges = Gauges{T,R}(net.nrows, net.ncols)
initialize_gauges!(net, gauge_type)
net
end
Expand Down Expand Up @@ -133,10 +133,15 @@ Calculate the bond energy between nodes `u` and `v` for a given index `σ` in th
## Returns
- `energies::Vector{T}`: Vector containing the bond energies between nodes `u` and `v` for index `σ`.
"""
function bond_energy(net::AbstractGibbsNetwork{T,S}, u::Node, v::Node, σ::Int) where {T,S}
function bond_energy(
net::AbstractGibbsNetwork{T,S,R},
u::Node,
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, σ)
vec(energies)
R.(vec(energies))
end

"""
Expand Down Expand Up @@ -231,8 +236,8 @@ Retrieve the local energy spectrum associated with a specific vertex in the Gibb
## Returns
- Local energy spectrum associated with the specified vertex.
"""
function local_energy(network::AbstractGibbsNetwork{S,T}, vertex::S) where {S,T}
spectrum(network, vertex).energies
function local_energy(network::AbstractGibbsNetwork{S,T,R}, vertex::S) where {S,T,R}
R.(spectrum(network, vertex).energies)
end


Expand Down Expand Up @@ -263,15 +268,15 @@ Compute the interaction energy between two vertices in a Gibbs network.
## Returns
- `energy::Matrix{T}`: Interaction energy matrix between vertices `v` and `w`.
"""
function interaction_energy(network::AbstractGibbsNetwork{S,T}, v::S, w::S) where {S,T}
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)
get_prop(cl_h, cl_h_w, cl_h_v, :en)'
R.(get_prop(cl_h, cl_h_w, cl_h_v, :en)')
elseif has_edge(cl_h, cl_h_v, cl_h_w)
get_prop(cl_h, cl_h_v, cl_h_w, :en)
R.(get_prop(cl_h, cl_h_v, cl_h_w, :en))
else
zeros(1, 1)
zeros(R, 1, 1)
end
end

Expand Down Expand Up @@ -307,13 +312,16 @@ Each gauge tensor is associated with two positions in the network and a type.
The positions are determined by the gauge's `positions` field, and the type is specified by the gauge's `type` field.
The initialization type can be either `:id` for identity tensors or `:rand` for random tensors.
"""
function initialize_gauges!(net::AbstractGibbsNetwork{S,T}, type::Symbol = :id) where {S,T}
function initialize_gauges!(
net::AbstractGibbsNetwork{S,T,R},
type::Symbol = :id,
) where {S,T,R}
@assert type (:id, :rand)
for gauge net.gauges.info
n1, n2 = gauge.positions
push!(net.tensors_map, n1 => gauge.type, n2 => gauge.type)
d = size(net, gauge.attached_tensor)[gauge.attached_leg]
X = type == :id ? ones(d) : rand(d) .+ 0.42
X = type == :id ? ones(R, d) : rand(R, d) .+ 0.42
push!(net.gauges.data, n1 => X, n2 => 1 ./ X)
end
end
Expand Down
Loading

2 comments on commit 4ab97c5

@lpawela
Copy link
Member Author

@lpawela lpawela commented on 4ab97c5 Jul 4, 2024

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/110425

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.0.2 -m "<description of version>" 4ab97c58fb6d9a063a7bdaaf10d839c6e96ca75c
git push origin v1.0.2

Please sign in to comment.