Open cyrilbouvier opened 5 months ago
It is certainly not safe to use rooted trees labelled by elements that cannot be sorted.
One can easily fix the specific issue in graphs by labeling this specific tree by strings everywhere.
Please provide if you can a minimal graph where the tree-styled decomposition fails.
Please provide if you can a minimal graph where the tree-styled decomposition fails.
G = Graph('GxJEE?') G.modular_decomposition(style='tuple') # works ('tuple' is the default value for the style parameter) G.modular_decomposition(style='tree') # trigger the bug
It is certainly not safe to use rooted trees labelled by elements that cannot be sorted.
I agree, but it is not specified in the documentation, and it is only needed in some special cases. And, as illustrated by the modular_decomposition
module, it is used with non sortable labels by Sage itself.
Steps To Reproduce
With Sage 10.2, the following code raises a
TypeError
:Expected Behavior
No error
Actual Behavior
Additional Information
The exemple is given with label from
sage.graphs.graph_decompositions.modular_decomposition
because I stumbled into this bug while callingmodular_decomposition(style='tree')
for some graphs. All the examples from the doc of the methodmodular_decomposition
works but when I tried with a more complicated graph, it raises the error leading to the bug.Note that there is nothing special about the class NodeType, to trigger the bug the labels only need to be hashable (required by LabelledRootedTree) but not comparable.
From what I was able to understand the problem comes from the method
normalize
(inherited fromRootedTree
) that sort the children of the root using the methodsort_key
as key.When one tries to create a
LabelledRootedTree
with at least two children such that the first different tuple in the output ofsort_key
is not comparable, the assertion is raised.This call works because the first tuples of the output of
sort_key
are comparable (as2 < 3
the second item of the tuple is not needed for the comparison)This call works because the first tuples of the output of
sort_key
are equal (both are(2, PARALLEL)
) and the remaining tuples are comparable.This call does not work because
(2, PARALLEL)
and(2, SERIES)
are not comparable.Environment
Checklist