Skip to content

Commit 549cba1

Browse files
authored
Update sweep_contract.jl
1 parent ef076ee commit 549cba1

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

src/sweep_contract.jl

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,45 @@ function permutebetween(from, to)
7575
end
7676

7777
"""
78-
sweep_contract!(TN::TensorNetwork, χ, τ;
78+
sweep_contract(LTN::LabelledTensorNetwork, χ, τ;
7979
fast=false, valid=false, planar=false, connected=false, report=false)
80-
sweep_contract!(LTN::LabelledTensorNetwork, χ, τ;
80+
sweep_contract(TN::TensorNetwork, χ, τ;
8181
fast=false, valid=false, planar=false, connected=false, report=false)
82-
8382
Returns the contraction of the `TensorNetwork TN`, or the `LabelledTensorNetwork LTN` using
8483
the sweepline contraction algorithm of `arXiv:2101.04125`. The MPS is truncated down to a
8584
bond dimension of `χ` whenever any bond dimension exceeds `τ`.
86-
8785
By default the network is checked for validity, planarised, and sweep-connected, where
8886
necessary. The keyword flags `valid`, `planar`, and `connected` can be used to skip these,
8987
or the flag `fast` can be used to skip them all. If these flags are enabled then contraction
9088
may fail on poorly formed networks.
91-
9289
To avoid underflow/overflow issues the contraction value of the network is returned as a
9390
tuple `(f::Float64, i::Int64)` where `1≦f<2` or `f` is `0`, representing a value of `f*2^i`.
9491
The function `ldexp` can be used to convert this back to a Float64.
92+
`sweep_contract` is non-mutating and acts upon a deep copy of the network, where possible
93+
use the more efficient mutating version `sweep_contract!`.
94+
"""
95+
sweep_contract(LTN::LabelledTensorNetwork, χ::Int, τ::Int;
96+
fast=false, valid=false, planar=false, connected=false, report=false) =
97+
sweep_contract!(deepcopy(LTN), χ, τ;
98+
fast=fast, planar=planar, connected=connected, report=report)
99+
100+
sweep_contract(TN::TensorNetwork, χ::Int, τ::Int;
101+
fast=false, valid=false, planar=false, connected=false, report=false) =
102+
sweep_contract!(deepcopy(TN), χ, τ;
103+
fast=fast, planar=planar, connected=connected, report=report)
104+
95105
"""
106+
sweep_contract!(LTN::LabelledTensorNetwork, χ, τ;
107+
fast=false, valid=false, planar=false, connected=false, report=false)
108+
sweep_contract!(TN::TensorNetwork, χ, τ;
109+
fast=false, valid=false, planar=false, connected=false, report=false)
110+
The mutating form of `sweep_contract`.
111+
"""
112+
sweep_contract!(LTN::LabelledTensorNetwork, χ::Int, τ::Int;
113+
fast=false, valid=false, planar=false, connected=false, report=false) =
114+
sweep_contract!(delabel(LTN), χ, τ;
115+
fast=fast, planar=planar, connected=connected, report=report)
116+
96117
function sweep_contract!(TN::TensorNetwork, χ::Int, τ::Int;
97118
fast=false,valid=false,planar=false,connected=false,report=false)::Tuple{Float64,Int}
98119
if !fast
@@ -198,27 +219,3 @@ function sweep_contract!(TN::TensorNetwork, χ::Int, τ::Int;
198219
h = Int(floor(log2(abs(res))));
199220
return (res/exp2(h),resexp+h);
200221
end
201-
202-
sweep_contract!(
203-
LTN::LabelledTensorNetwork, χ::Int, τ::Int;
204-
fast=false, valid=false, planar=false, connected=false, report=false
205-
) = sweep_contract!(
206-
delabel(LTN), χ, τ;
207-
fast=fast, planar=planar, connected=connected, report=report
208-
)
209-
210-
sweep_contract(
211-
TN::TensorNetwork, χ::Int, τ::Int;
212-
fast=false, valid=false, planar=false, connected=false, report=false
213-
) = sweep_contract!(
214-
deepcopy(TN), χ, τ;
215-
fast=fast, planar=planar, connected=connected, report=report
216-
)
217-
218-
sweep_contract(
219-
LTN::LabelledTensorNetwork, χ::Int, τ::Int;
220-
fast=false, valid=false, planar=false, connected=false, report=false
221-
) = sweep_contract!(
222-
deepcopy(LTN), χ, τ;
223-
fast=fast, planar=planar, connected=connected, report=report
224-
)

0 commit comments

Comments
 (0)