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] Update randomMPS linkdims syntax #1445

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 = randomMPS(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 = randomMPS(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 = randomMPS(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 = randomMPS(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 = randomMPS(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 = randomMPS(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 = randomMPS(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 = randomMPS(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 = randomMPS(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 = randomMPS(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
2 changes: 1 addition & 1 deletion docs/src/examples/MPSandMPO.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ using ITensors, ITensorMPS
N = 10
chi = 4
sites = siteinds("S=1/2",N)
psi = randomMPS(sites,chi)
psi = randomMPS(sites;linkdims=chi)
magz = expect(psi,"Sz")
for (j,mz) in enumerate(magz)
println("$j $mz")
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 = randomMPS(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 = randomMPS(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 = randomMPS(sites;linkdims=10)
```

by the lines
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 = randomMPS(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 = randomMPS(sites, state; linkdims=10)

# Check total number of particles:
@show flux(psi0)
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 = randomMPS(sites, state; linkdims=20)

nsweeps = 10
maxdim = [20, 60, 100, 100, 200, 400, 800]
Expand Down
Loading
Loading