Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
annamariadziubyna committed Nov 23, 2023
1 parent 250b4e3 commit efccf1c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Documenter, SpinGlassTensors

_pages = [
"User guide" => "index.md",
"Matrix Product States and Matrix Product Operations" => "mpo.md",
"API Reference" => "api.md"
]
# ============================
Expand Down
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ project_ket_on_bra
```
## MPS


## Compresions and Contractions
```@docs
update_env_left
Expand Down
4 changes: 3 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
Part of [SpinGlassPEPS](https://github.com/euro-hpc-pl/SpinGlassPEPS.jl) package. It constitutes the basis for the preparation of tensors and operations on them.

!!! info
We don't expect the user to interact with this package, as it is more of a "back-end" type. Nevertheless, we provide API references should the need arise.
We don't expect the user to interact with this package, as it is more of a "back-end" type. Nevertheless, we provide API references should the need arise.

This section of the package encompasses supplementary functionalities that serve as support for the main solver. It includes the creation and manipulation of tensors, with a particular emphasis on implementing Matrix Product States (MPS) and Matrix Product Operators (MPO).
5 changes: 5 additions & 0 deletions docs/src/mpo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Matrix Product States and Matrix Product Operations

```@docs
MpoTensor
```
36 changes: 36 additions & 0 deletions src/mps/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,49 @@ const Site = Union{Int, Rational{Int}}
const Sites = NTuple{N, Site} where N
const TensorMap{T} = Dict{Site, Union{Tensor{T, 2}, Tensor{T, 3}, Tensor{T, 4}}} # 2 and 4 - mpo; 3 - mps

"""
A mutable struct representing a Matrix Product Operator (MPO) tensor in a tensor network.
## Fields
- `top::Vector{Tensor{T, 2}}`: Vector of tensors representing the top tensor of the MPO. Empty if `N == 2`.
- `ctr::Union{Tensor{T, N}, Nothing}`: Central tensor of the MPO. `Nothing` if not present.
- `bot::Vector{Tensor{T, 2}}`: Vector of tensors representing the bottom tensor of the MPO. Empty if `N == 2`.
- `dims::Dims{N}`: Dimensions of the MPO tensor.
## Description
`MpoTensor{T, N}` is a mutable struct that represents a Matrix Product Operator tensor in a tensor network.
The MPO tensor is characterized by its top and bottom tensors, a central tensor (`ctr`), and dimensions (`dims`).
The top and bottom legs are vectors of two-dimensional tensors (`Tensor{T, 2}`).
The central tensor is of type `Tensor{T, N}` or `Nothing` if not present.
The dimensions of the MPO tensor are specified by `dims`.
"""
mutable struct MpoTensor{T <: Real, N}
top::Vector{Tensor{T, 2}} # N == 2 top = []
ctr::Union{Tensor{T, N}, Nothing}
bot::Vector{Tensor{T, 2}} # N == 2 bot = []
dims::Dims{N}
end

# """
# Constructor function for creating a Matrix Product Operator (MPO) tensor from a `TensorMap`.

# ## Arguments
# - `ten::TensorMap{T}`: A dictionary mapping `Site` indices to tensors of type `Tensor{T, 2}`, `Tensor{T, 3}`, or `Tensor{T, 4}`. The key `0` represents the central tensor (`ctr`) of the MPO.

# ## Returns
# - An instance of `MpoTensor{T, nn}` representing the Matrix Product Operator.

# ## Description
# The `MpoTensor` function constructs a Matrix Product Operator tensor from a `TensorMap`,
# where the keys are `Site` indices and the values are tensors of appropriate dimensions.
# The construction process involves sorting the tensor dictionary based on the site indices
# and separating tensors into the top, central, and bottom parts.
# The central tensor is identified by the key `0`.
# The resulting `MpoTensor` encapsulates the tensors along with their dimensions.

# ## Exceptions
# - Throws a `DomainError` if the central tensor (`ctr`) has dimensions other than 2 or 4.
# """
function MpoTensor(ten::TensorMap{T}) where T
sk = sort(collect(keys(ten)))
top = [ten[k] for k sk if k < 0]
Expand Down

0 comments on commit efccf1c

Please sign in to comment.