Skip to content

Commit

Permalink
Interface upadte: contraction complexity (#67)
Browse files Browse the repository at this point in the history
* use `contraction_complexity` and deprecate `timespacereadwrite_complexity`

* clean up pluto notebook building

* bump version

* update

* fix-cuda onehot
  • Loading branch information
GiggleLiu committed Aug 15, 2023
1 parent 39fea47 commit deb722d
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 288 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GenericTensorNetworks"
uuid = "3521c873-ad32-4bb4-b63d-f4f178f42b49"
authors = ["GiggleLiu <cacate0129@gmail.com> and contributors"]
version = "1.3.4"
version = "1.3.5"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ GenericTensorNetworks = "3521c873-ad32-4bb4-b63d-f4f178f42b49"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589"
PlutoStaticHTML = "359b1769-a58e-495b-9770-312e911026ad"
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
17 changes: 0 additions & 17 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ using GenericTensorNetworks
using GenericTensorNetworks: TropicalNumbers, Polynomials, Mods, OMEinsum, OMEinsum.OMEinsumContractionOrders, LuxorGraphPlot
using Documenter
using DocThemeIndigo
using PlutoStaticHTML
using Literate

for each in readdir(pkgdir(GenericTensorNetworks, "examples"))
Expand All @@ -14,22 +13,6 @@ for each in readdir(pkgdir(GenericTensorNetworks, "examples"))
Literate.markdown(input_file, output_dir; name=each[1:end-3], execute=false)
end

let
"""Run all Pluto notebooks (".jl" files) in `notebook_dir` and write outputs to HTML files."""
notebook_dir = joinpath(pkgdir(GenericTensorNetworks), "notebooks")
target_dir = joinpath(pkgdir(GenericTensorNetworks), "docs", "src", "notebooks")
cp(notebook_dir, target_dir; force=true)
@info "Building tutorials"
# Evaluate notebooks in the same process to avoid having to recompile from scratch each time.
# This is similar to how Documenter and Franklin evaluate code.
# Note that things like method overrides and other global changes may leak between notebooks!
use_distributed = true
output_format = documenter_output
bopts = BuildOptions(target_dir; use_distributed, output_format)
build_notebooks(bopts)
return nothing
end

indigo = DocThemeIndigo.install(GenericTensorNetworks)
DocMeta.setdocmeta!(GenericTensorNetworks, :DocTestSetup, :(using GenericTensorNetworks); recursive=true)

Expand Down
20 changes: 13 additions & 7 deletions docs/src/performancetips.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ It can remove all vertex tensors (vectors) before entering the contraction order

The returned object `problem` contains a field `code` that specifies the tensor network with optimized contraction order.
For an independent set problem, the optimal contraction time/space complexity is ``\sim 2^{{\rm tw}(G)}``, where ``{\rm tw(G)}`` is the [tree-width](https://en.wikipedia.org/wiki/Treewidth) of ``G``.
One can check the time, space and read-write complexity with the [`timespacereadwrite_complexity`](@ref) function.
One can check the time, space and read-write complexity with the [`contraction_complexity`](@ref) function.

```julia
julia> timespacereadwrite_complexity(problem)
(21.90683335864693, 17.0, 20.03588509836998)
julia> contraction_complexity(problem)
Time complexity (number of element-wise multiplications) = 2^20.568850503058382
Space complexity (number of elements in the largest intermediate tensor) = 2^16.0
Read-write complexity (number of element-wise read and write) = 2^18.70474460304404
```

The return values are `log2` values of the number of multiplications, the number elements in the largest tensor during contraction and the number of read-write operations to tensor elements.
Expand Down Expand Up @@ -81,13 +83,17 @@ julia> graph = random_regular_graph(120, 3)

julia> problem = IndependentSet(graph; optimizer=TreeSA(βs=0.01:0.1:25.0, ntrials=10, niters=10));

julia> timespacereadwrite_complexity(problem)
(20.856518235241687, 16.0, 18.88208476145812)
julia> contraction_complexity(problem)
Time complexity (number of element-wise multiplications) = 2^20.53277253647484
Space complexity (number of elements in the largest intermediate tensor) = 2^16.0
Read-write complexity (number of element-wise read and write) = 2^19.34699193791874

julia> problem = IndependentSet(graph; optimizer=TreeSA(βs=0.01:0.1:25.0, ntrials=10, niters=10, nslices=5));

julia> timespacereadwrite_complexity(problem)
(21.134967710592804, 11.0, 19.84529401927876)
julia> contraction_complexity(problem)
Time complexity (number of element-wise multiplications) = 2^21.117277836449578
Space complexity (number of elements in the largest intermediate tensor) = 2^11.0
Read-write complexity (number of element-wise read and write) = 2^19.854965754099602
```

In the second `IndependentSet` constructor, we slice over 5 degrees of freedom, which can reduce the space complexity by at most 5.
Expand Down
1 change: 0 additions & 1 deletion docs/src/ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ MergeGreedy
show_graph
show_gallery
show_einsum
spring_layout!
diagonal_coupled_graph
square_lattice_graph
Expand Down
2 changes: 1 addition & 1 deletion examples/DominatingSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ problem = DominatingSet(graph; optimizer=TreeSA());
# otherwise, if ``v`` is in ``D``, it has a contribution ``x_v^{w_v}`` to the final result.
# One can check the contraction time space complexity of a [`DominatingSet`](@ref) instance by typing:

timespacereadwrite_complexity(problem)
contraction_complexity(problem)

# ## Solving properties

Expand Down
3 changes: 1 addition & 2 deletions examples/IndependentSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ problem = IndependentSet(graph; optimizer=TreeSA());
# where ``{\rm tw(G)}`` is the [tree-width](https://en.wikipedia.org/wiki/Treewidth) of ``G`` (or `graph` in the code).
# We can check the time, space and read-write complexities by typing

timespacereadwrite_complexity(problem)
contraction_complexity(problem)

# The three return values are `log2` values of the the number of element-wise multiplication operations, the number elements in the largest tensor during contraction and the number of tensor element read-write operations.
# For more information about how to improve the contraction order, please check the [Performance Tips](@ref).

# ## Solution space properties
Expand Down
4 changes: 1 addition & 3 deletions examples/MaximalIS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ problem = MaximalIS(graph; optimizer=TreeSA());
# Its contraction time space complexity of a [`MaximalIS`](@ref) instance is no longer determined by the tree-width of the original graph ``G``.
# It is often harder to contract this tensor network than to contract the one for regular independent set problem.

timespacereadwrite_complexity(problem)

# Results are `log2` values.
contraction_complexity(problem)

# ## Solving properties

Expand Down
2 changes: 1 addition & 1 deletion examples/SetCovering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ problem = SetCovering(sets);
# This tensor means if none of the sets containing element ``a`` are included, then this configuration is forbidden,
# One can check the contraction time space complexity of a [`SetCovering`](@ref) instance by typing:

timespacereadwrite_complexity(problem)
contraction_complexity(problem)

# ## Solving properties

Expand Down
2 changes: 1 addition & 1 deletion examples/SetPacking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ problem = SetPacking(sets);
# This tensor means if in a configuration, two sets contain the element ``a``, then this configuration is forbidden,
# One can check the contraction time space complexity of a [`SetPacking`](@ref) instance by typing:

timespacereadwrite_complexity(problem)
contraction_complexity(problem)

# ## Solving properties

Expand Down
Loading

0 comments on commit deb722d

Please sign in to comment.