Skip to content

Commit

Permalink
final cleaning projectors
Browse files Browse the repository at this point in the history
  • Loading branch information
annamariadziubyna committed Sep 20, 2023
1 parent ea1e1d6 commit 19b1545
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
16 changes: 9 additions & 7 deletions src/bp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ function get_neighbors(cl_h::LabelledGraph{S, T}, vertex::NTuple) where {S, T}
src_node, dst_node = src(edge), dst(edge)
if src_node == vertex
en = get_prop(cl_h, src_node, dst_node, :en)
pv = get_prop(cl_h, src_node, dst_node, :pl)
# idx_pv = get_prop(cl_h, src_node, dst_node, :ipl)
# pv = get_projector!(get_prop(cl_h, :pool_of_projectors), idx_pv, :CPU)
idx_pv = get_prop(cl_h, src_node, dst_node, :ipl)
pv = get_projector!(get_prop(cl_h, :pool_of_projectors), idx_pv, :CPU)
push!(neighbors, (dst_node, pv, en))
elseif dst_node == vertex
en = get_prop(cl_h, src_node, dst_node, :en)'
pv = get_prop(cl_h, src_node, dst_node, :pr)
# idx_pv = get_prop(cl_h, src_node, dst_node, :ipr)
# pv = get_projector!(get_prop(cl_h, :pool_of_projectors), idx_pv, :CPU)
idx_pv = get_prop(cl_h, src_node, dst_node, :ipr)
pv = get_projector!(get_prop(cl_h, :pool_of_projectors), idx_pv, :CPU)
push!(neighbors, (src_node, pv, en))
end
end
Expand Down Expand Up @@ -150,6 +148,7 @@ function clustered_hamiltonian_2site(cl_h::LabelledGraph{S, T}, beta::Real) wher

unified_vertices = unique([vertex[1:2] for vertex in vertices(cl_h)])
new_cl_h = LabelledGraph{MetaDiGraph}(unified_vertices)
new_lp = PoolOfProjectors{Int}()

vertx = Set()
for v in vertices(cl_h)
Expand All @@ -175,9 +174,12 @@ function clustered_hamiltonian_2site(cl_h::LabelledGraph{S, T}, beta::Real) wher
add_edge!(new_cl_h, (v1, v2), (w1, w2))

E, pl, pr = merge_vertices(cl_h, beta, v, w)
set_props!(new_cl_h, (v1, v2), (w1, w2), Dict(:pl => pl, :en => E, :pr => pr))
ipl = add_projector!(new_lp, pl)
ipr = add_projector!(new_lp, pr)
set_props!(new_cl_h, (v1, v2), (w1, w2), Dict(:ipl => ipl, :en => E, :ipr => ipr))
push!(edge_states, sort([(v1, v2), (w1, w2)]))
end
set_props!(new_cl_h, Dict(:pool_of_projectors => new_lp))
new_cl_h
end

Expand Down
6 changes: 0 additions & 6 deletions src/clustered_hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ function clustered_hamiltonian(
ipr = add_projector!(lp, pr)

add_edge!(cl_h, v, w)
set_props!(
cl_h, v, w, Dict(:outer_edges => outer_edges, :pl => pl, :en => en, :pr => pr)
)
set_props!(
cl_h, v, w, Dict(:outer_edges => outer_edges, :ipl => ipl, :en => en, :ipr => ipr)
)
Expand Down Expand Up @@ -281,9 +278,6 @@ function truncate_clustered_hamiltonian(cl_h::LabelledGraph{S, T}, states::Dict)
set_props!(
new_cl_h, v, w, Dict(:outer_edges => outer_edges, :ipl => ipl, :en => en, :ipr => ipr)
)
set_props!(
new_cl_h, v, w, Dict(:outer_edges => outer_edges, :pl => pl_transition, :en => en, :pr => pr_transition)
)
end
set_props!(new_cl_h, Dict(:pool_of_projectors => new_lp))

Expand Down
9 changes: 7 additions & 2 deletions test/bp_2site.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,13 @@ end
@test E == get_prop(cl_h1, src(e), dst(e), :en)
end
for e edges(new_cl_h1)
@test get_prop(new_cl_h1, src(e), dst(e), :pl) == get_prop(cl_h1, src(e), dst(e), :pl)
@test get_prop(new_cl_h1, src(e), dst(e), :pr) == get_prop(cl_h1, src(e), dst(e), :pr)
il1 = get_prop(new_cl_h1, src(e), dst(e), :ipl)
il2 = get_prop(cl_h1, src(e), dst(e), :ipl)
ir1 = get_prop(new_cl_h1, src(e), dst(e), :ipr)
ir2 = get_prop(cl_h1, src(e), dst(e), :ipr)

@test get_projector!(get_prop(new_cl_h1, :pool_of_projectors), il1, :CPU) == get_projector!(get_prop(cl_h1, :pool_of_projectors), il2, :CPU)
@test get_projector!(get_prop(new_cl_h1, :pool_of_projectors), ir1, :CPU) == get_projector!(get_prop(cl_h1, :pool_of_projectors), ir2, :CPU)
end

beliefs = belief_propagation(new_cl_h1, beta; iter=iter, tol=tol)
Expand Down

0 comments on commit 19b1545

Please sign in to comment.