Skip to content

Commit 48f90d7

Browse files
committed
src/sage/graphs/generators: speed up Golay code graph construction
Reimplement shortened_000_111_extended_binary_Golay_code_graph() to load its vertices and edges from compressed, pickled data. This speeds up the construction significantly, and eliminates a persistent CI warning about the corresponding test being slow.
1 parent a55aec3 commit 48f90d7

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

src/sage/graphs/generators/distance_regular.pyx

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -488,34 +488,58 @@ def shortened_000_111_extended_binary_Golay_code_graph():
488488
EXAMPLES::
489489
490490
sage: # long time, needs sage.modules sage.rings.finite_rings
491-
sage: G = graphs.shortened_000_111_extended_binary_Golay_code_graph() # 25 s
491+
sage: G = graphs.shortened_000_111_extended_binary_Golay_code_graph()
492492
sage: G.is_distance_regular(True)
493493
([21, 20, 16, 9, 2, 1, None], [None, 1, 2, 3, 16, 20, 21])
494494
495495
ALGORITHM:
496496
497-
Compute the extended binary Golay code. Compute its subcode whose codewords
498-
start with 000 or 111. Remove the first 3 entries from all the codewords
499-
from the new linear code and compute its coset graph.
497+
The vertices and edges of this graph have been precomputed and
498+
pickled, so truthfully, we just unpickle them and pass them to the
499+
Graph constructor. But the algorithm used to compute those
500+
vertices and edges in the first place is,
500501
501-
REFERENCES:
502-
503-
Description and construction of this graph can be found in [BCN1989]_ p. 365.
504-
"""
505-
from sage.coding.linear_code import LinearCode
506-
507-
code = codes.GolayCode(GF(2))
508-
C_basis = code.basis()
502+
#. Compute the extended binary Golay code.
503+
#. Compute its subcode whose codewords start with 000 or 111.
504+
#. Remove the first 3 entries from all the codewords from the
505+
new linear code and compute its coset graph.
509506
510-
# now special shortening
511-
v = C_basis[0] + C_basis[1] + C_basis[2] # v has 111 at the start
512-
C_basis = C_basis[3:]
513-
C_basis.append(v)
514-
C_basis = list(map(lambda x: x[3:], C_basis))
507+
This construction is tested in ``generators_test.py``, where the
508+
result is compared with the result from this method.
515509
516-
code = LinearCode(Matrix(GF(2), C_basis))
510+
REFERENCES:
517511
518-
G = code.cosetGraph()
512+
The description and construction of this graph can be found in
513+
[BCN1989]_, page 365.
514+
"""
515+
import lzma
516+
from importlib.resources import as_file, files
517+
from pickle import load
518+
519+
# Path to the pickled-and-xz'd list of (vertices, edges)
520+
ppath = files('sage.graphs.generators').joinpath(
521+
"shortened_000_111_extended_binary_Golay_code_graph.pickle.xz"
522+
)
523+
524+
with as_file(ppath) as p:
525+
with lzma.open(p) as f:
526+
vs_and_es = load(f, fix_imports=False)
527+
528+
# Vertices/edges are pickled as tuples of ints, but should be
529+
# vectors with entries in GF(2).
530+
V = VectorSpace(GF(2), 21)
531+
for i in range(2048):
532+
# vertex i
533+
vs_and_es[0][i] = V(vs_and_es[0][i])
534+
vs_and_es[0][i].set_immutable()
535+
for i in range(21504):
536+
# edge i = (v1, v2, l)
537+
vs_and_es[1][i][0] = V(vs_and_es[1][i][0]) # v1
538+
vs_and_es[1][i][0].set_immutable()
539+
vs_and_es[1][i][1] = V(vs_and_es[1][i][1]) # v2
540+
vs_and_es[1][i][1].set_immutable()
541+
542+
G = Graph(vs_and_es, format='vertices_and_edges')
519543
G.name("Shortened 000 111 extended binary Golay code")
520544
return G
521545

0 commit comments

Comments
 (0)