Skip to content

Commit 79afae5

Browse files
committed
tensor from data docs update
1 parent 8a29479 commit 79afae5

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

docs/src/man/tensors.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,22 +297,37 @@ Furthermore, there could be specific implementations for tensors whose blocks ar
297297

298298
To create a `TensorMap` with existing data, one can use the aforementioned form but with
299299
the function `f` replaced with the actual data, i.e. `TensorMap(data, codomain, domain)` or
300-
any of its equivalents. For the specific form of `data`, we distinguish between the case
301-
without and with symmetry. In the former case, one can pass a `DenseArray`, either of
302-
rank `N₁+N₂` and with matching size `(dims(codomain)..., dims(domain)...)`, or just as a
303-
`DenseMatrix` with size `(dim(codomain), dim(domain))`. In the case of symmetry, `data`
304-
needs to be specified as a dictionary (some subtype of `AbstractDict`) with the
305-
blocksectors `c::I <: Sector` as keys and the corresponding matrix blocks as value, i.e.
306-
`data[c]` is some `DenseMatrix` of size `(blockdim(codomain, c), blockdim(domain, c))`.
307-
300+
any of its equivalents.
301+
302+
Here, `data` can be of two types. It can be a dictionary (any `Associative` subtype) which
303+
has blocksectors `c` of type `sectortype(codomain)` as keys, and the corresponding matrix
304+
blocks as value, i.e. `data[c]` is some `DenseMatrix` of size `(blockdim(codomain, c),
305+
blockdim(domain, c))`. This is the form of how the data is stored within the `TensorMap`
306+
objects.
307+
308+
For those space types for which a `TensorMap` can be converted to a plain multidimensional
309+
array, the `data` can also be a general `DenseArray`, either of rank `N₁+N₂` and with
310+
matching size `(dims(codomain)..., dims(domain)...)`, or just as a `DenseMatrix` with size
311+
`(dim(codomain), dim(domain))`. This is true in particular if the sector type is `Trivial`,
312+
e.g. for `CartesianSpace` or `ComplexSpace`. Then the `data` array is just reshaped into
313+
matrix form and referred to as such in the resulting `TensorMap` instance. When `spacetype`
314+
is `GradedSpace`, the `TensorMap` constructor will try to reconstruct the tensor data such
315+
that the resulting tensor `t` satisfies `data == convert(Array, t)`. This might not be
316+
possible, if the data does not respect the symmetry structure. Let's sketch this with a
317+
simple example
308318
```@repl tensors
309-
data = randn(3,3,3)
310-
t = TensorMap(data, ℂ^3 ⊗ ℂ^3, ℂ^3)
311-
t ≈ TensorMap(reshape(data, (9, 3)), ℂ^3 ⊗ ℂ^3, ℂ^3)
312-
V = ℤ₂Space(0=>2, 1=>2)
313-
data = Dict(Z2Irrep(0)=>randn(8,2), Z2Irrep(1)=>randn(8,2))
314-
t2 = TensorMap(data, V*V, V)
315-
for (c,b) in blocks(t2)
319+
data = zeros(2,2,2,2)
320+
# encode the operator (σ_x * σ_x + σ_y * σ_y + σ_z * σ_z)/2
321+
# that is, the swap gate, which maps the last two indices on the first two in reversed order
322+
# also known as Heisenberg interaction between two spin 1/2 particles
323+
data[1,1,1,1] = data[2,2,2,2] = data[1,2,2,1] = data[2,1,1,2] = 1
324+
V1 = ℂ^2 # generic qubit hilbert space
325+
t1 = TensorMap(data, V1 ⊗ V1, V1 ⊗ V1)
326+
V2 = SU2Space(1/2=>1) # hilbert space of an actual spin-1/2 particle, respecting symmetry
327+
t2 = TensorMap(data, V2 ⊗ V2, V2 ⊗ V2)
328+
V3 = U1Space(1/2=>1,-1/2=>1) # restricted space that only uses the `σ_z` rotation symmetry
329+
t3 = TensorMap(data, V3 ⊗ V3, V3 ⊗ V3)
330+
for (c,b) in blocks(t3)
316331
println("Data for block $c :")
317332
b |> disp
318333
println()

docs/src/man/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ The most important objects in TensorKit.jl are tensors, which we now create with
1414
(normally distributed) entries in the following manner
1515
```@repl tutorial
1616
A = Tensor(randn, ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4)
17-
space(A)
1817
```
1918
Note that we entered the tensor size not as plain dimensions, by specifying the vector
2019
space associated with these tensor indices, in this case `ℝ^n`, which can be obtained by
@@ -140,6 +139,7 @@ Another example involves checking that `U` from the singular value decomposition
140139
```@repl tutorial
141140
codomain(U)
142141
domain(U)
142+
space(U)
143143
U'*U # should be the identity on the corresponding domain = codomain
144144
U'*U ≈ one(U'*U)
145145
P = U*U' # should be a projector

0 commit comments

Comments
 (0)