-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathenvironment.jl
49 lines (42 loc) · 1.21 KB
/
environment.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using ITensors: contract
using NamedGraphs.PartitionedGraphs: PartitionedGraph
default_environment_algorithm() = "bp"
function environment(
tn::AbstractITensorNetwork,
vertices::Vector;
alg=default_environment_algorithm(),
kwargs...,
)
return environment(Algorithm(alg), tn, vertices; kwargs...)
end
function environment(
::Algorithm"exact", tn::AbstractITensorNetwork, verts::Vector; kwargs...
)
return [contract(subgraph(tn, setdiff(vertices(tn), verts)); kwargs...)]
end
function environment(
alg::Algorithm,
ptn::PartitionedGraph,
vertices::Vector;
(cache!)=nothing,
update_cache=isnothing(cache!),
cache_construction_kwargs=default_cache_construction_kwargs(alg, ptn),
cache_update_kwargs=default_cache_update_kwargs(alg),
)
if isnothing(cache!)
cache! = Ref(cache(alg, ptn; cache_construction_kwargs...))
end
if update_cache
cache![] = update(cache![]; cache_update_kwargs...)
end
return environment(cache![], vertices)
end
function environment(
alg::Algorithm,
tn::AbstractITensorNetwork,
vertices::Vector;
partitioned_vertices=default_partitioned_vertices(tn),
kwargs...,
)
return environment(alg, PartitionedGraph(tn, partitioned_vertices), vertices; kwargs...)
end