Skip to content

Commit 3d36e74

Browse files
authored
[ITensorMPS] Update examples to use ITensorMPS.jl (#1411)
1 parent 36da003 commit 3d36e74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+227
-187
lines changed

.github/workflows/Downstream.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
os: [ubuntu-latest]
1717
package:
1818
- {user: ITensor, repo: ITensorGaussianMPS.jl}
19+
- {user: ITensor, repo: ITensorMPS.jl}
1920
- {user: ITensor, repo: ITensorTDVP.jl}
2021
- {user: ITensor, repo: ITensorUnicodePlots.jl}
2122
- {user: ITensor, repo: ITensorVisualizationBase.jl}

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.0"
4+
version = "0.6.1"
55

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

docs/settings.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ settings = Dict(
4242
"Observer.md",
4343
"DMRGObserver.md",
4444
],
45-
"OpSum (AutoMPO)" => "OpSum.md",
45+
"OpSum" => "OpSum.md",
4646
],
4747
"Frequently Asked Questions" => [
4848
"Programming Language (Julia, C++, ...) FAQs" => "faq/JuliaAndCpp.md",

docs/src/AdvancedUsageGuide.md

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ NDTensors.Dense{Float64,Array{Float64,1}}
141141
A common place you might accidentally come across this is when
142142
you are creating a Hamiltonian with `OpSum`:
143143
```julia
144+
julia> using ITensors, ITensorMPS
145+
144146
julia> N = 4;
145147

146148
julia> sites = siteinds("S=1/2",N);
@@ -180,7 +182,7 @@ Julia provides many tools for searching for documentation interactively at the R
180182
julia> using ITensors
181183

182184
julia> ?ITensor
183-
search: ITensor ITensors itensor emptyITensor randomITensor
185+
search: ITensor ITensors itensor randomITensor
184186

185187
An ITensor is a tensor whose interface is independent of its
186188
memory layout. Therefore it is not necessary to know the ordering
@@ -220,27 +222,7 @@ julia> fieldnames(ITensor)
220222
```
221223
which shows the fields of a type. Note that in general the specific names of the fields and structures of types may change (we consider those to be internal details), however we often make functions to access the fields of a type that have the same name as the field, so it is a good place to get started. For example, you can access the storage and indices of an ITensor `A` with the functions `store(A)` and `inds(A)`.
222224

223-
Another helpful function is `apropos`, which search through all documentation for a string (ignoring the case) and prints a list of all types and methods with documentation that contain the string. For example:
224-
```julia
225-
julia> apropos("IndexSet")
226-
ITensors.IndexSet
227-
ITensors.push
228-
ITensors.insertat
229-
ITensors.getfirst
230-
ITensors.commoninds
231-
ITensors.pushfirst
232-
NDTensors.mindim
233-
[...]
234-
```
235-
This can often return too much information. A helpful way to narrow down the search is with regular expressions, for example:
236-
```julia
237-
julia> apropos(r"ITensor.*IndexSet")
238-
ITensors.block
239-
ITensors.hasinds
240-
ITensors.ITensor
241-
NDTensors.inds
242-
```
243-
where the notation `r"..."` is Julia notation for making a string that will be interpreted as a [regular expression](https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions). Here, we are searching for any documentation that contains the string "ITensor" followed at some point by "IndexSet". The notation `.*` is regular expression notation for matching any number of any type of character.
225+
Another helpful function is `apropos`, which search through all documentation for a string (ignoring the case) and prints a list of all types and methods with documentation that contain the string.
244226

245227
Based on the `apropos` function, we can make some helper functions that may be useful. For example:
246228
```julia
@@ -949,7 +931,7 @@ This allows us to have code like:
949931
julia> i = Index(2, "i")
950932
(dim=2|id=811|"i")
951933

952-
julia> A = emptyITensor(i', i);
934+
julia> A = ITensor(i', i);
953935

954936
julia> @show A;
955937
A = ITensor ord=2

docs/src/ContractionSequenceOptimization.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ h₃ = Index(k, "h₃")
3838
s₁ = Index(d, "s₁")
3939
s₂ = Index(d, "s₂")
4040
41-
H₁ = emptyITensor(dag(s₁), s₁', dag(h₁), h₂)
42-
H₂ = emptyITensor(dag(s₂), s₂', dag(h₂), h₃)
43-
L = emptyITensor(dag(l), l', h₁)
44-
R = emptyITensor(dag(r), r', h₃)
45-
ψ = emptyITensor(l, s₁, s₂, r)
41+
H₁ = ITensor(dag(s₁), s₁', dag(h₁), h₂)
42+
H₂ = ITensor(dag(s₂), s₂', dag(h₂), h₃)
43+
L = ITensor(dag(l), l', h₁)
44+
R = ITensor(dag(r), r', h₃)
45+
ψ = ITensor(l, s₁, s₂, r)
4646
4747
TN = [ψ, L, H₁, H₂, R]
4848
sequence1 = Any[2, Any[3, Any[4, Any[1, 5]]]]
@@ -80,11 +80,11 @@ function tensor_network(; m, k, d)
8080
s₁ = Index(d, "s₁")
8181
s₂ = Index(d, "s₂")
8282

83-
ψ = emptyITensor(l, s₁, s₂, r)
84-
L = emptyITensor(dag(l), l', h₁)
85-
H₁ = emptyITensor(dag(s₁), s₁', dag(h₁), h₂)
86-
H₂ = emptyITensor(dag(s₂), s₂', dag(h₂), h₃)
87-
R = emptyITensor(dag(r), r', h₃)
83+
ψ = ITensor(l, s₁, s₂, r)
84+
L = ITensor(dag(l), l', h₁)
85+
H₁ = ITensor(dag(s₁), s₁', dag(h₁), h₂)
86+
H₂ = ITensor(dag(s₂), s₂', dag(h₂), h₃)
87+
R = ITensor(dag(r), r', h₃)
8888
return [ψ, L, H₁, H₂, R]
8989
end
9090

docs/src/Multithreading.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ julia> using LinearAlgebra
3434
julia> BLAS.vendor() # Check which BLAS you are using
3535
:mkl
3636

37-
julia> using ITensors
38-
3937
julia> BLAS.get_num_threads()
4038
6
4139

@@ -60,17 +58,19 @@ $ julia -t 4
6058
julia> Threads.nthreads()
6159
4
6260

63-
julia> ITensors.Strided.get_num_threads()
61+
julia> using Strided
62+
63+
julia> Strided.get_num_threads()
6464
4
6565
```
6666
We find that this threading competes with BLAS threading as well as ITensors.jl's own block sparse
6767
multithreading, so if you are using Julia with multiple threads you may want to disable
6868
Strided.jl's threading with:
6969
```julia
70-
julia> ITensors.Strided.disable_threads()
70+
julia> Strided.disable_threads()
7171
1
7272

73-
julia> ITensors.Strided.get_num_threads()
73+
julia> Strided.get_num_threads()
7474
1
7575
```
7676
in favor of either BLAS threading or ITensors.jl's block sparse threading.
@@ -88,12 +88,13 @@ Here is a simple example of using block sparse multithreading to speed up a spar
8888
tensor contraction:
8989
```julia
9090
using BenchmarkTools
91-
using ITensors
91+
using ITensors, ITensorMPS
9292
using LinearAlgebra
93+
using Strided
9394

9495
function main(; d = 20, order = 4)
9596
BLAS.set_num_threads(1)
96-
ITensors.Strided.set_num_threads(1)
97+
Strided.set_num_threads(1)
9798

9899
println("#################################################")
99100
println("# order = ", order)
@@ -139,7 +140,7 @@ julia> main(d = 20, order = 4)
139140
Threads.nthreads() = 5
140141
Sys.CPU_THREADS = 6
141142
BLAS.get_num_threads() = 1
142-
ITensors.Strided.get_num_threads() = 1
143+
Strided.get_num_threads() = 1
143144
144145
Serial contract:
145146
21.558 ms (131 allocations: 7.34 MiB)

docs/src/Observer.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ For example, let's make a type called `DemoObserver`
3030
as:
3131

3232
```julia
33+
using ITensors, ITensorMPS
34+
3335
mutable struct DemoObserver <: AbstractObserver
3436
energy_tol::Float64
3537
last_energy::Float64
@@ -137,7 +139,7 @@ energy, psi = dmrg(H,psi0,sweeps; observer=obs, outputlevel=1)
137139
## Complete Sample Code
138140

139141
```julia
140-
using ITensors
142+
using ITensors, ITensorMPS
141143

142144
mutable struct DemoObserver <: AbstractObserver
143145
energy_tol::Float64

docs/src/examples/DMRG.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ or a wavefunction we need to construct a "site set" which will hold the site ind
77
the physical Hilbert space:
88

99
```julia
10+
using ITensors, ITensorMPS
1011
N = 100
1112
sites = siteinds("S=1",N)
1213
```
@@ -66,7 +67,7 @@ approximation to the ground state as the variable `psi`.
6667
Below you can find a complete working code that includes all of these steps:
6768

6869
```julia
69-
using ITensors
70+
using ITensors, ITensorMPS
7071

7172
let
7273
N = 100
@@ -118,7 +119,7 @@ These tags tell the OpSum system which local operators to use for these
118119
sites when building the Hamiltonian MPO.
119120

120121
```julia
121-
using ITensors
122+
using ITensors, ITensorMPS
122123

123124
let
124125
N = 100
@@ -208,7 +209,7 @@ the geometry a cylinder.
208209
**Full example code:**
209210

210211
```julia
211-
using ITensors
212+
using ITensors, ITensorMPS
212213

213214
let
214215
Ny = 6
@@ -285,7 +286,7 @@ within the same quantum number sector.
285286
**Full Example code:**
286287

287288
```julia
288-
using ITensors
289+
using ITensors, ITensorMPS
289290

290291
let
291292
N = 20
@@ -377,6 +378,8 @@ First we define our custom observer type, `EntanglementObserver`, and overload t
377378
for it:
378379

379380
```julia
381+
using ITensors, ITensorMPS
382+
380383
mutable struct EntanglementObserver <: AbstractObserver
381384
end
382385

@@ -398,7 +401,7 @@ has just finished optimizing.
398401
Here is a complete sample code including constructing the observer and passing it to DMRG:
399402

400403
```julia
401-
using ITensors
404+
using ITensors, ITensorMPS
402405

403406
mutable struct EntanglementObserver <: AbstractObserver
404407
end
@@ -473,6 +476,8 @@ First we define our custom observer type, `SizeObserver`, and overload the `meas
473476
for it:
474477

475478
```julia
479+
using ITensors, ITensorMPS
480+
476481
mutable struct SizeObserver <: AbstractObserver
477482
end
478483

@@ -493,7 +498,7 @@ When it runs, it calls `Base.summarysize` on the wavefunction `psi` object and t
493498
Here is a complete sample code including constructing the observer and passing it to DMRG:
494499

495500
```julia
496-
using ITensors
501+
using ITensors, ITensorMPS
497502

498503
mutable struct SizeObserver <: AbstractObserver
499504
end

docs/src/examples/MPSandMPO.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ In the example code below we will obtain the element ``T^{1,2,1,1,2,1,2,2,2,1}``
8383
which is (implicitly) defined by the MPS psi:
8484

8585
```@example mps_element
86-
using ITensors # hide
86+
using ITensors, ITensorMPS
8787
let # hide
8888
N = 10
8989
s = siteinds(2,N)
@@ -139,7 +139,7 @@ following example we will use a random MPS of bond dimension ``\chi=4`` but the
139139
MPS could be obtained other ways such as through a DMRG calculation.
140140

141141
```@example expect
142-
using ITensors # hide
142+
using ITensors, ITensorMPS
143143
N = 10
144144
chi = 4
145145
sites = siteinds("S=1/2",N)
@@ -306,6 +306,8 @@ as well as limits on the maximum bond dimension (`maxdim` keyword argument).
306306
**Complete code example**
307307

308308
```julia
309+
using ITensors, ITensorMPS
310+
309311
psi = orthogonalize(psi, 3)
310312

311313
wf = (psi[3] * psi[4]) * G
@@ -355,7 +357,8 @@ the algorithm for sampling MPS is a `perfect' sampling algorithm with no autocor
355357
In more detail, say we have a set of `N` site indices `s` and define a random MPS
356358
with these sites:
357359
```@example sample_mps; continued=true
358-
using ITensors # hide
360+
using ITensors, ITensorMPS
361+
359362
N = 10 # number of sites
360363
d = 3 # dimension of each site
361364
chi = 16 # bond dimension of the MPS
@@ -384,7 +387,7 @@ can be brought into orthogonal form by calling `psi = orthogonalize(psi, 1)`.
384387

385388
## Write and Read an MPS or MPO to Disk with HDF5
386389

387-
!!! info
390+
!!! info
388391
Make sure to install the HDF5 package to use this feature. (Run `julia> ] add HDF5` in the Julia REPL console.)
389392

390393
**Writing an MPS to an HDF5 File**
@@ -427,6 +430,8 @@ So for example, to create an MPO from an OpSum which has the same site indices
427430
as your MPS `psi`, do the following:
428431

429432
```julia
433+
using ITensors, ITensorMPS
434+
430435
os = OpSum()
431436
# Then put operators into os...
432437

0 commit comments

Comments
 (0)