From a010bb3f236f873fd41ec38196b42acf78ff8a31 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 25 Mar 2024 21:01:34 -0400 Subject: [PATCH 1/3] Update for ITensors.ITensorMPS --- src/alternating_update.jl | 4 ++-- src/projmpo_apply.jl | 9 +++++---- src/projmpo_mps2.jl | 11 ++++++----- src/projmps2.jl | 12 ++++++------ src/sweep_update.jl | 13 +++++++------ 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/alternating_update.jl b/src/alternating_update.jl index 728d915..4d5846f 100644 --- a/src/alternating_update.jl +++ b/src/alternating_update.jl @@ -1,4 +1,5 @@ -using ITensors: +using ITensors: permute +using ITensors.ITensorMPS: AbstractObserver, MPO, MPS, @@ -9,7 +10,6 @@ using ITensors: disk, linkind, maxlinkdim, - permute, siteinds function _compute_nsweeps(t; time_step=default_time_step(t), nsweeps=default_nsweeps()) diff --git a/src/projmpo_apply.jl b/src/projmpo_apply.jl index cf6d001..8b6cf84 100644 --- a/src/projmpo_apply.jl +++ b/src/projmpo_apply.jl @@ -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 @@ -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 @@ -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 diff --git a/src/projmpo_mps2.jl b/src/projmpo_mps2.jl index 2dd0645..bb9801d 100644 --- a/src/projmpo_mps2.jl +++ b/src/projmpo_mps2.jl @@ -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 @@ -15,9 +16,9 @@ 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) @@ -25,7 +26,7 @@ function ITensors.set_nsite!(P::ProjMPO_MPS2, nsite) 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) @@ -33,7 +34,7 @@ function ITensors.makeL!(P::ProjMPO_MPS2, psi::MPS, k::Int) 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) diff --git a/src/projmps2.jl b/src/projmps2.jl index f9a4e61..45a8eda 100644 --- a/src/projmps2.jl +++ b/src/projmps2.jl @@ -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 @@ -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 @@ -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 @@ -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)) diff --git a/src/sweep_update.jl b/src/sweep_update.jl index ea6c02d..3679e7a 100644 --- a/src/sweep_update.jl +++ b/src/sweep_update.jl @@ -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 @@ -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) @@ -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 From 8c204c679babc6f70576344fa82b8aaa7a587aa5 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Mon, 25 Mar 2024 21:05:35 -0400 Subject: [PATCH 2/3] Remove using ITensors: ITensors --- src/projmpo_apply.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/projmpo_apply.jl b/src/projmpo_apply.jl index 8b6cf84..0493e48 100644 --- a/src/projmpo_apply.jl +++ b/src/projmpo_apply.jl @@ -1,4 +1,4 @@ -using ITensors: ITensors, ITensor +using ITensors: ITensor using ITensors.ITensorMPS: ITensorMPS, AbstractProjMPO, MPO, MPS """ From 61be3858b941f48786ca3080af3b6cb53e33bc6a Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 25 Mar 2024 21:46:04 -0400 Subject: [PATCH 3/3] Loosen test bounds, bump versions --- Project.toml | 4 ++-- test/test_contract_mpo.jl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 334d0ef..29971f7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensorTDVP" uuid = "25707e16-a4db-4a07-99d9-4d67b7af0342" authors = ["Matthew Fishman and contributors"] -version = "0.2.0" +version = "0.2.1" [deps] ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" @@ -12,7 +12,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" [compat] -ITensors = "0.3.32" +ITensors = "0.3.58" KrylovKit = "0.6" Observers = "0.2" TimerOutputs = "0.5" diff --git a/test/test_contract_mpo.jl b/test/test_contract_mpo.jl index 549b3e6..a93cd46 100644 --- a/test/test_contract_mpo.jl +++ b/test/test_contract_mpo.jl @@ -35,7 +35,7 @@ using Test: @test, @testset H = MPO(elt, os, s) Hpsi = apply(H, psi; alg="fit", nsweeps=2) @test ITensors.scalartype(Hpsi) == elt - @test inner(psi, Hpsi) ≈ inner(psi', H, psi) rtol = √eps(real(elt)) + @test inner(psi, Hpsi) ≈ inner(psi', H, psi) rtol = 10 * √eps(real(elt)) # Change "top" indices of MPO to be a different set t = siteinds("S=1/2", N; conserve_qns) psit = deepcopy(psi) @@ -46,7 +46,7 @@ using Test: @test, @testset # Test with nsweeps=2 Hpsi = apply(H, psi; alg="fit", nsweeps=2) @test ITensors.scalartype(Hpsi) == elt - @test inner(psit, Hpsi) ≈ inner(psit, H, psi) rtol = √eps(real(elt)) + @test inner(psit, Hpsi) ≈ inner(psit, H, psi) rtol = 10 * √eps(real(elt)) # Test with less good initial guess MPS not equal to psi psi_guess = copy(psi) truncate!(psi_guess; maxdim=2)