From 5c085d0211a14c247ec556246b095dd501b5a2d4 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 16 May 2024 23:58:09 -0400 Subject: [PATCH 1/4] Use random_mps --- examples/01_tdvp.jl | 4 ++-- examples/03_tdvp_time_dependent.jl | 4 ++-- examples/Project.toml | 4 ++++ test/Project.toml | 4 ++++ test/test_contract.jl | 4 ++-- test/test_dmrg.jl | 4 ++-- test/test_expand.jl | 11 ++++++----- test/test_linsolve.jl | 6 +++--- test/test_tdvp.jl | 10 +++++----- test/test_tdvp_time_dependent.jl | 6 +++--- 10 files changed, 33 insertions(+), 24 deletions(-) diff --git a/examples/01_tdvp.jl b/examples/01_tdvp.jl index d200468..65844f6 100644 --- a/examples/01_tdvp.jl +++ b/examples/01_tdvp.jl @@ -1,4 +1,4 @@ -using ITensors: MPO, OpSum, dmrg, inner, randomMPS, siteinds +using ITensors: MPO, OpSum, dmrg, inner, random_mps, siteinds using ITensorTDVP: tdvp function main() @@ -16,7 +16,7 @@ function main() end H = MPO(heisenberg(n), s) - ψ = randomMPS(s, "↑"; linkdims=10) + ψ = random_mps(s, "↑"; linkdims=10) @show inner(ψ', H, ψ) / inner(ψ, ψ) diff --git a/examples/03_tdvp_time_dependent.jl b/examples/03_tdvp_time_dependent.jl index 2dc1ed8..c54b2cc 100644 --- a/examples/03_tdvp_time_dependent.jl +++ b/examples/03_tdvp_time_dependent.jl @@ -1,5 +1,5 @@ using ITensors: @disable_warn_order, contract -using ITensors: MPO, MPS, inner, randomMPS, siteinds +using ITensors: MPO, MPS, inner, random_mps, siteinds using ITensorTDVP: tdvp using LinearAlgebra: norm using Random: Random @@ -73,7 +73,7 @@ function main() # Initial state, ψ₀ = ψ(0) # Initialize as complex since that is what OrdinaryDiffEq.jl/DifferentialEquations.jl # expects. - ψ₀ = complex.(randomMPS(s, j -> isodd(j) ? "↑" : "↓"; linkdims=start_linkdim)) + ψ₀ = complex.(random_mps(s, j -> isodd(j) ? "↑" : "↓"; linkdims=start_linkdim)) @show norm(ψ₀) diff --git a/examples/Project.toml b/examples/Project.toml index 33496f7..2602366 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -6,3 +6,7 @@ KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77" Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[compat] +ITensorMPS = "0.2.2" +ITensors = "0.6.7" diff --git a/test/Project.toml b/test/Project.toml index 7e322e9..34849f1 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -11,3 +11,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[compat] +ITensorMPS = "0.2.2" +ITensors = "0.6.7" diff --git a/test/test_contract.jl b/test/test_contract.jl index 982acdc..e0dc288 100644 --- a/test/test_contract.jl +++ b/test/test_contract.jl @@ -1,6 +1,6 @@ @eval module $(gensym()) using ITensors: ITensors, dag, delta, denseblocks -using ITensors: MPO, OpSum, apply, contract, inner, randomMPS, siteinds, truncate! +using ITensors: MPO, OpSum, apply, contract, inner, random_mps, siteinds, truncate! using ITensorTDVP: ITensorTDVP using StableRNGs: StableRNG using Test: @test, @test_throws, @testset @@ -12,7 +12,7 @@ using Test: @test, @test_throws, @testset N = 20 s = siteinds("S=1/2", N; conserve_qns) rng = StableRNG(1234) - psi = randomMPS(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=8) + psi = random_mps(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=8) os = OpSum() for j in 1:(N - 1) os += 0.5, "S+", j, "S-", j + 1 diff --git a/test/test_dmrg.jl b/test/test_dmrg.jl index cfc245f..a7237c8 100644 --- a/test/test_dmrg.jl +++ b/test/test_dmrg.jl @@ -1,5 +1,5 @@ @eval module $(gensym()) -using ITensors: ITensors, MPO, OpSum, inner, randomMPS, siteinds +using ITensors: ITensors, MPO, OpSum, inner, random_mps, siteinds using ITensorTDVP: ITensorTDVP using StableRNGs: StableRNG using Test: @test, @test_throws, @testset @@ -20,7 +20,7 @@ using Test: @test, @test_throws, @testset end H = MPO(elt, os, s) rng = StableRNG(1234) - psi = randomMPS(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=20) + psi = random_mps(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=20) nsweeps = 10 maxdim = [10, 20, 40, 100] @test_throws ErrorException ITensorTDVP.dmrg(H, psi; maxdim, cutoff, nsite) diff --git a/test/test_expand.jl b/test/test_expand.jl index 34d8072..81b9d9a 100644 --- a/test/test_expand.jl +++ b/test/test_expand.jl @@ -1,6 +1,7 @@ @eval module $(gensym()) using ITensors: scalartype -using ITensors.ITensorMPS: OpSum, MPO, MPS, inner, linkdims, maxlinkdim, randomMPS, siteinds +using ITensors.ITensorMPS: + OpSum, MPO, MPS, inner, linkdims, maxlinkdim, random_mps, siteinds using ITensorTDVP: dmrg, expand, tdvp using LinearAlgebra: normalize using StableRNGs: StableRNG @@ -14,8 +15,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) n = 6 s = siteinds("S=1/2", n; conserve_qns) rng = StableRNG(1234) - state = randomMPS(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=4) - reference = randomMPS(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=2) + state = random_mps(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=4) + reference = random_mps(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=2) state_expanded = expand(state, [reference]; alg="orthogonalize") @test scalartype(state_expanded) === elt @test inner(state_expanded, state) ≈ inner(state, state) @@ -58,7 +59,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) end operator = MPO(elt, opsum, s) rng = StableRNG(1234) - init = randomMPS(rng, elt, s; linkdims=30) + init = random_mps(rng, elt, s; linkdims=30) reference_energy, reference_state = dmrg( operator, init; @@ -68,7 +69,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) noise=(√(eps(real(elt)))), ) rng = StableRNG(1234) - state = randomMPS(rng, elt, s) + state = random_mps(rng, elt, s) nexpansions = 10 tau = elt(0.5) for step in 1:nexpansions diff --git a/test/test_linsolve.jl b/test/test_linsolve.jl index 9338e3e..7079387 100644 --- a/test/test_linsolve.jl +++ b/test/test_linsolve.jl @@ -1,6 +1,6 @@ @eval module $(gensym()) using ITensors: scalartype -using ITensors.ITensorMPS: MPO, OpSum, apply, randomMPS, siteinds +using ITensors.ITensorMPS: MPO, OpSum, apply, random_mps, siteinds using ITensorTDVP: ITensorTDVP, dmrg using KrylovKit: linsolve using LinearAlgebra: norm @@ -23,7 +23,7 @@ using Random: Random H = MPO(elt, os, s) state = [isodd(n) ? "Up" : "Dn" for n in 1:N] rng = StableRNG(1234) - x_c = randomMPS(rng, elt, s, state; linkdims=2) + x_c = random_mps(rng, elt, s, state; linkdims=2) e, x_c = dmrg(H, x_c; nsweeps=10, cutoff=1e-6, maxdim=20, outputlevel=0) @test scalartype(x_c) == elt # Compute `b = H * x_c` @@ -31,7 +31,7 @@ using Random: Random @test scalartype(b) == elt # Starting guess rng = StableRNG(1234) - x0 = x_c + elt(0.05) * randomMPS(rng, elt, s, state; linkdims=2) + x0 = x_c + elt(0.05) * random_mps(rng, elt, s, state; linkdims=2) @test scalartype(x0) == elt nsweeps = 10 cutoff = 1e-5 diff --git a/test/test_tdvp.jl b/test/test_tdvp.jl index 514875f..3e032d0 100644 --- a/test/test_tdvp.jl +++ b/test/test_tdvp.jl @@ -13,7 +13,7 @@ using ITensors: noprime, op, prime, - randomMPS, + random_mps, scalar, siteinds using ITensorTDVP: ITensorTDVP, tdvp @@ -35,7 +35,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) end H = MPO(elt, os, s) rng = StableRNG(1234) - ψ0 = randomMPS(rng, elt, s; linkdims=10) + ψ0 = random_mps(rng, elt, s; linkdims=10) time_step = elt(0.1) * im # Time evolve forward: ψ1 = tdvp(H, -time_step, ψ0; cutoff, nsite=1) @@ -74,7 +74,7 @@ end H2 = MPO(elt, os2, s) Hs = [H1, H2] rng = StableRNG(1234) - ψ0 = randomMPS(rng, elt, s; linkdims=10) + ψ0 = random_mps(rng, elt, s; linkdims=10) ψ1 = tdvp(Hs, -elt(0.1) * im, ψ0; cutoff, nsite=1) @test ITensors.scalartype(ψ1) === complex(elt) @test norm(ψ1) ≈ 1 rtol = √eps(real(elt)) @@ -102,7 +102,7 @@ end end H = MPO(os, s) rng = StableRNG(1234) - ψ0 = randomMPS(rng, s; linkdims=10) + ψ0 = random_mps(rng, s; linkdims=10) function updater(PH, state0; internal_kwargs, kwargs...) return exponentiate(PH, internal_kwargs.time_step, state0; kwargs...) end @@ -257,7 +257,7 @@ end end H = MPO(os, s) rng = StableRNG(1234) - state = randomMPS(rng, s; linkdims=2) + state = random_mps(rng, s; linkdims=2) state2 = deepcopy(state) trange = 0.0:tau:ttotal for (step, t) in enumerate(trange) diff --git a/test/test_tdvp_time_dependent.jl b/test/test_tdvp_time_dependent.jl index 9a8e36c..26b3290 100644 --- a/test/test_tdvp_time_dependent.jl +++ b/test/test_tdvp_time_dependent.jl @@ -1,6 +1,6 @@ @eval module $(gensym()) -using ITensors: ITensors, Index, QN, contract, randomITensor, scalartype -using ITensors.ITensorMPS: MPO, MPS, ProjMPO, ProjMPOSum, randomMPS, position!, siteinds +using ITensors: ITensors, Index, QN, contract, scalartype +using ITensors.ITensorMPS: MPO, MPS, ProjMPO, ProjMPOSum, random_mps, position!, siteinds using ITensorTDVP: ITensorTDVP, TimeDependentSum, tdvp using LinearAlgebra: norm using StableRNGs: StableRNG @@ -19,7 +19,7 @@ include(joinpath(pkgdir(ITensorTDVP), "examples", "03_updaters.jl")) H⃗ = (H, H) region = 2:3 rng = StableRNG(1234) - ψ = randomMPS(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=2) + ψ = random_mps(rng, elt, s, j -> isodd(j) ? "↑" : "↓"; linkdims=2) H⃗ᵣ = ProjMPO.(H⃗) map(Hᵣ -> position!(Hᵣ, ψ, first(region)), H⃗ᵣ) ∑Hᵣ = ProjMPOSum(collect(H⃗)) From 81cc08cadee15913bc75a6e78e7da2f37fe7c633 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 17 May 2024 00:11:06 -0400 Subject: [PATCH 2/4] Update examples/Project.toml --- examples/Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/Project.toml b/examples/Project.toml index 2602366..d9d44c7 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -8,5 +8,4 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" [compat] -ITensorMPS = "0.2.2" ITensors = "0.6.7" From 020814540f583298febcc3524e62548ae92d00d7 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 17 May 2024 00:11:22 -0400 Subject: [PATCH 3/4] Update test/Project.toml --- test/Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index 34849f1..888b687 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -13,5 +13,4 @@ Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -ITensorMPS = "0.2.2" ITensors = "0.6.7" From 99bf3a0de648f941bf272be0ca2e49f954ac2aff Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 17 May 2024 00:47:44 -0400 Subject: [PATCH 4/4] Bump to v0.4.3 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 2c73f17..1d715cd 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.4.2" +version = "0.4.3" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"