Skip to content

Commit 424f036

Browse files
committed
Merge branch 'fix-example-caching' of github.com:quantumghent/PEPSKit.jl into fix-example-caching
2 parents 0b9f7ff + 4e86dd9 commit 424f036

File tree

6 files changed

+37
-18
lines changed

6 files changed

+37
-18
lines changed

src/PEPSKit.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using LinearAlgebra, Statistics, Base.Threads, Base.Iterators, Printf
44
using Compat
55
using Accessors: @set, @reset
66
using VectorInterface
7+
import VectorInterface as VI
78
using TensorKit, KrylovKit, OptimKit, TensorOperations
89
using ChainRulesCore, Zygote
910
using LoggingExtras

src/environments/ctmrg_environments.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,6 @@ end
488488
# big vector. In other words, the associated vector space is not the natural one associated
489489
# to the original (physical) system, and addition, scaling, etc. are performed element-wise.
490490

491-
import VectorInterface as VI
492-
493491
function VI.scalartype(::Type{CTMRGEnv{C,T}}) where {C,T}
494492
S₁ = scalartype(C)
495493
S₂ = scalartype(T)

src/operators/infinitepepo.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,8 @@ end
177177

178178
## Vector interface
179179

180-
function VectorInterface.scalartype(::Type{NT}) where {NT<:InfinitePEPO}
181-
return scalartype(eltype(NT))
182-
end
183-
function VectorInterface.zerovector(A::InfinitePEPO)
184-
return InfinitePEPO(zerovector(unitcell(A)))
185-
end
180+
VI.scalartype(::Type{NT}) where {NT<:InfinitePEPO} = scalartype(eltype(NT))
181+
VI.zerovector(A::InfinitePEPO) = InfinitePEPO(zerovector(unitcell(A)))
186182

187183
## (Approximate) equality
188184
function Base.:(==)(A₁::InfinitePEPO, A₂::InfinitePEPO)

src/states/infinitepartitionfunction.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,9 @@ end
157157

158158
## Vector interface
159159

160-
function VectorInterface.scalartype(::Type{NT}) where {NT<:InfinitePartitionFunction}
161-
return scalartype(eltype(NT))
162-
end
163-
function VectorInterface.zerovector(A::InfinitePartitionFunction)
164-
return InfinitePartitionFunction(zerovector(unitcell(A)))
160+
VI.scalartype(::Type{NT}) where {NT<:InfinitePartitionFunction} = scalartype(eltype(NT))
161+
function VI.zerovector(A::InfinitePartitionFunction)
162+
InfinitePartitionFunction(zerovector(unitcell(A)))
165163
end
166164

167165
## (Approximate) equality

src/states/infinitepeps.jl

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,36 @@ end
157157

158158
## Vector interface
159159

160-
function VectorInterface.scalartype(::Type{NT}) where {NT<:InfinitePEPS}
161-
return scalartype(eltype(NT))
160+
VI.scalartype(::Type{NT}) where {NT<:InfinitePEPS} = scalartype(eltype(NT))
161+
VI.zerovector(A::InfinitePEPS) = InfinitePEPS(zerovector(unitcell(A)))
162+
163+
function VI.scale::InfinitePEPS, α::Number)
164+
_scale = Base.Fix2(scale, α)
165+
return InfinitePEPS(map(_scale, unitcell(ψ)))
166+
end
167+
function VI.scale!::InfinitePEPS, α::Number)
168+
_scale! = Base.Fix2(scale!, α)
169+
foreach(_scale!, unitcell(ψ))
170+
return ψ
171+
end
172+
function VI.scale!(ψ₁::InfinitePEPS, ψ₂::InfinitePEPS, α::Number)
173+
_scale!(x, y) = scale!(x, y, α)
174+
foreach(_scale!, unitcell(ψ₁), unitcell(ψ₂))
175+
return ψ₁
176+
end
177+
VI.scale!!::InfinitePEPS, α::Number) = scale!(ψ, α)
178+
VI.scale!!(ψ₁::InfinitePEPS, ψ₂::InfinitePEPS, α::Number) = scale!(ψ₁, ψ₂, α)
179+
180+
function VI.add(ψ₁::InfinitePEPS, ψ₂::InfinitePEPS, α::Number, β::Number)
181+
_add(x, y) = add(x, y, α, β)
182+
return InfinitePEPS(map(_add, unitcell(ψ₁), unitcell(ψ₂)))
183+
end
184+
function VI.add!(ψ₁::InfinitePEPS, ψ₂::InfinitePEPS, α::Number, β::Number)
185+
_add!(x, y) = add!(x, y, α, β)
186+
foreach(_add!, unitcell(ψ₁), unitcell(ψ₂))
187+
return ψ₁
162188
end
163-
VectorInterface.zerovector(A::InfinitePEPS) = InfinitePEPS(zerovector(unitcell(A)))
189+
VI.add!!(ψ₁::InfinitePEPS, ψ₂::InfinitePEPS, α::Number, β::Number) = add!(ψ₁, ψ₂, α, β)
164190

165191
## Math
166192

@@ -194,7 +220,7 @@ Base.rotl90(A::InfinitePEPS) = InfinitePEPS(rotl90(rotl90.(unitcell(A))))
194220
Base.rotr90(A::InfinitePEPS) = InfinitePEPS(rotr90(rotr90.(unitcell(A))))
195221
Base.rot180(A::InfinitePEPS) = InfinitePEPS(rot180(rot180.(unitcell(A))))
196222

197-
## OptimKit optimization compatibility
223+
## OptimKit optimization backwards compatibility (v0.4 uses VectorInterface)
198224

199225
function LinearAlgebra.rmul!(A::InfinitePEPS, α::Number) # Used in _scale during OptimKit.optimize
200226
rmul!.(unitcell(A), α)

src/states/infiniteweightpeps.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Base.size(W::SUWeight, i) = size(W.data, i)
5858
Base.length(W::SUWeight) = length(W.data)
5959
Base.eltype(W::SUWeight) = eltype(typeof(W))
6060
Base.eltype(::Type{SUWeight{E}}) where {E} = E
61-
VectorInterface.scalartype(::Type{T}) where {T<:SUWeight} = scalartype(eltype(T))
61+
VI.scalartype(::Type{T}) where {T<:SUWeight} = scalartype(eltype(T))
6262

6363
Base.getindex(W::SUWeight, args...) = Base.getindex(W.data, args...)
6464
Base.setindex!(W::SUWeight, args...) = (Base.setindex!(W.data, args...); W)

0 commit comments

Comments
 (0)