From 38bbdc8c881f6c0dd7f0c1409584b9cc845fb0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawela?= <3093117+lpawela@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:08:00 +0200 Subject: [PATCH] Change some constructors to kwargs (#27) * initial version of kwarg constructors * update tests * fix tests * change `MpsContractor` and `merge_branches` * fix tests * fix tests * reformat --- Project.toml | 2 +- examples/pegasus.jl | 8 +-- examples/truncation_BP.jl | 5 -- src/contractor.jl | 8 +-- src/droplets.jl | 18 +++--- src/search.jl | 9 ++- test/chimera_overlap_python.jl | 12 ++-- test/experimental/gauges.jl | 4 +- test/experimental/gauges_cuda.jl | 4 +- test/experimental/mpo_size.jl | 4 +- test/experimental/sampling.jl | 4 +- test/experimental/search_chimera_gauge.jl | 4 +- .../squarestar_double_node_pegasus.jl | 10 +++- .../squarestar_double_node_zephyr.jl | 6 +- test/experimental/truncate.jl | 4 +- test/experimental/truncate_small.jl | 4 +- test/experimental/zipper.jl | 8 +-- test/mwe.jl | 60 +++++++++++++++++++ test/random_markov_field.jl | 11 ++-- test/search_chimera_droplets.jl | 15 +++-- test/search_chimera_full.jl | 15 +++-- test/search_chimera_pathological.jl | 8 +-- test/search_chimera_pathological_Z2.jl | 14 +++-- test/search_chimera_pathological_droplets.jl | 8 +-- test/search_chimera_pathological_hamming.jl | 8 +-- test/search_chimera_smallest.jl | 8 +-- test/search_chimera_smallest_droplets.jl | 14 +++-- test/search_cross_square_star.jl | 8 +-- test/search_pegasus_droplets.jl | 15 +++-- test/search_pegasus_nodiag_square_cross.jl | 8 +-- test/search_pegasus_square_cross.jl | 8 +-- test/search_smallest_cross_square_cross.jl | 8 +-- test/search_square_double_node_basic.jl | 12 ++-- test/search_square_lattice.jl | 8 +-- test/search_squarecross_double_node_basic.jl | 12 ++-- 35 files changed, 216 insertions(+), 138 deletions(-) create mode 100644 test/mwe.jl diff --git a/Project.toml b/Project.toml index 2086ac15..079f5a27 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SpinGlassEngine" uuid = "0563570f-ea1b-4080-8a64-041ac6565a4e" authors = ["Anna Maria Dziubyna ", "Tomasz Śmierzchalski ", "Bartłomiej Gardas ", "Konrad Jałowiecki ", "Łukasz Pawela ", "Marek M. Rams "] -version = "1.1.1" +version = "1.2.0" [deps] CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" diff --git a/examples/pegasus.jl b/examples/pegasus.jl index b99fd92f..1712add4 100644 --- a/examples/pegasus.jl +++ b/examples/pegasus.jl @@ -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 @@ -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, ) diff --git a/examples/truncation_BP.jl b/examples/truncation_BP.jl index d1bad3d0..560d8997 100644 --- a/examples/truncation_BP.jl +++ b/examples/truncation_BP.jl @@ -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 diff --git a/src/contractor.jl b/src/contractor.jl index 277720c4..29efd5e9 100644 --- a/src/contractor.jl +++ b/src/contractor.jl @@ -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, @@ -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} @@ -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) diff --git a/src/droplets.jl b/src/droplets.jl index d0778ab0..2fffa23d 100644 --- a/src/droplets.jl +++ b/src/droplets.jl @@ -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) @@ -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] diff --git a/src/search.jl b/src/search.jl index 31bc1916..8018c867 100644 --- a/src/search.jl +++ b/src/search.jl @@ -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 @@ -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} @@ -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) diff --git a/test/chimera_overlap_python.jl b/test/chimera_overlap_python.jl index 4617dce8..66f821f4 100644 --- a/test/chimera_overlap_python.jl +++ b/test/chimera_overlap_python.jl @@ -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 @@ -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] @@ -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) diff --git a/test/experimental/gauges.jl b/test/experimental/gauges.jl index 5ab94532..e96d340e 100644 --- a/test/experimental/gauges.jl +++ b/test/experimental/gauges.jl @@ -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 diff --git a/test/experimental/gauges_cuda.jl b/test/experimental/gauges_cuda.jl index 35b530c5..8641ab34 100644 --- a/test/experimental/gauges_cuda.jl +++ b/test/experimental/gauges_cuda.jl @@ -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) diff --git a/test/experimental/mpo_size.jl b/test/experimental/mpo_size.jl index c02fde44..a9b288c7 100644 --- a/test/experimental/mpo_size.jl +++ b/test/experimental/mpo_size.jl @@ -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))) diff --git a/test/experimental/sampling.jl b/test/experimental/sampling.jl index 44d2507e..55fb78b2 100644 --- a/test/experimental/sampling.jl +++ b/test/experimental/sampling.jl @@ -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) diff --git a/test/experimental/search_chimera_gauge.jl b/test/experimental/search_chimera_gauge.jl index 5e26d396..de8e9929 100644 --- a/test/experimental/search_chimera_gauge.jl +++ b/test/experimental/search_chimera_gauge.jl @@ -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) diff --git a/test/experimental/squarestar_double_node_pegasus.jl b/test/experimental/squarestar_double_node_pegasus.jl index 10fc9c0b..3c110c92 100644 --- a/test/experimental/squarestar_double_node_pegasus.jl +++ b/test/experimental/squarestar_double_node_pegasus.jl @@ -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) diff --git a/test/experimental/squarestar_double_node_zephyr.jl b/test/experimental/squarestar_double_node_zephyr.jl index 4e389878..aab12d7e 100644 --- a/test/experimental/squarestar_double_node_zephyr.jl +++ b/test/experimental/squarestar_double_node_zephyr.jl @@ -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 @@ -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 diff --git a/test/experimental/truncate.jl b/test/experimental/truncate.jl index 4516d4e2..ff1c9e17 100644 --- a/test/experimental/truncate.jl +++ b/test/experimental/truncate.jl @@ -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) diff --git a/test/experimental/truncate_small.jl b/test/experimental/truncate_small.jl index 76d115dd..f48d984e 100644 --- a/test/experimental/truncate_small.jl +++ b/test/experimental/truncate_small.jl @@ -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)) diff --git a/test/experimental/zipper.jl b/test/experimental/zipper.jl index 44d0ce10..4df3ba47 100644 --- a/test/experimental/zipper.jl +++ b/test/experimental/zipper.jl @@ -53,10 +53,10 @@ 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))) @@ -64,10 +64,10 @@ 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))) diff --git a/test/mwe.jl b/test/mwe.jl new file mode 100644 index 00000000..7b9dcc1d --- /dev/null +++ b/test/mwe.jl @@ -0,0 +1,60 @@ +using SpinGlassEngine, SpinGlassNetworks, SpinGlassTensors +using Test +m, n, t = 3, 4, 1 + +β = 0.5 +bond_dim = 8 +mstates = 10 +instance = "$(@__DIR__)/instances/pathological/pegasus_3_4_1.txt" + +iter = 2 +δp = 0.0 +MAX_SWEEPS = 0 +VAR_TOL = 1E-16 +TOL_SVD = 1E-16 +ITERS_SVD = 2 +ITERS_VAR = 1 +DTEMP_MULT = 2 +METHOD = :psvd_sparse +Strategy = Zipper +Sparsity = Sparse +Layout = GaugesEnergy +onGPU = true +transform = all_lattice_transformations[1] +ig = ising_graph(instance) +cl_h = clustered_hamiltonian( + ig, + spectrum = full_spectrum, + cluster_assignment_rule = pegasus_lattice((m, n, t)), +) + +Gauge = NoUpdate +for T in [Float64, Float32] + println("=========") + println("type ", T) + energies = Vector{T}[] + params = MpsParameters{T}(; + bond_dim, + T(VAR_TOL), + MAX_SWEEPS, + T(TOL_SVD), + ITERS_SVD, + ITERS_VAR, + DTEMP_MULT, + METHOD, + ) + search_params = SearchParameters(mstates, δp) + + net = PEPSNetwork{SquareCrossDoubleNode{Layout},Sparsity,T}(m, n, cl_h, transform) + ctr = MpsContractor{Strategy,Gauge,T}( + net, + params; + onGPU = onGPU, + βs = [β / 8, β / 4, β / 2, β], + graduate_truncation = :graduate_truncate, + ) + sol, s = low_energy_spectrum(ctr, search_params) + @test eltype(sol.energies) == T + println(sol.energies[1]) + clear_memoize_cache() +end diff --git a/test/random_markov_field.jl b/test/random_markov_field.jl index c07ae4ab..3577b6b2 100644 --- a/test/random_markov_field.jl +++ b/test/random_markov_field.jl @@ -7,8 +7,8 @@ num_states = 64 cl_h = clustered_hamiltonian(instance_dir) Nx, Ny = get_prop(cl_h, :Nx), get_prop(cl_h, :Ny) - 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) Gauge = NoUpdate graduate_truncation = :graduate_truncate energies = Vector{Float64}[] @@ -17,14 +17,13 @@ Sparsity = Sparse transform = rotation(0) net = PEPSNetwork{SquareCrossSingleNode{Layout},Sparsity}(Nx, Ny, cl_h, transform) - ctr = MpsContractor{Strategy,Gauge}( + ctr = MpsContractor{Strategy,Gauge,Float64}( net, - [β / 8, β / 4, β / 2, β], - graduate_truncation, params; onGPU = onGPU, + βs = [β / 8, β / 4, β / 2, β], + graduate_truncation = :graduate_truncate, mode = :RMF, ) sol_peps, s = low_energy_spectrum(ctr, search_params, merge_branches(ctr)) - # sol_peps, s = low_energy_spectrum(ctr, search_params, merge_branches(ctr, :nofit, SingleLayerDroplets(100.0, 100, :hamming, :RMF))) end diff --git a/test/search_chimera_droplets.jl b/test/search_chimera_droplets.jl index bf22b11d..b940a35d 100644 --- a/test/search_chimera_droplets.jl +++ b/test/search_chimera_droplets.jl @@ -24,8 +24,8 @@ function bench(instance::String) spectrum = my_brute_force, cluster_assignment_rule = super_square_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) energies = Vector{Float64}[] for Strategy ∈ (Zipper,), Sparsity ∈ (Dense,) @@ -39,16 +39,19 @@ function bench(instance::String) ) ctr = MpsContractor{Strategy,Gauge,Float64}( net, - all_betas, - :graduate_truncate, params; onGPU = onGPU, + βs = all_betas, + graduate_truncation = :graduate_truncate, ) - # sol1, s = low_energy_spectrum(ctr, search_params, merge_branches(ctr, :nofit, NoDroplets())) sol1, s = low_energy_spectrum( ctr, search_params, - merge_branches(ctr, :nofit, SingleLayerDroplets(1.0, 1000, :hamming)), + merge_branches( + ctr; + merge_type = :nofit, + update_droplets = SingleLayerDroplets(1.0, 1000, :hamming), + ), ) sol2 = unpack_droplets(sol1, β) diff --git a/test/search_chimera_full.jl b/test/search_chimera_full.jl index af61d588..60a97ca9 100644 --- a/test/search_chimera_full.jl +++ b/test/search_chimera_full.jl @@ -23,8 +23,8 @@ function bench(instance::String) spectrum = full_spectrum, cluster_assignment_rule = super_square_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) energies = Vector{Float64}[] for Strategy ∈ (SVDTruncate, Zipper), Sparsity ∈ (Dense, Sparse) @@ -39,13 +39,16 @@ function bench(instance::String) ) ctr = MpsContractor{Strategy,Gauge,Float64}( net, - all_betas, - :graduate_truncate, params; onGPU = onGPU, + βs = all_betas, + graduate_truncation = :graduate_truncate, + ) + sol, s = low_energy_spectrum( + ctr, + search_params, + merge_branches(ctr; merge_type = :nofit), ) - sol, s = - low_energy_spectrum(ctr, search_params, merge_branches(ctr, :nofit)) @test sol.energies[begin] ≈ ground_energy diff --git a/test/search_chimera_pathological.jl b/test/search_chimera_pathological.jl index 7a8f6bcb..a09e1536 100644 --- a/test/search_chimera_pathological.jl +++ b/test/search_chimera_pathological.jl @@ -114,8 +114,8 @@ transform = $transform spectrum = full_spectrum, cluster_assignment_rule = super_square_lattice((m, n, t)), ) - params = MpsParameters{Float64}(bond_dim, 1E-8, 4) - search_params = SearchParameters(num_states, 0.0) + params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 4) + search_params = SearchParameters(; max_states = num_states, cut_off_prob = 0.0) Gauge = NoUpdate energies = Vector{Float64}[] @@ -124,10 +124,10 @@ transform = $transform 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, s = low_energy_spectrum(ctr, search_params) diff --git a/test/search_chimera_pathological_Z2.jl b/test/search_chimera_pathological_Z2.jl index 32294e87..7f043e17 100644 --- a/test/search_chimera_pathological_Z2.jl +++ b/test/search_chimera_pathological_Z2.jl @@ -103,8 +103,8 @@ spectrum = full_spectrum, cluster_assignment_rule = super_square_lattice((m, n, t)), ) - params = MpsParameters{Float64}(bond_dim, 1E-8, 4) - search_params = SearchParameters(num_states, 0.0) + params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 4) + search_params = SearchParameters(; max_states = num_states, cut_off_prob = 0.0) Gauge = NoUpdate energies = Vector{Float64}[] @@ -121,15 +121,19 @@ ) 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, ) sol1, s = low_energy_spectrum( ctr, search_params, - merge_branches(ctr, :nofit, SingleLayerDroplets(10.0, 0, :hamming)), + merge_branches( + ctr; + merge_type = :nofit, + update_droplets = SingleLayerDroplets(10.0, 0, :hamming), + ), :Z2, ) sol2 = unpack_droplets(sol1, β) diff --git a/test/search_chimera_pathological_droplets.jl b/test/search_chimera_pathological_droplets.jl index 4a1f7d67..34c29754 100644 --- a/test/search_chimera_pathological_droplets.jl +++ b/test/search_chimera_pathological_droplets.jl @@ -104,8 +104,8 @@ spectrum = full_spectrum, cluster_assignment_rule = super_square_lattice((m, n, t)), ) - params = MpsParameters{Float64}(bond_dim, 1E-8, 4) - search_params = SearchParameters(num_states, 0.0) + params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 4) + search_params = SearchParameters(; max_states = num_states, cut_off_prob = 0.0) Gauge = NoUpdate energies = Vector{Float64}[] @@ -124,10 +124,10 @@ ) 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, ) sol1, s = low_energy_spectrum( ctr, diff --git a/test/search_chimera_pathological_hamming.jl b/test/search_chimera_pathological_hamming.jl index fc2126ca..a6776e85 100644 --- a/test/search_chimera_pathological_hamming.jl +++ b/test/search_chimera_pathological_hamming.jl @@ -117,8 +117,8 @@ end cluster_assignment_rule = super_square_lattice((m, n, t)), ) - params = MpsParameters{Float64}(bond_dim, 1E-8, 4) - search_params = SearchParameters(num_states, 0.0) + params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 4) + search_params = SearchParameters(; max_states = num_states, cut_off_prob = 0.0) Gauge = NoUpdate energies = Vector{Float64}[] @@ -135,10 +135,10 @@ end ) 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, ) sol1, s = low_energy_spectrum( ctr, diff --git a/test/search_chimera_smallest.jl b/test/search_chimera_smallest.jl index 08e75372..a77ebbb9 100644 --- a/test/search_chimera_smallest.jl +++ b/test/search_chimera_smallest.jl @@ -16,11 +16,11 @@ cluster_assignment_rule = super_square_lattice((m, n, t)), ) - search_params = SearchParameters(num_states, 0.0) + search_params = SearchParameters(; max_states = num_states, cut_off_prob = 0.0) Gauge = NoUpdate for T in [Float32, Float64] energies = Vector{T}[] - params = MpsParameters{T}(bond_dim, T(1E-8), 4) + params = MpsParameters{T}(; bd = bond_dim, ϵ = T(1E-8), sw = 4) for Strategy ∈ (SVDTruncate, Zipper), Sparsity ∈ (Dense, Sparse), Layout ∈ (EnergyGauges, GaugesEnergy, EngGaugesEng), @@ -29,10 +29,10 @@ net = PEPSNetwork{SquareSingleNode{Layout},Sparsity,T}(m, n, cl_h, transform) ctr = MpsContractor{Strategy,Gauge,T}( net, - T[β/8, β/4, β/2, β], - :graduate_truncate, params; onGPU = onGPU, + βs = T[β/8, β/4, β/2, β], + graduate_truncation = :graduate_truncate, ) sol, s = low_energy_spectrum(ctr, search_params) @test eltype(sol.energies) == T diff --git a/test/search_chimera_smallest_droplets.jl b/test/search_chimera_smallest_droplets.jl index 33363661..11ca746c 100644 --- a/test/search_chimera_smallest_droplets.jl +++ b/test/search_chimera_smallest_droplets.jl @@ -16,8 +16,8 @@ cluster_assignment_rule = super_square_lattice((m, n, t)), ) - params = MpsParameters{Float64}(bond_dim, 1E-8, 4) - search_params = SearchParameters(num_states, 0.0) + params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 4) + search_params = SearchParameters(; max_states = num_states, cut_off_prob = 0.0) Gauge = NoUpdate energies = Vector{Float64}[] @@ -32,16 +32,20 @@ ) ctr = MpsContractor{Strategy,Gauge,Float64}( net, - [β / 8, β / 4, β / 2, β], - :graduate_truncate, params; onGPU = onGPU, + βs = [β / 8, β / 4, β / 2, β], + graduate_truncation = :graduate_truncate, ) sol1, s = low_energy_spectrum( ctr, search_params, - merge_branches(ctr, :nofit, SingleLayerDroplets(2.2, 1, :hamming)), + merge_branches( + ctr; + merge_type = :nofit, + update_droplets = SingleLayerDroplets(2.2, 1, :hamming), + ), ) @test sol1.energies ≈ exact_energies[[1]] diff --git a/test/search_cross_square_star.jl b/test/search_cross_square_star.jl index b4ffd06b..0e9cee21 100644 --- a/test/search_cross_square_star.jl +++ b/test/search_cross_square_star.jl @@ -15,8 +15,8 @@ spectrum = full_spectrum, cluster_assignment_rule = super_square_lattice((m, n, t)), ) - params = MpsParameters{Float64}(bond_dim, 1E-8, 4) - search_params = SearchParameters(num_states, 0.0) + params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 4) + search_params = SearchParameters(; max_states = num_states, cut_off_prob = 0.0) Gauge = NoUpdate energies = Vector{Float64}[] @@ -26,10 +26,10 @@ net = PEPSNetwork{Lattice{Layout},Sparsity,Float64}(m, n, cl_h, transform) ctr = MpsContractor{Strategy,Gauge,Float64}( net, - [β / 2, β], - :graduate_truncate, params; onGPU = onGPU, + βs = [β / 2, β], + graduate_truncation = :graduate_truncate, ) sol, s = low_energy_spectrum(ctr, search_params) diff --git a/test/search_pegasus_droplets.jl b/test/search_pegasus_droplets.jl index ab1c75d4..2f57eb8c 100644 --- a/test/search_pegasus_droplets.jl +++ b/test/search_pegasus_droplets.jl @@ -24,8 +24,8 @@ function bench(instance::String) spectrum = my_brute_force, 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) energies = Vector{Float64}[] for Strategy ∈ (Zipper,), Sparsity ∈ (Sparse,) @@ -39,16 +39,19 @@ function bench(instance::String) ) ctr = MpsContractor{Strategy,Gauge,Float64}( net, - all_betas, - :graduate_truncate, params; onGPU = onGPU, + βs = all_betas, + graduate_truncation = :graduate_truncate, ) - # sol1, s = low_energy_spectrum(ctr, search_params, merge_branches(ctr, :nofit, NoDroplets())) sol1, s = low_energy_spectrum( ctr, search_params, - merge_branches(ctr, :nofit, SingleLayerDroplets(0.01, 20, :hamming)), + merge_branches( + ctr; + merge_type = :nofit, + update_droplets = SingleLayerDroplets(0.01, 20, :hamming), + ), ) sol2 = unpack_droplets(sol1, β) diff --git a/test/search_pegasus_nodiag_square_cross.jl b/test/search_pegasus_nodiag_square_cross.jl index 6eb13602..e525b9b1 100644 --- a/test/search_pegasus_nodiag_square_cross.jl +++ b/test/search_pegasus_nodiag_square_cross.jl @@ -19,8 +19,8 @@ function bench(instance::String) spectrum = my_brute_force, 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) # Solve using PEPS search energies = Vector{Float64}[] @@ -36,10 +36,10 @@ function bench(instance::String) ) ctr = MpsContractor{Strategy,NoUpdate,Float64}( net, - [β / 8, β / 4, β / 2, β], - :graduate_truncate, params; onGPU = onGPU, + βs = [β / 8, β / 4, β / 2, β], + graduate_truncation = :graduate_truncate, ) sol_peps, s = low_energy_spectrum(ctr, search_params, merge_branches(ctr)) push!(energies, sol_peps.energies) diff --git a/test/search_pegasus_square_cross.jl b/test/search_pegasus_square_cross.jl index c61915d2..798ec032 100644 --- a/test/search_pegasus_square_cross.jl +++ b/test/search_pegasus_square_cross.jl @@ -17,8 +17,8 @@ function bench(instance::String) spectrum = my_brute_force, 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) Gauge = NoUpdate graduate_truncation = :graduate_truncate @@ -36,10 +36,10 @@ function bench(instance::String) ) ctr = MpsContractor{Strategy,Gauge,Float64}( net, - [β / 8, β / 4, β / 2, β], - graduate_truncation, params; onGPU = onGPU, + βs = [β / 8, β / 4, β / 2, β], + graduate_truncation = graduate_truncation, ) sol_peps, s = low_energy_spectrum(ctr, search_params, merge_branches(ctr)) push!(energies, sol_peps.energies) diff --git a/test/search_smallest_cross_square_cross.jl b/test/search_smallest_cross_square_cross.jl index c5b0cf23..330a0c01 100644 --- a/test/search_smallest_cross_square_cross.jl +++ b/test/search_smallest_cross_square_cross.jl @@ -15,8 +15,8 @@ spectrum = full_spectrum, cluster_assignment_rule = super_square_lattice((m, n, t)), ) - params = MpsParameters{Float64}(bond_dim, 1E-8, 4) - search_params = SearchParameters(num_states, 0.0) + params = MpsParameters{Float64}(; bd = bond_dim, ϵ = 1E-8, sw = 4) + search_params = SearchParameters(; max_states = num_states, cut_off_prob = 0.0) for Strategy ∈ (SVDTruncate, MPSAnnealing, Zipper), Sparsity ∈ (Dense, Sparse) for Layout ∈ (EnergyGauges, GaugesEnergy, EngGaugesEng) @@ -29,10 +29,10 @@ ) ctr = MpsContractor{Strategy,NoUpdate,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, s = low_energy_spectrum(ctr, search_params) diff --git a/test/search_square_double_node_basic.jl b/test/search_square_double_node_basic.jl index d3c1350f..a6d0018a 100644 --- a/test/search_square_double_node_basic.jl +++ b/test/search_square_double_node_basic.jl @@ -20,8 +20,8 @@ function run_test_square_double_node(instance, m, n, t) cluster_assignment_rule = super_square_lattice((m, n, 8)), ) - 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) energies = [] Gauge = NoUpdate @@ -40,17 +40,17 @@ function run_test_square_double_node(instance, m, n, t) ctr = MpsContractor{Strategy,Gauge,Float64}( net, - βs, - :graduate_truncate, params; onGPU = onGPU, + βs = βs, + graduate_truncation = :graduate_truncate, ) ctr2 = MpsContractor{Strategy,Gauge,Float64}( net2, - βs, - :graduate_truncate, params; onGPU = onGPU, + βs = βs, + graduate_truncation = :graduate_truncate, ) sol, s = low_energy_spectrum(ctr, search_params) #, merge_branches(ctr)) diff --git a/test/search_square_lattice.jl b/test/search_square_lattice.jl index 8601a222..b6528e89 100644 --- a/test/search_square_lattice.jl +++ b/test/search_square_lattice.jl @@ -15,8 +15,8 @@ function bench(instance::String) spectrum = full_spectrum, 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) Gauge = NoUpdate graduate_truncation = :graduate_truncate energies = Vector{Float64}[] @@ -27,10 +27,10 @@ function bench(instance::String) net = PEPSNetwork{SquareCrossSingleNode{Layout},Sparsity}(m, n, cl_h, transform) ctr = MpsContractor{Strategy,Gauge}( net, - [β / 8, β / 4, β / 2, β], - graduate_truncation, params; onGPU = onGPU, + βs = [β / 8, β / 4, β / 2, β], + graduate_truncation = graduate_truncation, ) sol_peps, s = low_energy_spectrum(ctr, search_params, merge_branches(ctr)) push!(energies, sol_peps.energies) diff --git a/test/search_squarecross_double_node_basic.jl b/test/search_squarecross_double_node_basic.jl index d14c69fd..eb4eb1f5 100644 --- a/test/search_squarecross_double_node_basic.jl +++ b/test/search_squarecross_double_node_basic.jl @@ -20,8 +20,8 @@ function run_test_squarecross_double_node(instance, m, n, t) cluster_assignment_rule = super_square_lattice((m, n, 8)), ) - 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) energies = [] Gauge = NoUpdate βs = [β / 16, β / 8, β / 4, β / 2, β] @@ -45,17 +45,17 @@ function run_test_squarecross_double_node(instance, m, n, t) ctr = MpsContractor{Strategy,Gauge,Float64}( net, - βs, - :graduate_truncate, params; onGPU = onGPU, + βs = βs, + graduate_truncation = :graduate_truncate, ) ctr2 = MpsContractor{Strategy,Gauge,Float64}( net2, - βs, - :graduate_truncate, params; onGPU = onGPU, + βs = βs, + graduate_truncation = :graduate_truncate, ) sol, s = low_energy_spectrum(ctr, search_params) #, merge_branches(ctr))