Skip to content

Commit a48b7b8

Browse files
author
Release Manager
committed
gh-35891: Deprecate sorting by default in connected component methods for graphs Fixes #35889. ### 📚 Description We deprecate sorting by default in `connected_components` and `connected_component_containing_vertex`. The default value of parameter `sort` was `True`. We change it to `None` to identify calls when a deprecation warning is necessary. We also add parameter `key` so that users can define home made sorting rules. This deprecation is needed to avoid type errors when vertices have labels of incomparable type. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies URL: #35891 Reported by: David Coudert Reviewer(s): Dima Pasechnik
2 parents 8b3883d + efcf6f0 commit a48b7b8

39 files changed

+208
-103
lines changed

src/sage/algebras/fusion_rings/f_matrix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,11 +1726,11 @@ def _partition_eqns(self, eqns=None, verbose=True):
17261726
if eqns is None:
17271727
eqns = self.ideal_basis
17281728
graph = self.equations_graph(eqns)
1729-
partition = {tuple(c): [] for c in graph.connected_components()}
1729+
partition = {tuple(c): [] for c in graph.connected_components(sort=True)}
17301730
for eq_tup in eqns:
1731-
partition[tuple(graph.connected_component_containing_vertex(variables(eq_tup)[0]))].append(eq_tup)
1731+
partition[tuple(graph.connected_component_containing_vertex(variables(eq_tup)[0], sort=True))].append(eq_tup)
17321732
if verbose:
1733-
print("Partitioned {} equations into {} components of size:".format(len(eqns), len(graph.connected_components())))
1733+
print("Partitioned {} equations into {} components of size:".format(len(eqns), graph.connected_components_number()))
17341734
print(graph.connected_components_sizes())
17351735
return partition
17361736

src/sage/categories/complex_reflection_or_generalized_coxeter_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def irreducible_component_index_sets(self):
766766
for i,j in itertools.combinations(I,2)
767767
if s[i]*s[j] != s[j]*s[i] ]],
768768
format="vertices_and_edges")
769-
return G.connected_components()
769+
return G.connected_components(sort=False)
770770

771771
@abstract_method(optional=True)
772772
def irreducible_components(self):

src/sage/categories/loop_crystals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ def one_dimensional_configuration_sum(self, q=None, group_components=True):
868868
B = P0.algebra(q.parent())
869869
if group_components:
870870
G = self.digraph(index_set=self.cartan_type().classical().index_set())
871-
C = G.connected_components()
871+
C = G.connected_components(sort=False)
872872
return B.sum(q**(c[0].energy_function())*B.sum(B(P0(b.weight())) for b in c)
873873
for c in C)
874874
return B.sum(q**(b.energy_function())*B(P0(b.weight())) for b in self)

src/sage/combinat/cluster_algebra_quiver/mutation_type.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ def _connected_mutation_type_AAtildeD(dg, ret_conn_vert=False):
896896
dg_tmp = DiGraph( dg )
897897
dg_tmp.delete_vertices( c1 )
898898

899-
components = dg_tmp.connected_components()
899+
components = dg_tmp.connected_components(sort=False)
900900
# if not len(components) == 2:
901901
if len(components) != 2:
902902
return _false_return(4)
@@ -938,7 +938,7 @@ def _connected_mutation_type_AAtildeD(dg, ret_conn_vert=False):
938938
else:
939939
c2.reverse()
940940
dg_tmp.delete_edge( tuple( c2 ) )
941-
components = dg_tmp.connected_components()
941+
components = dg_tmp.connected_components(sort=False)
942942
if len(components) != 2:
943943
return _false_return(7)
944944
else:
@@ -1190,7 +1190,7 @@ def _connected_mutation_type_AAtildeD(dg, ret_conn_vert=False):
11901190
edge = long_cycle[0][0]
11911191
sg = DiGraph( dg )
11921192
sg. delete_vertices(edge)
1193-
connected_components = sg.connected_components()
1193+
connected_components = sg.connected_components(sort=False)
11941194
cycle = []
11951195
if connected_components:
11961196
cycle.append( ( edge[0], edge[1], len( connected_components[0] ) + 1 ) )
@@ -1200,7 +1200,7 @@ def _connected_mutation_type_AAtildeD(dg, ret_conn_vert=False):
12001200
for edge in tmp:
12011201
sg = DiGraph( dg )
12021202
sg. delete_vertices(edge)
1203-
connected_components = sg.connected_components()
1203+
connected_components = sg.connected_components(sort=False)
12041204
if len( connected_components ) == 2:
12051205
#if len( list_intersection( [ connected_components[0], list_substract( long_cycle[0], [edge] )[0] ] ) ) > 0:
12061206
if len( set(connected_components[0]).intersection( set(long_cycle[0]).difference([edge]).pop() ) ) > 0:

src/sage/combinat/cluster_algebra_quiver/quiver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ def mutation_type(self):
10071007

10081008
# checking the type for each connected component
10091009
mutation_type = []
1010-
connected_components = sorted(dg.connected_components())
1010+
connected_components = sorted(dg.connected_components(sort=False))
10111011
for component in connected_components:
10121012
# constructing the digraph for this component
10131013
dg_component = dg.subgraph( component )
@@ -1157,7 +1157,7 @@ def canonical_label(self, certificate=False):
11571157
if dg.is_connected():
11581158
Q._mutation_type = self._mutation_type
11591159
else:
1160-
CC = sorted( self._digraph.connected_components() )
1160+
CC = sorted(self._digraph.connected_components(sort=False))
11611161
CC_new = sorted(zip([sorted(iso[i] for i in L) for L in CC],
11621162
range(len(CC))))
11631163
comp_iso = [L[1] for L in CC_new]

src/sage/combinat/constellation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def connected_components(self):
475475
G.add_vertices(list(range(self.degree())))
476476
for p in self._g:
477477
G.add_edges(enumerate(p.domain()), loops=False)
478-
m = G.connected_components()
478+
m = G.connected_components(sort=False)
479479
if len(m) == 1:
480480
return [self]
481481
for mm in m:

src/sage/combinat/crystals/littelmann_path.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def weight(x):
809809
return P0.sum(int(c)*P0.basis()[i] for i,c in w if i in P0.index_set())
810810
if group_components:
811811
G = self.digraph(index_set=self.cartan_type().classical().index_set())
812-
C = G.connected_components()
812+
C = G.connected_components(sort=False)
813813
return sum(q**(c[0].energy_function())*B.sum(B(weight(b)) for b in c) for c in C)
814814
return B.sum(q**(b.energy_function())*B(weight(b)) for b in self)
815815

@@ -1081,7 +1081,7 @@ def energy_function(self):
10811081
sage: La = R.weight_space().basis()
10821082
sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1]+La[2])
10831083
sage: G = LS.digraph(index_set=[1,2])
1084-
sage: C = G.connected_components()
1084+
sage: C = G.connected_components(sort=False)
10851085
sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C]
10861086
[True, True, True, True]
10871087
@@ -1093,15 +1093,15 @@ def energy_function(self):
10931093
sage: [(x.weight(), x.energy_function()) for x in hw]
10941094
[(-2*Lambda[0] + Lambda[2], 0), (-2*Lambda[0] + Lambda[1], 1), (0, 2)]
10951095
sage: G = LS.digraph(index_set=J)
1096-
sage: C = G.connected_components()
1096+
sage: C = G.connected_components(sort=False)
10971097
sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C]
10981098
[True, True, True]
10991099
11001100
sage: R = RootSystem(CartanType(['G',2,1]).dual())
11011101
sage: La = R.weight_space().basis()
11021102
sage: LS = crystals.ProjectedLevelZeroLSPaths(La[1]+La[2])
11031103
sage: G = LS.digraph(index_set=[1,2])
1104-
sage: C = G.connected_components()
1104+
sage: C = G.connected_components(sort=False)
11051105
sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C] # long time
11061106
[True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]
11071107
@@ -1110,15 +1110,15 @@ def energy_function(self):
11101110
sage: La = R.weight_space().basis()
11111111
sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1]+La[2])
11121112
sage: G = LS.digraph(index_set=R.cartan_type().classical().index_set())
1113-
sage: C = G.connected_components()
1113+
sage: C = G.connected_components(sort=False)
11141114
sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C] # long time
11151115
[True, True, True, True, True, True, True, True, True, True, True]
11161116
11171117
sage: R = RootSystem(['BC',2,2])
11181118
sage: La = R.weight_space().basis()
11191119
sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1]+La[2])
11201120
sage: G = LS.digraph(index_set=R.cartan_type().classical().index_set())
1121-
sage: C = G.connected_components()
1121+
sage: C = G.connected_components(sort=False)
11221122
sage: [all(c[0].energy_function()==a.energy_function() for a in c) for c in C] # long time
11231123
[True, True, True, True, True, True, True, True, True, True, True, True, True, True, True,
11241124
True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True]

src/sage/combinat/partition_algebra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ def set_partition_composition(sp1, sp2):
19741974
True
19751975
"""
19761976
g = pair_to_graph(sp1, sp2)
1977-
connected_components = g.connected_components()
1977+
connected_components = g.connected_components(sort=False)
19781978

19791979
res = []
19801980
total_removed = 0

src/sage/combinat/posets/mobile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _is_valid_ribbon(self, ribbon):
123123
continue
124124

125125
G_un.delete_edge(lc, r)
126-
P = Poset(G.subgraph(G_un.connected_component_containing_vertex(lc)))
126+
P = Poset(G.subgraph(G_un.connected_component_containing_vertex(lc, sort=False)))
127127
if P.top() != lc or not P.is_d_complete():
128128
return False
129129
G_un.add_edge(lc, r)

src/sage/combinat/posets/posets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,11 +1368,11 @@ def _latex_(self):
13681368
EXAMPLES::
13691369
13701370
sage: P = Poset(([1,2], [[1,2]]), cover_relations = True)
1371-
sage: print(P._latex_()) #optional - dot2tex graphviz
1371+
sage: print(P._latex_()) # optional - dot2tex graphviz
13721372
\begin{tikzpicture}[>=latex,line join=bevel,]
13731373
%%
1374-
\node (node_...) at (6.0...bp,...bp) [draw,draw=none] {$...$};
1375-
\node (node_...) at (6.0...bp,...bp) [draw,draw=none] {$...$};
1374+
\node (node_...) at (5...bp,...bp) [draw,draw=none] {$...$};
1375+
\node (node_...) at (5...bp,...bp) [draw,draw=none] {$...$};
13761376
\draw [black,->] (node_...) ..controls (...bp,...bp) and (...bp,...bp) .. (node_...);
13771377
%
13781378
\end{tikzpicture}
@@ -5330,7 +5330,7 @@ def edge_color(va, vb):
53305330

53315331
fusion = fusion.transitive_closure()
53325332
resu = []
5333-
for s in fusion.connected_components():
5333+
for s in fusion.connected_components(sort=False):
53345334
subg = [x for x in prod_dg if all(x[i] == v0[i] for i in factors_range
53355335
if i not in s)]
53365336
resu.append(Poset(prod_dg.subgraph(subg)))

0 commit comments

Comments
 (0)