Skip to content

Commit

Permalink
Update for ITensors.ITensorMPS
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Mar 26, 2024
1 parent 3622d19 commit a010bb3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/alternating_update.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ITensors:
using ITensors: permute
using ITensors.ITensorMPS:
AbstractObserver,
MPO,
MPS,
Expand All @@ -9,7 +10,6 @@ using ITensors:
disk,
linkind,
maxlinkdim,
permute,
siteinds

function _compute_nsweeps(t; time_step=default_time_step(t), nsweeps=default_nsweeps())
Expand Down
9 changes: 5 additions & 4 deletions src/projmpo_apply.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ITensors: ITensors, AbstractProjMPO, ITensor, MPO, MPS
using ITensors: ITensors, ITensor
using ITensors.ITensorMPS: ITensorMPS, AbstractProjMPO, MPO, MPS

"""
A ProjMPOApply represents the application of an
Expand Down Expand Up @@ -35,12 +36,12 @@ function Base.copy(P::ProjMPOApply)
return ProjMPOApply(P.lpos, P.rpos, P.nsite, copy(P.psi0), copy(P.H), copy(P.LR))
end

function ITensors.set_nsite!(P::ProjMPOApply, nsite)
function ITensorMPS.set_nsite!(P::ProjMPOApply, nsite)
P.nsite = nsite
return P
end

function ITensors.makeL!(P::ProjMPOApply, psi::MPS, k::Int)
function ITensorMPS.makeL!(P::ProjMPOApply, psi::MPS, k::Int)
# Save the last `L` that is made to help with caching
# for DiskProjMPO
ll = P.lpos
Expand All @@ -64,7 +65,7 @@ function ITensors.makeL!(P::ProjMPOApply, psi::MPS, k::Int)
return P
end

function ITensors.makeR!(P::ProjMPOApply, psi::MPS, k::Int)
function ITensorMPS.makeR!(P::ProjMPOApply, psi::MPS, k::Int)
# Save the last `R` that is made to help with caching
# for DiskProjMPO
rl = P.rpos
Expand Down
11 changes: 6 additions & 5 deletions src/projmpo_mps2.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ITensors: AbstractProjMPO, ProjMPO, contract, makeL!, makeR!, nsite, set_nsite!
using ITensors: contract
using ITensors.ITensorMPS: AbstractProjMPO, ProjMPO, makeL!, makeR!, nsite, set_nsite!

mutable struct ProjMPO_MPS2 <: AbstractProjMPO
PH::ProjMPO
Expand All @@ -15,25 +16,25 @@ end

Base.copy(P::ProjMPO_MPS2) = ProjMPO_MPS2(copy(P.PH), copy(P.Ms))

ITensors.nsite(P::ProjMPO_MPS2) = nsite(P.PH)
ITensorMPS.nsite(P::ProjMPO_MPS2) = nsite(P.PH)

function ITensors.set_nsite!(P::ProjMPO_MPS2, nsite)
function ITensorMPS.set_nsite!(P::ProjMPO_MPS2, nsite)
set_nsite!(P.PH, nsite)
for m in P.Ms
set_nsite!(m, nsite)
end
return P
end

function ITensors.makeL!(P::ProjMPO_MPS2, psi::MPS, k::Int)
function ITensorMPS.makeL!(P::ProjMPO_MPS2, psi::MPS, k::Int)
makeL!(P.PH, psi, k)
for m in P.Ms
makeL!(m, psi, k)
end
return P
end

function ITensors.makeR!(P::ProjMPO_MPS2, psi::MPS, k::Int)
function ITensorMPS.makeR!(P::ProjMPO_MPS2, psi::MPS, k::Int)
makeR!(P.PH, psi, k)
for m in P.Ms
makeR!(m, psi, k)
Expand Down
12 changes: 6 additions & 6 deletions src/projmps2.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ITensors:
AbstractProjMPO, ITensor, OneITensor, dag, dim, lproj, prime, rproj, site_range
using ITensors: ITensor, dag, dim, prime
using ITensors.ITensorMPS: ITensorMPS, AbstractProjMPO, OneITensor, lproj, rproj, site_range

"""
Holds the following data where psi
Expand Down Expand Up @@ -29,12 +29,12 @@ function Base.copy(P::ProjMPS2)
return ProjMPS2(P.lpos, P.rpos, P.nsite, copy(P.M), copy(P.LR))
end

function ITensors.set_nsite!(P::ProjMPS2, nsite)
function ITensorMPS.set_nsite!(P::ProjMPS2, nsite)
P.nsite = nsite
return P
end

function ITensors.makeL!(P::ProjMPS2, psi::MPS, k::Int)
function ITensorMPS.makeL!(P::ProjMPS2, psi::MPS, k::Int)
# Save the last `L` that is made to help with caching
# for DiskProjMPO
ll = P.lpos
Expand All @@ -58,7 +58,7 @@ function ITensors.makeL!(P::ProjMPS2, psi::MPS, k::Int)
return P
end

function ITensors.makeR!(P::ProjMPS2, psi::MPS, k::Int)
function ITensorMPS.makeR!(P::ProjMPS2, psi::MPS, k::Int)
# Save the last `R` that is made to help with caching
# for DiskProjMPO
rl = P.rpos
Expand All @@ -82,7 +82,7 @@ function ITensors.makeR!(P::ProjMPS2, psi::MPS, k::Int)
return P
end

function ITensors.contract(P::ProjMPS2, v::ITensor)
function ITensorMPS.contract(P::ProjMPS2, v::ITensor)
itensor_map = Union{ITensor,OneITensor}[lproj(P)]
append!(itensor_map, [prime(t, "Link") for t in P.M[site_range(P)]])
push!(itensor_map, rproj(P))
Expand Down
13 changes: 7 additions & 6 deletions src/sweep_update.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ITensors:
MPS, isortho, orthocenter, orthogonalize!, position!, replacebond!, set_nsite!, uniqueinds
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
Expand Down Expand Up @@ -270,9 +271,9 @@ function region_update!(
psi[b] = U
phi0 = S * V
if isforward(direction)
ITensors.setleftlim!(psi, b)
ITensorMPS.setleftlim!(psi, b)
elseif isreverse(direction)
ITensors.setrightlim!(psi, b)
ITensorMPS.setrightlim!(psi, b)
end
set_nsite!(PH, nsite - 1)
position!(PH, psi, b1)
Expand All @@ -281,9 +282,9 @@ function region_update!(
normalize && (phi0 ./= norm(phi0))
psi[b + Δ] = phi0 * psi[b + Δ]
if isforward(direction)
ITensors.setrightlim!(psi, b + Δ + 1)
ITensorMPS.setrightlim!(psi, b + Δ + 1)
elseif isreverse(direction)
ITensors.setleftlim!(psi, b + Δ - 1)
ITensorMPS.setleftlim!(psi, b + Δ - 1)
end
set_nsite!(PH, nsite)
end
Expand Down

0 comments on commit a010bb3

Please sign in to comment.