Skip to content

Commit

Permalink
[ITensorMPS] Make ITensorTDVP functions into compatibility layer (#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
emstoudenmire authored Apr 2, 2024
1 parent f06d5c7 commit 9f1ee2a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/ITensorMPS/contract_mpo_mps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function contractmpo_solver(; kwargs...)
return solver
end

function ITensors.contract(
::Algorithm"fit", A::MPO, psi0::MPS; init_mps=psi0, nsweeps=1, kwargs...
function itensortdvp_contract(
alg::Algorithm"fit", A::MPO, psi0::MPS; init_mps=psi0, nsweeps=1, kwargs...
)::MPS
n = length(A)
n != length(psi0) &&
Expand Down
2 changes: 1 addition & 1 deletion src/ITensorMPS/dmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ function dmrg_solver(
return solver
end

function alternating_update_dmrg(
function itensortdvp_dmrg(
H,
psi0::MPS;
ishermitian=default_ishermitian(),
Expand Down
2 changes: 1 addition & 1 deletion src/ITensorMPS/dmrg_x.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function dmrg_x_solver(PH, t, psi0; current_time, outputlevel)
return U_max, nothing
end

function dmrg_x(PH, psi0::MPS; reverse_step=false, kwargs...)
function itensortdvp_dmrg_x(PH, psi0::MPS; reverse_step=false, kwargs...)
psi = alternating_update(dmrg_x_solver, PH, psi0; reverse_step, kwargs...)
return psi
end
2 changes: 1 addition & 1 deletion src/ITensorMPS/linsolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Keyword arguments:
```
See `KrylovKit.jl` documentation for more details on available keyword arguments.
"""
function KrylovKit.linsolve(
function itensortdvp_linsolve(
A::MPO,
b::MPS,
x₀::MPS,
Expand Down
3 changes: 1 addition & 2 deletions src/ITensorMPS/sweep_update.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ using ITensors: uniqueinds
using ITensors.ITensorMPS:
ITensorMPS, MPS, isortho, orthocenter, orthogonalize!, position!, replacebond!, set_nsite!
using LinearAlgebra: norm, normalize!, svd
using Observers: update!
using Printf: @printf

function sweep_update(
Expand Down Expand Up @@ -132,7 +131,7 @@ function sub_sweep_update(
end
flush(stdout)
end
update!(
update_observer!(
observer!;
psi,
bond=b,
Expand Down
24 changes: 12 additions & 12 deletions src/ITensorMPS/tdvp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function tdvp_solver(
return solver
end

function tdvp(
function itensortdvp_tdvp(
H,
t::Number,
psi0::MPS;
Expand All @@ -58,7 +58,7 @@ function tdvp(
solver_outputlevel=default_solver_outputlevel(solver_function),
kwargs...,
)
return tdvp(
return itensortdvp_tdvp(
tdvp_solver(
solver_function;
ishermitian,
Expand All @@ -75,12 +75,12 @@ function tdvp(
)
end

function tdvp(t::Number, H, psi0::MPS; kwargs...)
return tdvp(H, t, psi0; kwargs...)
function itensortdvp_tdvp(t::Number, H, psi0::MPS; kwargs...)
return itensortdvp_tdvp(H, t, psi0; kwargs...)
end

function tdvp(H, psi0::MPS, t::Number; kwargs...)
return tdvp(H, t, psi0; kwargs...)
function itensortdvp_tdvp(H, psi0::MPS, t::Number; kwargs...)
return itensortdvp_tdvp(H, t, psi0; kwargs...)
end

"""
Expand All @@ -100,16 +100,16 @@ Optional keyword arguments:
* `observer` - object implementing the [Observer](@ref observer) interface which can perform measurements and stop early
* `write_when_maxdim_exceeds::Int` - when the allowed maxdim exceeds this value, begin saving tensors to disk to free memory in large calculations
"""
function tdvp(solver, H::MPO, t::Number, psi0::MPS; kwargs...)
function itensortdvp_tdvp(solver, H::MPO, t::Number, psi0::MPS; kwargs...)
return alternating_update(solver, H, t, psi0; kwargs...)
end

function tdvp(solver, t::Number, H, psi0::MPS; kwargs...)
return tdvp(solver, H, t, psi0; kwargs...)
function itensortdvp_tdvp(solver, t::Number, H, psi0::MPS; kwargs...)
return itensortdvp_tdvp(solver, H, t, psi0; kwargs...)
end

function tdvp(solver, H, psi0::MPS, t::Number; kwargs...)
return tdvp(solver, H, t, psi0; kwargs...)
function itensortdvp_tdvp(solver, H, psi0::MPS, t::Number; kwargs...)
return itensortdvp_tdvp(solver, H, t, psi0; kwargs...)
end

"""
Expand All @@ -131,6 +131,6 @@ each step of the algorithm when optimizing the MPS.
Returns:
* `psi::MPS` - time-evolved MPS
"""
function tdvp(solver, Hs::Vector{MPO}, t::Number, psi0::MPS; kwargs...)
function itensortdvp_tdvp(solver, Hs::Vector{MPO}, t::Number, psi0::MPS; kwargs...)
return alternating_update(solver, Hs, t, psi0; kwargs...)
end
6 changes: 4 additions & 2 deletions src/ITensorMPS/update_observer.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Observers: Observers
function update_observer!(observer; kwargs...)
return error("Not implemented")
end

function Observers.update!(observer::AbstractObserver; kwargs...)
function update_observer!(observer::AbstractObserver; kwargs...)
return measure!(observer; kwargs...)
end

0 comments on commit 9f1ee2a

Please sign in to comment.