Skip to content

Commit 864af2a

Browse files
committed
format operators
1 parent c24dbb2 commit 864af2a

File tree

6 files changed

+317
-267
lines changed

6 files changed

+317
-267
lines changed

src/operators/abstractmpo.jl

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Abstract supertype for Matrix Product Operators (MPOs).
88
abstract type AbstractMPO{O} <: AbstractVector{O} end
99

1010
# useful union types
11-
const SparseMPO{O<:SparseBlockTensorMap} = AbstractMPO{O}
11+
const SparseMPO{O <: SparseBlockTensorMap} = AbstractMPO{O}
1212
Base.isfinite(O::AbstractMPO) = isfinite(typeof(O))
1313

1414
# By default, define things in terms of parent
@@ -32,13 +32,13 @@ physicalspace(mpo::AbstractMPO) = map(physicalspace, mpo)
3232

3333
for ftype in (:spacetype, :sectortype, :storagetype)
3434
@eval TensorKit.$ftype(mpo::AbstractMPO) = $ftype(typeof(mpo))
35-
@eval TensorKit.$ftype(::Type{MPO}) where {MPO<:AbstractMPO} = $ftype(eltype(MPO))
35+
@eval TensorKit.$ftype(::Type{MPO}) where {MPO <: AbstractMPO} = $ftype(eltype(MPO))
3636
end
3737

3838
# Utility functions
3939
# -----------------
40-
remove_orphans!(mpo::AbstractMPO; tol=eps(real(scalartype(mpo)))^(3 / 4)) = mpo
41-
function remove_orphans!(mpo::SparseMPO; tol=eps(real(scalartype(mpo)))^(3 / 4))
40+
remove_orphans!(mpo::AbstractMPO; tol = eps(real(scalartype(mpo)))^(3 / 4)) = mpo
41+
function remove_orphans!(mpo::SparseMPO; tol = eps(real(scalartype(mpo)))^(3 / 4))
4242
droptol!.(mpo, tol)
4343

4444
if isfinite(mpo)
@@ -70,7 +70,7 @@ function remove_orphans!(mpo::SparseMPO; tol=eps(real(scalartype(mpo)))^(3 / 4))
7070
# slice empty columns on right or empty rows on left
7171
mask = filter(1:size(mpo[i], 4)) do j
7272
return j getindex.(nonzero_keys(mpo[i]), 4) &&
73-
j getindex.(nonzero_keys(mpo[i + 1]), 1)
73+
j getindex.(nonzero_keys(mpo[i + 1]), 1)
7474
end
7575
changed |= length(mask) == size(mpo[i], 4)
7676
mpo[i] = mpo[i][:, :, :, mask]
@@ -130,20 +130,14 @@ function _fuse_mpo_mpo(O1::MPOTensor, O2::MPOTensor, Fₗ, Fᵣ)
130130
physicalspace(O2) fuse(right_virtualspace(O2) right_virtualspace(O1))
131131
return BraidingTensor{T}(V)
132132
elseif O1 isa BraidingTensor
133-
@plansor O′[-1 -2; -3 -4] := Fₗ[-1; 1 2] *
134-
O2[1 3; -3 5] *
135-
τ[2 -2; 3 4] *
136-
conj(Fᵣ[-4; 5 4])
133+
@plansor O′[-1 -2; -3 -4] := Fₗ[-1; 1 2] * O2[1 3; -3 5] *
134+
τ[2 -2; 3 4] * conj(Fᵣ[-4; 5 4])
137135
elseif O2 isa BraidingTensor
138-
@plansor O′[-1 -2; -3 -4] := Fₗ[-1; 1 2] *
139-
τ[1 3; -3 5] *
140-
O1[2 -2; 3 4] *
141-
conj(Fᵣ[-4; 5 4])
136+
@plansor O′[-1 -2; -3 -4] := Fₗ[-1; 1 2] * τ[1 3; -3 5] *
137+
O1[2 -2; 3 4] * conj(Fᵣ[-4; 5 4])
142138
else
143-
@plansor O′[-1 -2; -3 -4] := Fₗ[-1; 1 2] *
144-
O2[1 3; -3 5] *
145-
O1[2 -2; 3 4] *
146-
conj(Fᵣ[-4; 5 4])
139+
@plansor O′[-1 -2; -3 -4] := Fₗ[-1; 1 2] * O2[1 3; -3 5] *
140+
O1[2 -2; 3 4] * conj(Fᵣ[-4; 5 4])
147141
end
148142
end
149143

@@ -164,8 +158,9 @@ function fuse_mul_mpo(O1::BraidingTensor, O2::BraidingTensor)
164158
physicalspace(O2) fuse(right_virtualspace(O2) right_virtualspace(O1))
165159
return BraidingTensor{T}(V)
166160
end
167-
function fuse_mul_mpo(O1::AbstractBlockTensorMap{T₁,S,2,2},
168-
O2::AbstractBlockTensorMap{T₂,S,2,2}) where {T₁,T₂,S}
161+
function fuse_mul_mpo(
162+
O1::AbstractBlockTensorMap{T₁, S, 2, 2}, O2::AbstractBlockTensorMap{T₂, S, 2, 2}
163+
) where {T₁, T₂, S}
169164
TT = promote_type((eltype(O1)), eltype((O2)))
170165
V = fuse(left_virtualspace(O2) left_virtualspace(O1)) physicalspace(O1)
171166
physicalspace(O2) fuse(right_virtualspace(O2) right_virtualspace(O1))
@@ -174,10 +169,10 @@ function fuse_mul_mpo(O1::AbstractBlockTensorMap{T₁,S,2,2},
174169
else
175170
O = BlockTensorMap{TT}(undef, V)
176171
end
177-
cartesian_inds = reshape(CartesianIndices(O),
178-
size(O2, 1), size(O1, 1),
179-
size(O, 2), size(O, 3),
180-
size(O2, 4), size(O1, 4))
172+
cartesian_inds = reshape(
173+
CartesianIndices(O),
174+
size(O2, 1), size(O1, 1), size(O, 2), size(O, 3), size(O2, 4), size(O1, 4)
175+
)
181176
for (I, o2) in nonzero_pairs(O2), (J, o1) in nonzero_pairs(O1)
182177
K = cartesian_inds[I[1], J[1], I[2], I[3], I[4], J[4]]
183178
O[K] = fuse_mul_mpo(o1, o2)
@@ -190,8 +185,7 @@ function add_physical_charge(O::MPOTensor, charge::Sector)
190185
auxspace = Vect[typeof(charge)](charge => 1)'
191186
F = fuser(scalartype(O), physicalspace(O), auxspace)
192187
@plansor O_charged[-1 -2; -3 -4] := F[-2; 1 2] *
193-
O[-1 1; 4 3] *
194-
τ[3 2; 5 -4] * conj(F[-3; 4 5])
188+
O[-1 1; 4 3] * τ[3 2; 5 -4] * conj(F[-3; 4 5])
195189
return O_charged
196190
end
197191
function add_physical_charge(O::BraidingTensor, charge::Sector)
@@ -201,12 +195,14 @@ function add_physical_charge(O::BraidingTensor, charge::Sector)
201195
fuse(physicalspace(O), auxspace) right_virtualspace(O)
202196
return BraidingTensor{scalartype(O)}(V)
203197
end
204-
function add_physical_charge(O::AbstractBlockTensorMap{<:Any,<:Any,2,2}, charge::Sector)
198+
function add_physical_charge(O::AbstractBlockTensorMap{<:Any, <:Any, 2, 2}, charge::Sector)
205199
sectortype(O) == typeof(charge) || throw(SectorMismatch())
206200
auxspace = Vect[typeof(charge)](charge => 1)'
207-
Odst = similar(O,
208-
left_virtualspace(O) fuse(physicalspace(O), auxspace)
209-
fuse(physicalspace(O), auxspace) right_virtualspace(O))
201+
Odst = similar(
202+
O,
203+
left_virtualspace(O) fuse(physicalspace(O), auxspace)
204+
fuse(physicalspace(O), auxspace) right_virtualspace(O)
205+
)
210206
for (I, v) in nonzero_pairs(O)
211207
Odst[I] = add_physical_charge(v, charge)
212208
end
@@ -216,9 +212,11 @@ end
216212
# Contractions
217213
# ------------
218214
# This function usually does not require to be specified for many N, so @generated function is fine?
219-
@generated function _instantiate_finitempo(L::AbstractTensorMap{<:Any,S,1,2},
220-
O::NTuple{N,MPOTensor{S}},
221-
R::AbstractTensorMap{<:Any,S,2,1}) where {N,S}
215+
@generated function _instantiate_finitempo(
216+
L::AbstractTensorMap{<:Any, S, 1, 2},
217+
O::NTuple{N, MPOTensor{S}},
218+
R::AbstractTensorMap{<:Any, S, 2, 1}
219+
) where {N, S}
222220
sites = N + 2
223221
t_out = tensorexpr(:T, -(1:sites), -(1:sites) .- sites)
224222
t_left = tensorexpr(:L, -1, (-1 - sites, 1))
@@ -230,10 +228,12 @@ end
230228
return macroexpand(@__MODULE__, ex)
231229
end
232230

233-
@generated function _apply_finitempo(x::AbstractTensorMap{<:Any,S,M,A},
234-
L::AbstractTensorMap{<:Any,S,1,2},
235-
O::NTuple{N,MPOTensor{S}},
236-
R::AbstractTensorMap{<:Any,S,2,1}) where {N,M,S,A}
231+
@generated function _apply_finitempo(
232+
x::AbstractTensorMap{<:Any, S, M, A},
233+
L::AbstractTensorMap{<:Any, S, 1, 2},
234+
O::NTuple{N, MPOTensor{S}},
235+
R::AbstractTensorMap{<:Any, S, 2, 1}
236+
) where {N, M, S, A}
237237
M == N + 2 || throw(ArgumentError("Incompatible number of spaces"))
238238
t_out = tensorexpr(:y, -(1:M), -(1:A) .- M)
239239
t_in = tensorexpr(:x, 1:2:(2M - 1), -(1:A) .- M)

0 commit comments

Comments
 (0)