Skip to content

Commit 5346fc8

Browse files
authored
Polish docs 1 (#12)
* rename independence * rename independence
1 parent e3459cd commit 5346fc8

35 files changed

+423
-463
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ julia> using GraphTensorNetworks, Random, Graphs
5050
julia> graph = (Random.seed!(2); Graphs.smallgraph(:petersen))
5151
{10, 15} undirected simple Int64 graph
5252

53-
julia> problem = Independence(graph; optimizer=TreeSA(sc_target=0, sc_weight=1.0, ntrials=10, βs=0.01:0.1:15.0, niters=20, rw_weight=0.2));
53+
julia> problem = IndependentSet(graph; optimizer=TreeSA(sc_target=0, sc_weight=1.0, ntrials=10, βs=0.01:0.1:15.0, niters=20, rw_weight=0.2));
5454
┌ Warning: target space complexity not found, got: 4.0, with time complexity 7.965784284662087, read-right complexity 8.661778097771988.
5555
└ @ OMEinsumContractionOrders ~/.julia/dev/OMEinsumContractionOrders/src/treesa.jl:71
5656
time/space complexity is (7.965784284662086, 4.0)
5757
```
5858

59-
Here, the `problem` is a `Independence` instance, it contains the tensor network contraction tree for the target graph.
59+
Here, the `problem` is a `IndependentSet` instance, it contains the tensor network contraction tree for the target graph.
6060
Here, we choose the `TreeSA` optimizer to optimize the tensor network contraciton tree, it is a local search based algorithm, check [arXiv: 2108.05665](https://arxiv.org/abs/2108.05665). You will see some warnings, do not panic, this is because we set `sc_target` (target space complex) to 1 for agressive optimization of space complexity. Type `?TreeSA` in a Julia REPL for more information about the key word arguments.
61-
Similarly, one can select tensor network structures for solving other problems like `MaximalIndependence`, `MaxCut`, `Matching`, `Coloring{K}`, `PaintShop` and `set_packing`.
61+
Similarly, one can select tensor network structures for solving other problems like `MaximalIS`, `MaxCut`, `Matching`, `Coloring{K}`, `PaintShop` and `set_packing`.
6262

6363
#### 1. find MIS size, count MISs and count ISs
6464
```julia

docs/make.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ using DocThemeIndigo
66
using Literate
77

88
for each in readdir(pkgdir(GraphTensorNetworks, "examples"))
9-
project_dir = pkgdir(GraphTensorNetworks, "examples", each)
10-
isdir(project_dir) || continue
11-
@info "building" project_dir
12-
input_file = pkgdir(GraphTensorNetworks, "examples", each, "main.jl")
9+
input_file = pkgdir(GraphTensorNetworks, "examples", each)
10+
endswith(input_file, ".jl") || continue
11+
@info "building" input_file
1312
output_dir = pkgdir(GraphTensorNetworks, "docs", "src", "tutorials")
1413
@info "executing" input_file
15-
Literate.markdown(input_file, output_dir; name=each, execute=false)
14+
Literate.markdown(input_file, output_dir; name=each[1:end-3], execute=false)
1615
end
1716

1817
indigo = DocThemeIndigo.install(GraphTensorNetworks)
@@ -24,17 +23,17 @@ makedocs(;
2423
repo="https://github.com/Happy-Diode/GraphTensorNetworks.jl/blob/{commit}{path}#{line}",
2524
sitename="GraphTensorNetworks.jl",
2625
format=Documenter.HTML(;
27-
prettyurls=get(ENV, "CI", "false") == "true",
26+
prettyurls=false,
2827
canonical="https://Happy-Diode.github.io/GraphTensorNetworks.jl",
2928
assets=String[indigo],
3029
),
3130
pages=[
3231
"Home" => "index.md",
3332
"Tutorials" => [
34-
"Independent set problem" => "tutorials/Independence.md",
35-
"Maximal independent set problem" => "tutorials/MaximalIndependence.md",
33+
"Independent set problem" => "tutorials/IndependentSet.md",
34+
"Maximal independent set problem" => "tutorials/MaximalIS.md",
3635
"Cutting problem" => "tutorials/MaxCut.md",
37-
"Matching problem" => "tutorials/Coloring.md",
36+
"Matching problem" => "tutorials/Matching.md",
3837
"Binary paint shop problem" => "tutorials/PaintShop.md",
3938
"Coloring problem" => "tutorials/Coloring.md",
4039
"Other problems" => "tutorials/Others.md",

docs/src/ref.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
```@docs
44
solve
55
GraphProblem
6-
Independence
7-
MaximalIndependence
6+
IndependentSet
7+
MaximalIS
88
Matching
99
Coloring
1010
MaxCut

examples/Coloring.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# # Coloring problem
2+
3+
# !!! note
4+
# This tutorial only covers the coloring problem specific features,
5+
# It is recommended to read the [Independent set problem](@ref) tutorial too to know more about
6+
# * how to optimize the tensor network contraction order,
7+
# * what are the other graph properties computable,
8+
# * how to select correct method to compute graph properties,
9+
# * how to compute weighted graphs and handle open vertices.
10+
11+
# ## Problem definition
12+
# A [vertex coloring](https://en.wikipedia.org/wiki/Graph_coloring) is an assignment of labels or colors to each vertex of a graph such that no edge connects two identically colored vertices.
13+
# In the following, we are going to defined a 3-coloring problem for the Petersen graph.
14+
15+
using GraphTensorNetworks, Graphs
16+
17+
graph = Graphs.smallgraph(:petersen)
18+
19+
# We can visualize this graph using the following function
20+
rot15(a, b, i::Int) = cos(2i*π/5)*a + sin(2i*π/5)*b, cos(2i*π/5)*b - sin(2i*π/5)*a
21+
22+
locations = [[rot15(0.0, 1.0, i) for i=0:4]..., [rot15(0.0, 0.6, i) for i=0:4]...]
23+
24+
show_graph(graph; locs=locations)
25+
26+
# ## Tensor network representation
27+
# Type [`Coloring`](@ref) can be used for constructing the tensor network with optimized contraction order for a coloring problem.
28+
# Let us use 3-colouring problem defined on vertices as an example.
29+
# For a vertex ``v``, we define the degree of freedoms ``c_v\in\{1,2,3\}`` and a vertex tensor labelled by it as
30+
# ```math
31+
# W(v) = \left(\begin{matrix}
32+
# r_v\\
33+
# g_v\\
34+
# b_v
35+
# \end{matrix}\right).
36+
# ```
37+
# For an edge ``(u, v)``, we define an edge tensor as a matrix labelled by ``(c_u, c_v)`` to specify the constraint
38+
# ```math
39+
# B = \left(\begin{matrix}
40+
# 0 & 1 & 1\\
41+
# 1 & 0 & 1\\
42+
# 1 & 1 & 0
43+
# \end{matrix}\right).
44+
# ```
45+
# The number of possible colouring can be obtained by contracting this tensor network by setting vertex tensor elements ``r_v, g_v`` and ``b_v`` to 1.
46+
#
47+
# We construct the tensor network for the 3-coloring problem as
48+
problem = Coloring{3}(graph);
49+
50+
# ## Solving properties

examples/Coloring/main.jl

Lines changed: 0 additions & 31 deletions
This file was deleted.

examples/Independence/main.jl renamed to examples/IndependentSet.jl

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# # Independent set problem
22

3-
# ## Introduction
4-
using GraphTensorNetworks, Graphs
5-
6-
# Please check the docstring of [`Independence`](@ref) for the definition of independence problem.
7-
@doc Independence
8-
3+
# ## Problem definition
4+
# In graph theory, an [independent set](https://en.wikipedia.org/wiki/Independent_set_(graph_theory)) is a set of vertices in a graph, no two of which are adjacent.
95
# In the following, we are going to defined an independent set problem for the Petersen graph.
106

7+
using GraphTensorNetworks, Graphs
8+
119
graph = Graphs.smallgraph(:petersen)
1210

1311
# We can visualize this graph using the following function
@@ -17,17 +15,38 @@ locations = [[rot15(0.0, 1.0, i) for i=0:4]..., [rot15(0.0, 0.6, i) for i=0:4]..
1715

1816
show_graph(graph; locs=locations)
1917

18+
# ## Tensor network representation
19+
# Type [`IndependentSet`](@ref) can be used for constructing the tensor network with optimized contraction order for solving an independent set problem.
20+
# we map a vertex ``i\in V`` to a label ``s_i \in \{0, 1\}`` of dimension 2,
21+
# where we use 0 (1) to denote a vertex is absent (present) in the set.
22+
# For each label ``s_i``, we defined a parametrized rank-one vertex tensor ``W(x_i)`` as
23+
# ```math
24+
# W(x_i)_{s_i} = \left(\begin{matrix}
25+
# 1 \\
26+
# x_i
27+
# \end{matrix}\right)_{s_i}
28+
# ```
29+
# We use subscripts to index tensor elements, e.g.``W(x_i)_0=1`` is the first element associated
30+
# with ``s_i=0`` and ``W(x_i)_1=x_i`` is the second element associated with ``s_i=1``.
31+
# Similarly, on each edge ``(u, v)``, we define a matrix ``B`` indexed by ``s_u`` and ``s_v`` as
32+
# ```math
33+
# B_{s_i s_j} = \left(\begin{matrix}
34+
# 1 & 1\\
35+
# 1 & 0
36+
# \end{matrix}\right)_{s_is_j}
37+
# ```
2038
# Let us contruct the problem instance with optimized tensor network contraction order as bellow.
21-
problem = Independence(graph; optimizer=TreeSA(sc_weight=1.0, ntrials=10,
39+
problem = IndependentSet(graph; optimizer=TreeSA(sc_weight=1.0, ntrials=10,
2240
βs=0.01:0.1:15.0, niters=20, rw_weight=0.2),
2341
simplifier=MergeGreedy());
2442

25-
# The `optimizer` is for optimizing the contraction orders.
43+
# In the input arguments of [`IndependentSet`](@ref), the `optimizer` is for optimizing the contraction orders.
2644
# Here we use the local search based optimizer in [arXiv:2108.05665](https://arxiv.org/abs/2108.05665).
2745
# If no optimizer is specified, the default fast (in terms of the speed of searching contraction order)
2846
# but worst (in term of contraction complexity) [`GreedyMethod`](@ref) will be used.
2947
# `simplifier` is a preprocessing routine to speed up the `optimizer`.
30-
# Please check section [Tensor Network](@ref) for more details.
48+
# The returned instance `problem` contains a field `code` that specifies the tensor network contraction order.
49+
# Its contraction time space complexity is ``2^{{\rm tw}(G)}``, where ``{\rm tw(G)}`` is the [tree-width](https://en.wikipedia.org/wiki/Treewidth) of ``G``.
3150
# One can check the time, space and read-write complexity with the following function.
3251

3352
timespacereadwrite_complexity(problem)
@@ -48,7 +67,13 @@ count_all_independent_sets = solve(problem, CountingAll())[]
4867
count_max2_independent_sets = solve(problem, CountingMax(2))[]
4968

5069
# ##### independence polynomial
51-
# For the definition of independence polynomial, please check the docstring of [`Independence`](@ref) or this [wiki page](https://mathworld.wolfram.com/IndependencePolynomial.html).
70+
# The graph polynomial defined for the independence problem is known as the independence polynomial.
71+
# ```math
72+
# I(G, x) = \sum_{k=0}^{\alpha(G)} a_k x^k,
73+
# ```
74+
# where ``\alpha(G)`` is the maximum independent set size,
75+
# ``a_k`` is the number of independent sets of size ``k`` in graph ``G=(V,E)``.
76+
# The total number of independent sets is thus equal to ``I(G, 1)``.
5277
# There are 3 methods to compute a graph polynomial, `:finitefield`, `:fft` and `:polynomial`.
5378
# These methods are introduced in the docstring of [`GraphPolynomial`](@ref).
5479
independence_polynomial = solve(problem, GraphPolynomial(; method=:finitefield))[]
@@ -98,17 +123,17 @@ loaded_sets = load_configs(filename; format=:binary, bitlength=10)
98123
# Because the bitstring length is not stored.
99124

100125
# ## Weights and open vertices
101-
# [`Independence`] accepts weights as a key word argument.
126+
# [`IndependentSet`] accepts weights as a key word argument.
102127
# The following code computes the weighted MIS problem.
103-
problem = Independence(graph; weights=collect(1:10))
128+
problem = IndependentSet(graph; weights=collect(1:10))
104129

105130
max_config_weighted = solve(problem, SingleConfigMax())[]
106131

107132
show_graph(graph; locs=locations, colors=
108133
[iszero(max_config_weighted.c.data[i]) ? "white" : "red" for i=1:nv(graph)])
109134

110135
# The following code computes the MIS tropical tensor (reference to be added) with open vertices 1 and 2.
111-
problem = Independence(graph; openvertices=[1,2,3])
136+
problem = IndependentSet(graph; openvertices=[1,2,3])
112137

113138
mis_tropical_tensor = solve(problem, SizeMax())
114139

examples/Matching.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# # Vertex matching problem
2+
3+
# !!! note
4+
# This tutorial only covers the vertex matching problem specific features,
5+
# It is recommended to read the [Independent set problem](@ref) tutorial too to know more about
6+
# * how to optimize the tensor network contraction order,
7+
# * what are the other graph properties computable,
8+
# * how to select correct method to compute graph properties,
9+
# * how to compute weighted graphs and handle open vertices.
10+
11+
# ## Problem definition
12+
# A ``k``-matching in a graph ``G`` is a set of k edges, no two of which have a vertex in common.
13+
14+
using GraphTensorNetworks, Graphs
15+
16+
# In the following, we are going to defined a matching problem for the Petersen graph.
17+
18+
graph = Graphs.smallgraph(:petersen)
19+
20+
# We can visualize this graph using the following function
21+
rot15(a, b, i::Int) = cos(2i*π/5)*a + sin(2i*π/5)*b, cos(2i*π/5)*b - sin(2i*π/5)*a
22+
23+
locations = [[rot15(0.0, 1.0, i) for i=0:4]..., [rot15(0.0, 0.6, i) for i=0:4]...]
24+
25+
show_graph(graph; locs=locations)
26+
27+
# ## Tensor network representation
28+
# Type [`Matching`](@ref) can be used for constructing the tensor network with optimized contraction order for a matching problem.
29+
# We map an edge ``(u, v) \in E`` to a label ``\langle u, v\rangle \in \{0, 1\}`` in a tensor network,
30+
# where 1 means two vertices of an edge are matched, 0 means otherwise.
31+
# Then we define a tensor of rank ``d(v) = |N(v)|`` on vertex ``v`` such that,
32+
# ```math
33+
# W_{\langle v, n_1\rangle, \langle v, n_2 \rangle, \ldots, \langle v, n_{d(v)}\rangle} = \begin{cases}
34+
# 1, & \sum_{i=1}^{d(v)} \langle v, n_i \rangle \leq 1,\\
35+
# 0, & \text{otherwise},
36+
# \end{cases}
37+
# ```
38+
# and a tensor of rank 1 on the bond
39+
# ```math
40+
# B_{\langle v, w\rangle} = \begin{cases}
41+
# 1, & \langle v, w \rangle = 0 \\
42+
# x, & \langle v, w \rangle = 1,
43+
# \end{cases}
44+
# ```
45+
# where label ``\langle v, w \rangle`` is equivalent to ``\langle w,v\rangle``.
46+
#
47+
# We construct the tensor network for the matching problem by typing
48+
problem = Matching(graph);
49+
50+
# ## Solving properties
51+
# The graph polynomial defined for the independence problem is known as the matching polynomial.
52+
# Here, we adopt the first definition in the [wiki page](https://en.wikipedia.org/wiki/Matching_polynomial).
53+
# ```math
54+
# M(G, x) = \sum\limits_{k=1}^{|V|/2} c_k x^k,
55+
# ```
56+
# where ``k`` is the number of matches, and coefficients ``c_k`` are the corresponding counting.

examples/Matching/main.jl

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)