You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/performancetips.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -193,7 +193,7 @@ Slicing technique has been used for graphs with space complexity greater than ``
193
193
While in panel (d), the computation time of configuration enumeration also strongly correlates with other factors such as the configuration space size.
194
194
Among these benchmarks, computational tasks with data types real numbers, complex numbers, or [`Tropical`](@ref) numbers (CPU only) can utilize fast basic linear algebra subprograms (BLAS) functions. These tasks usually compute much faster than ones with other element types in the same category.
195
195
Immutable data types with no reference to other values can be compiled to GPU devices that run much faster than CPUs in all cases when the problem scale is big enough.
196
-
These data types do not include those defined in [`Polynomial`](@ref), [`ConfigEnumerator`](@ref), [`ExtendedTropical`](@ref) and [`SumProductTree`](@ref) or a data type containing them as a part.
196
+
These data types do not include those defined in [`Polynomial`](https://juliamath.github.io/Polynomials.jl/stable/polynomials/polynomial/#Polynomial-2), [`ConfigEnumerator`](@ref), [`ExtendedTropical`](@ref) and [`SumProductTree`](@ref) or a data type containing them as a part.
197
197
In panel (c), one can see the Fourier transformation-based method is the fastest in computing the independence polynomial,
198
198
but it may suffer from round-off errors. The finite field (GF(p)) approach is the only method that does not have round-off errors and can be run on a GPU.
199
199
In panel (d), one can see the technique to bound the enumeration space (see paper) improves the performance formore than one order of magnitudein enumerating the MISs. The bounding technique can also reduce the memory usage significantly, without which the largest computable graph size is only ``\sim150`` on a device with 32GB main memory.
Copy file name to clipboardExpand all lines: docs/src/ref.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ Matching
9
9
Coloring
10
10
DominatingSet
11
11
SpinGlass
12
+
MaxCut
12
13
PaintShop
13
14
Satisfiability
14
15
SetCovering
@@ -28,6 +29,7 @@ labels
28
29
terms
29
30
flavors
30
31
get_weights
32
+
chweights
31
33
nflavor
32
34
fixedvertices
33
35
```
@@ -93,7 +95,7 @@ SumProductTree
93
95
ConfigSampler
94
96
```
95
97
96
-
`GenericTensorNetworks` also exports the [`Polynomial`](https://juliamath.github.io/Polynomials.jl/stable/polynomials/polynomial/#Polynomial-2)type defined in package `Polynomials`.
98
+
`GenericTensorNetworks` also exports the [`Polynomial`](https://juliamath.github.io/Polynomials.jl/stable/polynomials/polynomial/#Polynomial-2)and [`LaurentPolynomial`](https://juliamath.github.io/Polynomials.jl/stable/polynomials/polynomial/#Polynomials.LaurentPolynomial) types defined in package `Polynomials`.
locations = [[rot15(0.0, 2.0, i) for i=0:4]..., [rot15(0.0, 1.0, i) for i=0:4]...]
22
+
23
+
show_graph(graph; locs=locations, format=:svg)
24
+
25
+
# ## Generic tensor network representation
26
+
# We define the cutting problem as
27
+
problem =MaxCut(graph);
28
+
29
+
# ### Theory (can skip)
30
+
#
31
+
# We associated a vertex ``v\in V`` with a boolean degree of freedom ``s_v\in\{0, 1\}``.
32
+
# Then the maximum cutting problem can be encoded to tensor networks by mapping an edge ``(i,j)\in E`` to an edge matrix labelled by ``s_i`` and ``s_j``
33
+
# ```math
34
+
# B(x_i, x_j, w_{ij}) = \left(\begin{matrix}
35
+
# 1 & x_{i}^{w_{ij}}\\
36
+
# x_{j}^{w_{ij}} & 1
37
+
# \end{matrix}\right),
38
+
# ```
39
+
# where ``w_{ij}`` is a real number associated with edge ``(i, j)`` as the edge weight.
40
+
# If and only if the bipartition cuts on edge ``(i, j)``,
41
+
# this tensor contributes a factor ``x_{i}^{w_{ij}}`` or ``x_{j}^{w_{ij}}``.
42
+
# Similarly, one can assign weights to vertices, which corresponds to the onsite energy terms in the spin glass.
43
+
# The vertex tensor is
44
+
# ```math
45
+
# W(x_i, w_i) = \left(\begin{matrix}
46
+
# 1\\
47
+
# x_{i}^{w_i}
48
+
# \end{matrix}\right),
49
+
# ```
50
+
# where ``w_i`` is a real number associated with vertex ``i`` as the vertex weight.
51
+
52
+
# 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``.
53
+
54
+
# ## Solving properties
55
+
# ### Maximum cut size ``\gamma(G)``
56
+
max_cut_size =solve(problem, SizeMax())[]
57
+
58
+
# ### Counting properties
59
+
# ##### graph polynomial
60
+
# The graph polynomial defined for the cutting problem is
61
+
# ```math
62
+
# C(G, x) = \sum_{k=0}^{\gamma(G)} c_k x^k,
63
+
# ```
64
+
# where ``\gamma(G)`` is the maximum cut size,
65
+
# ``c_k/2`` is the number of cuts of size ``k`` in graph ``G=(V,E)``.
66
+
# Since the variable ``x`` is defined on edges,
67
+
# the coefficients of the polynomial is the number of configurations having different number of anti-parallel edges.
# It is highly recommended to read the [Independent set problem](@ref) chapter before reading this one.
5
5
6
6
# ## Problem definition
7
7
# Let ``G=(V, E)`` be a graph, the [spin-glass](https://en.wikipedia.org/wiki/Spin_glass) problem in physics is characterized by the following energy function
# where ``h_i`` is an onsite energy term associated with spin ``s_i \in \{0, 1\}``, and ``J_{ij}`` is the coupling strength between spins ``s_i`` and ``s_j``.
12
-
#
13
-
# The spin glass problem very close related to the cutting problem in graph theory.
14
-
# A [cut](https://en.wikipedia.org/wiki/Cut_(graph_theory)) is a partition of the vertices of a graph into two disjoint subsets.
15
-
# Finding the maximum cut (the spin glass maximum energy) is NP-Hard, where a maximum cut is a cut whose size is at least the size of any other cut,
16
-
# where the size of a cut is the number of edges (or the sum of weights on edges) crossing the cut.
11
+
# where ``h_i`` is an onsite energy term associated with spin ``s_i \in \{-1, 1\}``, and ``J_{ij}`` is the coupling strength between spins ``s_i`` and ``s_j``.
12
+
# In the program, we use boolean variable ``n_i = \frac{1-s_i}{2}`` to represent a spin configuration.
17
13
18
14
using GenericTensorNetworks, Graphs
19
15
@@ -29,52 +25,46 @@ locations = [[rot15(0.0, 2.0, i) for i=0:4]..., [rot15(0.0, 1.0, i) for i=0:4]..
29
25
show_graph(graph; locs=locations, format=:svg)
30
26
31
27
# ## Generic tensor network representation
32
-
# We define the spin glass problem as
33
-
problem =SpinGlass(graph);
28
+
# We define an anti-ferromagnetic spin glass problem as
29
+
problem =SpinGlass(graph; J=fill(-1, ne(graph)));
34
30
35
31
# ### Theory (can skip)
36
-
#
37
-
# For a vertex ``v\in V``, we define a boolean degree of freedom ``s_v\in\{0, 1\}``.
38
-
# Then the spin glass problem can be encoded to tensor networks by mapping an edge ``(i,j)\in E`` to an edge matrix labelled by ``s_is_j``
32
+
# The spin glass problem is reduced to the [Cutting problem](@ref) for solving.
33
+
# Let ``G=(V,E)`` be a graph, the cutting problem can also be described by the following energy model
39
34
# ```math
40
-
# B(x_{\langle i, j\rangle}) = \left(\begin{matrix}
41
-
# 1 & x_{\langle i, j\rangle}^{w_{\langle i,j \rangle}}\\
42
-
# x_{\langle i, j\rangle}^{w_{\langle i,j \rangle}} & 1
# If and only if the spin configuration is anti-parallel on edge ``(i, j)``,
46
-
# this tensor contributes a factor ``x_{\langle i, j\rangle}^{w_{\langle i,j \rangle}}``,
47
-
# where ``w_{\langle i,j\rangle}`` is the weight of this edge.
48
-
# Similar to other problems, we can define a polynomial about edges variables by setting ``x_{\langle i, j\rangle} = x``,
49
-
# where its k-th coefficient is two times the number of configurations with energy (cut size) k.
50
-
51
-
# 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``.
37
+
# where ``n_i`` is the same as the partition index in the cutting problem,
38
+
# ``C_{ij} = 2J_{ij}`` are edge weights and ``w_i = -2h_i`` are vertex weights.
39
+
# The total energy is shifted by ``-\sum_{ij\in E}J_{ij} + \sum_{i \in V} h_i``.
52
40
53
41
# ## Solving properties
54
-
# ### Maximum energy ``E^*(G)``
42
+
# ### Minimum and maximum energies
43
+
# Its ground state energy is -9.
44
+
Emin =solve(problem, SizeMin())[]
45
+
# While the state correspond to the highest energy has the ferromagnetic order.
55
46
Emax =solve(problem, SizeMax())[]
56
47
57
48
# ### Counting properties
58
49
# ##### graph polynomial
59
-
# The graph polynomial defined for the spin glass problem is
50
+
# The graph polynomial defined for the spin glass problem is a Laurent polynomial
0 commit comments