Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time dependent TDVP #52

Closed
wants to merge 96 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
3069350
first version
DaanMaertens Apr 17, 2023
7fbd8dd
Merge branch 'master' into TimeDependent
lkdvos Apr 29, 2023
75a6f4c
integrators.jl streamline
DaanMaertens Jun 19, 2023
2f344c6
now with @with_kw
DaanMaertens Jun 20, 2023
f2f2fd0
Merge branch 'master' into TimeDependent
DaanMaertens Jun 20, 2023
368172e
did i get all @with_kw ?
DaanMaertens Jun 20, 2023
d3feb92
Window and WindowMPS
DaanMaertens Jun 21, 2023
4ae4529
Revert "Window and WindowMPS"
DaanMaertens Jun 21, 2023
212bfc6
renamed mpscomoving to windowmps
DaanMaertens Jun 21, 2023
9dd6edf
added window.jl
DaanMaertens Jun 21, 2023
8219ffa
Update MPSKit.jl
DaanMaertens Jun 21, 2023
d1c9d44
Merge branch 'WindowMPS' into TimeDependent
DaanMaertens Jun 21, 2023
e317c6e
Fix small typo
lkdvos Jun 22, 2023
6f8a3b1
Rename example from comoving to windowmps
lkdvos Jun 22, 2023
550a9a7
Update docstring of WindowMPS
lkdvos Jun 22, 2023
1d64dd2
Refactor and cleanup windowmps
lkdvos Jun 22, 2023
4f1baf2
mend
lkdvos Jun 22, 2023
889461d
rework but not tested
DaanMaertens Jun 23, 2023
73a7320
Merge branch 'WindowMPS' into TimeDependent
DaanMaertens Jun 23, 2023
04acb44
Update .gitignore
DaanMaertens Jun 23, 2023
ec15675
added copies to left and right part
DaanMaertens Jun 23, 2023
00f23e7
Update .gitignore
DaanMaertens Jun 23, 2023
d1731ba
almost final update
DaanMaertens Jun 26, 2023
15b3c49
final version (tests coming soon)
DaanMaertens Jun 26, 2023
5b4c737
Specialize `+(MPOHamiltonian, AbstractVector)`
lkdvos Jun 27, 2023
67ad64f
isapprox added
DaanMaertens Jun 27, 2023
a29d28e
Merge branch 'TimeDependent' of https://github.com/maartenvd/MPSKit.j…
DaanMaertens Jun 27, 2023
2a57305
bugfix left_virtualspace
DaanMaertens Jun 27, 2023
08c67d1
tests for all new features
DaanMaertens Jun 28, 2023
ac11b23
some bugfixes
DaanMaertens Jul 4, 2023
af24f84
isapprox fix
DaanMaertens Jul 5, 2023
0d15788
LinearCombination as SumOfOperators
DaanMaertens Jul 6, 2023
d6154c6
bugfix left_virtualspace
DaanMaertens Jul 10, 2023
81d4da8
cleanup
DaanMaertens Jul 12, 2023
c3558e0
Merge branch 'master' into TimeDependent
DaanMaertens Jul 12, 2023
958cb79
fixed my wrong merge
DaanMaertens Jul 12, 2023
0473aaf
left virtual space bugfix?
DaanMaertens Jul 12, 2023
e6ae6d6
bugfixes + tests
DaanMaertens Jul 13, 2023
2345567
Update expval.jl
DaanMaertens Jul 14, 2023
1c6fc3b
some bugfixes
DaanMaertens Aug 29, 2023
43a32cc
Merge branch 'Daan-vumps&tdvp' of https://github.com/maartenvd/MPSKit…
DaanMaertens Sep 8, 2023
f1be338
Merge branch 'master' into TimeDependent
DaanMaertens Sep 8, 2023
4d987f8
removed duplicate in derivatives.jl
DaanMaertens Sep 15, 2023
41d648a
fixed my mistake in outer constructor for windowmps
DaanMaertens Sep 15, 2023
368b60a
Update states.jl
DaanMaertens Sep 15, 2023
78e4c74
removed problematic integrators
DaanMaertens Sep 25, 2023
dbb807e
Format .jl files
DaanMaertens Sep 25, 2023
cd9fe69
Merge pull request #68 from maartenvd/auto-juliaformatter-pr
DaanMaertens Sep 25, 2023
472e496
fixed the failing tests
DaanMaertens Sep 25, 2023
f71d9fd
small fix
DaanMaertens Sep 26, 2023
b910e66
Format .jl files
DaanMaertens Sep 26, 2023
da9e5b7
Merge pull request #69 from maartenvd/auto-juliaformatter-pr
DaanMaertens Sep 26, 2023
2883dc1
new standards
DaanMaertens Oct 10, 2023
5f6eb2d
Merge branch 'master' into TimeDependent
lkdvos Oct 10, 2023
78e4f7f
Add docstring to fix `expectation_value` interface
lkdvos Oct 10, 2023
46bca57
expval formatting and small refactors
lkdvos Oct 10, 2023
331aad8
Fix `time_evolve` interface with docstring
lkdvos Oct 10, 2023
b984fb7
Implement `time_evolve`
lkdvos Oct 10, 2023
aef1190
Fix `timestep` interface with docstring
lkdvos Oct 10, 2023
3c9ffb3
Add `time_evolve` implementation
lkdvos Oct 10, 2023
277d479
Fix `integrate` interface
lkdvos Oct 10, 2023
6788093
Adapt tests to new timestep syntax
lkdvos Oct 10, 2023
38420de
adapt tdvp to new timestep syntax
lkdvos Oct 10, 2023
7e62814
fix boolean use in integrate
lkdvos Oct 10, 2023
d6776de
Update tests to reflex changes
lkdvos Oct 11, 2023
8356452
small updates and bugfixes
lkdvos Oct 11, 2023
d6d7a50
Remove double definition
lkdvos Oct 16, 2023
3e80dbd
Remove some tests
lkdvos Oct 16, 2023
33cea2b
formatter
lkdvos Oct 16, 2023
d2fa83a
more improvements
lkdvos Oct 16, 2023
40cff8b
Formatter
lkdvos Oct 16, 2023
c44fa49
Merge branch 'master' into TimeDependent
lkdvos Oct 16, 2023
ceadd2d
Updates
lkdvos Oct 16, 2023
798716d
Format
lkdvos Oct 16, 2023
bce45b6
change unstable tests
lkdvos Oct 16, 2023
18fff1f
export time_evolve
DaanMaertens Oct 20, 2023
65c2074
const DerivativeOperator
DaanMaertens Oct 20, 2023
9d7eb2c
integrate now does i d/dt = f(y,t)
DaanMaertens Oct 20, 2023
17657e5
one line verbose in time_evolve
DaanMaertens Oct 20, 2023
54b62e2
removed unnecessary finalize
DaanMaertens Oct 20, 2023
df4e5ec
Merge branch 'master' into TimeDependent
lkdvos Oct 25, 2023
6d3e042
Update integrators.jl
DaanMaertens Oct 27, 2023
abe7480
expval for WindowMPS and SumOfOperators
DaanMaertens Oct 27, 2023
f415a47
dt in timestep
DaanMaertens Oct 27, 2023
9a5f17f
DerivativeOperator two argument call
DaanMaertens Oct 27, 2023
ff3bf42
callable window
DaanMaertens Oct 27, 2023
705197d
(t) of mutipliedoperator and sumofoperators
DaanMaertens Oct 27, 2023
2c17a38
Update windowtdvp.jl
DaanMaertens Oct 27, 2023
510bb24
Merge branch 'master' into TimeDependent
lkdvos Nov 7, 2023
92fcf55
cleanup of multipliedoperator and sumofoperators
DaanMaertens Nov 14, 2023
8f8c09b
better typing for sumofoperators
DaanMaertens Nov 15, 2023
d711f7b
safer derivative for MultipliedOperator
DaanMaertens Nov 15, 2023
32294c4
even better typing for SumOfOperators
DaanMaertens Nov 16, 2023
655fd23
some fixes
DaanMaertens Nov 20, 2023
748ea45
tests should be fixed now
DaanMaertens Nov 20, 2023
c05e56b
renaming to LazySum
DaanMaertens Nov 25, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
docs/build
Manifest.toml
.vscode
.DS_Store
73 changes: 73 additions & 0 deletions examples/timeevolution.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using MPSKit, MPSKitModels, TensorKit, Test

#local redefinition
function nonsym_ising(; J=1, g=0.5)
(sx, _, sz) = nonsym_spintensors(1//2)

return MPOHamiltonian(
LocalOperator(-4 * J * sz ⊗ sz, (1, 2)) + LocalOperator(-2 * g * sx, (1,))
)
end

# for now this uses the old MPSKitModels code

(sx, _, sz) = nonsym_spintensors(1//2)
σₓ = 2 * sx;
σz = 2 * sz; #factor 2 to get pauli matrices
J = 1;
g = 0.5;

HJ = MPOHamiltonian(LocalOperator(-J * σz ⊗ σz, (1, 2)))
Hg = MPOHamiltonian(LocalOperator(-g * σₓ, (1,)))
H₀ = HJ + Hg

gs = InfiniteMPS([2], [50]); #create MPS with physical bond dimension d=2 and virtual D=50
(gs, envs, _) = find_groundstate(gs, H₀, VUMPS(; maxiter=400));

sx_gs = sum(expectation_value(gs, σₓ)) / length(gs)
@show sx_gs
E_gs = sum(expectation_value(gs, H₀, envs)) / length(gs)
@show E_gs

# some time function that slowly ramps
f = t -> t == 0.0 ? 1 : 1 + 2 * min(0.1 * t, 2.0)

# time dependent Hamiltonian = HJ+f(t)*Hg
Hₜ = TimeDepProblem((HJ, Hg), (t -> 1, f));

# the corresponding environment
envs = environments(gs, Hₜ);

# the algorithm we will use for time evolution
# expalg performs the integration of the tdvp equations
# here we choose the implicit midpoint method IM() (others are availible/ easily implemented see integrators.jl)
alg = TDVP(; expalg=IM())

# timestep and how many steps
dt = 0.001
N = 100

# containers for observables
sxs = zeros(ComplexF64, N + 1)
Es = zeros(ComplexF64, N + 1)

# the actual time evolution
let nstate = copy(gs), nenvs = environments(gs, Hₜ), t = 0.0
for i in 1:(N + 1)
sxs[i] = expectation_value(nstate, σₓ, 1)
Es[i] = expectation_value(nstate, Hₜ, t, nenvs)[1]
nstate, nenvs = timestep(nstate, Hₜ, t, dt, alg, nenvs)
t += dt
end
end

#check that for t=0 before timestep everything is same as in gs
@test real(sxs[1]) ≈ real(sx_gs)
@test real(Es[1]) ≈ real(E_gs)

# numerical free fermion solution @ t=0.1
sxt = 0.25869106309840484
Et = -1.0661310695057724

@show abs(real(sxs[end]) / sxt - 1)
@show abs(real(Es[end]) / Et - 1)
10 changes: 9 additions & 1 deletion src/MPSKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export entanglementplot, transferplot

# hamiltonian things
export Cache
export SparseMPO, MPOHamiltonian, DenseMPO, MPOMultiline
export SparseMPO,
MPOHamiltonian, DenseMPO, MPOMultiline, UntimedOperator, TimedOperator, LazySum, ConvertOperator
export ∂C, ∂AC, ∂AC2, environments, expectation_value, effective_excitation_hamiltonian
export leftenv, rightenv

Expand All @@ -37,6 +38,7 @@ export VUMPS, DMRG, DMRG2, IDMRG1, IDMRG2, GradientGrassmann
export excitations, FiniteExcited, QuasiparticleAnsatz
export marek_gap, correlation_length, correlator
export timestep!, timestep, TDVP, TDVP2, make_time_mpo, WI, WII, TaylorCluster
export time_evolve, time_evolve!
export splitham, infinite_temperature, entanglement_spectrum, transfer_spectrum, variance
export changebonds!, changebonds, VUMPSSvdCut, OptimalExpand, SvdCut, UnionTrunc, RandExpand
export entropy
Expand Down Expand Up @@ -79,6 +81,8 @@ include("operators/sparsempo/sparsempo.jl")
include("operators/mpohamiltonian.jl") # the mpohamiltonian objects
include("operators/mpomultiline.jl")
include("operators/projection.jl")
include("operators/multipliedoperator.jl")
include("operators/lazysum.jl")

include("transfermatrix/transfermatrix.jl")
include("transfermatrix/transfer.jl")
Expand All @@ -89,6 +93,7 @@ include("environments/FinEnv.jl")
include("environments/abstractinfenv.jl")
include("environments/permpoinfenv.jl")
include("environments/mpohaminfenv.jl")
include("environments/multipleenv.jl")
include("environments/qpenv.jl")
include("environments/idmrgenv.jl")
include("environments/lazylincocache.jl")
Expand All @@ -108,7 +113,10 @@ include("algorithms/changebonds/svdcut.jl")
include("algorithms/changebonds/randexpand.jl")

include("algorithms/timestep/tdvp.jl")
include("algorithms/timestep/windowtdvp.jl")
include("algorithms/timestep/timeevmpo.jl")
include("algorithms/timestep/integrators.jl")
include("algorithms/timestep/time_evolve.jl")

include("algorithms/groundstate/vumps.jl")
include("algorithms/groundstate/idmrg.jl")
Expand Down
40 changes: 39 additions & 1 deletion src/algorithms/derivatives.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Given a state and it's environments, we can act on it

#make this into one struct?
"""
Draft operators
"""
Expand All @@ -21,12 +22,16 @@ struct MPO_∂∂AC2{O,L,R}
rightenv::R
end

Base.:*(h::Union{MPO_∂∂C,MPO_∂∂AC,MPO_∂∂AC2}, v) = h(v);
const DerivativeOperator = Union{MPO_∂∂C,MPO_∂∂AC,MPO_∂∂AC2}

Base.:*(h::DerivativeOperator, v) = h(v);

(h::MPO_∂∂C)(x) = ∂C(x, h.leftenv, h.rightenv);
(h::MPO_∂∂AC)(x) = ∂AC(x, h.o, h.leftenv, h.rightenv);
(h::MPO_∂∂AC2)(x) = ∂AC2(x, h.o1, h.o2, h.leftenv, h.rightenv);
(h::DerivativeOperator)(v, ::Number) = h(v)

# can we reduce code duplication for ∂∂C,∂∂AC,∂∂AC2 by defining constructors for DerivativeOperator?
# draft operator constructors
function ∂∂C(pos::Int, mps, opp::Union{MPOHamiltonian,SparseMPO,DenseMPO}, cache)
return MPO_∂∂C(leftenv(cache, pos + 1, mps), rightenv(cache, pos, mps))
Expand Down Expand Up @@ -326,3 +331,36 @@ function ∂∂AC2(pos::Int, state, opp::ProjectionOperator, env)
rightenv(env, pos + 1, state),
)
end

# MultipliedOperator and SumOfOperators
(x::TimedOperator{<:DerivativeOperator})(y, t::Number) = x.f(t) * x.op(y)
(x::UntimedOperator{<:DerivativeOperator})(y, ::Number) = x.f * x.op(y)
(x::LazySum{<:Union{MPSKit.MultipliedOperator{D}, D} where {D<:MPSKit.DerivativeOperator}})(y, t::Number) = sum(O -> O(y, t), x) #not strict enough?

function ∂∂C(pos::Int, mps, opp::MultipliedOperator, cache)
return MultipliedOperator(∂∂C(pos::Int, mps, opp.op, cache), opp.f)
end

function ∂∂AC(pos::Int, mps, opp::MultipliedOperator, cache)
return MultipliedOperator(∂∂AC(pos::Int, mps, opp.op, cache), opp.f)
end

function ∂∂AC2(pos::Int, mps, opp::MultipliedOperator, cache)
return MultipliedOperator(∂∂AC2(pos::Int, mps, opp.op, cache), opp.f)
end

function ∂∂C(pos::Int, mps, opp::LazySum, cache::MultipleEnvironments)
return LazySum{Union{MPO_∂∂C,MultipliedOperator{<:MPO_∂∂C}}}(map((op, openv) -> ∂∂C(pos, mps, op, openv), opp.ops, cache.envs))
end

function ∂∂AC(pos::Int, mps, opp::LazySum, cache::MultipleEnvironments)
return LazySum{Union{MPO_∂∂AC,MultipliedOperator{<:MPO_∂∂AC}}}(
map((op, openv) -> ∂∂AC(pos, mps, op, openv), opp.ops, cache.envs)
)
end

function ∂∂AC2(pos::Int, mps, opp::LazySum, cache::MultipleEnvironments)
return LazySum{Union{MPO_∂∂AC2,MultipliedOperator{<:MPO_∂∂AC2}}}(
map((op, openv) -> ∂∂AC2(pos, mps, op, openv), opp.ops, cache.envs)
)
end
Loading