Skip to content

Commit

Permalink
refactor plots
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Nov 25, 2024
1 parent e6d6f0c commit e702f52
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 39 deletions.
3 changes: 1 addition & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ using Documenter
using DocumenterVitepress
using DocumenterCitations
using Tenet
using CairoMakie
using GraphMakie
using Makie
using LinearAlgebra

DocMeta.setdocmeta!(Tenet, :DocTestSetup, :(using Tenet); recursive=true)
Expand Down
49 changes: 16 additions & 33 deletions docs/src/manual/ansatz/mps.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
# Matrix Product States (MPS)

Matrix Product States (MPS) are a Quantum Tensor Network ansatz whose tensors are laid out in a 1D chain.
Due to this, these networks are also known as _Tensor Trains_ in other mathematical fields.
Depending on the boundary conditions, the chains can be open or closed (i.e. periodic boundary conditions).

```@setup viz
using Makie
Makie.inline!(true)
set_theme!(resolution=(800,200))
using CairoMakie
using Tenet
using GraphMakie
using NetworkLayout
```

```@example viz
fig = Figure() # hide
tn_open = rand(MatrixProduct{State,Open}, n=10, χ=4) # hide
tn_periodic = rand(MatrixProduct{State,Periodic}, n=10, χ=4) # hide
using Tenet
plot!(fig[1,1], tn_open, layout=Spring(iterations=1000, C=0.5, seed=100)) # hide
plot!(fig[1,2], tn_periodic, layout=Spring(iterations=1000, C=0.5, seed=100)) # hide
# Page(offline=true)
# WGLMakie.activate!()
CairoMakie.activate!(type = "svg")
Makie.inline!(true)
set_theme!(resolution=(800,200))
```

Label(fig[1,1, Bottom()], "Open") # hide
Label(fig[1,2, Bottom()], "Periodic") # hide
Matrix Product States (MPS) are a Quantum Tensor Network ansatz whose tensors are laid out in a 1D chain.
Due to this, these networks are also known as _Tensor Trains_ in other mathematical fields.
Depending on the boundary conditions, the chains can be open or closed (i.e. periodic boundary conditions).

fig # hide
```@example viz
tn = rand(MPS; n=10, maxdim=2) # hide
graphplot(tn; layout=Stress()) # hide
```

## Matrix Product Operators (MPO)
Expand All @@ -36,18 +29,8 @@ Matrix Product Operators (MPO) are the operator version of [Matrix Product State
The major difference between them is that MPOs have 2 indices per site (1 input and 1 output) while MPSs only have 1 index per site (i.e. an output).

```@example viz
fig = Figure() # hide
tn_open = rand(MatrixProduct{Operator,Open}, n=10, χ=4) # hide
tn_periodic = rand(MatrixProduct{Operator,Periodic}, n=10, χ=4) # hide
plot!(fig[1,1], tn_open, layout=Spring(iterations=1000, C=0.5, seed=100)) # hide
plot!(fig[1,2], tn_periodic, layout=Spring(iterations=1000, C=0.5, seed=100)) # hide
Label(fig[1,1, Bottom()], "Open") # hide
Label(fig[1,2, Bottom()], "Periodic") # hide
fig # hide
tn = rand(MPO, n=10, maxdim=2) # hide
graphplot(tn; layout=Stress()) # hide
```

In `Tenet`, the generic `MatrixProduct` ansatz implements this topology. Type variables are used to address their functionality (`State` or `Operator`) and their boundary conditions (`Open` or `Periodic`).
11 changes: 7 additions & 4 deletions docs/src/manual/transformations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

```@setup plot
using Makie
Makie.inline!(true)
using GraphMakie
using CairoMakie
using Tenet
using GraphMakie
using NetworkLayout
using Tenet
CairoMakie.activate!(type = "svg")
Makie.inline!(true)
set_theme!(resolution=(800,200))
```

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 Down Expand Up @@ -123,7 +126,7 @@ tn = TensorNetwork([ #hide
reduced = transform(tn, Tenet.SplitSimplification) #hide
graphplot!(fig[1, 1], tn; layout=Stress(), labels=true) #hide
graphplot!(fig[1, 2], reduced, layout=Spring(C=11); 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
Expand Down

0 comments on commit e702f52

Please sign in to comment.