Skip to content

Commit 460a30d

Browse files
committed
fix documents
1 parent 9cf235c commit 460a30d

File tree

16 files changed

+63
-67
lines changed

16 files changed

+63
-67
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
2. Rename `best_solutions` to `largest_solutions`, `best2_solutions` to `largest2_solutions` and `bestk_solutions` to `largestk_solutions`.
55
3. Remove the weights from `PaintShop`.
66
4. Remove the weights on vertices from `MaxCut`.
7-
5. `SpinGlass` is no longer specified by cliques. It is now specified by graphs or hypergraphs. Weights can be defined on both edges and vertices.
7+
5. `SpinGlass` is no longer specified by cliques. It is now specified by graphs or hypergraphs. Weights can be defined on both edges and vertices.
8+
6. Remove `unit_disk_graph`, replace it with `UnitDiskGraph` from `ProblemReductions`.

docs/make.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Pkg
22
using GenericTensorNetworks
3-
using GenericTensorNetworks: TropicalNumbers, Polynomials, OMEinsum, OMEinsum.OMEinsumContractionOrders, LuxorGraphPlot
3+
using GenericTensorNetworks: TropicalNumbers, Polynomials, OMEinsum, OMEinsum.OMEinsumContractionOrders, LuxorGraphPlot, ProblemReductions
44
using Documenter
55
using DocThemeIndigo
66
using Literate
@@ -17,7 +17,7 @@ indigo = DocThemeIndigo.install(GenericTensorNetworks)
1717
DocMeta.setdocmeta!(GenericTensorNetworks, :DocTestSetup, :(using GenericTensorNetworks); recursive=true)
1818

1919
makedocs(;
20-
modules=[GenericTensorNetworks, TropicalNumbers, OMEinsum, OMEinsumContractionOrders, LuxorGraphPlot],
20+
modules=[GenericTensorNetworks, ProblemReductions, TropicalNumbers, OMEinsum, OMEinsumContractionOrders, LuxorGraphPlot],
2121
authors="Jinguo Liu",
2222
repo="https://github.com/QuEraComputing/GenericTensorNetworks.jl/blob/{commit}{path}#{line}",
2323
sitename="GenericTensorNetworks.jl",
@@ -40,7 +40,6 @@ makedocs(;
4040
"Satisfiability problem" => "generated/Satisfiability.md",
4141
"Set covering problem" => "generated/SetCovering.md",
4242
"Set packing problem" => "generated/SetPacking.md",
43-
#"Other problems" => "generated/Others.md",
4443
],
4544
"Topics" => [
4645
"Gist" => "gist.md",

docs/src/ref.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,33 @@ PaintShop
1515
Satisfiability
1616
SetCovering
1717
SetPacking
18-
OpenPitMining
1918
```
2019

2120
#### Constraint Satisfaction Problem Interfaces
2221

2322
To subtype [`ConstraintSatisfactionProblem`](@ref), a new type must contain a `code` field to represent the (optimized) tensor network.
24-
Interfaces [`GenericTensorNetworks.generate_tensors`](@ref), [`labels`](@ref), [`flavors`](@ref) and [`weights`](@ref) are required.
23+
Interfaces [`GenericTensorNetworks.generate_tensors`](@ref), [`flavors`](@ref) and [`weights`](@ref) are required.
2524
[`num_flavors`](@ref) is optional.
2625

2726
```@docs
2827
GenericTensorNetworks.generate_tensors
29-
labels
30-
energy_terms
3128
flavors
3229
weights
3330
set_weights
31+
is_weighted
3432
num_flavors
3533
fixedvertices
3634
```
3735

3836
#### Constraint Satisfaction Problem Utilities
3937
```@docs
38+
hard_constraints
39+
is_satisfied
40+
local_solution_spec
41+
solution_size
42+
energy_mode
43+
energy
44+
4045
is_independent_set
4146
is_maximal_independent_set
4247
is_dominating_set
@@ -46,10 +51,7 @@ is_set_covering
4651
is_set_packing
4752
4853
cut_size
49-
spinglass_energy
5054
num_paint_shop_color_switch
51-
paint_shop_coloring_from_config
52-
mis_compactify!
5355
5456
CNF
5557
CNFClause
@@ -60,8 +62,7 @@ satisfiable
6062
¬
6163
6264
63-
is_valid_mining
64-
print_mining
65+
mis_compactify!
6566
```
6667

6768
## Properties
@@ -145,7 +146,12 @@ MergeGreedy
145146

146147
## Others
147148
#### Graph
149+
Except the `SimpleGraph` defined in [Graphs](https://github.com/JuliaGraphs/Graphs.jl), `GenericTensorNetworks` also defines the following types and functions.
150+
148151
```@docs
152+
HyperGraph
153+
UnitDiskGraph
154+
149155
show_graph
150156
show_configs
151157
show_einsum
@@ -162,7 +168,6 @@ render_locs
162168
163169
diagonal_coupled_graph
164170
square_lattice_graph
165-
unit_disk_graph
166171
line_graph
167172
168173
random_diagonal_coupled_graph

docs/src/tensornetwork.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ The maximum/minimum solution sizes can be represented as a tensor network as wel
5151
which can be represented as a tropical tensor network[^Liu2021] $(V, \{h_{\sigma_e} \mid e\in E\}, \emptyset)$, where $h_{\sigma_e}$ is a tensor labeled by $\sigma_e \subseteq V$, and its elements are defined by $h_{\sigma_e}= h_e(\sigma_e)$.
5252

5353
## Problems
54-
### Independent set problem
5554
The independent set problem on graph $G=(V, E)$ is characterized by the Hamiltonian
5655
```math
5756
H(\sigma) = U \sum_{(i, j) \in E} n_i n_j - \sum_{i \in V} n_i

examples/Coloring.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ problem = GenericTensorNetwork(coloring)
4646

4747
# ## Solving properties
4848
# ##### counting all possible coloring
49-
num_of_coloring = solve(problem, CountingMax())[]
49+
# The size of a coloring problem is the number of violations of the coloring constraint.
50+
num_of_coloring = solve(problem, CountingMin())[]
5051

5152
# ##### finding one best coloring
52-
single_solution = solve(problem, SingleConfigMax())[]
53+
single_solution = solve(problem, SingleConfigMin())[]
5354
read_config(single_solution)
5455

5556
is_vertex_coloring(graph, read_config(single_solution))
@@ -68,7 +69,7 @@ show_graph(linegraph, [(locations[e.src] .+ locations[e.dst])
6869
# Let us construct the tensor network and see if there are solutions.
6970
lineproblem = Coloring{3}(linegraph);
7071

71-
num_of_coloring = solve(GenericTensorNetwork(lineproblem), CountingMax())[]
72+
num_of_coloring = solve(GenericTensorNetwork(lineproblem), CountingMin())[]
7273
read_size_count(num_of_coloring)
7374

7475
# You will see the maximum size 28 is smaller than the number of edges in the `linegraph`,

examples/PaintShop.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# In the following, we use a character to represent a car,
1313
# and defined a binary paint shop problem as a string that each character appear exactly twice.
1414

15-
using GenericTensorNetworks, Graphs
15+
using GenericTensorNetworks, Graphs, GenericTensorNetworks.ProblemReductions
1616

1717
sequence = collect("iadgbeadfcchghebif")
1818

@@ -88,7 +88,7 @@ best_configs = solve(problem, ConfigsMin())[]
8888

8989
# One can see to identical bitstrings corresponding two different vertex configurations, they are related to bit-flip symmetry.
9090

91-
painting1 = paint_shop_coloring_from_config(pshop, read_config(best_configs)[1])
91+
painting1 = ProblemReductions.paint_shop_coloring_from_config(pshop, read_config(best_configs)[1])
9292

9393
show_graph(graph, locations; format=:svg, texts=string.(sequence),
9494
edge_colors=[sequence[e.src] == sequence[e.dst] ? "blue" : "black" for e in edges(graph)],

examples/Satisfiability.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# One can specify a satisfiable problem in the [conjunctive normal form](https://en.wikipedia.org/wiki/Conjunctive_normal_form).
99
# In boolean logic, a formula is in conjunctive normal form (CNF) if it is a conjunction (∧) of one or more clauses,
1010
# where a clause is a disjunction (∨) of literals.
11-
using GenericTensorNetworks
11+
using GenericTensorNetworks, GenericTensorNetworks.ProblemReductions
1212

1313
@bools a b c d e f g
1414

@@ -48,15 +48,15 @@ problem = GenericTensorNetwork(sat)
4848

4949
# ## Solving properties
5050
# #### Satisfiability and its counting
51-
# The size of a satisfiability problem is defined by the number of satisfiable clauses.
52-
num_satisfiable = solve(problem, SizeMax())[]
51+
# The size of a satisfiability problem is defined by the number of unsatisfied clauses.
52+
num_satisfiable = solve(problem, SizeMin())[]
5353

5454
# The [`GraphPolynomial`](@ref) of a satisfiability problem counts the number of solutions that `k` clauses satisfied.
5555
num_satisfiable_count = read_size_count(solve(problem, GraphPolynomial())[])
5656

5757
# #### Find one of the solutions
58-
single_config = read_config(solve(problem, SingleConfigMax())[])
58+
single_config = read_config(solve(problem, SingleConfigMin())[])
5959

6060
# One will see a bit vector printed.
6161
# One can create an assignment and check the validity with the following statement:
62-
satisfiable(cnf, Dict(zip(labels(problem), single_config)))
62+
satisfiable(cnf, Dict(zip(ProblemReductions.symbols(problem.problem), single_config)))

examples/SetCovering.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ min_configs = read_config(solve(problem, ConfigsMin())[])
7373
# Hence the two optimal solutions are ``\{z_1, z_3, z_5, z_6\}`` and ``\{z_2, z_3, z_4, z_5\}``.
7474
# The correctness of this result can be checked with the [`is_set_covering`](@ref) function.
7575

76-
all(c->is_set_covering(sets, c), min_configs)
76+
all(c->is_set_covering(problem.problem, c), min_configs)
7777

7878
# Similarly, if one is only interested in computing one of the minimum set coverings,
7979
# one can use the graph property [`SingleConfigMin`](@ref).

examples/SetPacking.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ max_configs = read_config(solve(problem, ConfigsMax())[])
7474
# Hence the only optimal solution is ``\{z_1, z_3, z_6\}`` that has size 3.
7575
# The correctness of this result can be checked with the [`is_set_packing`](@ref) function.
7676

77-
all(c->is_set_packing(sets, c), max_configs)
77+
all(c->is_set_packing(problem.problem, c), max_configs)
7878

7979
# Similarly, if one is only interested in computing one of the maximum set packing,
8080
# one can use the graph property [`SingleConfigMax`](@ref).

examples/SpinGlass.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ show_graph(graph, locations; format=:svg)
2626

2727
# ## Generic tensor network representation
2828
# An anti-ferromagnetic spin glass problem can be defined with the [`SpinGlass`](@ref) type as
29-
spinglass = SpinGlass(graph, fill(1, ne(graph)))
29+
spinglass = SpinGlass(graph, fill(1, ne(graph)), zeros(Int, nv(graph)))
3030

3131
# The tensor network representation of the set packing problem can be obtained by
3232
problem = GenericTensorNetwork(spinglass)
@@ -81,8 +81,10 @@ partition_function = solve(problem, GraphPolynomial())[]
8181
# The ground state of the spin glass problem can be found by the [`SingleConfigMin`](@ref) solver.
8282
ground_state = read_config(solve(problem, SingleConfigMin())[])
8383

84-
# The energy of the ground state can be verified by the [`spinglass_energy`](@ref) function.
85-
Emin_verify = spinglass_energy(spinglass, ground_state)
84+
# The energy of the ground state can be verified by the [`energy`](@ref) function.
85+
# Note the output of the ground state can not be directly used as the input of the `energy` function.
86+
# It needs to be converted to the spin configurations.
87+
Emin_verify = energy(problem.problem, 1 .- 2 .* Int.(ground_state))
8688

8789
# You should see a consistent result as above `Emin`.
8890

@@ -117,7 +119,7 @@ weights = [-1, 1, -1, 1, -1, 1, -1, 1];
117119
# \end{align*}
118120
# ```
119121
# A spin glass problem can be defined with the [`SpinGlass`](@ref) type as
120-
hyperspinglass = SpinGlass(num_vertices, hyperedges, weights)
122+
hyperspinglass = SpinGlass(HyperGraph(num_vertices, hyperedges), weights, zeros(Int, num_vertices))
121123

122124
# The tensor network representation of the set packing problem can be obtained by
123125
hyperproblem = GenericTensorNetwork(hyperspinglass)
@@ -155,8 +157,8 @@ poly = solve(hyperproblem, GraphPolynomial())[]
155157
# The ground state of the spin glass problem can be found by the [`SingleConfigMin`](@ref) solver.
156158
ground_state = read_config(solve(hyperproblem, SingleConfigMin())[])
157159

158-
# The energy of the ground state can be verified by the [`spinglass_energy`](@ref) function.
160+
# The energy of the ground state can be verified by the [`energy`](@ref) function.
159161

160-
Emin_verify = spinglass_energy(hyperspinglass, ground_state)
162+
Emin_verify = energy(hyperproblem.problem, 1 .- 2 .* Int.(ground_state))
161163

162164
# You should see a consistent result as above `Emin`.

0 commit comments

Comments
 (0)