Skip to content

Commit

Permalink
Further changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Oct 26, 2023
1 parent 0832ad5 commit dfec1e2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
3 changes: 2 additions & 1 deletion examples/gauging/gauging_itns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using ITensorNetworks:
using NamedGraphs
using NamedGraphs: add_edges!, rem_vertex!, hexagonal_lattice_graph
using Graphs
using MKL

"""Eager Gauging"""
function eager_gauging::ITensorNetwork, bond_tensors::DataGraph, mts::DataGraph)
Expand Down Expand Up @@ -85,7 +86,7 @@ function benchmark_state_gauging(

C[i] = vidal_itn_canonicalness(ψ, bond_tensors)
end

@show times_iters, time
simulation_times = cumsum(times_iters) + times_gauging

return simulation_times, C
Expand Down
12 changes: 7 additions & 5 deletions src/beliefpropagation/beliefpropagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ function message_tensors_skeleton(subgraphs::DataGraph)
end

function message_tensors(
subgraphs::DataGraph; itensor_constructor=inds_e -> dense(delta(inds_e))
subgraphs::DataGraph; itensor_constructor=x -> ITensor[dense(delta(i)) for i in x]
)
mts = message_tensors_skeleton(subgraphs)
for e in edges(subgraphs)
inds_e = commoninds(subgraphs[src(e)], subgraphs[dst(e)])
mts[e] = ITensorNetwork(map(itensor_constructor, inds_e))
inds_e = [i for i in commoninds(subgraphs[src(e)], subgraphs[dst(e)])]
itensors = itensor_constructor(inds_e)
mts[e] = ITensorNetwork(itensors)
mts[reverse(e)] = dag(mts[e])
end
return mts
Expand Down Expand Up @@ -118,7 +119,7 @@ function belief_propagation(
contract_kwargs=(; alg="density_matrix", output_structure=path_graph_structure, maxdim=1),
niters=20,
target_precision::Union{Float64,Nothing}=nothing,
update_sequence::String="parallel",
update_sequence::String="sequential",
edges = edge_update_order(undirected_graph(underlying_graph(mts)))
)
compute_norm = target_precision == nothing ? false : true
Expand All @@ -143,10 +144,11 @@ function belief_propagation(
npartitions=nothing,
subgraph_vertices=nothing,
niters=20,
update_sequence::String="sequential",
target_precision::Union{Float64,Nothing}=nothing,
)
mts = message_tensors(tn; nvertices_per_partition, npartitions, subgraph_vertices)
return belief_propagation(tn, mts; contract_kwargs, niters, target_precision)
return belief_propagation(tn, mts; contract_kwargs, niters, target_precision, update_sequence)
end

"""
Expand Down
6 changes: 3 additions & 3 deletions src/beliefpropagation/sqrt_beliefpropagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function sqrt_belief_propagation(
tn::ITensorNetwork,
mts::DataGraph;
niters=20,
update_sequence::String="parallel",
update_sequence::String="sequential",
# target_precision::Union{Float64,Nothing}=nothing,
)
# compute_norm = target_precision == nothing ? false : true
Expand All @@ -27,8 +27,8 @@ end
function sqrt_belief_propagation_iteration(
tn::ITensorNetwork,
sqrt_mts::DataGraph;
update_sequence::String="parallel",
edges=Graphs.edges(sqrt_mts),
update_sequence::String="sequential",
edges=edge_update_order(undirected_graph(underlying_graph(mts))),

# compute_norm=false,
)
Expand Down
3 changes: 2 additions & 1 deletion src/gauging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ function vidal_gauge(
regularization=10 * eps(real(scalartype(ψ))),
niters=30,
target_canonicalness::Union{Nothing,Float64}=nothing,
update_sequence = "sequential",
svd_kwargs...,
)
ψψ = norm_network(ψ)
Z = partition(ψψ; subgraph_vertices=collect(values(group(v -> v[1], vertices(ψψ)))))
mts = message_tensors(Z)

mts = belief_propagation(
ψψ, mts; contract_kwargs=(; alg="exact"), niters, target_precision=target_canonicalness
ψψ, mts; contract_kwargs=(; alg="exact"), niters, target_precision=target_canonicalness, update_sequence
)
return vidal_gauge(
ψ, mts; eigen_message_tensor_cutoff, regularization, niters, svd_kwargs...
Expand Down
10 changes: 5 additions & 5 deletions test/test_belief_propagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ITensors.disable_warn_order()
ψψ, mts, [(v, 1)]; verts_tn=ITensorNetwork(ITensor[apply(op("Sz", s[v]), ψ[v])])
)
denominator_network = approx_network_region(ψψ, mts, [(v, 1)])
bp_sz = contract(numerator_network)[] / contract(denominator_network)[]
bp_sz = ITensors.contract(numerator_network)[] / ITensors.contract(denominator_network)[]

@test abs.(bp_sz - exact_sz) <= 1e-14

Expand Down Expand Up @@ -85,7 +85,7 @@ ITensors.disable_warn_order()
ψψ, mts, [(v, 1)]; verts_tn=ITensorNetwork(ITensor[apply(op("Sz", s[v]), ψ[v])])
)
denominator_network = approx_network_region(ψψ, mts, [(v, 1)])
bp_sz = contract(numerator_network)[] / contract(denominator_network)[]
bp_sz = ITensors.contract(numerator_network)[] / ITensors.contract(denominator_network)[]

@test abs.(bp_sz - exact_sz) <= 1e-14

Expand All @@ -112,7 +112,7 @@ ITensors.disable_warn_order()
)

denominator_network = approx_network_region(ψψ, mts, vs)
bp_szsz = contract(numerator_network)[] / contract(denominator_network)[]
bp_szsz = ITensors.contract(numerator_network)[] / ITensors.contract(denominator_network)[]

@test abs.(bp_szsz - actual_szsz) <= 0.05

Expand All @@ -134,7 +134,7 @@ ITensors.disable_warn_order()
mts = belief_propagation(ψψ, mts; contract_kwargs=(; alg="exact"))

ψψsplit = split_index(ψψ, NamedEdge.([(v, 1) => (v, 2) for v in vs]))
rdm = contract(
rdm = ITensors.contract(
approx_network_region(
ψψ,
mts,
Expand Down Expand Up @@ -183,7 +183,7 @@ ITensors.disable_warn_order()
numerator_network = approx_network_region(ψψ, mts, [v]; verts_tn=ITensorNetwork(ψOψ[v]))

denominator_network = approx_network_region(ψψ, mts, [v])
bp_sz = contract(numerator_network)[] / contract(denominator_network)[]
bp_sz = ITensors.contract(numerator_network)[] / ITensors.contract(denominator_network)[]

exact_sz =
contract_boundary_mps(ψOψ; cutoff=1e-16) / contract_boundary_mps(ψψ; cutoff=1e-16)
Expand Down
2 changes: 1 addition & 1 deletion test/test_gauging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using SplitApplyCombine
dims = (n, n)
g = named_grid(dims)
s = siteinds("S=1/2", g)
χ = 3
χ = 6

Random.seed!(5467)
ψ = randomITensorNetwork(s; link_space=χ)
Expand Down

0 comments on commit dfec1e2

Please sign in to comment.