7171∂∂AC (pos:: CartesianIndex , mps, operator, envs) = ∂∂AC (Tuple (pos)... , mps, operator, envs)
7272∂∂AC2 (pos:: CartesianIndex , mps, operator, envs) = ∂∂AC2 (Tuple (pos)... , mps, operator, envs)
7373
74- """
75- One-site derivative
76- """
77-
78- # function ∂AC(x::MPSTensor, H::SparseMPOSlice, leftenv, rightenv)::typeof(x)
79- # local y
80- # @static if Defaults.parallelize_derivatives
81- # @floop WorkStealingEx() for (i, j) in keys(H)
82- # t = ∂AC(x, H.Os[i, j], leftenv[i], rightenv[j])
83- # @reduce(y = inplace_add!(nothing, t))
84- # end
85- # else
86- # els = collect(keys(H))
87- # y = ∂AC(x, H.Os[els[1]...], leftenv[els[1][1]], rightenv[els[1][2]])
88- # for (i, j) in els[2:end]
89- # add!(y, ∂AC(x, H.Os[i, j], leftenv[i], rightenv[j]))
90- # end
91- # end
92- #
93- # return y
94- # end
95-
9674function ∂AC (x:: MPSTensor{S} , operator:: MPOTensor{S} , leftenv:: MPSTensor{S} ,
9775 rightenv:: MPSTensor{S} ):: typeof (x) where {S}
9876 @plansor y[- 1 - 2 ; - 3 ] := leftenv[- 1 5 ; 4 ] * x[4 2 ; 1 ] * operator[5 - 2 ; 2 3 ] *
@@ -114,45 +92,6 @@ function ∂AC(x::MPSTensor, ::Nothing, leftenv, rightenv)
11492 return _transpose_front (leftenv * _transpose_tail (x * rightenv))
11593end
11694
117- """
118- Two-site derivative
119- """
120- # function ∂AC2(x::MPOTensor, h1::SparseMPOSlice, h2::SparseMPOSlice, leftenv,
121- # rightenv)::typeof(x)
122- # local toret
123- #
124- # tl = tensormaptype(spacetype(x), 2, 3, storagetype(x))
125- # hl = Vector{Union{Nothing,tl}}(undef, h1.odim)
126- # @threads for j in 1:(h1.odim)
127- # @floop WorkStealingEx() for i in keys(h1, :, j)
128- # if isscal(h1, i, j)
129- # @plansor t[-1 -2; -3 -4 -5] := (h1.Os[i, j] * leftenv[i])[-1 1; 2] *
130- # τ[1 -2; 3 -5] * x[2 3; -3 -4]
131- # else
132- # @plansor t[-1 -2; -3 -4 -5] := leftenv[i][-1 1; 2] * h1[i, j][1 -2; 3 -5] *
133- # x[2 3; -3 -4]
134- # end
135- # @reduce(curel = inplace_add!(nothing, t))
136- # end
137- # hl[j] = curel
138- # end
139- #
140- # @floop WorkStealingEx() for (j, k) in keys(h2)
141- # isnothing(hl[j]) && continue
142- #
143- # if isscal(h2, j, k)
144- # @plansor t[-1 -2; -3 -4] := (h2.Os[j, k] * hl[j])[-1 -2; 5 3 4] * τ[4 -4; 3 6] *
145- # rightenv[k][5 6; -3]
146- # else
147- # @plansor t[-1 -2; -3 -4] := hl[j][-1 -2; 5 3 4] * h2[j, k][4 -4; 3 6] *
148- # rightenv[k][5 6; -3]
149- # end
150- #
151- # @reduce(toret = inplace_add!(nothing, t))
152- # end
153- #
154- # return toret
155- # end
15695function ∂AC2 (x:: MPOTensor , operator1:: MPOTensor , operator2:: MPOTensor , leftenv, rightenv)
15796 @plansor toret[- 1 - 2 ; - 3 - 4 ] := leftenv[- 1 7 ; 6 ] * x[6 5 ; 1 3 ] * operator1[7 - 2 ; 5 4 ] *
15897 operator2[4 - 4 ; 3 2 ] * rightenv[1 2 ; - 3 ]
0 commit comments