Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change some constructors to kwargs #27

Merged
merged 7 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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.1.1"
version = "1.2.0"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down
8 changes: 4 additions & 4 deletions examples/pegasus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function bench(instance::String, β::Real, bond_dim::Integer, num_states::Intege
cluster_assignment_rule = pegasus_lattice((m, n, t)),
)

params = MpsParameters{Float64}(bond_dim, 1E-8, 10, 1E-16)
search_params = SearchParameters(num_states, δp)
params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 4, ts = 1E-16)
search_params = SearchParameters(; max_states = num_states, cut_off_prob = δp)
Strategy = Zipper
Sparsity = Sparse
Layout = GaugesEnergy
Expand All @@ -35,9 +35,9 @@ function bench(instance::String, β::Real, bond_dim::Integer, num_states::Intege
net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparsity,Float64}(m, n, cl_h, transform)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
all_betas,
:graduate_truncate,
params;
βs = all_betas,
graduate_truncation = :graduate_truncate,
onGPU = onGPU,
)

Expand Down
5 changes: 0 additions & 5 deletions examples/truncation_BP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,5 @@ for cs ∈ cl_states
for v in vertices(cl_h)
println(length(get_prop(cl_h, v, :spectrum).states))
end
# net = PEPSNetwork{SquareCrossDoubleNode{Layout}, Sparse}(m, n, cl_h, tran)
# ctr = MpsContractor{Strategy, Gauge}(net, [β/6, β/3, β/2, β], :graduate_truncate, params; onGPU=onGPU)
# sol, schmidts = low_energy_spectrum(ctr, search_params, merge_branches(ctr))
# println("sol ", sol)
# println("Schmidts ", schmidts)
end
end
8 changes: 4 additions & 4 deletions src/contractor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct MpsParameters{S<:Real}
Dtemp_multiplier::Int
method::Symbol

MpsParameters{S}(
MpsParameters{S}(;
bd = typemax(Int),
ϵ::S = S(1E-8),
sw = 4,
Expand Down Expand Up @@ -160,9 +160,9 @@ mutable struct MpsContractor{T<:AbstractStrategy,R<:AbstractGauge,S<:Real} <:

function MpsContractor{T,R,S}(
net,
params;
βs::Vector{S},
graduate_truncation::Symbol,
params;
onGPU = true,
depth::Int = 0,
) where {T,R,S}
Expand Down Expand Up @@ -193,12 +193,12 @@ $(TYPEDSIGNATURES)
Get the strategy used to contract the PEPS network.

# Arguments
- `ctr::MpsContractor{T}`: The MpsContractor object representing the PEPS network contraction.
- `::MpsContractor{T}`: The MpsContractor object representing the PEPS network contraction.

# Returns
- `T`: The strategy used for network contraction.
"""
strategy(ctr::MpsContractor{T}) where {T} = T
strategy(::MpsContractor{T}) where {T} = T

"""
$(TYPEDSIGNATURES)
Expand Down
18 changes: 9 additions & 9 deletions src/droplets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ The `NoDroplets` strategy represents a scenario in which no droplets are present
- `NoDroplets()`: An instance of the `NoDroplets` strategy indicating that no excitation information is calculated in this scenario.
"""
(method::NoDroplets)(
ctr::MpsContractor{T},
best_idx::Int,
energies::Vector{<:Real},
states::Vector{Vector{Int}},
droplets::Vector{Droplets},
spins::Vector{Vector{Int}},
) where {T} = NoDroplets()
::MpsContractor,
::Int,
::Vector{<:Real},
::Vector{Vector{Int}},
::Vector{Droplets},
::Vector{Vector{Int}},
) = NoDroplets()

# """
# $(TYPEDSIGNATURES)
Expand All @@ -143,13 +143,13 @@ The `NoDroplets` strategy represents a scenario in which no droplets are present
# A new `Droplets` object representing the updated droplets based on the `SingleLayerDroplets` strategy
# """
function (method::SingleLayerDroplets)(
ctr::MpsContractor{T},
::MpsContractor,
best_idx::Int,
energies::Vector{<:Real},
states::Vector{Vector{Int}},
droplets::Vector{Droplets},
spins::Vector{Vector{Int}},
) where {T}
)
ndroplets = copy(droplets[best_idx])
bstate = states[best_idx]
benergy = energies[best_idx]
Expand Down
9 changes: 6 additions & 3 deletions src/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct SearchParameters
max_states::Int
cut_off_prob::Real

function SearchParameters(max_states::Int = 1, cut_off_prob::Real = 0.0)
function SearchParameters(; max_states::Int = 1, cut_off_prob::Real = 0.0)
new(max_states, cut_off_prob)
end
end
Expand Down Expand Up @@ -307,7 +307,7 @@ A function `_merge` that can be used to merge branches in a solution.
The `_merge` function can be applied to a `Solution` object to merge its branches based on the specified merge type and droplet update strategy.
"""
function merge_branches(
ctr::MpsContractor{T},
ctr::MpsContractor{T};
merge_type::Symbol = :nofit,
update_droplets = NoDroplets(),
) where {T}
Expand Down Expand Up @@ -415,7 +415,10 @@ function merge_branches_blur(
update_droplets = NoDroplets(),
) where {T}
function _merge_blur(psol::Solution)
psol = merge_branches(ctr, merge_type, update_droplets)(psol)
psol =
merge_branches(ctr; merge_type = merge_type, update_droplets = update_droplets)(
psol,
)
node = get(ctr.nodes_search_order, length(psol.states[1]) + 1, ctr.node_outside)
boundaries = boundary_states(ctr, psol.states, node)
sorted_indices = sortperm(psol.probabilities, rev = true)
Expand Down
12 changes: 6 additions & 6 deletions test/chimera_overlap_python.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ cl_h = clustered_hamiltonian(
cluster_assignment_rule = super_square_lattice((m, n, t)),
)

params = MpsParameters{Float64}(bond_dim, 1E-8, 10)
search_params = SearchParameters(num_states, δp)
params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 4)
search_params = SearchParameters(; max_states = num_states, cut_off_prob = δp)

Strategy = SVDTruncate
Gauge = NoUpdate
Expand All @@ -42,10 +42,10 @@ Gauge = NoUpdate
)
ctr = MpsContractor{Strategy,Gauge,Float64}(
network,
[β / 8, β / 4, β / 2, β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β / 8, β / 4, β / 2, β],
graduate_truncation = :graduate_truncate,
)
@testset "Compare the results with Python" begin
overlap_python = [0.2637787707674837, 0.2501621729619047, 0.2951954406837012]
Expand Down Expand Up @@ -73,10 +73,10 @@ end
)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β / 8, β / 4, β / 2, β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β / 8, β / 4, β / 2, β],
graduate_truncation = :graduate_truncate,
)
for i = 1:n-1
psi_top = mps_top(ctr, i, 4)
Expand Down
4 changes: 2 additions & 2 deletions test/experimental/gauges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ search_params = SearchParameters(num_states, δp)
)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β / 8, β / 4, β / 2, β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β / 8, β / 4, β / 2, β],
graduate_truncation = :graduate_truncate,
)

@testset "Overlaps calculated differently are the same." begin
Expand Down
4 changes: 2 additions & 2 deletions test/experimental/gauges_cuda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ end
)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β / 6, β / 3, β / 2, β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β / 6, β / 3, β / 2, β],
graduate_truncation = :graduate_truncate,
)
update_gauges!(ctr, m, INDβ, Val(:up))
sol, s = low_energy_spectrum(ctr, search_params)
Expand Down
4 changes: 2 additions & 2 deletions test/experimental/mpo_size.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ for cl_states in cluster_states
net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparse,Float64}(m, n, cl_h, tran)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β],
graduate_truncation = :graduate_truncate,
)
Ws = SpinGlassEngine.mpo(ctr, ctr.layers.main, i, indβ)
# println(" Ws -> ", which_device(Ws), " ", format_bytes.(measure_memory(Ws)))
Expand Down
4 changes: 2 additions & 2 deletions test/experimental/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ transform = rotation(0)
net = PEPSNetwork{Lattice{Layout},Sparsity,Float64}(m, n, cl_h, transform)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β / 8.0, β / 4.0, β / 2.0, β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β / 8.0, β / 4.0, β / 2.0, β],
graduate_truncation = :graduate_truncate,
)
sol = gibbs_sampling(ctr, search_params)

Expand Down
4 changes: 2 additions & 2 deletions test/experimental/search_chimera_gauge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β / 6, β / 3, β / 2, β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β / 6, β / 3, β / 2, β],
graduate_truncation = :graduate_truncate,
)
update_gauges!(ctr, m, INDβ, Val(:up))
sol, s = low_energy_spectrum(ctr, search_params)
Expand Down
10 changes: 7 additions & 3 deletions test/experimental/squarestar_double_node_pegasus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,19 @@ for tran ∈ all_lattice_transformations #[LatticeTransformation((1, 2, 3, 4), f
net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparsity,Float64}(m, n, cl_h, tran)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β / 6, β / 3, β / 2, β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β / 6, β / 3, β / 2, β],
graduate_truncation = :graduate_truncate,
)
sol, s = low_energy_spectrum(
ctr,
search_params,
merge_branches(ctr, :nofit, SingleLayerDroplets(eng, hamming_dist, :hamming)),
merge_branches(
ctr;
merge_type = :nofit,
update_droplets = SingleLayerDroplets(eng, hamming_dist, :hamming),
),
)
println(sol.energies)
# println(sol.states)
Expand Down
6 changes: 3 additions & 3 deletions test/experimental/squarestar_double_node_zephyr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cl_h = clustered_hamiltonian(
iter = iter,
)

params = MpsParameters{Float64}(bond_dim, 1E-8, 10, 1E-16)
params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 10, ts = 1E-16)
search_params = SearchParameters(num_states, δp)

# Solve using PEPS search
Expand All @@ -48,10 +48,10 @@ Gauge = NoUpdate
net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparsity,Float64}(m, n, cl_h, tran)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β / 6, β / 3, β / 2, β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β / 6, β / 3, β / 2, β],
graduate_truncation = :graduate_truncate,
)

# for i in 1//2 : 1//2 : m
Expand Down
4 changes: 2 additions & 2 deletions test/experimental/truncate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ for cs ∈ cl_states
net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparse}(m, n, cl_h, tran)
ctr = MpsContractor{Strategy,Gauge}(
net,
[β / 6, β / 3, β / 2, β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β / 6, β / 3, β / 2, β],
graduate_truncation = :graduate_truncate,
)
sol, schmidts = low_energy_spectrum(ctr, search_params, merge_branches(ctr))
println("sol ", sol)
Expand Down
4 changes: 2 additions & 2 deletions test/experimental/truncate_small.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ function run_test(instance, m, n, t)

ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
βs,
:graduate_truncate,
params;
onGPU = onGPU,
βs = βs,
graduate_truncation = :graduate_truncate,
)

sol, schmidts = low_energy_spectrum(ctr, search_params, merge_branches(ctr)) #, merge_branches(ctr))
Expand Down
8 changes: 4 additions & 4 deletions test/experimental/zipper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ indβ = 1
net = PEPSNetwork{SquareSingleNode{Layout},Sparse,Float64}(m, n, cl_h, tran)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β],
graduate_truncation = :graduate_truncate,
)
Ws = SpinGlassEngine.mpo(ctr, ctr.layers.main, i, indβ)
println(" Ws -> ", which_device(Ws), " ", format_bytes.(measure_memory(Ws)))

net = PEPSNetwork{SquareSingleNode{Layout},Dense,Float64}(m, n, cl_h, tran)
ctr = MpsContractor{Strategy,Gauge,Float64}(
net,
[β],
:graduate_truncate,
params;
onGPU = onGPU,
βs = [β],
graduate_truncation = :graduate_truncate,
)
Wd = SpinGlassEngine.mpo(ctr, ctr.layers.main, i, indβ)
println(" Wd -> ", which_device(Wd), " ", format_bytes.(measure_memory(Wd)))
Expand Down
Loading
Loading