Skip to content
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
Expand Up @@ -3,7 +3,7 @@ uuid = "4de3b72a-362e-43dd-83ff-3f381eda9f9c"
authors = ["JoeyT1994 <jtindall@flatironinstitute.org>", "MSRudolph <manuel.rudolph@web.de>","and contributors"]
description = "A Julia package for simulating quantum circuits and dynamics with tensor networks of near-arbritrary topology."
license = "MIT"
version = "0.1.03"
version = "0.1.04"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
6 changes: 3 additions & 3 deletions src/Backend/abstractbeliefpropagationcache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,12 @@ end
"""
Do a sequential update of the message tensors on `edges`
"""
function update_iteration(
function update_iteration!(
alg::Algorithm"bp",
bpc::AbstractBeliefPropagationCache,
edges::Vector;
(update_diff!) = nothing,
)
bpc = copy(bpc)
for e in edges
prev_message = !isnothing(update_diff!) ? message(bpc, e) : nothing
update_message!(alg.kwargs.message_update_alg, bpc, e)
Expand All @@ -187,9 +186,10 @@ function update(alg::Algorithm"bp", bpc::AbstractBeliefPropagationCache)
if isnothing(alg.kwargs.maxiter)
error("You need to specify a number of iterations for BP!")
end
bpc = copy(bpc)
for i in 1:alg.kwargs.maxiter
diff = compute_error ? Ref(0.0) : nothing
bpc = update_iteration(alg, bpc, alg.kwargs.edge_sequence; (update_diff!) = diff)
update_iteration!(alg, bpc, alg.kwargs.edge_sequence; (update_diff!) = diff)
if compute_error && (diff.x / length(alg.kwargs.edge_sequence)) <= alg.kwargs.tolerance
if alg.kwargs.verbose
println("BP converged to desired precision after $i iterations.")
Expand Down
3 changes: 2 additions & 1 deletion src/Backend/beliefpropagationcache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ end

#TODO: Take `dot` without precontracting the messages to allow scaling to more complex messages
function message_diff(message_a::ITensor, message_b::ITensor)
f = abs2(dot((message_a / norm(message_a)), (message_b / norm(message_b))))
n_a, n_b = norm(message_a), norm(message_b)
f = abs2(dot(message_a, message_b) / (n_a * n_b))
return 1 - f
end

Expand Down
9 changes: 4 additions & 5 deletions src/expect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,20 @@ function expect(
iszero(coeff) && return 0

#For boundary MPS, must stay in partition
if length(obs_vs) == 1
steiner_vs = obs_vs
elseif alg == Algorithm("bp")
steiner_vs = collect(vertices(steiner_tree(network(cache), obs_vs)))
if alg == Algorithm("bp")
steiner_vs = length(obs_vs) == 1 ? obs_vs : collect(vertices(steiner_tree(network(cache), obs_vs)))
elseif alg == Algorithm("boundarymps")
partitions = unique(partitionvertices(cache, obs_vs))
length(partitions) > 1 && error("Observable support must be within a single partition (row/ column) of the graph for now.")
partition = only(partitions)
g = partition_graph(cache, partition)
steiner_vs = collect(vertices(steiner_tree(g, obs_vs)))
steiner_vs = length(obs_vs) == 1 ? obs_vs : collect(vertices(steiner_tree(g, obs_vs)))

if !bmps_messages_up_to_date
cache = update_partition(cache, partition)
end
end

op_string_f = v -> v ∈ obs_vs ? op_strings[findfirst(x -> x == v, obs_vs)] : "I"

#TODO: If there are a lot of tensors here, (more than 100 say), we need to think about defining a custom sequence as optimal may be too slow
Expand Down
7 changes: 2 additions & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ function is_line_graph(g::AbstractGraph)
end

function is_ring_graph(g::AbstractGraph)
isempty(edges(g)) && return false
g_mod = rem_edge(g, first(edges(g)))
return is_line_graph(g_mod)
end

function no_inds_per_site(sinds::Dictionary)
return only(unique(length.(collect(values(sinds)))))
end

function pseudo_sqrt_inv_sqrt(M::ITensor; cutoff = 10 * eps(real(scalartype(M))))
@assert length(inds(M)) == 2
Q, D, Qdag = ITensorNetworks.ITensorsExtensions.eigendecomp(M, inds(M)[1], inds(M)[2]; ishermitian = true)
Expand Down Expand Up @@ -66,4 +63,4 @@ end

default_alg(bp_cache::BeliefPropagationCache) = "bp"
default_alg(bmps_cache::BoundaryMPSCache) = "boundarymps"
default_alg(any) = error("You must specify a contraction algorithm. Currently supported: exact, bp and boundarymps.")
default_alg(any) = error("You must specify a contraction algorithm. Currently supported: exact, bp and boundarymps.")