Skip to content

Commit

Permalink
[ITensorMPS] Rename randomMPS to random_mps (#1446)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed May 16, 2024
1 parent 3c20776 commit 4351285
Show file tree
Hide file tree
Showing 43 changed files with 319 additions and 285 deletions.
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
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;linkdims=4)
psi0 = random_mps(s;linkdims=4)

nsweeps = 5
cutoff = 1E-8
Expand Down
18 changes: 9 additions & 9 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;linkdims=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 Down Expand Up @@ -85,7 +85,7 @@ let
maxdim = [10,20,100,100,200] # gradually increase states kept
cutoff = [1E-10] # desired truncation error

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

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

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

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

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

Expand Down Expand Up @@ -238,7 +238,7 @@ let
# Initialize wavefunction to a random MPS
# of bond-dimension 10 with same quantum
# numbers as `state`
psi0 = randomMPS(sites,state;linkdims=20)
psi0 = random_mps(sites,state;linkdims=20)

nsweeps = 10
maxdim = [20,60,100,100,200,400,800]
Expand Down Expand Up @@ -328,15 +328,15 @@ let
#
# Compute the ground state psi0
#
psi0_init = randomMPS(sites;linkdims=2)
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)
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
Expand All @@ -357,7 +357,7 @@ let
#
# Compute the second excited state psi2
#
psi2_init = randomMPS(sites;linkdims=2)
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
Expand Down Expand Up @@ -429,7 +429,7 @@ 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]
Expand Down Expand Up @@ -523,7 +523,7 @@ 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]
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;linkdims=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
4 changes: 2 additions & 2 deletions docs/src/tutorials/DMRG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let
end
H = MPO(os,sites)

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

nsweeps = 5
maxdim = [10,20,100,100,200]
Expand Down Expand Up @@ -92,7 +92,7 @@ physical indices given by the array `sites`.
The line

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

constructs an MPS `psi0` which has the physical indices `sites` and a bond dimension of 10.
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;linkdims=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 @@ -24,7 +24,7 @@ let
H = MPO(os, sites)

state = [isodd(n) ? "Up" : "Dn" for n in 1:N]
psi0 = randomMPS(sites, state; linkdims=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; linkdims=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 @@ -22,7 +22,7 @@ let
# Initialize wavefunction to a random MPS
# of bond-dimension 10 with same quantum
# numbers as `state`
psi0 = randomMPS(sites, state; linkdims=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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function main(; Nx=6, Ny=3, U=4.0, t=1.0)
# Initialize wavefunction to a random MPS
# of bond-dimension 10 with same quantum
# numbers as `state`
psi0 = randomMPS(sites, state)
psi0 = random_mps(sites, state)

energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff, noise)
@show t, U
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function main(;
end
display(state)

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

energy, psi = @time dmrg(H, psi0; nsweeps, maxdim, cutoff, noise, outputlevel)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let
H = MPO(os, sites)

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

# Plan to do 5 DMRG sweeps:
nsweeps = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function main(n; blas_num_threads=Sys.CPU_THREADS, fuse=true, binary=true)
s = siteinds("S=1/2", n; conserve_qns=true)
H = MPO(heisenberg(n), s)
initstate(j) = isodd(j) ? "" : ""
ψ0 = randomMPS(s, initstate; linkdims=10)
ψ0 = random_mps(s, initstate; linkdims=10)

edmrg, ψdmrg = dmrg(H, ψ0; nsweeps=10, cutoff=1e-6)

Expand Down
2 changes: 1 addition & 1 deletion src/lib/ITensorMPS/examples/finite_temperature/metts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function main(; N=10, cutoff=1E-8, δτ=0.1, beta=2.0, NMETTS=3000, Nwarm=10)
Ry_gates = ops([("Ry", n, (θ=π / 2,)) for n in 1:N], s)

# Arbitrary initial state
psi = randomMPS(s)
psi = random_mps(s)

# Make H for measuring the energy
terms = OpSum()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ N = 4
nmps = 3
cutoff = 1e-8
s = siteinds("S=1/2", N)
ψs = [randomMPS(s; linkdims=2) for _ in 1:nmps]
ψs = [random_mps(s; linkdims=2) for _ in 1:nmps]
ρs = [outer(ψ, ψ; cutoff) for ψ in ψs]
ρ = sum(ρs; cutoff)

Expand Down
Loading

2 comments on commit 4351285

@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.

Error while trying to register: Version 0.6.6 already exists

Please sign in to comment.