Repository navigation
Fix bugs in all_node_cuts, address #3025 - #3039
Conversation
|
I have a few specific questions about some design decisions to make:
Besides these two questions, I would also hope the code to be reviewed a bit since I think the change is quite substantial. I wonder if you guys can take some look. Thank you. @jtorrents @dschult |
|
I took the liberty for these design questions and I think it's ready to merge now but let me know if you have issues with it. |
|
Does If I understand correctly, the change that fixes the algorithm is to move out of the loop over antichains the code that puts x and v in the auxillary graphs. I don't know the algorithm well, but: once we yield a node_cut do we need to consider any other antichains for those values of x and v? That is, is it possible to have another antichain produce a node_cut with that same value of x, v, H and R? Thanks for this -- it helps a lot. |
|
I did some basic profiling on very small graph and it seems that there is no obvious optimization available. I don't think the type of Each of them takes about 20% execution time. There seems to have multiple incorrect implementation in the original code and one of them is ignoring other antichains, original bug report is about missing some cuts and those cuts are generated by other antichains we skipped. Profiling on first 20 cuts in `torrents_and_ferraro_graph` |
|
Yes -- the time seems to be mostly in those two set comprehensions and the graph lookups. All the suggestions here cut the time t less than half. Not a huge savings, but given the now longer time maybe worthwhile... I think the first set comprehension is taking time because A couple of other things get about 5-10% improvement: ============ =========== Full patchEverything included the patch becomes: (is there a better way to show a patch here?) |
|
It is much better to have the code that doesn't skip those antichains. There is more work to do here in terms of looking for algorithmic shortcuts and so forth. |
|
Thanks for all these suggestions, I benchmarked each of these changes and all of them can speed it up a bit. The most speedup actually comes from not reversing the graph. There is another potential optimization that might help: we can test Newer profiling results |
|
Nice layout code for the comment! I didn't know you could hide details. :) Yes, I agree that the next place to look for speedup is the antichains. I think this is ready to merge. Anything else? |
|
I'm checking to see if we can afford larger tests with the newer code, so maybe a bit later. |
|
It seems the code works fine with We may want to see if using customized antichains can help, but I think it's ready to merge now. |
…ithm. The Even-Tarjan auxiliary digraph built by build_auxiliary_node_connectivity sets capacity=1 on all edges. This is correct for computing the node connectivity value, but Kanevsky's algorithm depends on the structure of the residual graph, which requires infinite capacity on external edges as the original Even-Tarjan reduction specifies. With unit-capacity external edges, these edges get saturated by the flow, producing a residual graph with the wrong structure. The condensation DAG has too many nodes, and the antichain count explodes exponentially. This bug (introduced by me in the original NetworkX implementation) was not identified when correctness bugs were reported in networkx#3025. The fix in PR networkx#3039 addressed the symptoms (missing cuts) by adding compensating filters: VE1 incident-node filtering, transitive closure on the full residual graph, and internal-edge validation; and also introduced two additional bugs: - Removing backward arcs from the residual graph (capacity=0 edges with negative flow that represent cancellable flow and must be preserved) - Building closed sets using predecessors instead of successors in the condensation DAG, producing the wrong side of the cut partition These filters discarded most of the millions of spurious antichains generated by the broken condensation DAG, making results mostly correct but at enormous computational cost. This fix addresses the root cause and restores the algorithm to match the paper's specification: - Set infinite capacity on external edges before building the residual - Remove only edges with zero residual capacity (capacity == flow) - Build successor-closed sets from antichins of the condensation DAG - Find cut edges from S to ~S using H successors. The compensating code is no longer needed and has been removed. Performance on grid_2d_graph(11,11) improves from 180s to 0.16s (n=121) (1000x+), and now scales polynomially as predicted by the paper. Results verified identical to igraph's C implementation at all tested sizes. Fixes networkx#7994. Tests previously marked @pytest.mark.slow are now fast enough to run by default, and MAX_CUTSETS_TO_TEST is restored from 4 to 100.
…ithm. The Even-Tarjan auxiliary digraph built by build_auxiliary_node_connectivity sets capacity=1 on all edges. This is correct for computing the node connectivity value, but Kanevsky's algorithm depends on the structure of the residual graph, which requires infinite capacity on external edges as the original Even-Tarjan reduction specifies. With unit-capacity external edges, these edges get saturated by the flow, producing a residual graph with the wrong structure. The condensation DAG has too many nodes, and the antichain count explodes exponentially. This bug (introduced by me in the original NetworkX implementation) was not identified when correctness bugs were reported in networkx#3025. The fix in PR networkx#3039 addressed the symptoms (missing cuts) by adding compensating filters: VE1 incident-node filtering, transitive closure on the full residual graph, and internal-edge validation; and also introduced two additional bugs: - Removing backward arcs from the residual graph (capacity=0 edges with negative flow that represent cancellable flow and must be preserved) - Building closed sets using predecessors instead of successors in the condensation DAG, producing the wrong side of the cut partition These filters discarded most of the millions of spurious antichains generated by the broken condensation DAG, making results mostly correct but at enormous computational cost. This fix addresses the root cause and restores the algorithm to match the paper's specification: - Set infinite capacity on external edges before building the residual - Remove only edges with zero residual capacity (capacity == flow) - Build successor-closed sets from antichins of the condensation DAG - Find cut edges from S to ~S using H successors. The compensating code is no longer needed and has been removed. Performance on grid_2d_graph(11,11) improves from 180s to 0.16s (n=121) (1000x+), and now scales polynomially as predicted by the paper. Results verified identical to igraph's C implementation at all tested sizes. Fixes networkx#7994. Tests previously marked @pytest.mark.slow are now fast enough to run by default, and MAX_CUTSETS_TO_TEST is restored from 4 to 100.
…ithm (#8586) Fix all_node_cuts: correct Even-Tarjan reduction for Kanevsky's algorithm. The Even-Tarjan auxiliary digraph built by build_auxiliary_node_connectivity sets capacity=1 on all edges. This is correct for computing the node connectivity value, but Kanevsky's algorithm depends on the structure of the residual graph, which requires infinite capacity on external edges as the original Even-Tarjan reduction specifies. With unit-capacity external edges, these edges get saturated by the flow, producing a residual graph with the wrong structure. The condensation DAG has too many nodes, and the antichain count explodes exponentially. This bug (introduced by me in the original NetworkX implementation) was not identified when correctness bugs were reported in #3025. The fix in PR #3039 addressed the symptoms (missing cuts) by adding compensating filters: VE1 incident-node filtering, transitive closure on the full residual graph, and internal-edge validation; and also introduced two additional bugs: - Removing backward arcs from the residual graph (capacity=0 edges with negative flow that represent cancellable flow and must be preserved) - Building closed sets using predecessors instead of successors in the condensation DAG, producing the wrong side of the cut partition These filters discarded most of the millions of spurious antichains generated by the broken condensation DAG, making results mostly correct but at enormous computational cost. This fix addresses the root cause and restores the algorithm to match the paper's specification: - Set infinite capacity on external edges before building the residual - Remove only edges with zero residual capacity (capacity == flow) - Build successor-closed sets from antichins of the condensation DAG - Find cut edges from S to ~S using H successors. The compensating code is no longer needed and has been removed. Performance on grid_2d_graph(11,11) improves from 180s to 0.16s (n=121) (1000x+), and now scales polynomially as predicted by the paper. Results verified identical to igraph's C implementation at all tested sizes. Fixes #7994. Tests previously marked @pytest.mark.slow are now fast enough to run by default, and MAX_CUTSETS_TO_TEST is restored from 4 to 100.
Address #3025.
I made quite some changes to the original implementation and this probably need to be carefully reviewed.
The code correctly find much more cuts from
torrents_and_ferraro_graphand doesn't need to deal with cycle graph separately. However it's also significantly slower than before, so I turned off a few tests for now.I will explain a bit about the changes later and probably add more comments, but I'd like to get some feedback.