From 10821427b0906f8a940c79006ba074e185482000 Mon Sep 17 00:00:00 2001 From: AFeuerpfeil Date: Tue, 2 Dec 2025 15:27:08 -0500 Subject: [PATCH 1/4] start adaptation of algorithms to styles --- src/algorithms/groundstate/find_groundstate.jl | 4 ++-- src/algorithms/groundstate/idmrg.jl | 1 + src/algorithms/groundstate/vumps.jl | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/algorithms/groundstate/find_groundstate.jl b/src/algorithms/groundstate/find_groundstate.jl index 30a5abcfd..39a8c62fa 100644 --- a/src/algorithms/groundstate/find_groundstate.jl +++ b/src/algorithms/groundstate/find_groundstate.jl @@ -26,7 +26,7 @@ function find_groundstate( tol = Defaults.tol, maxiter = Defaults.maxiter, verbosity = Defaults.verbosity, trscheme = nothing ) - if isa(ψ, InfiniteMPS) + if GeometryStyle(ψ) == InfiniteChainStyle() alg = VUMPS(; tol = max(1.0e-4, tol), verbosity, maxiter) if tol < 1.0e-4 alg = alg & GradientGrassmann(; tol = tol, maxiter, verbosity) @@ -34,7 +34,7 @@ function find_groundstate( if !isnothing(trscheme) alg = IDMRG2(; tol = min(1.0e-2, 100tol), verbosity, trscheme) & alg end - elseif isa(ψ, AbstractFiniteMPS) + elseif GeometryStyle(ψ) == FiniteChainStyle() alg = DMRG(; tol, maxiter, verbosity) if !isnothing(trscheme) alg = DMRG2(; tol = min(1.0e-2, 100tol), verbosity, trscheme) & alg diff --git a/src/algorithms/groundstate/idmrg.jl b/src/algorithms/groundstate/idmrg.jl index 6cb71afd3..62f2116a9 100644 --- a/src/algorithms/groundstate/idmrg.jl +++ b/src/algorithms/groundstate/idmrg.jl @@ -72,6 +72,7 @@ end function find_groundstate(mps, operator, alg::alg_type, envs = environments(mps, operator)) where {alg_type <: Union{<:IDMRG, <:IDMRG2}} (length(mps) ≤ 1 && alg isa IDMRG2) && throw(ArgumentError("unit cell should be >= 2")) + GeometryStyle(operator, mps) == InfiniteChainStyle() && throw(ArgumentError("IDMRG only supports infinite systems.")) log = alg isa IDMRG ? IterLog("IDMRG") : IterLog("IDMRG2") mps = copy(mps) iter = 0 diff --git a/src/algorithms/groundstate/vumps.jl b/src/algorithms/groundstate/vumps.jl index 99da8234c..a72ff3dbb 100644 --- a/src/algorithms/groundstate/vumps.jl +++ b/src/algorithms/groundstate/vumps.jl @@ -46,7 +46,7 @@ struct VUMPSState{S, O, E} end function find_groundstate( - mps::InfiniteMPS, operator, alg::VUMPS, envs = environments(mps, operator) + mps, operator, alg::VUMPS, envs = environments(mps, operator) ) return dominant_eigsolve(operator, mps, alg, envs; which = :SR) end @@ -55,6 +55,7 @@ function dominant_eigsolve( operator, mps, alg::VUMPS, envs = environments(mps, operator); which ) + GeometryStyle(operator, mps) == InfiniteChainStyle() && throw(ArgumentError("VUMPS only supports infinite systems.")) log = IterLog("VUMPS") iter = 0 ϵ = calc_galerkin(mps, operator, mps, envs) From d45f42e56f436ee572bbe58e53efa6535fb86769 Mon Sep 17 00:00:00 2001 From: AFeuerpfeil Date: Tue, 2 Dec 2025 15:31:57 -0500 Subject: [PATCH 2/4] fix logic --- src/algorithms/groundstate/idmrg.jl | 2 +- src/algorithms/groundstate/vumps.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algorithms/groundstate/idmrg.jl b/src/algorithms/groundstate/idmrg.jl index 62f2116a9..801b868c4 100644 --- a/src/algorithms/groundstate/idmrg.jl +++ b/src/algorithms/groundstate/idmrg.jl @@ -72,7 +72,7 @@ end function find_groundstate(mps, operator, alg::alg_type, envs = environments(mps, operator)) where {alg_type <: Union{<:IDMRG, <:IDMRG2}} (length(mps) ≤ 1 && alg isa IDMRG2) && throw(ArgumentError("unit cell should be >= 2")) - GeometryStyle(operator, mps) == InfiniteChainStyle() && throw(ArgumentError("IDMRG only supports infinite systems.")) + GeometryStyle(operator, mps) != InfiniteChainStyle() && throw(ArgumentError("IDMRG only supports infinite systems.")) log = alg isa IDMRG ? IterLog("IDMRG") : IterLog("IDMRG2") mps = copy(mps) iter = 0 diff --git a/src/algorithms/groundstate/vumps.jl b/src/algorithms/groundstate/vumps.jl index a72ff3dbb..5199b4ad4 100644 --- a/src/algorithms/groundstate/vumps.jl +++ b/src/algorithms/groundstate/vumps.jl @@ -55,7 +55,7 @@ function dominant_eigsolve( operator, mps, alg::VUMPS, envs = environments(mps, operator); which ) - GeometryStyle(operator, mps) == InfiniteChainStyle() && throw(ArgumentError("VUMPS only supports infinite systems.")) + GeometryStyle(operator, mps) != InfiniteChainStyle() && throw(ArgumentError("VUMPS only supports infinite systems.")) log = IterLog("VUMPS") iter = 0 ϵ = calc_galerkin(mps, operator, mps, envs) From a4f2ec8f320a258c94b5b0cfd21e1374b26849c1 Mon Sep 17 00:00:00 2001 From: AFeuerpfeil Date: Thu, 4 Dec 2025 16:07:25 -0500 Subject: [PATCH 3/4] fix test failes due to LazySum --- src/operators/lazysum.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/operators/lazysum.jl b/src/operators/lazysum.jl index 7bb2b5ce8..8aa727d86 100644 --- a/src/operators/lazysum.jl +++ b/src/operators/lazysum.jl @@ -30,6 +30,9 @@ Base.complex(x::LazySum) = LazySum(complex.(x.ops)) TimeDependence(x::LazySum) = istimed(x) ? TimeDependent() : NotTimeDependent() istimed(x::LazySum) = any(istimed, x) +OperatorStyle(::Type{LazySum{O}}) where {O} = OperatorStyle(O) +GeometryStyle(::Type{LazySum{O}}) where {O} = GeometryStyle(O + # constructors LazySum(x) = LazySum([x]) LazySum(ops::AbstractVector, fs::AbstractVector) = LazySum(map(MultipliedOperator, ops, fs)) From 3d1f6c04e25f1e360ea205a5a5723f2d960f9606 Mon Sep 17 00:00:00 2001 From: AFeuerpfeil Date: Thu, 4 Dec 2025 16:10:31 -0500 Subject: [PATCH 4/4] fix formatting and misspelling in last commit --- src/algorithms/groundstate/find_groundstate.jl | 2 +- src/operators/lazysum.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algorithms/groundstate/find_groundstate.jl b/src/algorithms/groundstate/find_groundstate.jl index 39a8c62fa..493dbdc45 100644 --- a/src/algorithms/groundstate/find_groundstate.jl +++ b/src/algorithms/groundstate/find_groundstate.jl @@ -26,7 +26,7 @@ function find_groundstate( tol = Defaults.tol, maxiter = Defaults.maxiter, verbosity = Defaults.verbosity, trscheme = nothing ) - if GeometryStyle(ψ) == InfiniteChainStyle() + if GeometryStyle(ψ) == InfiniteChainStyle() alg = VUMPS(; tol = max(1.0e-4, tol), verbosity, maxiter) if tol < 1.0e-4 alg = alg & GradientGrassmann(; tol = tol, maxiter, verbosity) diff --git a/src/operators/lazysum.jl b/src/operators/lazysum.jl index 8aa727d86..366a221d7 100644 --- a/src/operators/lazysum.jl +++ b/src/operators/lazysum.jl @@ -31,7 +31,7 @@ TimeDependence(x::LazySum) = istimed(x) ? TimeDependent() : NotTimeDependent() istimed(x::LazySum) = any(istimed, x) OperatorStyle(::Type{LazySum{O}}) where {O} = OperatorStyle(O) -GeometryStyle(::Type{LazySum{O}}) where {O} = GeometryStyle(O +GeometryStyle(::Type{LazySum{O}}) where {O} = GeometryStyle(O) # constructors LazySum(x) = LazySum([x])