Skip to content

Commit 0848b1c

Browse files
authored
Upgrade LuxorGraphPlot to v0.5 (#84)
* upgrade LuxorGraphPlot to v0.5 * update * fix docs * update * update docstring * update docs * update
1 parent 4c03fb0 commit 0848b1c

25 files changed

+301
-82
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DocStringExtensions = "0.8, 0.9"
3737
FFTW = "1.4"
3838
Graphs = "1.7"
3939
LinearAlgebra = "1"
40-
LuxorGraphPlot = "0.4"
40+
LuxorGraphPlot = "0.5"
4141
OMEinsum = "0.8"
4242
Polynomials = "4"
4343
Primes = "0.5"

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
23
DocThemeIndigo = "8bac0ac5-51bf-41f9-885e-2bf1ac2bec5f"
34
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
45
GenericTensorNetworks = "3521c873-ad32-4bb4-b63d-f4f178f42b49"

docs/src/ref.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ ConfigSampler
9999

100100
`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`.
101101

102+
103+
For reading the properties from the above element types, one can use the following functions.
104+
105+
```@docs
106+
read_size
107+
read_count
108+
read_config
109+
read_size_count
110+
read_size_config
111+
```
112+
113+
The following functions are for saving and loading configurations.
114+
102115
```@docs
103116
StaticBitVector
104117
StaticElementVector
@@ -136,8 +149,15 @@ MergeGreedy
136149
show_graph
137150
show_configs
138151
show_einsum
152+
show_landscape
139153
GraphDisplayConfig
140-
Layout
154+
AbstractLayout
155+
SpringLayout
156+
StressLayout
157+
SpectralLayout
158+
Layered
159+
LayeredSpringLayout
160+
LayeredStressLayout
141161
render_locs
142162
143163
diagonal_coupled_graph

docs/src/sumproduct.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ It is a sum-product expression tree to store [`ConfigEnumerator`](@ref) in a laz
44
Although it is space efficient, it is in general not easy to extract information from it due to the exponential large configuration space.
55
Directed sampling is one of its most important operations, with which one can get some statistic properties from it with an intermediate effort. For example, if we want to check some property of an intermediate scale graph, one can type
66
```@repl sumproduct
7+
using GenericTensorNetworks
78
graph = random_regular_graph(70, 3)
89
problem = GenericTensorNetwork(IndependentSet(graph); optimizer=TreeSA());
910
tree = solve(problem, ConfigsAll(; tree_storage=true))[]
@@ -15,11 +16,14 @@ However, this sum-product binary tree structure supports efficient and unbiased
1516
samples = generate_samples(tree, 1000)
1617
```
1718

18-
With these samples, one can already compute useful properties like Hamming distance (see [`hamming_distribution`](@ref)) distribution.
19+
With these samples, one can already compute useful properties like Hamming distance (see [`hamming_distribution`](@ref)) distribution. The following code visualizes this distribution with `CairoMakie`.
1920

20-
```@repl sumproduct
21-
using UnicodePlots
22-
lineplot(hamming_distribution(samples, samples))
23-
```
24-
25-
Here, the ``x``-axis is the Hamming distance and the ``y``-axis is the counting of pair-wise Hamming distances.
21+
```@example sumproduct
22+
using CairoMakie
23+
dist = hamming_distribution(samples, samples)
24+
# bar plot
25+
fig = Figure()
26+
ax = Axis(fig[1, 1]; xlabel="Hamming distance", ylabel="Frequency")
27+
barplot!(ax, 0:length(dist)-1, dist)
28+
fig
29+
```

examples/Coloring.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,26 @@ num_of_coloring = solve(problem, CountingMax())[]
5050

5151
# ##### finding one best coloring
5252
single_solution = solve(problem, SingleConfigMax())[]
53+
read_config(single_solution)
5354

54-
is_vertex_coloring(graph, single_solution.c.data)
55+
is_vertex_coloring(graph, read_config(single_solution))
5556

5657
vertex_color_map = Dict(0=>"red", 1=>"green", 2=>"blue")
5758

5859
show_graph(graph, locations; format=:svg, vertex_colors=[vertex_color_map[Int(c)]
59-
for c in single_solution.c.data])
60+
for c in read_config(single_solution)])
6061

6162
# Let us try to solve the same issue on its line graph, a graph that generated by mapping an edge to a vertex and two edges sharing a common vertex will be connected.
6263
linegraph = line_graph(graph)
6364

64-
show_graph(linegraph, [0.5 .* (locations[e.src] .+ locations[e.dst])
65+
show_graph(linegraph, [(locations[e.src] .+ locations[e.dst])
6566
for e in edges(graph)]; format=:svg)
6667

6768
# Let us construct the tensor network and see if there are solutions.
6869
lineproblem = Coloring{3}(linegraph);
6970

7071
num_of_coloring = solve(GenericTensorNetwork(lineproblem), CountingMax())[]
72+
read_size_count(num_of_coloring)
7173

7274
# You will see the maximum size 28 is smaller than the number of edges in the `linegraph`,
7375
# meaning no solution for the 3-coloring on edges of a Petersen graph.

examples/DominatingSet.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ counting_min_dominating_set = solve(problem, CountingMin())[]
6868
# ### Configuration properties
6969
# ##### finding minimum dominating set
7070
# One can enumerate all minimum dominating sets with the [`ConfigsMin`](@ref) property in the program.
71-
min_configs = solve(problem, ConfigsMin())[].c
71+
min_configs = read_config(solve(problem, ConfigsMin())[])
7272

7373
all(c->is_dominating_set(graph, c), min_configs)
7474

examples/IndependentSet.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ maximum_independent_set_size = solve(problem, SizeMax())[]
6565

6666
# Here [`SizeMax`](@ref) means finding the solution with maximum set size.
6767
# The return value has [`Tropical`](@ref) type. We can get its content by typing
68-
maximum_independent_set_size.n
68+
read_size(maximum_independent_set_size)
6969

7070
# ### Counting properties
7171
# ##### Count all solutions and best several solutions
@@ -81,15 +81,15 @@ count_maximum_independent_sets = solve(problem, CountingMax())[]
8181
# The return value has type [`CountingTropical`](@ref), which contains two fields.
8282
# They are `n` being the maximum independent set size and `c` being the number of the maximum independent sets.
8383

84-
count_maximum_independent_sets.c
84+
read_size_count(count_maximum_independent_sets)
8585

8686
# Similarly, we can count independent sets of sizes ``\alpha(G)`` and ``\alpha(G)-1`` by feeding an integer positional argument to [`CountingMax`](@ref).
8787
count_max2_independent_sets = solve(problem, CountingMax(2))[]
8888

8989
# The return value has type [`TruncatedPoly`](@ref), which contains two fields.
9090
# They are `maxorder` being the maximum independent set size and `coeffs` being the number of independent sets having sizes ``\alpha(G)-1`` and ``\alpha(G)``.
9191

92-
count_max2_independent_sets.coeffs
92+
read_size_count(count_max2_independent_sets)
9393

9494
# ##### Find the graph polynomial
9595
# We can count the number of independent sets at any size, which is equivalent to finding the coefficients of an independence polynomial that defined as
@@ -104,7 +104,7 @@ count_max2_independent_sets.coeffs
104104
independence_polynomial = solve(problem, GraphPolynomial(; method=:finitefield))[]
105105

106106
# The return type is [`Polynomial`](https://juliamath.github.io/Polynomials.jl/stable/polynomials/polynomial/#Polynomial-2).
107-
independence_polynomial.coeffs
107+
read_size_count(independence_polynomial)
108108

109109
# ### Configuration properties
110110
# ##### Find one best solution
@@ -116,7 +116,7 @@ independence_polynomial.coeffs
116116
max_config = solve(problem, SingleConfigMax(; bounded=false))[]
117117

118118
# The return value has type [`CountingTropical`](@ref) with its counting field having [`ConfigSampler`](@ref) type. The `data` field of [`ConfigSampler`](@ref) is a bit string that corresponds to the solution
119-
single_solution = max_config.c.data
119+
single_solution = read_config(max_config)
120120

121121
# This bit string should be read from left to right, with the i-th bit being 1 (0) to indicate the i-th vertex is present (absent) in the set.
122122
# We can visualize this MIS with the following function.
@@ -130,10 +130,10 @@ all_max_configs = solve(problem, ConfigsMax(; bounded=true))[]
130130

131131
# The return value has type [`CountingTropical`](@ref), while its counting field having type [`ConfigEnumerator`](@ref). The `data` field of a [`ConfigEnumerator`](@ref) instance contains a vector of bit strings.
132132

133-
all_max_configs.c.data
133+
_, configs_vector = read_size_config(all_max_configs)
134134

135135
# These solutions can be visualized with the [`show_configs`](@ref) function.
136-
show_configs(graph, locations, reshape(collect(all_max_configs.c), 1, length(all_max_configs.c)); padding_left=20)
136+
show_configs(graph, locations, reshape(configs_vector, 1, :); padding_left=20)
137137

138138
# We can use [`ConfigsAll`](@ref) to enumerate all sets satisfying the independence constraint.
139139
all_independent_sets = solve(problem, ConfigsAll())[]

examples/Matching.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ problem = GenericTensorNetwork(matching)
4949
# ## Solving properties
5050
# The maximum matching size can be obtained by
5151
max_matching = solve(problem, SizeMax())[]
52+
read_size(max_matching)
5253
# The largest number of matching is 5, which means we have a perfect matching (vertices are all paired).
5354

5455
# The graph polynomial defined for the matching problem is known as the matching polynomial.
@@ -59,14 +60,16 @@ max_matching = solve(problem, SizeMax())[]
5960
# where ``k`` is the number of matches, and coefficients ``c_k`` are the corresponding counting.
6061

6162
matching_poly = solve(problem, GraphPolynomial())[]
63+
read_size_count(matching_poly)
6264

6365
# ### Configuration properties
6466

6567
# ##### one of the perfect matches
6668
match_config = solve(problem, SingleConfigMax())[]
69+
read_size_config(match_config)
6770

6871
# Let us show the result by coloring the matched edges to red
6972
show_graph(graph, locations; format=:svg, edge_colors=
70-
[isone(match_config.c.data[i]) ? "red" : "black" for i=1:ne(graph)])
73+
[isone(read_config(match_config)[i]) ? "red" : "black" for i=1:ne(graph)])
7174

7275
# where we use edges with red color to related pairs of matched vertices.

examples/MaxCut.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ max_config = solve(problem, GraphPolynomial())[]
7070

7171
# ### Configuration properties
7272
# ##### finding one max cut solution
73-
max_vertex_config = solve(problem, SingleConfigMax())[].c.data
73+
max_vertex_config = read_config(solve(problem, SingleConfigMax())[])
7474

7575
max_cut_size_verify = cut_size(graph, max_vertex_config)
7676

examples/MaximalIS.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ counting_min_maximal_independent_set = solve(problem, CountingMin())[]
6666

6767
# ### Configuration properties
6868
# ##### finding all maximal independent set
69-
maximal_configs = solve(problem, ConfigsAll())[]
69+
maximal_configs = read_config(solve(problem, ConfigsAll())[])
7070

7171
all(c->is_maximal_independent_set(graph, c), maximal_configs)
7272

@@ -81,7 +81,7 @@ cliques = maximal_cliques(complement(graph))
8181

8282
# ##### finding minimum maximal independent set
8383
# It is the [`ConfigsMin`](@ref) property in the program.
84-
minimum_maximal_configs = solve(problem, ConfigsMin())[].c
84+
minimum_maximal_configs = read_config(solve(problem, ConfigsMin())[])
8585

8686
show_configs(graph, locations, reshape(collect(minimum_maximal_configs), 2, 5); padding_left=20)
8787

0 commit comments

Comments
 (0)