Skip to content

Commit d813098

Browse files
committed
Format code examples in docs
1 parent e9227d4 commit d813098

4 files changed

Lines changed: 48 additions & 48 deletions

File tree

docs/src/computing_properties.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ using ITensors: Op
77
using LinearAlgebra: norm
88
using NamedGraphs.NamedGraphGenerators: named_grid
99
10-
g = named_grid((4,))
11-
s = siteinds("S=1/2", g)
10+
g = named_grid((4,))
11+
s = siteinds("S=1/2", g)
1212
phi = normalize(random_ttn(s; link_space = 2))
1313
psi = normalize(random_ttn(s; link_space = 2))
14-
x = normalize(random_ttn(s; link_space = 2))
15-
y = normalize(random_ttn(s; link_space = 2))
14+
x = normalize(random_ttn(s; link_space = 2))
15+
y = normalize(random_ttn(s; link_space = 2))
1616
v = first(vertices(psi))
1717
```
1818

@@ -24,23 +24,23 @@ contracting the combined bra–ket network. The default algorithm is **belief pr
2424
exact contraction (only practical for small networks or trees).
2525

2626
```@example main
27-
z = inner(phi, psi) # ⟨ϕ|ψ⟩
28-
n = norm(psi) # √⟨ψ|ψ⟩
27+
z = inner(phi, psi) # ⟨ϕ|ψ⟩
28+
n = norm(psi) # √⟨ψ|ψ⟩
2929
```
3030

3131
For numerically large tensor networks where the inner product would overflow, use the
3232
logarithmic variant:
3333

3434
```@example main
35-
logz = loginner(phi, psi) # log(⟨ϕ|ψ⟩) (numerically stable)
35+
logz = loginner(phi, psi) # log(⟨ϕ|ψ⟩) (numerically stable)
3636
```
3737

3838
For `TreeTensorNetwork`, specialised exact methods exploit the tree structure directly
3939
without belief propagation:
4040

4141
```@example main
42-
z = inner(x, y) # ⟨x|y⟩ via DFS contraction
43-
n = norm(psi) # uses ortho_region if available for efficiency
42+
z = inner(x, y) # ⟨x|y⟩ via DFS contraction
43+
n = norm(psi) # uses ortho_region if available for efficiency
4444
```
4545

4646
```@docs; canonical=false
@@ -57,8 +57,8 @@ ITensors.inner(::ITensorNetworks.AbstractTreeTensorNetwork, ::ITensorNetworks.Ab
5757
For `TreeTensorNetwork`, the normalisation is applied directly at the orthogonality centre.
5858

5959
```@example main
60-
psi = normalize(psi) # exact (default)
61-
psi_bp = normalize(psi; alg = "bp") # belief-propagation (for large loopy networks)
60+
psi = normalize(psi) # exact (default)
61+
psi_bp = normalize(psi; alg = "bp") # belief-propagation (for large loopy networks)
6262
```
6363

6464
```@docs; canonical=false
@@ -97,8 +97,8 @@ available. The operator name is passed as the **first** argument (note the diffe
9797
argument order from the general form above):
9898

9999
```@example main
100-
sz = expect("Sz", psi) # all sites
101-
sz = expect("Sz", psi; vertices = [(1,), (3,)]) # selected sites
100+
sz = expect("Sz", psi) # all sites
101+
sz = expect("Sz", psi; vertices = [(1,), (3,)]) # selected sites
102102
```
103103

104104
This is more efficient than the belief propagation approach for tree-structured networks

docs/src/itensor_networks.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ using NamedGraphs.NamedGraphGenerators: named_grid
3131
3232
# 3×3 square-lattice tensor network
3333
g = named_grid((3, 3))
34-
s = siteinds("S=1/2", g) # one spin-½ Index per vertex
34+
s = siteinds("S=1/2", g) # one spin-½ Index per vertex
3535
3636
# Zero-initialized, bond dimension 2
3737
ψ = ITensorNetwork(s; link_space = 2)
@@ -47,12 +47,12 @@ When you already have `ITensor`s in hand, edges are inferred automatically from
4747
indices:
4848

4949
```@example main
50-
i, j, k = Index(2,"i"), Index(2,"j"), Index(2,"k")
51-
A, B, C = ITensor(i,j), ITensor(j,k), ITensor(k)
50+
i, j, k = Index(2, "i"), Index(2, "j"), Index(2, "k")
51+
A, B, C = ITensor(i, j), ITensor(j, k), ITensor(k)
5252
53-
tn = ITensorNetwork([A, B, C]) # integer vertices 1, 2, 3
54-
tn = ITensorNetwork(["A","B","C"], [A, B, C]) # named vertices
55-
tn = ITensorNetwork(["A"=>A, "B"=>B, "C"=>C]) # from pairs
53+
tn = ITensorNetwork([A, B, C]) # integer vertices 1, 2, 3
54+
tn = ITensorNetwork(["A", "B", "C"], [A, B, C]) # named vertices
55+
tn = ITensorNetwork(["A" => A, "B" => B, "C" => C]) # from pairs
5656
```
5757

5858
```@docs; canonical=false
@@ -63,14 +63,14 @@ ITensorNetworks.ITensorNetwork
6363

6464
```@example main
6565
v = (1, 2)
66-
T = ψ[v] # ITensor at vertex (1,2)
67-
ψ[v] = T # replace tensor at a vertex
68-
vertices(ψ) # all vertex labels
69-
edges(ψ) # all edges
70-
neighbors(ψ, v) # neighbouring vertices of v
71-
nv(ψ), ne(ψ) # vertex / edge counts
72-
siteinds(ψ) # IndsNetwork of site (physical) indices
73-
linkinds(ψ) # IndsNetwork of bond (virtual) indices
66+
T = ψ[v] # ITensor at vertex (1,2)
67+
ψ[v] = T # replace tensor at a vertex
68+
vertices(ψ) # all vertex labels
69+
edges(ψ) # all edges
70+
neighbors(ψ, v) # neighbouring vertices of v
71+
nv(ψ), ne(ψ) # vertex / edge counts
72+
siteinds(ψ) # IndsNetwork of site (physical) indices
73+
linkinds(ψ) # IndsNetwork of bond (virtual) indices
7474
```
7575

7676
## Adding Two `ITensorNetwork`s
@@ -96,9 +96,9 @@ ITensorNetworks.add(::ITensorNetworks.AbstractITensorNetwork, ::ITensorNetworks.
9696
A single bond (edge) of any `ITensorNetwork` can be truncated by SVD:
9797

9898
```@example main
99-
edge = (1,2) => (1,3)
100-
ψ12 = truncate(ψ12, (1,2) => (1,3)) # truncate the bond between vertices (1,2) and (1,3)
101-
ψ12 = truncate(ψ12, edge) # or pass an AbstractEdge directly
99+
edge = (1, 2) => (1, 3)
100+
ψ12 = truncate(ψ12, (1, 2) => (1, 3)) # truncate the bond between vertices (1,2) and (1,3)
101+
ψ12 = truncate(ψ12, edge) # or pass an AbstractEdge directly
102102
```
103103

104104
Truncation parameters (`cutoff`, `maxdim`, `mindim`, …) are forwarded to `ITensors.svd`.

docs/src/solvers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ using ITensors: OpSum
2121
using NamedGraphs.NamedGraphGenerators: named_comb_tree
2222
2323
# Build a Heisenberg Hamiltonian on a comb tree
24-
g = named_comb_tree((3, 2))
25-
s = siteinds("S=1/2", g)
24+
g = named_comb_tree((3, 2))
25+
s = siteinds("S=1/2", g)
2626
H = let h = OpSum()
2727
for e in edges(g)
2828
h += 0.5, "S+", src(e), "S-", dst(e)
2929
h += 0.5, "S-", src(e), "S+", dst(e)
30-
h += "Sz", src(e), "Sz", dst(e)
30+
h += "Sz", src(e), "Sz", dst(e)
3131
end
3232
ttn(h, s)
3333
end

docs/src/tree_tensor_networks.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ using NamedGraphs.NamedGraphGenerators: named_comb_tree
2929
g = named_comb_tree((3, 2))
3030
sites = siteinds("S=1/2", g)
3131
32-
psi = ttn(sites) # zero-initialised
33-
psi = ttn(v -> "Up", sites) # product state
32+
psi = ttn(sites) # zero-initialised
33+
psi = ttn(v -> "Up", sites) # product state
3434
3535
# Random TTN
3636
psi = random_ttn(sites; link_space = 2)
3737
3838
# 1D MPS
3939
s1d = siteinds("S=1/2", 6)
40-
mps_state = mps(v -> "Up", s1d) # product MPS
41-
mps_state = random_mps(s1d; link_space = 2)
40+
mps_state = mps(v -> "Up", s1d) # product MPS
41+
mps_state = random_mps(s1d; link_space = 2)
4242
```
4343

4444
```@docs; canonical=false
@@ -56,8 +56,8 @@ orthogonality region. Use the `TreeTensorNetwork` constructor to convert a plain
5656
gauge metadata when you need a plain network again.
5757

5858
```@example main
59-
itn = ITensorNetwork(psi) # TTN → ITensorNetwork
60-
psi = TreeTensorNetwork(itn) # ITensorNetwork → TTN
59+
itn = ITensorNetwork(psi) # TTN → ITensorNetwork
60+
psi = TreeTensorNetwork(itn) # ITensorNetwork → TTN
6161
```
6262

6363
```@docs; canonical=false
@@ -72,9 +72,9 @@ tree edges. Truncation parameters (e.g. `cutoff`, `maxdim`) are forwarded to the
7272
factorisation step.
7373

7474
```@example main
75-
g = named_comb_tree((3,1))
76-
sites = siteinds("S=1/2",g)
77-
A = ITensors.random_itensor(only(sites[(1,1)]), only(sites[(2,1)]), only(sites[(3,1)]))
75+
g = named_comb_tree((3, 1))
76+
sites = siteinds("S=1/2", g)
77+
A = ITensors.random_itensor(only(sites[(1, 1)]), only(sites[(2, 1)]), only(sites[(3, 1)]))
7878
ttn_A = ttn(A, sites)
7979
```
8080

@@ -93,13 +93,13 @@ eigenvalue problems numerically efficient and stable.
9393
The current orthogonality center is tracked by the `ortho_region` field.
9494

9595
```@example main
96-
v = collect(vertices(psi))[1]
96+
v = collect(vertices(psi))[1]
9797
v1 = collect(vertices(psi))[1]
9898
v2 = collect(vertices(psi))[2]
9999
vs = [v]
100-
psi = orthogonalize(psi, v) # QR-sweep to put ortho center at vertex v
100+
psi = orthogonalize(psi, v) # QR-sweep to put ortho center at vertex v
101101
psi = orthogonalize(psi, [v1, v2]) # two-site center (for nsites=2 sweeps)
102-
ortho_region(psi) # query current ortho region (returns an index set)
102+
ortho_region(psi) # query current ortho region (returns an index set)
103103
```
104104

105105
```@docs; canonical=false
@@ -137,11 +137,11 @@ dimension equal to the **sum** of the two inputs, and can be recompressed with `
137137

138138
```@example main
139139
psi1, psi2 = psi, psi
140-
psi3 = psi1 + psi2 # or add(psi1, psi2)
140+
psi3 = psi1 + psi2 # or add(psi1, psi2)
141141
psi3 = truncate(psi3; cutoff = 1e-10, maxdim = 50)
142142
143-
2.0 * psi # scalar multiplication
144-
psi / norm(psi) # manual normalisation
143+
2 * psi # scalar multiplication
144+
psi / norm(psi) # manual normalisation
145145
```
146146

147147
```@docs; canonical=false

0 commit comments

Comments
 (0)