Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ITensorMPS] Rename randomMPS to random_mps #1446

Merged
merged 10 commits into from
May 16, 2024
4 changes: 2 additions & 2 deletions NDTensors/test/ITensors/TestITensorDMRG/dmrg.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ITensors: MPO, OpSum, dmrg, randomMPS, siteinds
using ITensors: MPO, OpSum, dmrg, random_mps, siteinds
using Random: Random
using Test: @test
include("../../NDTensorsTestUtils/NDTensorsTestUtils.jl")
Expand All @@ -19,7 +19,7 @@ function test_dmrg(

Random.seed!(1234)
init = j -> isodd(j) ? "↑" : "↓"
psi0 = dev(randomMPS(elt, sites, init; linkdims=4))
psi0 = dev(random_mps(elt, sites, init; linkdims=4))
H = dev(MPO(elt, os, sites))

nsweeps = 3
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensors"
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
authors = ["Matthew Fishman <[email protected]>", "Miles Stoudenmire <[email protected]>"]
version = "0.6.5"
version = "0.6.6"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
6 changes: 3 additions & 3 deletions docs/src/MPSandMPO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ MPO
```@docs
MPS(::Int)
MPS(::Type{<:Number}, ::Vector{<:Index})
randomMPS(sites::Vector{<:Index})
randomMPS(::Type{<:Number}, sites::Vector{<:Index})
randomMPS(::Vector{<:Index}, ::Any)
random_mps(sites::Vector{<:Index})
random_mps(::Type{<:Number}, sites::Vector{<:Index})
random_mps(::Vector{<:Index}, ::Any)
MPS(::Vector{<:Index}, ::Any)
MPS(::Type{<:Number}, ::Vector{<:Index}, ::Any)
MPS(::Vector{<:Pair{<:Index}})
Expand Down
2 changes: 1 addition & 1 deletion docs/src/Observer.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ let
a += 0.5,"S-",n,"S+",n+1
end
H = MPO(a,s)
psi0 = randomMPS(s,4)
psi0 = random_mps(s;linkdims=4)

nsweeps = 5
cutoff = 1E-8
Expand Down
46 changes: 23 additions & 23 deletions docs/src/examples/DMRG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The random starting wavefunction `psi0` must be defined in the same Hilbert spac
as the Hamiltonian, so we construct it using the same collection of site indices:

```julia
psi0 = randomMPS(sites,2)
psi0 = random_mps(sites;linkdims=2)
```

Here we have made a random MPS of bond dimension 2. We could have used a random product
Expand All @@ -58,7 +58,7 @@ stuck in local minima. We could also set psi to some specific initial state usin
Finally, we are ready to call DMRG:

```julia
energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)
```

When the algorithm is done, it returns the ground state energy as the variable `energy` and an MPS
Expand All @@ -85,9 +85,9 @@ let
maxdim = [10,20,100,100,200] # gradually increase states kept
cutoff = [1E-10] # desired truncation error

psi0 = randomMPS(sites,2)
psi0 = random_mps(sites;linkdims=2)

energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)

return
end
Expand Down Expand Up @@ -158,9 +158,9 @@ let
maxdim = [10,10,20,40,80,100,140,180,200]
cutoff = [1E-8]

psi0 = randomMPS(sites,4)
psi0 = random_mps(sites;linkdims=4)

energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)

return
end
Expand All @@ -178,7 +178,7 @@ more efficient than if the MPOs had been summed together into a single MPO.
To use this version of DMRG, say you have MPOs `H1`, `H2`, and `H3`.
Then call DMRG like this:
```julia
energy,psi = dmrg([H1,H2,H3],psi0; nsweeps, maxdim, cutoff)
energy,psi = dmrg([H1,H2,H3],psi0;nsweeps,maxdim,cutoff)
```

## Make a 2D Hamiltonian for DMRG
Expand Down Expand Up @@ -228,23 +228,23 @@ let
# Define the Heisenberg spin Hamiltonian on this lattice
os = OpSum()
for b in lattice
os .+= 0.5, "S+", b.s1, "S-", b.s2
os .+= 0.5, "S-", b.s1, "S+", b.s2
os .+= "Sz", b.s1, "Sz", b.s2
os += 0.5, "S+", b.s1, "S-", b.s2
os += 0.5, "S-", b.s1, "S+", b.s2
os += "Sz", b.s1, "Sz", b.s2
end
H = MPO(os,sites)

state = [isodd(n) ? "Up" : "Dn" for n=1:N]
# Initialize wavefunction to a random MPS
# of bond-dimension 10 with same quantum
# numbers as `state`
psi0 = randomMPS(sites,state,20)
psi0 = random_mps(sites,state;linkdims=20)

nsweeps = 10
maxdim = [20,60,100,100,200,400,800]
cutoff = [1E-8]

energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)

return
end
Expand All @@ -257,7 +257,7 @@ These additional 'penalty states' are provided as an array of MPS just
after the Hamiltonian, like this:

```julia
energy,psi3 = dmrg(H,[psi0,psi1,psi2],psi3_init; nsweeps, maxdim, cutoff)
energy,psi3 = dmrg(H,[psi0,psi1,psi2],psi3_init;nsweeps,maxdim,cutoff)
```

Here the penalty states are `[psi0,psi1,psi2]`.
Expand Down Expand Up @@ -328,16 +328,16 @@ let
#
# Compute the ground state psi0
#
psi0_init = randomMPS(sites,linkdims=2)
energy0,psi0 = dmrg(H,psi0_init; nsweeps, maxdim, cutoff, noise)
psi0_init = random_mps(sites;linkdims=2)
energy0,psi0 = dmrg(H,psi0_init;nsweeps,maxdim,cutoff,noise)

println()

#
# Compute the first excited state psi1
#
psi1_init = randomMPS(sites,linkdims=2)
energy1,psi1 = dmrg(H,[psi0],psi1_init; nsweeps, maxdim, cutoff, noise, weight)
psi1_init = random_mps(sites;linkdims=2)
energy1,psi1 = dmrg(H,[psi0],psi1_init;nsweeps,maxdim,cutoff,noise,weight)

# Check psi1 is orthogonal to psi0
@show inner(psi1,psi0)
Expand All @@ -357,8 +357,8 @@ let
#
# Compute the second excited state psi2
#
psi2_init = randomMPS(sites,linkdims=2)
energy2,psi2 = dmrg(H,[psi0,psi1],psi2_init; nsweeps, maxdim, cutoff, noise, weight)
psi2_init = random_mps(sites;linkdims=2)
energy2,psi2 = dmrg(H,[psi0,psi1],psi2_init;nsweeps,maxdim,cutoff,noise,weight)

# Check psi2 is orthogonal to psi0 and psi1
@show inner(psi2,psi0)
Expand Down Expand Up @@ -429,15 +429,15 @@ let
a += 0.5,"S-",n,"S+",n+1
end
H = MPO(a,s)
psi0 = randomMPS(s,linkdims=4)
psi0 = random_mps(s;linkdims=4)

nsweeps = 5
maxdim = [10,20,80,160]
cutoff = 1E-8

observer = EntanglementObserver()

energy, psi = dmrg(H,psi0; nsweeps, maxdim, cutoff, observer, outputlevel=2)
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff,observer,outputlevel=2)

return
end
Expand Down Expand Up @@ -523,15 +523,15 @@ let
a += 0.5,"S-",n,"S+",n+1
end
H = MPO(a,s)
psi0 = randomMPS(s,linkdims=4)
psi0 = random_mps(s;linkdims=4)

nsweeps = 5
maxdim = [10,20,80,160]
cutoff = 1E-8

obs = SizeObserver()

energy, psi = dmrg(H,psi0; nsweeps, maxdim, cutoff, observer=obs)
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff,observer=obs)

return
end
Expand Down
6 changes: 3 additions & 3 deletions docs/src/examples/MPSandMPO.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let # hide
N = 10
s = siteinds(2,N)
chi = 4
psi = randomMPS(s;linkdims=chi)
psi = random_mps(s;linkdims=chi)

# Make an array of integers of the element we
# want to obtain
Expand Down Expand Up @@ -143,7 +143,7 @@ using ITensors, ITensorMPS
N = 10
chi = 4
sites = siteinds("S=1/2",N)
psi = randomMPS(sites,chi)
psi = random_mps(sites;linkdims=chi)
magz = expect(psi,"Sz")
for (j,mz) in enumerate(magz)
println("$j $mz")
Expand Down Expand Up @@ -362,7 +362,7 @@ N = 10 # number of sites
d = 3 # dimension of each site
chi = 16 # bond dimension of the MPS
s = siteinds(d,N)
psi = randomMPS(s;linkdims=chi)
psi = random_mps(s;linkdims=chi)
```

We can now draw some samples from this MPS as
Expand Down
2 changes: 1 addition & 1 deletion docs/src/faq/DMRG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ When DMRG is failing to converge, here are some of the steps you can take to imp
up on the left-hand side only, it can take DMRG a very long time to converge.

* Try using a random MPS with a modestly large bond dimension. ITensor offers a function
called [`randomMPS`](@ref) which can be used to make random MPS in both the quantum number (QN)
called [`random_mps`](@ref) which can be used to make random MPS in both the quantum number (QN)
conserving and non-QN conserving cases. Because random MPS have properties
which are "typical" of most ground states, they can be good initial states for DMRG.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ let
H = MPO(os,sites)

# Create an initial random matrix product state
psi0 = randomMPS(sites)
psi0 = random_mps(sites)

# Plan to do 5 passes or 'sweeps' of DMRG,
# setting maximum MPS internal dimensions
Expand Down
8 changes: 4 additions & 4 deletions docs/src/tutorials/DMRG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ let
end
H = MPO(os,sites)

psi0 = randomMPS(sites,10)
psi0 = random_mps(sites;linkdims=10)

nsweeps = 5
maxdim = [10,20,100,100,200]
cutoff = [1E-10]

energy, psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)

return
end
Expand Down Expand Up @@ -92,7 +92,7 @@ physical indices given by the array `sites`.
The line

```julia
psi0 = randomMPS(sites,10)
psi0 = random_mps(sites;linkdims=10)
```

constructs an MPS `psi0` which has the physical indices `sites` and a bond dimension of 10.
Expand All @@ -116,7 +116,7 @@ specified than sweeps, the last value is used for all remaining sweeps).
Finally the call

```julia
energy, psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)
```

runs the DMRG algorithm included in ITensor, using `psi0` as an
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/QN_DMRG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ To make change (2), instead of constructing the initial MPS `psi0` to be an arbi
So we will replace the line

```julia
psi0 = randomMPS(sites,10)
psi0 = random_mps(sites;linkdims=10)
```

by the lines
Expand Down
4 changes: 2 additions & 2 deletions ext/ITensorsPackageCompilerExt/precompile_itensors.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ITensors.ITensorMPS: MPO, OpSum, dmrg, randomMPS, siteinds
using ITensors.ITensorMPS: MPO, OpSum, dmrg, random_mps, siteinds

# TODO: This uses all of the tests to make
# precompile statements, but takes a long time
Expand All @@ -19,7 +19,7 @@ function main(; N, dmrg_kwargs)
for conserve_qns in (false, true)
sites = siteinds("S=1", N; conserve_qns)
H = MPO(opsum, sites)
ψ0 = randomMPS(sites, j -> isodd(j) ? "↑" : "↓"; linkdims=2)
ψ0 = random_mps(sites, j -> isodd(j) ? "↑" : "↓"; linkdims=2)
dmrg(H, ψ0; outputlevel=0, dmrg_kwargs...)
end
return nothing
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ITensorMPS/examples/autodiff/mps_autodiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ h = 0.5

# Loss function only works with `Vector{ITensor}`,
# extract with `ITensors.data`.
ψ0 = ITensors.data(randomMPS(s; linkdims=10))
ψ0 = ITensors.data(random_mps(s; linkdims=10))
H = ITensors.data(MPO(ising(n; J, h), s))

loss(ψ) = loss(H, ψ)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ITensorMPS/examples/dmrg/1d_heisenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let
H = MPO(os, sites)

# Create an initial random matrix product state
psi0 = randomMPS(sites; linkdims=10)
psi0 = random_mps(sites; linkdims=10)

# Plan to do 5 DMRG sweeps:
nsweeps = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ let

os = OpSum()
for j in 1:(N - 1)
os .+= 0.5, "S+", j, "S-", j + 1
os .+= 0.5, "S-", j, "S+", j + 1
os .+= "Sz", j, "Sz", j + 1
os += 0.5, "S+", j, "S-", j + 1
os += 0.5, "S-", j, "S+", j + 1
os += "Sz", j, "Sz", j + 1
end
H = MPO(os, sites)

state = [isodd(n) ? "Up" : "Dn" for n in 1:N]
psi0 = randomMPS(sites, state, 10)
psi0 = random_mps(sites, state; linkdims=10)

# Plan to do 5 DMRG sweeps:
nsweeps = 5
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ITensorMPS/examples/dmrg/1d_hubbard_extended.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let
# Initialize wavefunction to be bond
# dimension 10 random MPS with number
# of particles the same as `state`
psi0 = randomMPS(sites, state, 10)
psi0 = random_mps(sites, state; linkdims=10)

# Check total number of particles:
@show flux(psi0)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ITensorMPS/examples/dmrg/1d_ising_with_observer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end
let
N = 100
sites = siteinds("S=1/2", N)
psi0 = randomMPS(sites; linkdims=10)
psi0 = random_mps(sites; linkdims=10)

# define parameters for DMRG sweeps
nsweeps = 15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ let

os = OpSum()
for b in lattice
os .+= 0.5, "S+", b.s1, "S-", b.s2
os .+= 0.5, "S-", b.s1, "S+", b.s2
os .+= "Sz", b.s1, "Sz", b.s2
os += 0.5, "S+", b.s1, "S-", b.s2
os += 0.5, "S-", b.s1, "S+", b.s2
os += "Sz", b.s1, "Sz", b.s2
end
H = MPO(os, sites)

state = [isodd(n) ? "Up" : "Dn" for n in 1:N]
# Initialize wavefunction to a random MPS
# of bond-dimension 10 with same quantum
# numbers as `state`
psi0 = randomMPS(sites, state, 20)
psi0 = random_mps(sites, state; linkdims=20)

nsweeps = 10
maxdim = [20, 60, 100, 100, 200, 400, 800]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function main(;
display(state)

psi0 = if random_init
randomMPS(itensor_rng, sites, state; linkdims=2)
random_mps(itensor_rng, sites, state; linkdims=2)
else
MPS(sites, state)
end
Expand Down
Loading
Loading