sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.47k stars 488 forks source link

Meta-ticket: make graphs compatible with Python 3 #26640

Closed dcoudert closed 4 years ago

dcoudert commented 6 years ago

This ticket is used to keep track of the progress towards python3 in graphs.

Major issues

Needs work:

Needs review:

Done

Optional packages:

With #27628, #27811, #27948, #28108 and #28371 all failing doctests of the optional packages used in the graph module are fixed: benzene, bliss, buckygen, csdp, dot2tex and graphviz, gap_packages, igraph and python_igraph, mcqd, plantri, tdlib

CC: @tscrim @fchapoton @jhpalmieri @jfraymond

Component: graph theory

Author: David Coudert

Reviewer: John Palmieri

Issue created by migration from https://trac.sagemath.org/ticket/26640

dcoudert commented 6 years ago

Description changed:

--- 
+++ 
@@ -7,6 +7,7 @@

 **Done**
+- #26618 avoid using `.vertices()` in `centrality.pyx`
 - #26621 avoid using `.vertices()` and `.edges()` in `bliss.pyx`
dcoudert commented 6 years ago

Description changed:

--- 
+++ 
@@ -4,9 +4,11 @@
 **Major issues**
 - methods `.vertices()` and `.edges()` use sort by default
 - direct comparison of vertex labels (e.g., in method `iterator_edges` of `base/sparse_graph.pyx`)
-
+- all `min_spanning_tree` methods sort edges before returning the result

 **Done**
+- #26469 avoid sorting vertex labels in `graph_plot.py` 
+- #26531 avoid using `.vertices()` in asteroidal_triples
 - #26618 avoid using `.vertices()` in `centrality.pyx`
 - #26621 avoid using `.vertices()` and `.edges()` in `bliss.pyx`
dcoudert commented 6 years ago
comment:4

I'm answering here the question of #26567#comment:9 about how to make iterator_edges of sparse_graph.pyx py3 compatible, and if something similar to #26567 for dense_graph.pyx can be done for sparse_graph.pyx.

So far, I don't know what's the best option.

All these options have pros and cons, and each of them will require a significant amount of work to fix doctests and algorithms.

In the last months, we did significant progresses on reducing the dependency on ordering, but this is not enough and this central issue is very complex to fix. Which is the best option in the short/long term ?

fchapoton commented 6 years ago

Description changed:

--- 
+++ 
@@ -12,4 +12,13 @@
 - #26618 avoid using `.vertices()` in `centrality.pyx`
 - #26621 avoid using `.vertices()` and `.edges()` in `bliss.pyx`

+**Needs review**:

+- #26520   clean graph decompositions
+- #26633   clean generic_graph.py (part 4) 
+- #26634   clean generic_graph.py (part 5)
+- #26663   clean generic_graph.py (part 8) - connectivity  
+- #26675   clean generic_graph.py (part 11) - substructures
+- #26678   clean generic_graph.py (part 12) - centrality and distances
+- #26679   clean generic_graph.py (part 13) - searches and constructors
+- #26680   clean generic_graph.py (part 14) - visualization
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -6,19 +6,44 @@
 - direct comparison of vertex labels (e.g., in method `iterator_edges` of `base/sparse_graph.pyx`)
 - all `min_spanning_tree` methods sort edges before returning the result

-**Done**
-- #26469 avoid sorting vertex labels in `graph_plot.py` 
-- #26531 avoid using `.vertices()` in asteroidal_triples
-- #26618 avoid using `.vertices()` in `centrality.pyx`
-- #26621 avoid using `.vertices()` and `.edges()` in `bliss.pyx`
+
+**Needs work**:
+- #26800   py3: bug with canonical_label
+

 **Needs review**:
-
 - #26520   clean graph decompositions
-- #26633   clean generic_graph.py (part 4) 
 - #26634   clean generic_graph.py (part 5)
 - #26663   clean generic_graph.py (part 8) - connectivity  
 - #26675   clean generic_graph.py (part 11) - substructures
 - #26678   clean generic_graph.py (part 12) - centrality and distances
 - #26679   clean generic_graph.py (part 13) - searches and constructors
+- #26779   py3: fix `graph_input.py` and `hypergraph_generators.py`
+- #26812   py3: fix doctest in `graph_generators.py`
+
+
+**Done**
+- #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
+- #26282   avoid comparison of vertex labels in MIP - graph.py
+- #26284   avoid comparison of vertex labels in MIP - connectivity.pyx
+- #26285   avoid comparison of vertex labels in MIP - generic_graph.py
+- #26469   avoid sorting vertex labels in `graph_plot.py`
+- #26484   clean graph_coloring.py and avoid comparison of vertex labels
+- #26528   avoid using `.vertices()` in comparability, hyperbolicity and distances_all_pairs
+- #26531   avoid using `.vertices()` in asteroidal_triples
+- #26534   avoid using `.vertices()` in weakly_chordal.pyx
+- #26554   improve the boost graph interface to avoid using `.vertices()` 
+- #26618   avoid using `.vertices()` in `centrality.pyx`
+- #26621   avoid using `.vertices()` and `.edges()` in `bliss.pyx`
+- #26622   avoid using `.vertices()` in convexity_properties.pyx
+- #26633   clean generic_graph.py (part 4) 
 - #26680   clean generic_graph.py (part 14) - visualization
+- #26711   avoid `.vertices()` in graph_coloring.py
+- #26712   avoid `.vertices()` in independent_sets.pyx
+- #26757   py3: fixing round in graph_latex.py
+- #26761   py3: fix `BlanusaSecondSnarkGraph`
+- #26762   py3: fix `HortonGraph` generator
+- #26763   py3: fix `SzekeresSnarkGraph` generator
+- #26801   py3: change sorting of neighbors labels in `static_sparse_graph.pyx`
+
+
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -16,7 +16,7 @@
 - #26634   clean generic_graph.py (part 5)
 - #26663   clean generic_graph.py (part 8) - connectivity  
 - #26675   clean generic_graph.py (part 11) - substructures
-- #26678   clean generic_graph.py (part 12) - centrality and distances
+- #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #26779   py3: fix `graph_input.py` and `hypergraph_generators.py`
 - #26812   py3: fix doctest in `graph_generators.py`
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -12,7 +12,7 @@

 **Needs review**:
-- #26520   clean graph decompositions
+- #26520   Meta-ticket for methods in `src/sage/graphs/graph_decomposition/` - #26827, #26828, #26829, #26830, #26831, #26832, #26833, #26834
 - #26634   clean generic_graph.py (part 5)
 - #26663   clean generic_graph.py (part 8) - connectivity  
 - #26675   clean generic_graph.py (part 11) - substructures
fchapoton commented 5 years ago
comment:9

May I ask in which ticket, if any, you do touch the "is_isomorphic" method ?

I would really like this to work with python 3:

sage: G = Graph()
sage: G.add_edge((1,'a'))
sage: G
Graph on 2 vertices
sage: G.is_isomorphic(G)
dcoudert commented 5 years ago
comment:10

I have not touched any method related to isomorphism. I have only opened a ticket to show a bug with canonical_label #26800.

fchapoton commented 5 years ago
comment:11

ok.. Then either we wait for all these tickets to be closed (and this may take a lot of time) or we can try to fix this isomorphism problem now..

dcoudert commented 5 years ago
comment:12

We can start working on it. In the worst case, I will have to fix some merge conflicts.

fchapoton commented 5 years ago
comment:13

I have made a first tentative at u/chapoton/graphe_iso

dcoudert commented 5 years ago
comment:14

I'm not good enough with git to know what you have changed, except the first 2 calls to .vertices(). It seems ok. Note that the function has 2 more calls to .vertices() that are clearly useless. I think the proposed change fix some doctests, so you should open a ticket.

fchapoton commented 5 years ago
comment:15

I made #26846 for graph isomorphism

fchapoton commented 5 years ago

Description changed:

--- 
+++ 
@@ -20,7 +20,7 @@
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #26779   py3: fix `graph_input.py` and `hypergraph_generators.py`
 - #26812   py3: fix doctest in `graph_generators.py`
-
+- #26846        for graph isomorphism

 **Done**
 - #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -21,6 +21,8 @@
 - #26779   py3: fix `graph_input.py` and `hypergraph_generators.py`
 - #26812   py3: fix doctest in `graph_generators.py`
 - #26846        for graph isomorphism
+- #26851   py3: avoid `.vertices()` and `.edges()` in `union` of graphs 
+

 **Done**
 - #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -14,12 +14,10 @@
 **Needs review**:
 - #26520   Meta-ticket for methods in `src/sage/graphs/graph_decomposition/` - #26827, #26828, #26829, #26830, #26831, #26832, #26833, #26834
 - #26634   clean generic_graph.py (part 5)
-- #26663   clean generic_graph.py (part 8) - connectivity  
 - #26675   clean generic_graph.py (part 11) - substructures
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #26779   py3: fix `graph_input.py` and `hypergraph_generators.py`
-- #26812   py3: fix doctest in `graph_generators.py`
 - #26846        for graph isomorphism
 - #26851   py3: avoid `.vertices()` and `.edges()` in `union` of graphs 

@@ -38,7 +36,15 @@
 - #26618   avoid using `.vertices()` in `centrality.pyx`
 - #26621   avoid using `.vertices()` and `.edges()` in `bliss.pyx`
 - #26622   avoid using `.vertices()` in convexity_properties.pyx
-- #26633   clean generic_graph.py (part 4) 
+- #26624   clean generic_graph.py (part 1)
+- #26627   clean generic_graph.py (part 2)
+- #26630   clean generic_graph.py (part 3)
+- #26633   clean generic_graph.py (part 4)
+- #26637   clean generic_graph.py (part 6)
+- #26658   clean generic_graph.py (part 7) - planarity
+- #26663   clean generic_graph.py (part 8) - connectivity  
+- #26666   clean generic_graph.py (part 9) - edge and vertex handlers
+- #26672   clean generic_graph.py (part 10) - degree
 - #26680   clean generic_graph.py (part 14) - visualization
 - #26711   avoid `.vertices()` in graph_coloring.py
 - #26712   avoid `.vertices()` in independent_sets.pyx
@@ -47,5 +53,6 @@
 - #26762   py3: fix `HortonGraph` generator
 - #26763   py3: fix `SzekeresSnarkGraph` generator
 - #26801   py3: change sorting of neighbors labels in `static_sparse_graph.pyx`
+- #26812   py3: fix doctest in `graph_generators.py`
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -13,11 +13,8 @@

 **Needs review**:
 - #26520   Meta-ticket for methods in `src/sage/graphs/graph_decomposition/` - #26827, #26828, #26829, #26830, #26831, #26832, #26833, #26834
-- #26634   clean generic_graph.py (part 5)
-- #26675   clean generic_graph.py (part 11) - substructures
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
-- #26779   py3: fix `graph_input.py` and `hypergraph_generators.py`
 - #26846        for graph isomorphism
 - #26851   py3: avoid `.vertices()` and `.edges()` in `union` of graphs 

@@ -40,11 +37,13 @@
 - #26627   clean generic_graph.py (part 2)
 - #26630   clean generic_graph.py (part 3)
 - #26633   clean generic_graph.py (part 4)
+- #26634   clean generic_graph.py (part 5)
 - #26637   clean generic_graph.py (part 6)
 - #26658   clean generic_graph.py (part 7) - planarity
 - #26663   clean generic_graph.py (part 8) - connectivity  
 - #26666   clean generic_graph.py (part 9) - edge and vertex handlers
 - #26672   clean generic_graph.py (part 10) - degree
+- #26675   clean generic_graph.py (part 11) - substructures
 - #26680   clean generic_graph.py (part 14) - visualization
 - #26711   avoid `.vertices()` in graph_coloring.py
 - #26712   avoid `.vertices()` in independent_sets.pyx
@@ -52,6 +51,7 @@
 - #26761   py3: fix `BlanusaSecondSnarkGraph`
 - #26762   py3: fix `HortonGraph` generator
 - #26763   py3: fix `SzekeresSnarkGraph` generator
+- #26779   py3: fix `graph_input.py` and `hypergraph_generators.py`
 - #26801   py3: change sorting of neighbors labels in `static_sparse_graph.pyx`
 - #26812   py3: fix doctest in `graph_generators.py`
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -17,6 +17,7 @@
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #26846        for graph isomorphism
 - #26851   py3: avoid `.vertices()` and `.edges()` in `union` of graphs 
+- #26869   py3: improve `is_aperiodic` to fix doctests (due to deprecation warning in networkx)

 **Done**
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -18,6 +18,7 @@
 - #26846        for graph isomorphism
 - #26851   py3: avoid `.vertices()` and `.edges()` in `union` of graphs 
 - #26869   py3: improve `is_aperiodic` to fix doctests (due to deprecation warning in networkx)
+- #26870   py3: fix error with `map` in `strongly_regular_db.pyx`

 **Done**
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -19,6 +19,7 @@
 - #26851   py3: avoid `.vertices()` and `.edges()` in `union` of graphs 
 - #26869   py3: improve `is_aperiodic` to fix doctests (due to deprecation warning in networkx)
 - #26870   py3: fix error with `map` in `strongly_regular_db.pyx`
+- #26871   py3: fix doctests in `digraph_generators.py`

 **Done**
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -4,7 +4,7 @@
 **Major issues**
 - methods `.vertices()` and `.edges()` use sort by default
 - direct comparison of vertex labels (e.g., in method `iterator_edges` of `base/sparse_graph.pyx`)
-- all `min_spanning_tree` methods sort edges before returning the result
+- all `min_spanning_tree` methods sort edges before returning the result - #26940 is attempt to stop sorting returned list of edges

 **Needs work**:
@@ -20,7 +20,7 @@
 - #26869   py3: improve `is_aperiodic` to fix doctests (due to deprecation warning in networkx)
 - #26870   py3: fix error with `map` in `strongly_regular_db.pyx`
 - #26871   py3: fix doctests in `digraph_generators.py`
-
+- #26940   stop sorting returned list of edges in spanning tree methods 

 **Done**
 - #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -15,11 +15,6 @@
 - #26520   Meta-ticket for methods in `src/sage/graphs/graph_decomposition/` - #26827, #26828, #26829, #26830, #26831, #26832, #26833, #26834
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
-- #26846        for graph isomorphism
-- #26851   py3: avoid `.vertices()` and `.edges()` in `union` of graphs 
-- #26869   py3: improve `is_aperiodic` to fix doctests (due to deprecation warning in networkx)
-- #26870   py3: fix error with `map` in `strongly_regular_db.pyx`
-- #26871   py3: fix doctests in `digraph_generators.py`
 - #26940   stop sorting returned list of edges in spanning tree methods 

 **Done**
@@ -57,5 +52,10 @@
 - #26779   py3: fix `graph_input.py` and `hypergraph_generators.py`
 - #26801   py3: change sorting of neighbors labels in `static_sparse_graph.pyx`
 - #26812   py3: fix doctest in `graph_generators.py`
+- #26846        for graph isomorphism
+- #26851   py3: avoid `.vertices()` and `.edges()` in `union` of graphs 
+- #26869   py3: improve `is_aperiodic` to fix doctests (due to deprecation warning in networkx)
+- #26870   py3: fix error with `map` in `strongly_regular_db.pyx`
+- #26871   py3: fix doctests in `digraph_generators.py`
fchapoton commented 5 years ago
comment:24

Salut !

dcoudert commented 5 years ago
comment:25

See #26469, #26478, #26480, #26484.

I will check #26971 soon.

dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -16,6 +16,8 @@
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #26940   stop sorting returned list of edges in spanning tree methods 
+- #26971   py3: some minor fix for traveling salesman
+

 **Done**
 - #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
@@ -23,7 +25,9 @@
 - #26284   avoid comparison of vertex labels in MIP - connectivity.pyx
 - #26285   avoid comparison of vertex labels in MIP - generic_graph.py
 - #26469   avoid sorting vertex labels in `graph_plot.py`
-- #26484   clean graph_coloring.py and avoid comparison of vertex labels
+- #26478   clean `graph_plot_js.py`, `graph_list.py` and `graph_input.py`
+- #26480   clean graph_latex.py
+- #26484   clean `graph_coloring.py` and avoid comparison of vertex labels
 - #26528   avoid using `.vertices()` in comparability, hyperbolicity and distances_all_pairs
 - #26531   avoid using `.vertices()` in asteroidal_triples
 - #26534   avoid using `.vertices()` in weakly_chordal.pyx
fchapoton commented 5 years ago
comment:26

Concerning plot, there are still problems in py3 when plotting posets. This point to the remaining

File "/home/u1/chapoton/sage3/local/lib/python3.6/site-packages/sage/graphs/graph_plot.py", line 255, in __init__
        self._nodelist = graph.vertices()
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -17,6 +17,7 @@
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #26940   stop sorting returned list of edges in spanning tree methods 
 - #26971   py3: some minor fix for traveling salesman
+- #26973   py3: avoid `.vertices()` in `graph_plot.py`

 **Done**
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -15,9 +15,6 @@
 - #26520   Meta-ticket for methods in `src/sage/graphs/graph_decomposition/` - #26827, #26828, #26829, #26830, #26831, #26832, #26833, #26834
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
-- #26940   stop sorting returned list of edges in spanning tree methods 
-- #26971   py3: some minor fix for traveling salesman
-- #26973   py3: avoid `.vertices()` in `graph_plot.py`

 **Done**
@@ -62,5 +59,8 @@
 - #26869   py3: improve `is_aperiodic` to fix doctests (due to deprecation warning in networkx)
 - #26870   py3: fix error with `map` in `strongly_regular_db.pyx`
 - #26871   py3: fix doctests in `digraph_generators.py`
+- #26940   stop sorting returned list of edges in spanning tree methods 
+- #26971   py3: some minor fix for traveling salesman
+- #26973   py3: avoid `.vertices()` in `graph_plot.py`
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -15,7 +15,7 @@
 - #26520   Meta-ticket for methods in `src/sage/graphs/graph_decomposition/` - #26827, #26828, #26829, #26830, #26831, #26832, #26833, #26834
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
-
+- #27007   py3: avoid `.vertices()` in `planarity.pyx`

 **Done**
 - #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -16,6 +16,8 @@
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #27007   py3: avoid `.vertices()` in `planarity.pyx`
+- #27008   py3: avoid `.vertices()` in method `apex_vertices`$
+

 **Done**
 - #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -17,6 +17,7 @@
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #27007   py3: avoid `.vertices()` in `planarity.pyx`
 - #27008   py3: avoid `.vertices()` in method `apex_vertices`$
+- #27009   py3: avoid sorting vertices and edges in method treewidth

 **Done**
dcoudert commented 5 years ago
comment:32

With #27008, #27009 and #27010, all remaining doctest errors in graph.py concern the order in which solutions are displayed (not always the same in py2 and py3).

dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -18,7 +18,7 @@
 - #27007   py3: avoid `.vertices()` in `planarity.pyx`
 - #27008   py3: avoid `.vertices()` in method `apex_vertices`$
 - #27009   py3: avoid sorting vertices and edges in method treewidth
-
+- #27010   py3: avoid `.vertices()` in methods `_ford_fulkerson`, `edge_cut`, `bounded_outdegree_orientation` and `gomory_hu_tree`

 **Done**
 - #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -19,6 +19,7 @@
 - #27008   py3: avoid `.vertices()` in method `apex_vertices`$
 - #27009   py3: avoid sorting vertices and edges in method treewidth
 - #27010   py3: avoid `.vertices()` in methods `_ford_fulkerson`, `edge_cut`, `bounded_outdegree_orientation` and `gomory_hu_tree`
+- #27059   py3: improve doctests in `spanning_tree.pyx`

 **Done**
 - #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
embray commented 5 years ago
comment:34

Retarging tickets optimistically to the next milestone. If you are responsible for this ticket (either its reporter or owner) and don't believe you are likely to complete this ticket before the next release (8.7) please retarget this ticket's milestone to sage-pending or sage-wishlist.

jhpalmieri commented 5 years ago
comment:35

I would like to ask some questions about how to deal with simplicial complexes.

sage: g.edge_labels()
[None,
 None,
 'special_edge',
 'special_edge']

This fails in Python 3 because it tries to sort edges, and it can't sort str and NoneType. It is easy enough to provide labels in this case, but should the graph is_isomorphic method deal well with graphs where some edges have labels and some don't? (I don't have an opinion and I will fix the simplicial complex code separately.)

sage: S1 = simplicial_complexes.Sphere(1)
sage: g = S1.wedge(S1).graph()
sage: g
Graph on 5 vertices
sage: g.vertices()
[0, 'L1', 'L2', 'R1', 'R2']

In Python 3, the last line instead raises an error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-b2087dfc7b91> in <module>()
----> 1 g.vertices()

/Users/jpalmier/Desktop/Sage/sage_builds/PYTHON3/sage-8.6.rc1/local/lib/python3.6/site-packages/sage/graphs/generic_graph.py in vertices(self, sort, key)
  10053             raise ValueError('sort keyword is False, yet a key function is given')
  10054         if sort:
> 10055             return sorted(list(self.vertex_iterator()), key=key)
  10056         return list(self.vertex_iterator())
  10057 

TypeError: '<' not supported between instances of 'int' and 'str'
sage: g.min_spanning_tree()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-8a025bbcbd58> in <module>()
----> 1 g.min_spanning_tree()

/Users/jpalmier/Desktop/Sage/sage_builds/PYTHON3/sage-8.6.rc1/local/lib/python3.6/site-packages/sage/graphs/generic_graph.py in min_spanning_tree(self, weight_function, algorithm, starting_vertex, check)
   4231                 return min_spanning_tree(g,
   4232                                          weight_function=wfunction_float,
-> 4233                                          algorithm=algorithm.split("_")[0])
   4234 
   4235         if algorithm == "Prim_fringe":

/Users/jpalmier/Desktop/Sage/sage_builds/PYTHON3/sage-8.6.rc1/local/lib/python3.6/site-packages/sage/graphs/base/boost_graph.pyx in sage.graphs.base.boost_graph.min_spanning_tree (build/cythonized/sage/graphs/base/boost_graph.cpp:9345)()
    604 
    605 
--> 606 cpdef min_spanning_tree(g,
    607                         weight_function=None,
    608                         algorithm='Kruskal'):

/Users/jpalmier/Desktop/Sage/sage_builds/PYTHON3/sage-8.6.rc1/local/lib/python3.6/site-packages/sage/graphs/base/boost_graph.pyx in sage.graphs.base.boost_graph.min_spanning_tree (build/cythonized/sage/graphs/base/boost_graph.cpp:9100)()
    719     else:
    720         edges = [(int_to_vertex[<int> result[2*i]], int_to_vertex[<int> result[2*i+1]]) for i in range(n-1)]
--> 721         return [(min(e[0],e[1]), max(e[0],e[1]), g.edge_label(e[0], e[1])) for e in edges]
    722 
    723 

TypeError: '<' not supported between instances of 'int' and 'str'

In Python 2, g.min_spanning_tree() works, while in Python 3, it raises a similar TypeError:

sage: g.min_spanning_tree()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-8a025bbcbd58> in <module>()
----> 1 g.min_spanning_tree()

/Users/jpalmier/Desktop/Sage/sage_builds/PYTHON3/sage-8.6.rc1/local/lib/python3.6/site-packages/sage/graphs/generic_graph.py in min_spanning_tree(self, weight_function, algorithm, starting_vertex, check)
   4231                 return min_spanning_tree(g,
   4232                                          weight_function=wfunction_float,
-> 4233                                          algorithm=algorithm.split("_")[0])
   4234 
   4235         if algorithm == "Prim_fringe":

/Users/jpalmier/Desktop/Sage/sage_builds/PYTHON3/sage-8.6.rc1/local/lib/python3.6/site-packages/sage/graphs/base/boost_graph.pyx in sage.graphs.base.boost_graph.min_spanning_tree (build/cythonized/sage/graphs/base/boost_graph.cpp:9345)()
    604 
    605 
--> 606 cpdef min_spanning_tree(g,
    607                         weight_function=None,
    608                         algorithm='Kruskal'):

/Users/jpalmier/Desktop/Sage/sage_builds/PYTHON3/sage-8.6.rc1/local/lib/python3.6/site-packages/sage/graphs/base/boost_graph.pyx in sage.graphs.base.boost_graph.min_spanning_tree (build/cythonized/sage/graphs/base/boost_graph.cpp:9100)()
    719     else:
    720         edges = [(int_to_vertex[<int> result[2*i]], int_to_vertex[<int> result[2*i+1]]) for i in range(n-1)]
--> 721         return [(min(e[0],e[1]), max(e[0],e[1]), g.edge_label(e[0], e[1])) for e in edges]
    722 
    723 

TypeError: '<' not supported between instances of 'int' and 'str'

Once again, I could probably get around this by translating all of the vertices to something sortable and then translating back, but I do think that the graph theory code should be able to handle graphs whose vertices are a combination of int and str and anything else. I would like to put in a request for fixing this particular problem.

jhpalmieri commented 5 years ago
comment:36

Maybe one of these (the second one, I think) was taken care of by #27027.

jhpalmieri commented 5 years ago
comment:37

See #27067 for simplicial complexes fixes for the first two items.

dcoudert commented 5 years ago
comment:38

I fully agree that the graph theory code should be able to handle vertices of different types. We have done significant progresses recently, and many methods are no longer sorting vertices. But a lot remains to be done since a huge part of the code uses vertex ids instead of internal int labels. We have to find solutions for instance for listing edges as end points are currently sorted...

Note that I'm not able to try your example with py3 as this S1.wedge(S1).graph() already raises an error.

jhpalmieri commented 5 years ago
comment:39

First, you have all done great work with graphs, and you've made a tremendous amount of progress. Partly my questions were because I don't know whether some of these things have been done in tickets which have not yet been merged, but I think that's not the case.

Speaking of things which have not yet been merged, you need #26966 to be able to do S1.wedge(S1).graph(). Sorry, I hadn't realized that when I posted my example.

jhpalmieri commented 5 years ago
comment:40

Also, as I hope was clear in my questions, the first two are not critiques but honest questions: I don't know how Sage should handle those situations. The fact that things happen to work in Python 2 does not mean that they should automatically work in Python 3. For example, if you explicitly ask for isomorphisms preserving edge labels, an argument could be made that you should actually label all of the edges. The last item on my list was an explicit request, which it sounds like you agree with but also sounds like it take some work.

dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -15,10 +15,6 @@
 - #26520   Meta-ticket for methods in `src/sage/graphs/graph_decomposition/` - #26827, #26828, #26829, #26830, #26831, #26832, #26833, #26834
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
-- #27007   py3: avoid `.vertices()` in `planarity.pyx`
-- #27008   py3: avoid `.vertices()` in method `apex_vertices`$
-- #27009   py3: avoid sorting vertices and edges in method treewidth
-- #27010   py3: avoid `.vertices()` in methods `_ford_fulkerson`, `edge_cut`, `bounded_outdegree_orientation` and `gomory_hu_tree`
 - #27059   py3: improve doctests in `spanning_tree.pyx`

 **Done**
@@ -66,5 +62,9 @@
 - #26940   stop sorting returned list of edges in spanning tree methods 
 - #26971   py3: some minor fix for traveling salesman
 - #26973   py3: avoid `.vertices()` in `graph_plot.py`
+- #27007   py3: avoid `.vertices()` in `planarity.pyx`
+- #27008   py3: avoid `.vertices()` in method `apex_vertices`
+- #27009   py3: avoid sorting vertices and edges in method treewidth
+- #27010   py3: avoid `.vertices()` in methods `_ford_fulkerson`, `edge_cut`, `bounded_outdegree_orientation` and `gomory_hu_tree`
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -16,6 +16,10 @@
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #27059   py3: improve doctests in `spanning_tree.pyx`
+- #27123   bliss `automorphism_group()` shouldn't sort vertices 
+- #27125   py3: fix some doctests in `graph.py`
+- #27127   py3: avoid `.vertices()` in method `ear_decomposition`
+

 **Done**
 - #26274   avoid comparison of vertex labels in MIP - graph_coloring.py
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -19,6 +19,7 @@
 - #27123   bliss `automorphism_group()` shouldn't sort vertices 
 - #27125   py3: fix some doctests in `graph.py`
 - #27127   py3: avoid `.vertices()` in method `ear_decomposition`
+- #27129   py3: fix other doctests in `graph.py`

 **Done**
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -12,13 +12,10 @@

 **Needs review**:
-- #26520   Meta-ticket for methods in `src/sage/graphs/graph_decomposition/` - #26827, #26828, #26829, #26830, #26831, #26832, #26833, #26834
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
-- #27059   py3: improve doctests in `spanning_tree.pyx`
-- #27123   bliss `automorphism_group()` shouldn't sort vertices 
-- #27125   py3: fix some doctests in `graph.py`
-- #27127   py3: avoid `.vertices()` in method `ear_decomposition`
+- #27029   Avoid calling `.vertices()` in `graph_isom_equivalent_non_edge_labeled_graph()`
+- #27123   bliss `automorphism_group()` shouldn't sort vertices
 - #27129   py3: fix other doctests in `graph.py`

@@ -31,6 +28,7 @@
 - #26478   clean `graph_plot_js.py`, `graph_list.py` and `graph_input.py`
 - #26480   clean graph_latex.py
 - #26484   clean `graph_coloring.py` and avoid comparison of vertex labels
+- #26520   Meta-ticket for methods in `src/sage/graphs/graph_decomposition/` - #26827, #26828, #26829, #26830, #26831, #26832, #26833, #26834
 - #26528   avoid using `.vertices()` in comparability, hyperbolicity and distances_all_pairs
 - #26531   avoid using `.vertices()` in asteroidal_triples
 - #26534   avoid using `.vertices()` in weakly_chordal.pyx
@@ -71,5 +69,8 @@
 - #27008   py3: avoid `.vertices()` in method `apex_vertices`
 - #27009   py3: avoid sorting vertices and edges in method treewidth
 - #27010   py3: avoid `.vertices()` in methods `_ford_fulkerson`, `edge_cut`, `bounded_outdegree_orientation` and `gomory_hu_tree`
+- #27059   py3: improve doctests in `spanning_tree.pyx`
+- #27125   py3: fix some doctests in `graph.py`
+- #27127   py3: avoid `.vertices()` in method `ear_decomposition`
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -17,6 +17,7 @@
 - #27029   Avoid calling `.vertices()` in `graph_isom_equivalent_non_edge_labeled_graph()`
 - #27123   bliss `automorphism_group()` shouldn't sort vertices
 - #27129   py3: fix other doctests in `graph.py`
+- #27144   py3: fix doctests in `connectivity.pyx`

 **Done**
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -18,6 +18,10 @@
 - #27123   bliss `automorphism_group()` shouldn't sort vertices
 - #27129   py3: fix other doctests in `graph.py`
 - #27144   py3: fix doctests in `connectivity.pyx`
+- #27147   py3: fix doctests in `dense_graph.pyx`, `sparse_graph.pyx`, `static_sparse_graph.pyx`
+- #27148   py3: fix doctests in `centrality.pyx`
+- #27149   py3: fix doctests in `comparability.pyx`
+- #27151   py3: fix doctests in `vertex_separation.pyx`

 **Done**
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -22,6 +22,9 @@
 - #27148   py3: fix doctests in `centrality.pyx`
 - #27149   py3: fix doctests in `comparability.pyx`
 - #27151   py3: fix doctests in `vertex_separation.pyx`
+- #27158   py3: fix doctests in `boost_graph.pyx`
+- #27159   py3: fix doctests in `strongly_regular_db.pyx`
+- #27160   py3: fix doctests in `hyperbolicity` and `graph_coloring`

 **Done**
dcoudert commented 5 years ago

Description changed:

--- 
+++ 
@@ -15,7 +15,6 @@
 - #26678   clean generic_graph.py (part 12) - meta-ticket for methods related to clustering, centrality and distances. Tickets are #26803, #26813, #26814, #26815, #26819, #26820, #26821, #26822, #26823, #26824, #26825, #26826
 - #26679   clean generic_graph.py (part 13) - searches and constructors
 - #27029   Avoid calling `.vertices()` in `graph_isom_equivalent_non_edge_labeled_graph()`
-- #27123   bliss `automorphism_group()` shouldn't sort vertices
 - #27129   py3: fix other doctests in `graph.py`
 - #27144   py3: fix doctests in `connectivity.pyx`
 - #27147   py3: fix doctests in `dense_graph.pyx`, `sparse_graph.pyx`, `static_sparse_graph.pyx`
@@ -25,6 +24,7 @@
 - #27158   py3: fix doctests in `boost_graph.pyx`
 - #27159   py3: fix doctests in `strongly_regular_db.pyx`
 - #27160   py3: fix doctests in `hyperbolicity` and `graph_coloring`
+- #27165   py3: fix doctests in `c_graph.pyx`

 **Done**
@@ -78,6 +78,7 @@
 - #27009   py3: avoid sorting vertices and edges in method treewidth
 - #27010   py3: avoid `.vertices()` in methods `_ford_fulkerson`, `edge_cut`, `bounded_outdegree_orientation` and `gomory_hu_tree`
 - #27059   py3: improve doctests in `spanning_tree.pyx`
+- #27123   bliss `automorphism_group()` shouldn't sort vertices
 - #27125   py3: fix some doctests in `graph.py`
 - #27127   py3: avoid `.vertices()` in method `ear_decomposition`