diff --git a/Project.toml b/Project.toml index 9751d890..cffc9c1a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PEPSKit" uuid = "52969e89-939e-4361-9b68-9bc7cde4bdeb" -authors = ["Maarten Vandamme", "Paul Brehmer", "Lander Burgelman", "Rui-Zhen Huang", "Daan Maertens", "Lukas Devos "] +version = "0.3.0" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" @@ -40,7 +40,7 @@ Random = "1" Statistics = "1" TensorKit = "0.12.5" TensorOperations = "4" -VectorInterface = "0.4" +VectorInterface = "0.4, 0.5" Zygote = "0.6" julia = "1.10" diff --git a/src/algorithms/contractions/localoperator.jl b/src/algorithms/contractions/localoperator.jl index fef30e20..324bb028 100644 --- a/src/algorithms/contractions/localoperator.jl +++ b/src/algorithms/contractions/localoperator.jl @@ -237,9 +237,10 @@ end end end - return quote + returnex = quote @tensor opt = $opt_ex $multiplication_ex end + return macroexpand(@__MODULE__, returnex) end """ @@ -445,7 +446,8 @@ end end end - return quote + returnex = quote @tensor opt = $opt_ex $multiplication_ex end + return macroexpand(@__MODULE__, returnex) end diff --git a/src/algorithms/peps_opt.jl b/src/algorithms/peps_opt.jl index b84467da..39e138a1 100644 --- a/src/algorithms/peps_opt.jl +++ b/src/algorithms/peps_opt.jl @@ -142,13 +142,13 @@ The function returns a `NamedTuple` which contains the following entries: - `numfg`: total number of calls to the energy function """ function fixedpoint( - ψ₀::InfinitePEPS{T}, + ψ₀::InfinitePEPS{F}, H, alg::PEPSOptimize, - env₀::CTMRGEnv=CTMRGEnv(ψ₀, field(T)^20); + env₀::CTMRGEnv=CTMRGEnv(ψ₀, field(F)^20); (finalize!)=OptimKit._finalize!, symmetrization=nothing, -) where {T} +) where {F} if isnothing(symmetrization) retract = peps_retract else @@ -157,6 +157,13 @@ function fixedpoint( finalize! = (x, f, g, numiter) -> fin!(symm_finalize!(x, f, g, numiter)..., numiter) end + if scalartype(env₀) <: Real + env₀ = complex(env₀) + @warn "the provided real environment was converted to a complex environment since\ + :fixed mode generally produces complex gauges; use :diffgauge mode instead to work\ + with purely real environments" + end + (peps, env), E, ∂E, numfg, convhistory = optimize( (ψ₀, env₀), alg.optimizer; retract, inner=real_inner, finalize! ) do (peps, envs) diff --git a/src/environments/ctmrg_environments.jl b/src/environments/ctmrg_environments.jl index 460faf5b..c026762b 100644 --- a/src/environments/ctmrg_environments.jl +++ b/src/environments/ctmrg_environments.jl @@ -380,6 +380,9 @@ function eachcoordinate(x::CTMRGEnv, dirs) return collect(Iterators.product(dirs, axes(x, 2), axes(x, 3))) end +Base.real(env::CTMRGEnv) = CTMRGEnv(real.(env.corners), real.(env.edges)) +Base.complex(env::CTMRGEnv) = CTMRGEnv(complex.(env.corners), complex.(env.edges)) + # In-place update of environment function update!(env::CTMRGEnv{C,T}, env´::CTMRGEnv{C,T}) where {C,T} env.corners .= env´.corners diff --git a/src/operators/derivatives.jl b/src/operators/derivatives.jl index 36c0d149..dd025411 100644 --- a/src/operators/derivatives.jl +++ b/src/operators/derivatives.jl @@ -48,11 +48,9 @@ end (H::PEPS_∂∂C)(x) = MPSKit.∂C(x, H.GL, H.GR) (H::PEPS_∂∂AC)(x) = MPSKit.∂AC(x, (H.top, H.bot), H.GL, H.GR) -function MPSKit.∂AC(x::RecursiveVec, O::Tuple, GL, GR) - return RecursiveVec( - circshift( - map((v, O1, O2, l, r) -> ∂AC(v, (O1, O2), l, r), x.vecs, O[1], O[2], GL, GR), 1 - ), +function MPSKit.∂AC(x::Vector, O::Tuple, GL, GR) + return circshift( + map((v, O1, O2, l, r) -> ∂AC(v, (O1, O2), l, r), x, O[1], O[2], GL, GR), 1 ) end @@ -203,20 +201,12 @@ end (H::PEPO_∂∂C)(x) = MPSKit.∂C(x, H.GL, H.GR) (H::PEPO_∂∂AC)(x) = MPSKit.∂AC(x, (H.top, H.bot, H.mid), H.GL, H.GR) -function MPSKit.∂AC(x::RecursiveVec, O::Tuple{T,T,P}, GL, GR) where {T,P} - return RecursiveVec( - circshift( - map( - (v, O1, O2, O3, l, r) -> ∂AC(v, (O1, O2, O3), l, r), - x.vecs, - O[1], - O[2], - O[3], - GL, - GR, - ), - 1, +function MPSKit.∂AC(x::Vector, O::Tuple{T,T,P}, GL, GR) where {T,P} + return circshift( + map( + (v, O1, O2, O3, l, r) -> ∂AC(v, (O1, O2, O3), l, r), x, O[1], O[2], O[3], GL, GR ), + 1, ) end