Skip to content

Commit 20b6fd5

Browse files
authored
Merge pull request #39 from JoeyT1994/speed_up_expect
Speed up expect
2 parents 156c863 + 2fa3c16 commit 20b6fd5

File tree

5 files changed

+9
-29
lines changed

5 files changed

+9
-29
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "4de3b72a-362e-43dd-83ff-3f381eda9f9c"
33
authors = ["JoeyT1994 <jtindall@flatironinstitute.org>", "MSRudolph <manuel.rudolph@web.de>","and contributors"]
44
description = "A Julia package for simulating quantum circuits and dynamics with tensor networks of near-arbritrary topology."
55
license = "MIT"
6-
version = "0.1.02"
6+
version = "0.1.03"
77

88
[deps]
99
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/Backend/abstractbeliefpropagationcache.jl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,6 @@ function update_iteration(
179179
return bpc
180180
end
181181

182-
"""
183-
Do parallel updates between groups of edges of all message tensors
184-
Currently we send the full message tensor data struct to update for each edge_group. But really we only need the
185-
mts relevant to that group.
186-
"""
187-
function update_iteration(
188-
alg::Algorithm"bp",
189-
bpc::AbstractBeliefPropagationCache,
190-
edge_groups::Vector{<:Vector{<:AbstractEdge}};
191-
(update_diff!) = nothing,
192-
)
193-
new_mts = empty(messages(bpc))
194-
for edges in edge_groups
195-
bpc_t = update_iteration(alg.kwargs.message_update_alg, bpc, edges; (update_diff!))
196-
for e in edges
197-
set!(new_mts, e, message(bpc_t, e))
198-
end
199-
end
200-
return set_messages(bpc, new_mts)
201-
end
202-
203182
"""
204183
More generic interface for update, with default params
205184
"""

src/expect.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ function expect(
8282
end
8383
op_string_f = v -> v obs_vs ? op_strings[findfirst(x -> x == v, obs_vs)] : "I"
8484

85+
#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
8586
incoming_ms = incoming_messages(cache, steiner_vs)
8687
ψIψ_tensors = ITensor[norm_factors(network(cache), steiner_vs); incoming_ms]
87-
denom_seq = contraction_sequence(ψIψ_tensors; alg = "einexpr", optimizer = Greedy())
88+
denom_seq = contraction_sequence(ψIψ_tensors; alg = "optimal")
8889
denom = contract(ψIψ_tensors; sequence = denom_seq)[]
8990

9091
ψOψ_tensors = ITensor[norm_factors(network(cache), steiner_vs; op_strings = op_string_f); incoming_ms]
91-
numer_seq = contraction_sequence(ψOψ_tensors; alg = "einexpr", optimizer = Greedy())
92+
numer_seq = contraction_sequence(ψOψ_tensors; alg = "optimal")
9293
numer = contract(ψOψ_tensors; sequence = numer_seq)[]
9394

9495
return coeff * numer / denom

src/symmetric_gauge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,6 @@ end
136136
- The truncated `tns::TensorNetworkState`.
137137
"""
138138
function ITensors.truncate(tns::TensorNetworkState, args...; alg, kwargs...)
139-
algorithm_check(tns, alg)
139+
algorithm_check(tns, "truncate", alg)
140140
return truncate(Algorithm(alg), tns, args...; kwargs...)
141141
end

src/utils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ function algorithm_check(tns::Union{AbstractBeliefPropagationCache, TensorNetwor
4343
return error("Expected BeliefPropagationCache or TensorNetworkState for 'loop correctiom' algorithm, got $(typeof(tns))")
4444
end
4545

46-
if f ["normalize", "expect", "entanglement", "sample"]
46+
if f ["normalize", "expect", "entanglement", "sample", "truncate"]
4747
return error("Loop correction-based contraction not supported for this functionality yet")
4848
end
4949
elseif alg == "boundarymps"
5050
if !((tns isa BoundaryMPSCache) || (tns isa TensorNetworkState))
5151
return error("Expected BoundaryMPSCache or TensorNetworkState for 'boundarymps' algorithm, got $(typeof(tns))")
5252
end
53-
if f ["normalize", "entanglement"]
53+
if f ["normalize", "entanglement", "truncate"]
5454
return error("boundarymps contraction not supported for this functionality yet")
5555
end
5656
elseif alg == "exact"
57-
if f ["normalize", "entanglement", "sample"]
57+
if f ["normalize", "entanglement", "sample", "truncate"]
5858
return error("exact contraction not supported for this functionality yet")
5959
end
6060
elseif alg ["exact", "bp", "loopcorrections", "boundarymps"]
@@ -66,4 +66,4 @@ end
6666

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

0 commit comments

Comments
 (0)