Skip to content

Commit

Permalink
Use random_mps (#81)
Browse files Browse the repository at this point in the history
* Use `random_mps`

* Bump to v0.4.3
  • Loading branch information
mtfishman authored May 17, 2024
1 parent 6ae4306 commit 70b8a5f
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensorTDVP"
uuid = "25707e16-a4db-4a07-99d9-4d67b7af0342"
authors = ["Matthew Fishman <mfishman@flatironinstitute.org> and contributors"]
version = "0.4.2"
version = "0.4.3"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
4 changes: 2 additions & 2 deletions examples/01_tdvp.jl
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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(ψ, ψ)

Expand Down
4 changes: 2 additions & 2 deletions examples/03_tdvp_time_dependent.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(ψ₀)

Expand Down
3 changes: 3 additions & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ 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]
ITensors = "0.6.7"
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ 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]
ITensors = "0.6.7"
4 changes: 2 additions & 2 deletions test/test_contract.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_dmrg.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions test/test_expand.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/test_linsolve.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,15 +23,15 @@ 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`
b = apply(H, x_c; cutoff=1e-8)
@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
Expand Down
10 changes: 5 additions & 5 deletions test/test_tdvp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using ITensors:
noprime,
op,
prime,
randomMPS,
random_mps,
scalar,
siteinds
using ITensorTDVP: ITensorTDVP, tdvp
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/test_tdvp_time_dependent.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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⃗))
Expand Down

2 comments on commit 70b8a5f

@mtfishman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/107063

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.3 -m "<description of version>" 70b8a5f47314aa67dcbd52b693670c7ff64d7f97
git push origin v0.4.3

Please sign in to comment.