Skip to content

Commit 2219484

Browse files
committed
HM
almost complete HM
1 parent 25e178a commit 2219484

File tree

9 files changed

+1634
-1058
lines changed

9 files changed

+1634
-1058
lines changed

ext/MakieExt/LDPC/codes.jl

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023 - 2024 Eric Sabo
1+
# Copyright (c) 2023 - 2025 Eric Sabo
22
# All rights reserved.
33
#
44
# This source code is licensed under the BSD-style license found in the
@@ -43,131 +43,6 @@ function CodingTheory.degree_distributions_plot(C::AbstractLDPCCode)
4343
return f
4444
end
4545

46-
# """
47-
# $TYPEDSIGNATURES
48-
49-
# Return a bar graph and a dictionary of (length, count) pairs for unique short
50-
# cycles in the Tanner graph of `C`. An empty graph and dictionary are returned
51-
# when there are no cycles.
52-
53-
# # Note
54-
# - Short cycles are defined to be those with lengths between ``g`` and ``2g - 2``,
55-
# where ``g`` is the girth.
56-
# - Run `using Makie` to activate this extension.
57-
# """
58-
# function CodingTheory.count_short_cycles_plot(C::AbstractLDPCCode)
59-
# if isempty(C.short_cycle_counts) || isempty(C.elementary_cycle_counts)
60-
# CodingTheory._count_cycles(C)
61-
# end
62-
63-
# len = length(C.short_cycle_counts)
64-
# x_data = [0 for _ in 1:len]
65-
# y_data = [0 for _ in 1:len]
66-
# index = 1
67-
# for (i, j) in C.short_cycle_counts
68-
# x_data[index] = i
69-
# y_data[index] = j
70-
# index += 1
71-
# end
72-
73-
# fig = Figure();
74-
# ax = Axis(fig[1, 1], xlabel = "Cycle Length", ylabel = "Occurrences",
75-
# title = "Short Cycle Counts")
76-
# barplot!(ax, x_data, y_data, bar_width = 1, xticks = x_data, yticks = y_data)
77-
# # fig = Plots.bar(x_data, y_data, bar_width = 1, xticks = x_data, yticks = y_data,
78-
# # legend = false, xlabel = "Cycle Length", ylabel = "Occurrences",
79-
# # title = "Short Cycle Counts")
80-
# display(fig)
81-
# return fig, C.short_cycle_counts
82-
# end
83-
84-
# """
85-
# $TYPEDSIGNATURES
86-
87-
# Return a bar graph and a dictionary of (length, count) pairs for unique elementary
88-
# cycles in the Tanner graph of `C`. An empty graph and dictionary are returned
89-
# when there are no cycles.
90-
91-
# # Note
92-
# - Elementary cycles do not contain the same vertex twice and are unable to be
93-
# decomposed into a sequence of shorter cycles.
94-
# - Run `using Makie` to activate this extension.
95-
# """
96-
# function CodingTheory.count_elementary_cycles_plot(C::AbstractLDPCCode)
97-
# if isempty(C.short_cycle_counts) || isempty(C.elementary_cycle_counts)
98-
# CodingTheory._count_cycles(C)
99-
# end
100-
101-
# len = length(C.elementary_cycle_counts)
102-
# x_data = [0 for _ in 1:len]
103-
# y_data = [0 for _ in 1:len]
104-
# index = 1
105-
# for (i, j) in C.elementary_cycle_counts
106-
# x_data[index] = i
107-
# y_data[index] = j
108-
# index += 1
109-
# end
110-
111-
# fig = Figure();
112-
# ax = Axis(fig[1, 1], xlabel = "Cycle Length", ylabel = "Occurrences",
113-
# title = "Elementary Cycle Counts")
114-
# barplot!(ax, x_data, y_data, bar_width = 1, xticks = x_data, yticks = y_data)
115-
# # fig = Plots.bar(x_data, y_data, bar_width = 1, xticks = x_data, yticks = y_data,
116-
# # legend = false, xlabel = "Cycle Length", ylabel = "Occurrences",
117-
# # title = "Elementary Cycle Counts")
118-
# display(fig)
119-
# return fig, C.elementary_cycle_counts
120-
# end
121-
122-
"""
123-
$TYPEDSIGNATURES
124-
125-
Return an interactive figure and data for the ACE spectrum of the Tanner graph of `C`.
126-
127-
# Note
128-
- Run `using Makie` to activate this extension.
129-
"""
130-
function CodingTheory.ACE_spectrum_plot(C::AbstractLDPCCode)
131-
# TODO: remove WGLMakie as a default use and only use for interactive plots
132-
fig = Figure();
133-
ax = Axis(fig[1, 1], xlabel = "ACE", ylabel = "Occurrences", title = "ACE Spectrum")
134-
sg = SliderGrid(fig[2, 1], (label = "Cycle Length", range = girth:2:2 * girth - 2,
135-
startvalue = 4))
136-
137-
x_max = maximum(reduce(vcat, vs_ACEs))
138-
y_max = 0
139-
counts = ACE_spectrum(C)
140-
X_data = Observable(Vector{Int}())
141-
Y_data = Observable(Vector{Int}())
142-
barplot!(ax, X_data, Y_data, bar_width = 1, xticks = X_data, yticks = Y_data)
143-
for (k, l) in enumerate(girth:2:2 * girth - 2)
144-
145-
ys = collect(values(counts[k]))
146-
y_max = maximum([y_max; ys])
147-
148-
on(sg.sliders[1].value) do val
149-
if to_value(val) == l
150-
X_data.val = collect(keys(counts[k]))
151-
Y_data.val = ys
152-
notify(X_data)
153-
notify(Y_data)
154-
end
155-
end
156-
end
157-
158-
GLMakie.limits!(0, x_max + 1, 0, y_max + 2)
159-
display(fig)
160-
return fig, counts
161-
end
162-
163-
mutable struct _ComputationGraphNode
164-
id::Int
165-
parent_id::Int
166-
lvl::Int
167-
vertex_number::Int
168-
type::Symbol
169-
end
170-
17146
# doesn't seem to be a point in making this dynamic with a slider, as it simply
17247
# continues in the same tree shape and no useful information is gained from watching it
17348
"""

ext/MakieExt/LDPC/cycles.jl

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Copyright (c) 2023 - 2025 Eric Sabo
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
#############################
8+
# simple cycles
9+
#############################
10+
11+
"""
12+
$TYPEDSIGNATURES
13+
14+
Return a bar graph and dictionary of (length, count) pairs for the unique simple cycles up to
15+
length `len` of the Tanner graph of `L`. If `len` is `-1`, then all simple cycles will be
16+
enumerated. An empty figure and dictionary are returned when there are no cycles.
17+
18+
# Note
19+
- Simple cycles do not contain the same vertex twice.
20+
- This function calls `enumerate_simple_cycles(L, len = len)`, which could be expensive if not
21+
already cached.
22+
- Run `using Makie` to activate this extension.
23+
"""
24+
function CodingTheory.simple_cycle_length_distribution_plot(L::AbstractLDPCCode; len::Int = -1)
25+
dist = simple_cycle_length_distribution(L, len = len)
26+
x_data = collect(keys(dist))
27+
y_data = collect(values(dist))
28+
29+
fig = Figure();
30+
ax = Axis(fig[1, 1], xlabel = "Cycle Length", ylabel = "Occurrences",
31+
title = "Simple Cycle Counts", xticks = x_data, yticks = y_data)
32+
barplot!(ax, x_data, y_data, strokewidth = 1)
33+
display(fig)
34+
return fig
35+
end
36+
37+
"""
38+
$TYPEDSIGNATURES
39+
40+
Return bar graph and a dictionary of (node, count) pairs for the unique simple cycles up to length
41+
`len` of the Tanner graph of `L`. If `len` is `-1`, then all simple cycles will be enumerated. An
42+
empty figure and dictionary are returned when there are no cycles.
43+
44+
# Note
45+
- Simple cycles do not contain the same vertex twice.
46+
- This function calls `enumerate_simple_cycles(L, len = len)`, which could be expensive if not
47+
already cached.
48+
- Run `using Makie` to activate this extension.
49+
"""
50+
function CodingTheory.simple_cycle_distribution_by_variable_node_plot(L::AbstractLDPCCode;
51+
len::Int = -1)
52+
53+
dist = simple_cycle_distribution_by_variable_node(L, len = len)
54+
collect(keys(dist))
55+
collect(values(dist))
56+
57+
fig = Figure();
58+
ax = Axis(fig[1, 1], xlabel = "Variable Node Index", ylabel = "Occurrences",
59+
title = "Simple Cycles By Variable Node", xticks = x_data, yticks = y_data)
60+
barplot!(ax, x_data, y_data, strokewidth = 1)
61+
display(fig)
62+
return fig
63+
end
64+
65+
#############################
66+
# short cycles
67+
#############################
68+
69+
"""
70+
$TYPEDSIGNATURES
71+
72+
Return a bar graph and dictionary of (length, count) pairs for the unique short cycles up to
73+
length `len` of the Tanner graph of `L`. If `len` is `-1`, then all short cycles will be
74+
enumerated. An empty figure and dictionary are returned when there are no cycles.
75+
76+
# Note
77+
- Short cycles are defined to be those with lengths between ``g`` and ``2g - 2``,
78+
where ``g`` is the girth.
79+
- This function calls `enumerate_simple_cycles(L, len = len)`, which could be expensive if not
80+
already cached.
81+
- Run `using Makie` to activate this extension.
82+
"""
83+
function CodingTheory.short_cycle_length_distribution_plot(L::AbstractLDPCCode; len::Int = -1)
84+
dist = short_cycle_length_distribution(L, len = len)
85+
x_data = collect(keys(dist))
86+
y_data = collect(values(dist))
87+
88+
fig = Figure()
89+
ax = Axis(fig[1, 1], xlabel = "Cycle Length", ylabel = "Occurrences",
90+
title = "Short Cycle Counts", xticks = x_data, yticks = y_data)
91+
barplot!(ax, x_data, y_data, strokewidth = 1)
92+
display(fig)
93+
return fig
94+
end
95+
96+
"""
97+
$TYPEDSIGNATURES
98+
99+
Return bar graph and a dictionary of (node, count) pairs for the unique short cycles up to length
100+
`len` of the Tanner graph of `L`. If `len` is `-1`, then all short cycles will be enumerated. An
101+
empty figure and dictionary are returned when there are no cycles.
102+
103+
# Note
104+
- Short cycles are defined to be those with lengths between ``g`` and ``2g - 2``,
105+
where ``g`` is the girth.
106+
- This function calls `enumerate_simple_cycles(L, len = len)`, which could be expensive if not
107+
already cached.
108+
- Run `using Makie` to activate this extension.
109+
"""
110+
function CodingTheory.short_cycle_distribution_by_variable_node_plot(L::AbstractLDPCCode;
111+
len::Int = -1)
112+
113+
dist = short_cycle_distribution_by_variable_node(L, len = len)
114+
x_data = collect(keys(dist))
115+
y_data = collect(values(dist))
116+
117+
fig = Figure();
118+
ax = Axis(fig[1, 1], xlabel = "Variable Node Index", ylabel = "Occurrences",
119+
title = "Short Cycles By Variable Node", xticks = x_data, yticks = y_data)
120+
barplot!(ax, x_data, y_data, strokewidth = 1)
121+
display(fig)
122+
return fig
123+
end
124+
125+
#############################
126+
# lollipops
127+
#############################
128+
129+
130+
# one for short cycles which cuts off stems at the correct lengths
131+
# one for doing all of them
132+
133+
134+
135+
136+
137+
#############################
138+
# ACE
139+
#############################
140+
141+
"""
142+
$TYPEDSIGNATURES
143+
144+
Return an interactive figure and data for the ACE spectrum of the Tanner graph of `C`.
145+
146+
# Note
147+
- Run `using Makie` to activate this extension.
148+
"""
149+
function CodingTheory.ACE_spectrum_plot(C::AbstractLDPCCode)
150+
vs_ACEs, _ = ACE_distribution(C, collect(1:C.n))
151+
grth = girth(C)
152+
# TODO: remove WGLMakie as a default use and only use for interactive plots
153+
fig = Figure();
154+
ax = Axis(fig[1, 1], xlabel = "ACE", ylabel = "Occurrences", title = "ACE Spectrum")
155+
sg = SliderGrid(fig[2, 1], (label = "Cycle Length", range = grth:2:2 * grth - 2,
156+
startvalue = 4))
157+
158+
x_max = maximum(reduce(vcat, vs_ACEs))
159+
y_max = 0
160+
counts = ACE_spectrum(C)
161+
X_data = Observable(Vector{Int}())
162+
Y_data = Observable(Vector{Int}())
163+
barplot!(ax, X_data, Y_data, strokewidth = 1, xticks = X_data, yticks = Y_data)
164+
for (k, l) in enumerate(grth:2:2 * grth - 2)
165+
166+
ys = collect(values(counts[k]))
167+
y_max = maximum([y_max; ys])
168+
169+
on(sg.sliders[1].value) do val
170+
if to_value(val) == l
171+
X_data.val = collect(keys(counts[k]))
172+
Y_data.val = ys
173+
notify(X_data)
174+
notify(Y_data)
175+
end
176+
end
177+
end
178+
179+
GLMakie.limits!(0, x_max + 1, 0, y_max + 2)
180+
display(fig)
181+
return fig, counts
182+
end

ext/MakieExt/MakieExt.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module MakieExt
22

33
import CodingTheory, Oscar
4-
import CodingTheory: Tanner_graph_plot, weight_plot, EXIT_chart_plot, degree_distributions_plot, count_short_cycles_plot, count_elementary_cycles_plot, ACE_spectrum_plot, computation_graph, weight_plot_CSS_X, weight_plot_CSS_Z, weight_plot_CSS, AbstractLinearCode, AbstractLDPCCode,
5-
LDPCEnsemble, AbstractClassicalNoiseChannel, AbstractStabilizerCode, AbstractStabilizerCodeCSS
4+
import CodingTheory: Tanner_graph_plot, weight_plot, EXIT_chart_plot, degree_distributions_plot, simple_cycle_length_distribution_plot, ACE_spectrum_plot, computation_graph, weight_plot_CSS_X, weight_plot_CSS_Z, weight_plot_CSS, AbstractLinearCode, AbstractLDPCCode,
5+
LDPCEnsemble, AbstractClassicalNoiseChannel, AbstractStabilizerCode, AbstractStabilizerCodeCSS,
6+
simple_cycle_length_distribution, simple_cycle_distribution_by_variable_node, ACE_distribution,
7+
short_cycle_length_distribution, short_cycle_distribution_by_variable_node, girth
68
# import Makie
79
using Makie, NetworkLayout, CairoMakie, GraphMakie, GLMakie, WGLMakie#, GraphPlot
810
import CairoMakie: @L_str #, Figure, Axis, hidespines!, hidedecorations!, lines!, text!
@@ -13,6 +15,7 @@ using DocStringExtensions
1315
include("Classical/Tanner.jl")
1416
include("Classical/weight_dist.jl")
1517
include("LDPC/codes.jl")
18+
include("LDPC/cycles.jl")
1619
include("LDPC/analysis.jl")
1720
include("Quantum/weight_dist.jl")
1821

src/CodingTheory.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,21 @@ export LDPCCode, regular_LDPC_code, variable_degree_distribution, check_degree_d
153153
degree_distributions, column_bound, row_bound, column_row_bounds, limited, density,
154154
is_regular, variable_degree_polynomial, check_degree_polynomial, degree_distributions_plot,
155155
girth, computation_graph, enumerate_simple_cycles, simple_cycle_length_distribution,
156-
simple_cycle_length_distribution_plot, average_simple_cycle_length, median_simple_cycle_length,
156+
average_simple_cycle_length, median_simple_cycle_length,
157157
mode_simple_cycle_length, count_simple_cycles, simple_cycle_distribution_by_variable_node,
158158
simple_cycle_distribution_by_variable_node, enumerate_short_cycles,
159-
short_cycle_length_distribution, short_cycle_length_distribution_plot,
159+
short_cycle_length_distribution,
160160
average_short_cycle_length, median_short_cycle_length, mode_short_cycle_length,
161-
count_short_cycles, short_cycle_distribution_by_variable_node,
162-
short_cycle_distribution_by_variable_node_plot
161+
count_short_cycles, short_cycle_distribution_by_variable_node
163162

164163
#############################
165164
# LDPC/cycles.jl
166165
#############################
167166

168167
include("LDPC/cycles.jl")
169-
export remove_cycles
168+
export remove_cycles, simple_cycle_length_distribution_plot,
169+
simple_cycle_distribution_by_variable_node_plot, short_cycle_length_distribution_plot,
170+
short_cycle_distribution_by_variable_node_plot, ACE_spectrum_plot
170171

171172
# #############################
172173
# # LDPC/algorithms.jl
@@ -464,4 +465,12 @@ include("Quantum/weight_reduction.jl")
464465
export copying, gauging, thickening_and_choose_heights, coning, quantum_weight_reduction,
465466
copying_as_coning, gauging_as_coning
466467

468+
469+
#############################
470+
# Quantum/homological_measurements.jl
471+
#############################
472+
473+
include("Quantum/homological_measurements.jl")
474+
export homological_measurement, Cheeger_constant
475+
467476
end

0 commit comments

Comments
 (0)