Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9e97336
make derivatives it's own folder
lkdvos Feb 14, 2025
d622805
Rewrite single-site hamiltonian
lkdvos Feb 14, 2025
1779716
Add benchmark script
lkdvos Feb 15, 2025
dcd43d2
gitignore dev/
lkdvos Feb 15, 2025
914c183
Start twosite derivative
lkdvos Feb 15, 2025
e3332d7
start playing with JordanMPOTensor
lkdvos Mar 14, 2025
e88e611
Contraction fixes
lkdvos Mar 15, 2025
7c683d9
JordanMPO fixes
lkdvos Mar 15, 2025
86ac51b
Start simplified implementations
lkdvos Mar 15, 2025
22494b7
Add support to `force_planar` for testing
lkdvos Mar 15, 2025
e426c63
Fix derivative
lkdvos Mar 22, 2025
3a05d3a
remove stray contractcheck
lkdvos Mar 22, 2025
8354125
Start supporting finite systems
lkdvos Mar 22, 2025
cc4f2de
First attempt at twosite version
lkdvos Mar 22, 2025
57cd920
Reorganize derivatives
lkdvos Mar 23, 2025
b0b4e3c
Improve jordanmpotensor
lkdvos Mar 23, 2025
960ef70
various fixes
lkdvos Mar 23, 2025
a3f38e4
make warnings toggleable
lkdvos Mar 23, 2025
4e8031f
signature fixes
lkdvos Mar 23, 2025
d8e1fbd
small fixes
lkdvos Mar 23, 2025
df56a1d
Fix periodic boundary
lkdvos Mar 23, 2025
96f88e1
Make SVD algorithm accessible and trscheme mandatory
lkdvos Mar 24, 2025
1b2e629
small improvement hamiltonian derivative
lkdvos Mar 24, 2025
b1c5742
Fix bad merge
lkdvos Mar 24, 2025
c5a47d7
Add required kwarg in test
lkdvos Mar 24, 2025
5a51625
Fix `nonzero_length`
lkdvos Mar 26, 2025
92b56d3
restrict `ham_derivatives` types
lkdvos Mar 27, 2025
f6696b8
Reorganize derivatives
lkdvos Mar 28, 2025
a240620
remove BlockTensorKit code duplication
lkdvos Mar 28, 2025
11aa1f4
implement fallback case that should never happen
lkdvos Mar 31, 2025
5d797fc
Add space assertions in constructor
lkdvos Mar 31, 2025
d0bc673
implement some mpotensor kernels
lkdvos Mar 31, 2025
d8e6c7e
`copy(::JordanMPOTensor)`
lkdvos Mar 31, 2025
42a7772
Go all in and replace all MPOHamiltonian objects
lkdvos Mar 31, 2025
ebfc2d5
Bump version
lkdvos Mar 31, 2025
84955d4
Merge branch 'master' into derivatives
lkdvos Mar 31, 2025
78a3c08
Remove unused files
lkdvos Mar 31, 2025
03d2a20
Formatter
lkdvos Mar 31, 2025
6dbb110
move `ac_proj` and friends
lkdvos Apr 7, 2025
1408d85
consistent naming for Projection_derivatives
lkdvos Apr 7, 2025
6cffb55
Apply suggestions from code review
lkdvos Apr 7, 2025
43a34dc
move some definitons around
lkdvos Apr 7, 2025
b6c5ad0
Merge branch 'derivatives' of https://github.com/QuantumKitHub/MPSKit…
lkdvos Apr 7, 2025
9b322fd
standardize ham derivative property names
lkdvos Apr 7, 2025
6920494
Add `JordanMPOTensor` space checks
lkdvos Apr 7, 2025
2d5bdd9
No default `trscheme`
lkdvos Apr 7, 2025
a791799
Remove obsolete code
lkdvos Apr 7, 2025
8eaa06a
Remove obsolete to do
lkdvos Apr 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MPSKit"
uuid = "bb1c41ca-d63c-52ed-829e-0820dda26502"
authors = "Lukas Devos, Maarten Van Damme and contributors"
version = "0.12.6"
version = "0.13.0-DEV"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand All @@ -25,7 +25,7 @@ VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
[compat]
Accessors = "0.1"
Aqua = "0.8.9"
BlockTensorKit = "0.1.4"
BlockTensorKit = "0.1.6"
Combinatorics = "1"
Compat = "3.47, 4.10"
DocStringExtensions = "0.9.3"
Expand Down
9 changes: 7 additions & 2 deletions src/MPSKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ using Compat: @compat
using TensorKit
using TensorKit: BraidingTensor
using BlockTensorKit
using BlockTensorKit: TensorMapSumSpace
using TensorOperations
using KrylovKit
using KrylovKit: KrylovAlgorithm
Expand All @@ -75,7 +76,7 @@ using DocStringExtensions
using LinearAlgebra: diag, Diagonal
using LinearAlgebra: LinearAlgebra
using Random
using Base: @kwdef
using Base: @kwdef, @propagate_inbounds
using LoggingExtras
using OhMyThreads

Expand Down Expand Up @@ -112,6 +113,7 @@ include("states/ortho.jl")

include("operators/abstractmpo.jl")
include("operators/mpo.jl")
include("operators/jordanmpotensor.jl")
include("operators/mpohamiltonian.jl") # the mpohamiltonian objects
include("operators/multilinempo.jl")
include("operators/projection.jl")
Expand All @@ -131,7 +133,10 @@ include("environments/multiple_envs.jl")
include("environments/lazylincocache.jl")

include("algorithms/fixedpoint.jl")
include("algorithms/derivatives.jl")
include("algorithms/derivatives/derivatives.jl")
include("algorithms/derivatives/mpo_derivatives.jl")
include("algorithms/derivatives/hamiltonian_derivatives.jl")
include("algorithms/derivatives/projection_derivatives.jl")
include("algorithms/expval.jl")
include("algorithms/toolbox.jl")
include("algorithms/grassmann.jl")
Expand Down
8 changes: 3 additions & 5 deletions src/algorithms/approximate/idmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function approximate!(ψ::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
for col in 1:size(ψ, 2)
for row in 1:size(ψ, 1)
AC2′ = ac2_proj(row, col, ψ, toapprox, envs)
al, c, ar, = tsvd!(AC2′; trunc=alg.trscheme, alg=TensorKit.SVD())
al, c, ar, = tsvd!(AC2′; trunc=alg.trscheme, alg=alg.alg_svd)
normalize!(c)

ψ.AL[row + 1, col] = al
Expand All @@ -90,10 +90,8 @@ function approximate!(ψ::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
for row in 1:size(ψ, 1)
# TODO: also write this as ac2_proj?
AC2 = ϕ.AL[row, col] * _transpose_tail(ϕ.AC[row, col + 1])
AC2′ = ∂AC2(AC2, O[row, col], O[row, col + 1],
leftenv(envs[row], col, ψ[row]),
rightenv(envs[row], col, ψ[row]))
al, c, ar, = tsvd!(AC2′; trunc=alg.trscheme, alg=TensorKit.SVD())
AC2′ = ∂∂AC2(row, col, ψ, O, envs) * AC2
Comment thread
leburgel marked this conversation as resolved.
al, c, ar, = tsvd!(AC2′; trunc=alg.trscheme, alg=alg.alg_svd)
normalize!(c)

ψ.AL[row + 1, col] = al
Expand Down
13 changes: 8 additions & 5 deletions src/algorithms/changebonds/optimalexpand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ dominant contributions of a two-site updated MPS tensor, orthogonal to the origi

$(TYPEDFIELDS)
"""
@kwdef struct OptimalExpand <: Algorithm
@kwdef struct OptimalExpand{S} <: Algorithm
"algorithm used for the singular value decomposition"
alg_svd::S = Defaults.alg_svd()

"algorithm used for truncating the expanded space"
trscheme::TruncationScheme = truncdim(1)
trscheme::TruncationScheme
end

function changebonds(ψ::InfiniteMPS, H::InfiniteMPOHamiltonian, alg::OptimalExpand,
Expand All @@ -28,7 +31,7 @@ function changebonds(ψ::InfiniteMPS, H::InfiniteMPOHamiltonian, alg::OptimalExp
VL = leftnull(ψ.AL[i])
VR = rightnull!(_transpose_tail(ψ.AR[i + 1]))
intermediate = adjoint(VL) * AC2 * adjoint(VR)
U, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=SVD())
U, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=alg.alg_svd)

AL′[i] = VL * U
AR′[i + 1] = V * VR
Expand All @@ -54,7 +57,7 @@ function changebonds(ψ::MultilineMPS, H, alg::OptimalExpand, envs=environments(
VL = leftnull(ψ.AL[i, j])
VR = rightnull!(_transpose_tail(ψ.AR[i, j + 1]))
intermediate = adjoint(VL) * AC2 * adjoint(VR)
U, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=SVD())
U, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=alg.alg_svd)

AL′[i, j] = VL * U
AR′[i, j + 1] = V * VR
Expand Down Expand Up @@ -85,7 +88,7 @@ function changebonds!(ψ::AbstractFiniteMPS, H, alg::OptimalExpand, envs=environ

#Use this nullspaces and SVD decomposition to determine the optimal expansion space
intermediate = adjoint(NL) * AC2 * adjoint(NR)
_, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=SVD())
_, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=alg.alg_svd)

ar_re = V * NR
ar_le = zerovector!(similar(ar_re, codomain(ψ.AC[i]) ← space(V, 1)))
Expand Down
11 changes: 7 additions & 4 deletions src/algorithms/changebonds/randexpand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ two-site MPS tensor, which is made orthogonal to the existing state.

$(TYPEDFIELDS)
"""
@kwdef struct RandExpand <: Algorithm
@kwdef struct RandExpand{S} <: Algorithm
"algorithm used for the singular value decomposition"
alg_svd::S = Defaults.alg_svd()

"algorithm used for [truncation](@extref TensorKit.tsvd] the expanded space"
trscheme::TruncationScheme = truncdim(1)
trscheme::TruncationScheme
end

function changebonds(ψ::InfiniteMPS, alg::RandExpand)
Expand All @@ -26,7 +29,7 @@ function changebonds(ψ::InfiniteMPS, alg::RandExpand)
VL = leftnull(ψ.AL[i])
VR = rightnull!(_transpose_tail(ψ.AR[i + 1]))
intermediate = adjoint(VL) * AC2 * adjoint(VR)
U, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=SVD())
U, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=alg.alg_svd)

AL′[i] = VL * U
AR′[i + 1] = V * VR
Expand All @@ -50,7 +53,7 @@ function changebonds!(ψ::AbstractFiniteMPS, alg::RandExpand)

#Use this nullspaces and SVD decomposition to determine the optimal expansion space
intermediate = adjoint(NL) * AC2 * adjoint(NR)
_, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=SVD())
_, _, V, = tsvd!(intermediate; trunc=alg.trscheme, alg=alg.alg_svd)

ar_re = V * NR
ar_le = zerovector!(similar(ar_re, codomain(ψ.AC[i]) ← space(V, 1)))
Expand Down
15 changes: 9 additions & 6 deletions src/algorithms/changebonds/svdcut.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ An algorithm that uses truncated SVD to change the bond dimension of a ψ.

$(TYPEDFIELDS)
"""
@kwdef struct SvdCut <: Algorithm
@kwdef struct SvdCut{S} <: Algorithm
"algorithm used for the singular value decomposition"
alg_svd::S = Defaults.alg_svd()

"algorithm used for [truncation][@extref TensorKit.tsvd] of the gauge tensors"
trscheme::TruncationScheme = notrunc()
trscheme::TruncationScheme
end

function changebonds(ψ::AbstractFiniteMPS, alg::SvdCut; kwargs...)
return changebonds!(copy(ψ), alg; kwargs...)
end
function changebonds!(ψ::AbstractFiniteMPS, alg::SvdCut; normalize::Bool=true)
for i in (length(ψ) - 1):-1:1
U, S, V, = tsvd(ψ.C[i]; trunc=alg.trscheme, alg=TensorKit.SVD())
U, S, V, = tsvd(ψ.C[i]; trunc=alg.trscheme, alg=alg.alg_svd)
AL′ = ψ.AL[i] * U
ψ.AC[i] = (AL′, complex(S))
AR′ = _transpose_front(V * _transpose_tail(ψ.AR[i + 1]))
Expand All @@ -41,7 +44,7 @@ function changebonds!(mpo::FiniteMPO, alg::SvdCut)
O_left = transpose(mpo[1], ((3, 1, 2), (4,)))
local O_right
for i in 2:length(mpo)
U, S, V, = tsvd!(O_left; trunc=alg.trscheme, alg=TensorKit.SVD())
U, S, V, = tsvd!(O_left; trunc=alg.trscheme, alg=alg.alg_svd)
@inbounds mpo[i - 1] = transpose(U, ((2, 3), (1, 4)))
if i < length(mpo)
@plansor O_left[-3 -1 -2; -4] := S[-1; 1] * V[1; 2] * mpo[i][2 -2; -3 -4]
Expand All @@ -52,7 +55,7 @@ function changebonds!(mpo::FiniteMPO, alg::SvdCut)

# right to left
for i in (length(mpo) - 1):-1:1
U, S, V, = tsvd!(O_right; trunc=alg.trscheme, alg=TensorKit.SVD())
U, S, V, = tsvd!(O_right; trunc=alg.trscheme, alg=alg.alg_svd)
@inbounds mpo[i + 1] = transpose(V, ((1, 4), (2, 3)))
if i > 1
@plansor O_right[-1; -3 -4 -2] := mpo[i][-1 -2; -3 2] * U[2; 1] * S[1; -4]
Expand Down Expand Up @@ -81,7 +84,7 @@ function changebonds(ψ::InfiniteMPS, alg::SvdCut)
ncr = ψ.C[1]

for i in 1:length(ψ)
U, ncr, = tsvd(ψ.C[i]; trunc=alg.trscheme, alg=TensorKit.SVD())
U, ncr, = tsvd(ψ.C[i]; trunc=alg.trscheme, alg=alg.alg_svd)
copied[i] = copied[i] * U
copied[i + 1] = _transpose_front(U' * _transpose_tail(copied[i + 1]))
end
Expand Down
41 changes: 20 additions & 21 deletions src/algorithms/changebonds/vumpssvd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ An algorithm that uses a two-site update step to change the bond dimension of a
$(TYPEDFIELDS)
"""
@kwdef struct VUMPSSvdCut <: Algorithm
"tolerance for gauging algorithm"
tol_gauge = Defaults.tolgauge
"tolerance for the eigenvalue solver"
tol_eigenval = Defaults.tol
"algorithm used for gauging the `InfiniteMPS`"
alg_gauge = Defaults.alg_gauge(; dynamic_tols=false)

"algorithm used for the eigenvalue solvers"
alg_eigsolve = Defaults.alg_eigsolve(; dynamic_tols=false)

"algorithm used for the singular value decomposition"
alg_svd = Defaults.alg_svd()

"algorithm used for [truncation][@extref TensorKit.tsvd] of the two-site update"
trscheme::TruncationScheme = notrunc()
trscheme::TruncationScheme
end

function changebonds_1(state::InfiniteMPS, H, alg::VUMPSSvdCut,
Expand All @@ -31,11 +36,12 @@ function changebonds_1(state::InfiniteMPS, H, alg::VUMPSSvdCut,

# collapse back to 1 site
if D2 != D1
(nstate, nenvs) = changebonds(nstate, nH,
SvdCut(; trscheme=truncspace(infimum(D1, D2))), nenvs)
cut_alg = SvdCut(; alg.alg_svd, trscheme=truncspace(infimum(D1, D2)))
nstate, nenvs = changebonds(nstate, nH, cut_alg, nenvs)
end

collapsed = InfiniteMPS([nstate.AL[1]], nstate.C[1]; tol=alg.tol_gauge)
collapsed = InfiniteMPS([nstate.AL[1]], nstate.C[1]; alg.alg_gauge.tol,
alg.alg_gauge.maxiter)
recalculate!(envs, collapsed, H, collapsed)

return collapsed, envs
Expand All @@ -47,17 +53,13 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environment
@plansor AC2[-1 -2; -3 -4] := state.AC[loc][-1 -2; 1] * state.AR[loc + 1][1 -4; -3]

h_ac2 = ∂∂AC2(loc, state, H, envs)
(vals, vecs, _) = eigsolve(h_ac2, AC2, 1, :SR; tol=alg.tol_eigenval,
ishermitian=false)
nAC2 = vecs[1]
_, nAC2 = fixedpoint(h_ac2, AC2, :SR, alg.alg_eigsolve)

h_c = ∂∂C(loc + 1, state, H, envs)
(vals, vecs, _) = eigsolve(h_c, state.C[loc + 1], 1, :SR; tol=alg.tol_eigenval,
ishermitian=false)
nC2 = vecs[1]
_, nC2 = fixedpoint(h_c, state.C[loc + 1], :SR, alg.alg_eigsolve)

#svd ac2, get new AL1 and S,V ---> AC
(AL1, S, V, eps) = tsvd(nAC2; trunc=alg.trscheme, alg=TensorKit.SVD())
AL1, S, V, eps = tsvd!(nAC2; trunc=alg.trscheme, alg=alg.alg_svd)
@plansor AC[-1 -2; -3] := S[-1; 1] * V[1; -3 -2]
meps = max(eps, meps)

Expand All @@ -72,16 +74,13 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environment
copied = copy(state.AL)
copied[loc] = AL1
copied[loc + 1] = AL2
state = InfiniteMPS(copied; tol=alg.tol_gauge)
state = InfiniteMPS(copied; alg.alg_gauge.tol, alg.alg_gauge.maxiter)
recalculate!(envs, state, H, state)
end
return state, envs
end

function changebonds(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environments(state, H))
if (length(state) == 1)
return changebonds_1(state, H, alg, envs)
else
return changebonds_n(state, H, alg, envs)
end
return length(state) == 1 ? changebonds_1(state, H, alg, envs) :
changebonds_n(state, H, alg, envs)
end
Loading
Loading