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

Move code to ITensors.ITensorMPS #67

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
40ce92c
Remove codes, now moved to ITensors.ITensorMPS
emstoudenmire Mar 27, 2024
b7ee90b
Update tests
emstoudenmire Mar 27, 2024
86afc5d
Add Reexport to dependencies
emstoudenmire Mar 27, 2024
344d485
Update test_tdvp to avoid warning
emstoudenmire Mar 27, 2024
4e5d5d9
Update example code
emstoudenmire Mar 27, 2024
7ddf347
Update src/ITensorTDVP.jl
emstoudenmire Mar 29, 2024
f4d56fc
Update test/test_dmrg.jl
emstoudenmire Mar 29, 2024
a8eeacc
Update test/test_dmrg_x.jl
emstoudenmire Mar 29, 2024
eadd062
Restore test of applyexp solver backend
emstoudenmire Mar 29, 2024
80b4da7
Bump ITensors compat to v0.3.59
mtfishman Mar 30, 2024
91cd565
Reflect rename to ITensorMPS.alternating_update_dmrg
emstoudenmire Mar 31, 2024
261ff90
Remove unused dependencies
emstoudenmire Mar 31, 2024
204a765
Add compat entry for Reexport
emstoudenmire Mar 31, 2024
010a696
Bump ITensors compat to v0.3.60
mtfishman Mar 31, 2024
8042972
Remove example that was using code internals
emstoudenmire Apr 1, 2024
d7a587b
Restore solver_utils.jl and associated exports
emstoudenmire Apr 1, 2024
62d08eb
Call new internal names for ITensorTDVP functions inside ITensorMPS
emstoudenmire Apr 1, 2024
9358bf3
Bump to v0.3
mtfishman Apr 1, 2024
58ef5d7
More specific wrappers for ITensorTDVP interface
emstoudenmire Apr 1, 2024
34e4b19
Update naming conventions
emstoudenmire Apr 1, 2024
e825129
Update function argument names
emstoudenmire Apr 3, 2024
70e4442
Merge branch 'main' into import_from_ITensorMPS
mtfishman Apr 15, 2024
24572a2
Merge branch 'main' into import_from_ITensorMPS
mtfishman Apr 15, 2024
590f13c
Merge branch 'main' into import_from_ITensorMPS
emstoudenmire Apr 25, 2024
3777752
Add Reexport as dependency
emstoudenmire Apr 25, 2024
2e1f1ad
Change most functions to be reexported from ITensorMPS
emstoudenmire Apr 25, 2024
f78b291
Reexport linsolve from KrylovKit
emstoudenmire Apr 25, 2024
0094d7e
Add test of exports
emstoudenmire Apr 28, 2024
1bcded0
Restore ITensorMPS wrappers and remove Reexport dependency
emstoudenmire Apr 28, 2024
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
3 changes: 1 addition & 2 deletions Project.toml
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ version = "0.2.1"

[deps]
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"

[compat]
ITensors = "0.3.60"
Reexport = "1"
julia = "1.6"

[extras]
Expand Down
52 changes: 0 additions & 52 deletions examples/05_tdvp_nonuniform_timesteps.jl

This file was deleted.

85 changes: 0 additions & 85 deletions examples/05_utils.jl
emstoudenmire marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

24 changes: 20 additions & 4 deletions src/ITensorTDVP.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
module ITensorTDVP

using Reexport: @reexport
@reexport using ITensors.ITensorMPS: tdvp, dmrg_x, to_vec, TimeDependentSum, linsolve

using ITensors: ITensors, MPO
using ITensors.NDTensors: @Algorithm_str
using ITensors.ITensorMPS: ITensorMPS
dmrg(args...; kwargs...) = ITensorMPS.alternating_update_dmrg(args...; kwargs...)
using KrylovKit: KrylovKit

tdvp(args...; kwargs...) = ITensorMPS.itensortdvp_tdvp(args...; kwargs...)

function KrylovKit.linsolve(A::MPO, args...; kwargs...)
return ITensorMPS.itensortdvp_linsolve(A, args...; kwargs...)
end

dmrg(args...; kwargs...) = ITensorMPS.itensortdvp_dmrg(args...; kwargs...)

dmrg_x(args...; kwargs...) = ITensorMPS.itensortdvp_dmrg_x(args...; kwargs...)

function ITensors.contract(alg::Algorithm"fit", args...; kwargs...)
return ITensorMPS.itensortdvp_contract(alg, args...; kwargs...)
end
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved

include("solver_utils.jl")
export TimeDependentSum, to_vec

end
69 changes: 69 additions & 0 deletions src/solver_utils.jl
emstoudenmire marked this conversation as resolved.
Outdated
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using ITensors: ITensor, apply, array, inds, itensor, permute, ProjMPOSum

# Utilities for making it easier
# to define solvers (like ODE solvers)
# for TDVP

"""
to_vec(x)
Transform `x` into a `Vector`, and return the vector, and a closure which inverts the
transformation.

Modeled after FiniteDifferences.to_vec:

https://github.com/JuliaDiff/FiniteDifferences.jl/blob/main/src/to_vec.jl
"""
to_vec(x) = error("Not implemented")

function to_vec(x::ITensor)
function to_itensor(x_vec)
return itensor(x_vec, inds(x))
end
return vec(array(x)), to_itensor
end

# Represents a time-dependent sum of terms:
#
# H(t) = f[1](t) * H0[1] + f[2](t) * H0[2] + …
#
struct TimeDependentSum{S,T}
f::Vector{S}
H0::T
end
TimeDependentSum(f::Vector, H0::ProjMPOSum) = TimeDependentSum(f, ITensors.terms(H0))
Base.length(H::TimeDependentSum) = length(H.f)

function Base.:*(c::Number, H::TimeDependentSum)
return TimeDependentSum([t -> c * fₙ(t) for fₙ in H.f], H.H0)
end
Base.:*(H::TimeDependentSum, c::Number) = c * H

# Calling a `TimeDependentOpSum` at a certain time like:
#
# H(t)
#
# Returns a `ScaledSum` at that time.
(H::TimeDependentSum)(t::Number) = ScaledSum([fₙ(t) for fₙ in H.f], H.H0)

# Represents the sum of scaled terms:
#
# H = coefficient[1] * H[1] + coefficient * H[2] + …
#
struct ScaledSum{S,T}
coefficients::Vector{S}
H::T
end
Base.length(H::ScaledSum) = length(H.coefficients)

# Apply the scaled sum of terms:
#
# H(ψ₀) = coefficient[1] * H[1](ψ₀) + coefficient[2] * H[2](ψ₀) + …
#
# onto ψ₀.
function (H::ScaledSum)(ψ₀)
ψ = ITensor(inds(ψ₀))
for n in 1:length(H)
ψ += H.coefficients[n] * apply(H.H[n], ψ₀)
end
return permute(ψ, inds(ψ₀))
end
6 changes: 1 addition & 5 deletions test/test_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ using ITensorTDVP: ITensorTDVP
using Test: @testset
@testset "Run examples" begin
examples_files = [
"01_tdvp.jl",
"02_dmrg-x.jl",
"03_tdvp_time_dependent.jl",
"04_tdvp_observers.jl",
"05_tdvp_nonuniform_timesteps.jl",
"01_tdvp.jl", "02_dmrg-x.jl", "03_tdvp_time_dependent.jl", "04_tdvp_observers.jl"
]
examples_path = joinpath(pkgdir(ITensorTDVP), "examples")
@testset "Running example file $f" for f in examples_files
Expand Down
Loading