Skip to content

Commit

Permalink
Some docs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed May 4, 2024
1 parent 935c15d commit 1318c5d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 166 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ EinExprs = "0.5, 0.6"
GraphMakie = "0.4,0.5"
Graphs = "1.7"
LinearAlgebra = "1.9"
Makie = "0.18, 0.19"
Makie = "0.18,0.19,0.20"
Muscle = "0.1"
OMEinsum = "0.7, 0.8"
Random = "1.9"
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ makedocs(;
"Alternatives" => "alternatives.md",
"References" => "references.md",
],
pagesonly=true,
format=Documenter.HTML(;
prettyurls=false, assets=["assets/favicon.ico", "assets/citations.css", "assets/youtube.css"]
),
Expand Down
202 changes: 39 additions & 163 deletions docs/src/transformations.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,6 @@ using GraphMakie
using CairoMakie
using Tenet
using NetworkLayout
function smooth_annotation!(f; color=Makie.RGBAf(110 // 256, 170 // 256, 250 // 256, 60 // 256), xlims=[-2, 2], ylims=[-2, 2], offset_x=0.0, offset_y=0.0, radius_x=1.0, radius_y=1.0, num_waves=5, fluctuation_amplitude=0.1, phase_shift=0.0)
ax = Axis(f)
hidedecorations!(ax)
hidespines!(ax)
# Define limits of the plot
xlims!(ax, xlims...)
ylims!(ax, ylims...)
# Create a perturbed filled shape
theta = LinRange(0, 2π, 100)
fluctuations = fluctuation_amplitude .* sin.(num_waves .* theta .+ phase_shift)
# Apply the fluctuations and radius scaling
perturbed_radius_x = radius_x .+ fluctuations
perturbed_radius_y = radius_y .+ fluctuations
circle_points = [Point2f((perturbed_radius_x[i]) * cos(theta[i]) + offset_x,
(perturbed_radius_y[i]) * sin(theta[i]) + offset_y) for i in eachindex(theta)]
poly!(ax, circle_points, color=color, closed=true)
end
bg_blue = Makie.RGBAf(110 // 256, 170 // 256, 250 // 256, 50 // 256)
orange = Makie.RGBf(240 // 256, 180 // 256, 100 // 256)
red = Makie.RGBf(240 // 256, 90 // 256, 70 // 256)
```

In tensor network computations, it is good practice to apply various transformations to simplify the network structure, reduce computational cost, or prepare the network for further operations. These transformations modify the network's structure locally by permuting, contracting, factoring or truncating tensors.
Expand All @@ -59,6 +31,33 @@ Tenet.HyperFlatten
Tenet.HyperGroup
```

### Contraction simplification

```@docs
Tenet.ContractSimplification
```

```@example plot
set_theme!(resolution=(800,200)) # hide
fig = Figure() #hide
A = Tensor(rand(2, 2, 2, 2), (:i, :j, :k, :l)) #hide
B = Tensor(rand(2, 2), (:i, :m)) #hide
C = Tensor(rand(2, 2, 2), (:m, :n, :o)) #hide
E = Tensor(rand(2, 2, 2, 2), (:o, :p, :q, :j)) #hide
tn = TensorNetwork([A, B, C, E]) #hide
reduced = transform(tn, Tenet.ContractSimplification) #hide
graphplot!(fig[1, 1], tn; layout=Stress(), labels=true) #hide
graphplot!(fig[1, 2], reduced; layout=Stress(), labels=true) #hide
Label(fig[1, 1, Bottom()], "Original") #hide
Label(fig[1, 2, Bottom()], "Transformed") #hide
fig #hide
```

### Diagonal reduction

```@docs
Expand All @@ -85,33 +84,8 @@ C = Tensor(rand(2, 2), (:j, :n)) #hide
tn = TensorNetwork([A, B, C]) #hide
reduced = transform(tn, Tenet.DiagonalReduction) #hide
smooth_annotation!( #hide
fig[1, 1]; #hide
color = bg_blue, #hide
xlims = [-2, 2], #hide
ylims = [-2, 2], #hide
offset_x = -0.21, #hide
offset_y = -0.42, #hide
radius_x = 0.38, #hide
radius_y = 0.8, #hide
num_waves = 6, #hide
fluctuation_amplitude = 0.02, #hide
phase_shift = 0.0) #hide
graphplot!(fig[1, 1], tn, layout=Spring(iterations=1000, C=0.5, seed=100); node_color=[red, orange, orange]) #hide
smooth_annotation!( #hide
fig[1, 2]; #hide
color = bg_blue, #hide
xlims = [-2, 2], #hide
ylims = [-2, 2], #hide
offset_x = 0.1, #hide
offset_y = -0.35, #hide
radius_x = 0.38, #hide
radius_y = 1.1, #hide
num_waves = 5, #hide
fluctuation_amplitude = 0.02, #hide
phase_shift = 1.9) #hide
graphplot!(fig[1, 2], reduced, layout=Spring(iterations=1000, C=0.5, seed=100), node_color=[orange, orange, red, :black]) #hide
graphplot!(fig[1, 1], tn; layout=Stress(), labels=true) #hide
graphplot!(fig[1, 2], reduced; layout=Stress(), labels=true) #hide
Label(fig[1, 1, Bottom()], "Original") #hide
Label(fig[1, 2, Bottom()], "Transformed") #hide
Expand All @@ -125,59 +99,7 @@ fig #hide
Tenet.AntiDiagonalGauging
```

### Contraction simplification

```@docs
Tenet.ContractSimplification
```

```@example plot
set_theme!(resolution=(800,200)) # hide
fig = Figure() #hide
A = Tensor(rand(2, 2, 2, 2), (:i, :j, :k, :l)) #hide
B = Tensor(rand(2, 2), (:i, :m)) #hide
C = Tensor(rand(2, 2, 2), (:m, :n, :o)) #hide
E = Tensor(rand(2, 2, 2, 2), (:o, :p, :q, :j)) #hide
tn = TensorNetwork([A, B, C, E]) #hide
reduced = transform(tn, Tenet.ContractSimplification) #hide
smooth_annotation!( #hide
fig[1, 1]; #hide
color = bg_blue, #hide
xlims = [-2, 2], #hide
ylims = [-2, 2], #hide
offset_x = -0.32, #hide
offset_y = -0.5, #hide
radius_x = 0.25, #hide
radius_y = 0.94, #hide
num_waves = 6, #hide
fluctuation_amplitude = 0.01, #hide
phase_shift = 0.0) #hide
graphplot!(fig[1, 1], tn, layout=Spring(iterations=1000, C=0.5, seed=20); node_color=[orange, red, orange, orange]) #hide
smooth_annotation!( #hide
fig[1, 2]; #hide
color = bg_blue, #hide
xlims = [-2, 2], #hide
ylims = [-2, 2], #hide
offset_x = 0.12, #hide
offset_y = -0.62, #hide
radius_x = 0.18, #hide
radius_y = 0.46, #hide
num_waves = 5, #hide
fluctuation_amplitude = 0.01, #hide
phase_shift = 0) #hide
graphplot!(fig[1, 2], reduced, layout=Spring(iterations=1000, C=0.5, seed=1); node_color=[red, orange, orange]) #hide
Label(fig[1, 1, Bottom()], "Original") #hide
Label(fig[1, 2, Bottom()], "Transformed") #hide
fig #hide
```

### Column reduction
### Dimension truncation

```@docs
Tenet.Truncate
Expand All @@ -197,36 +119,11 @@ C = Tensor(rand(3, 3), (:l, :m)) #hide
tn = TensorNetwork([A, B, C]) #hide
reduced = transform(tn, Tenet.Truncate) #hide
smooth_annotation!( #hide
fig[1, 1]; #hide
color = bg_blue, #hide
xlims = [-2, 2], #hide
ylims = [-2, 2], #hide
offset_x = -1.12, #hide
offset_y = -0.22, #hide
radius_x = 0.35, #hide
radius_y = 0.84, #hide
num_waves = 4, #hide
fluctuation_amplitude = 0.02, #hide
phase_shift = 0.0) #hide
graphplot!(fig[1, 1], tn, layout=Spring(iterations=1000, C=0.5, seed=6); node_color=[red, orange, orange]) #hide
smooth_annotation!( #hide
fig[1, 2]; #hide
color = bg_blue, #hide
xlims = [-2, 2], #hide
ylims = [-2, 2], #hide
offset_x = -0.64, #hide
offset_y = 1.2, #hide
radius_x = 0.32, #hide
radius_y = 0.78, #hide
num_waves = 5, #hide
fluctuation_amplitude = 0.02, #hide
phase_shift = 0) #hide
graphplot!(fig[1, 1], tn; layout=Spring(C=10), labels=true) #hide
graphplot!(fig[1, 2], reduced; layout=Spring(C=10), labels=true) #hide
Label(fig[1, 1, Bottom()], "Original") #hide
Label(fig[1, 2, Bottom()], "Transformed") #hide
graphplot!(fig[1, 2], reduced, layout=Spring(iterations=2000, C=40, seed=8); node_color=[red, orange, orange]) #hide
fig #hide
```
Expand All @@ -248,39 +145,18 @@ m1 = Tensor(rand(3, 3), (:k, :l)) #hide
t1 = contract(v1, v2) #hide
tensor = contract(t1, m1) #hide
tn = TensorNetwork([tensor, Tensor(rand(3, 3, 3), (:k, :m, :n)), Tensor(rand(3, 3, 3), (:l, :n, :o))]) #hide
tn = TensorNetwork([ #hide
tensor, #hide
Tensor(rand(3, 3, 3), (:k, :m, :n)), #hide
Tensor(rand(3, 3, 3), (:l, :n, :o)) #hide
]) #hide
reduced = transform(tn, Tenet.SplitSimplification) #hide
smooth_annotation!( #hide
fig[1, 1]; #hide
color = bg_blue, #hide
xlims = [-2, 2], #hide
ylims = [-2, 2], #hide
offset_x = 0.24, #hide
offset_y = 0.6, #hide
radius_x = 0.32, #hide
radius_y = 0.78, #hide
num_waves = 5, #hide
fluctuation_amplitude = 0.015, #hide
phase_shift = 0.0) #hide
graphplot!(fig[1, 1], tn, layout=Spring(iterations=10000, C=0.5, seed=12); node_color=[red, orange, orange]) #hide
smooth_annotation!( #hide
fig[1, 2]; #hide
color = bg_blue, #hide
xlims = [-2, 2], #hide
ylims = [-2, 2], #hide
offset_x = -0.2, #hide
offset_y = -0.4, #hide
radius_x = 1.1, #hide
radius_y = 0.75, #hide
num_waves = 3, #hide
fluctuation_amplitude = 0.18, #hide
phase_shift = 0.8) #hide
graphplot!(fig[1, 1], tn; layout=Stress(), labels=true) #hide
graphplot!(fig[1, 2], reduced, layout=Spring(C=11); labels=true) #hide
Label(fig[1, 1, Bottom()], "Original") #hide
Label(fig[1, 2, Bottom()], "Transformed") #hide
graphplot!(fig[1, 2], reduced, layout=Spring(iterations=10000, C=13, seed=151); node_color=[orange, orange, red, red, red]) #hide
fig #hide
```
6 changes: 4 additions & 2 deletions docs/src/visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
```@setup viz
using Makie
using GraphMakie
using NetworkLayout
Makie.inline!(true)
set_theme!(resolution=(800,400))
Expand All @@ -12,13 +14,13 @@ CairoMakie.activate!(type = "svg")
using Tenet
```

`Tenet` provides a Package Extension for `Makie` support. You can just import a `Makie` backend and call [`Makie.plot`](@ref) on a [`TensorNetwork`](@ref).
`Tenet` provides a Package Extension for `Makie` support. You can just import a `Makie` backend and call [`GraphMakie.graphplot`](@ref) on a [`TensorNetwork`](@ref).

```@docs
GraphMakie.graphplot(::Tenet.TensorNetwork)
```

```@example viz
tn = rand(TensorNetwork, 14, 4, seed=0) # hide
graphplot(tn, labels=true)
graphplot(tn, layout=Stress(), labels=true)
```

0 comments on commit 1318c5d

Please sign in to comment.