Skip to content

Commit 3c20776

Browse files
authored
[ITensorMPS] Update randomMPS linkdims syntax (#1445)
1 parent 4dc0f78 commit 3c20776

25 files changed

+101
-597
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensors"
22
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
33
authors = ["Matthew Fishman <[email protected]>", "Miles Stoudenmire <[email protected]>"]
4-
version = "0.6.5"
4+
version = "0.6.6"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

docs/src/Observer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ let
184184
a += 0.5,"S-",n,"S+",n+1
185185
end
186186
H = MPO(a,s)
187-
psi0 = randomMPS(s,4)
187+
psi0 = randomMPS(s;linkdims=4)
188188

189189
nsweeps = 5
190190
cutoff = 1E-8

docs/src/examples/DMRG.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The random starting wavefunction `psi0` must be defined in the same Hilbert spac
4747
as the Hamiltonian, so we construct it using the same collection of site indices:
4848

4949
```julia
50-
psi0 = randomMPS(sites,2)
50+
psi0 = randomMPS(sites;linkdims=2)
5151
```
5252

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

6060
```julia
61-
energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
61+
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)
6262
```
6363

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

88-
psi0 = randomMPS(sites,2)
88+
psi0 = randomMPS(sites;linkdims=2)
8989

90-
energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
90+
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)
9191

9292
return
9393
end
@@ -158,9 +158,9 @@ let
158158
maxdim = [10,10,20,40,80,100,140,180,200]
159159
cutoff = [1E-8]
160160

161-
psi0 = randomMPS(sites,4)
161+
psi0 = randomMPS(sites;linkdims=4)
162162

163-
energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
163+
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)
164164

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

184184
## Make a 2D Hamiltonian for DMRG
@@ -228,23 +228,23 @@ let
228228
# Define the Heisenberg spin Hamiltonian on this lattice
229229
os = OpSum()
230230
for b in lattice
231-
os .+= 0.5, "S+", b.s1, "S-", b.s2
232-
os .+= 0.5, "S-", b.s1, "S+", b.s2
233-
os .+= "Sz", b.s1, "Sz", b.s2
231+
os += 0.5, "S+", b.s1, "S-", b.s2
232+
os += 0.5, "S-", b.s1, "S+", b.s2
233+
os += "Sz", b.s1, "Sz", b.s2
234234
end
235235
H = MPO(os,sites)
236236

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

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

247-
energy,psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
247+
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)
248248

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

259259
```julia
260-
energy,psi3 = dmrg(H,[psi0,psi1,psi2],psi3_init; nsweeps, maxdim, cutoff)
260+
energy,psi3 = dmrg(H,[psi0,psi1,psi2],psi3_init;nsweeps,maxdim,cutoff)
261261
```
262262

263263
Here the penalty states are `[psi0,psi1,psi2]`.
@@ -328,16 +328,16 @@ let
328328
#
329329
# Compute the ground state psi0
330330
#
331-
psi0_init = randomMPS(sites,linkdims=2)
332-
energy0,psi0 = dmrg(H,psi0_init; nsweeps, maxdim, cutoff, noise)
331+
psi0_init = randomMPS(sites;linkdims=2)
332+
energy0,psi0 = dmrg(H,psi0_init;nsweeps,maxdim,cutoff,noise)
333333

334334
println()
335335

336336
#
337337
# Compute the first excited state psi1
338338
#
339-
psi1_init = randomMPS(sites,linkdims=2)
340-
energy1,psi1 = dmrg(H,[psi0],psi1_init; nsweeps, maxdim, cutoff, noise, weight)
339+
psi1_init = randomMPS(sites;linkdims=2)
340+
energy1,psi1 = dmrg(H,[psi0],psi1_init;nsweeps,maxdim,cutoff,noise,weight)
341341

342342
# Check psi1 is orthogonal to psi0
343343
@show inner(psi1,psi0)
@@ -357,8 +357,8 @@ let
357357
#
358358
# Compute the second excited state psi2
359359
#
360-
psi2_init = randomMPS(sites,linkdims=2)
361-
energy2,psi2 = dmrg(H,[psi0,psi1],psi2_init; nsweeps, maxdim, cutoff, noise, weight)
360+
psi2_init = randomMPS(sites;linkdims=2)
361+
energy2,psi2 = dmrg(H,[psi0,psi1],psi2_init;nsweeps,maxdim,cutoff,noise,weight)
362362

363363
# Check psi2 is orthogonal to psi0 and psi1
364364
@show inner(psi2,psi0)
@@ -429,15 +429,15 @@ let
429429
a += 0.5,"S-",n,"S+",n+1
430430
end
431431
H = MPO(a,s)
432-
psi0 = randomMPS(s,linkdims=4)
432+
psi0 = randomMPS(s;linkdims=4)
433433

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

438438
observer = EntanglementObserver()
439439

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

442442
return
443443
end
@@ -523,15 +523,15 @@ let
523523
a += 0.5,"S-",n,"S+",n+1
524524
end
525525
H = MPO(a,s)
526-
psi0 = randomMPS(s,linkdims=4)
526+
psi0 = randomMPS(s;linkdims=4)
527527

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

532532
obs = SizeObserver()
533533

534-
energy, psi = dmrg(H,psi0; nsweeps, maxdim, cutoff, observer=obs)
534+
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff,observer=obs)
535535

536536
return
537537
end

docs/src/examples/MPSandMPO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ using ITensors, ITensorMPS
143143
N = 10
144144
chi = 4
145145
sites = siteinds("S=1/2",N)
146-
psi = randomMPS(sites,chi)
146+
psi = randomMPS(sites;linkdims=chi)
147147
magz = expect(psi,"Sz")
148148
for (j,mz) in enumerate(magz)
149149
println("$j $mz")

docs/src/tutorials/DMRG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ let
3838
end
3939
H = MPO(os,sites)
4040

41-
psi0 = randomMPS(sites,10)
41+
psi0 = randomMPS(sites;linkdims=10)
4242

4343
nsweeps = 5
4444
maxdim = [10,20,100,100,200]
4545
cutoff = [1E-10]
4646

47-
energy, psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
47+
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)
4848

4949
return
5050
end
@@ -92,7 +92,7 @@ physical indices given by the array `sites`.
9292
The line
9393

9494
```julia
95-
psi0 = randomMPS(sites,10)
95+
psi0 = randomMPS(sites;linkdims=10)
9696
```
9797

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

118118
```julia
119-
energy, psi = dmrg(H,psi0; nsweeps, maxdim, cutoff)
119+
energy,psi = dmrg(H,psi0;nsweeps,maxdim,cutoff)
120120
```
121121

122122
runs the DMRG algorithm included in ITensor, using `psi0` as an

docs/src/tutorials/QN_DMRG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ To make change (2), instead of constructing the initial MPS `psi0` to be an arbi
8181
So we will replace the line
8282

8383
```julia
84-
psi0 = randomMPS(sites,10)
84+
psi0 = randomMPS(sites;linkdims=10)
8585
```
8686

8787
by the lines

src/lib/ITensorMPS/examples/dmrg/1d_heisenberg_conserve_spin.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ let
1717

1818
os = OpSum()
1919
for j in 1:(N - 1)
20-
os .+= 0.5, "S+", j, "S-", j + 1
21-
os .+= 0.5, "S-", j, "S+", j + 1
22-
os .+= "Sz", j, "Sz", j + 1
20+
os += 0.5, "S+", j, "S-", j + 1
21+
os += 0.5, "S-", j, "S+", j + 1
22+
os += "Sz", j, "Sz", j + 1
2323
end
2424
H = MPO(os, sites)
2525

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

2929
# Plan to do 5 DMRG sweeps:
3030
nsweeps = 5

src/lib/ITensorMPS/examples/dmrg/1d_hubbard_extended.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let
5454
# Initialize wavefunction to be bond
5555
# dimension 10 random MPS with number
5656
# of particles the same as `state`
57-
psi0 = randomMPS(sites, state, 10)
57+
psi0 = randomMPS(sites, state; linkdims=10)
5858

5959
# Check total number of particles:
6060
@show flux(psi0)

src/lib/ITensorMPS/examples/dmrg/2d_heisenberg_conserve_spin.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ let
1212

1313
os = OpSum()
1414
for b in lattice
15-
os .+= 0.5, "S+", b.s1, "S-", b.s2
16-
os .+= 0.5, "S-", b.s1, "S+", b.s2
17-
os .+= "Sz", b.s1, "Sz", b.s2
15+
os += 0.5, "S+", b.s1, "S-", b.s2
16+
os += 0.5, "S-", b.s1, "S+", b.s2
17+
os += "Sz", b.s1, "Sz", b.s2
1818
end
1919
H = MPO(os, sites)
2020

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

2727
nsweeps = 10
2828
maxdim = [20, 60, 100, 100, 200, 400, 800]

0 commit comments

Comments
 (0)