Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
annamariadziubyna committed Jan 25, 2024
1 parent 6b38307 commit cfff407
Showing 1 changed file with 18 additions and 47 deletions.
65 changes: 18 additions & 47 deletions src/truncate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ function load_file(filename)
end
end

"""
$(TYPEDSIGNATURES)
Truncate a clustered Hamiltonian based on 2-site belief propagation states.
This function truncates a clustered Hamiltonian by considering 2-site belief propagation states and selecting the most probable states
to keep. It computes the beliefs for all 2-site combinations and selects the states that maximize the probability.
# Arguments:
- `cl_h::LabelledGraph{S, T}`: The clustered Hamiltonian represented as a labelled graph.
- `beliefs::Dict`: A dictionary containing belief values for 2-site interactions.
- `num_states::Int`: The maximum number of most probable states to keep.
- `beta::Real (optional)`: The inverse temperature parameter (default is 1.0).
# Returns:
- `LabelledGraph{S, T}`: A truncated clustered Hamiltonian.
"""
function truncate_clustered_hamiltonian_2site_BP(
cl_h::LabelledGraph{S, T},
beliefs::Dict,
Expand Down Expand Up @@ -158,50 +175,4 @@ function truncate_clustered_hamiltonian(cl_h, β, cs, result_folder, inst; tol=1
cl_h = truncate_clustered_hamiltonian(cl_h, states)
end
cl_h
end

"""
$(TYPEDSIGNATURES)
Truncate a clustered Hamiltonian based on 2-site belief propagation states.
This function truncates a clustered Hamiltonian by considering 2-site belief propagation states and selecting the most probable states
to keep. It computes the beliefs for all 2-site combinations and selects the states that maximize the probability.
# Arguments:
- `cl_h::LabelledGraph{S, T}`: The clustered Hamiltonian represented as a labelled graph.
- `beliefs::Dict`: A dictionary containing belief values for 2-site interactions.
- `num_states::Int`: The maximum number of most probable states to keep.
- `beta::Real (optional)`: The inverse temperature parameter (default is 1.0).
# Returns:
- `LabelledGraph{S, T}`: A truncated clustered Hamiltonian.
"""
# function truncate_clustered_hamiltonian_2site_BP(
# cl_h::LabelledGraph{S, T},
# beliefs::Dict,
# num_states::Int,
# result_folder::String = "results_folder",
# inst::String = "inst";
# beta=1.0
# ) where {S, T}
# states = Dict()

# saved_states = load_file(joinpath(result_folder, "$(inst).jld2"))
# if saved_states == nothing
# for node in vertices(cl_h)
# i, j, _ = node
# sx = has_vertex(cl_h, (i, j, 1)) ? length(get_prop(cl_h, (i, j, 1), :spectrum).energies) : 1
# E = beliefs[(i, j)]
# ind1, ind2 = select_numstate_best(E, sx, num_states)
# push!(states, (i, j, 1) => ind1)
# push!(states, (i, j, 2) => ind2)
# end
# path = joinpath(result_folder, "$(inst).jld2")
# save_object(string(path), states)
# else
# states = saved_states
# end
# truncate_clustered_hamiltonian(cl_h, states)
# end

end

0 comments on commit cfff407

Please sign in to comment.