only allow topological node consolidation to be run once on a graph #1273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes inscrutable error messages from occurring when trying to run topological node consolidation via the
consolidate_intersections
more than once on the same graph.For example, consider the snippet:
Would give you:
And if you instead set
tolerance=1
you'd get:These errors are impossible for a user to understand what's wrong. The nature of the problem is that the node consolidation algorithm can only be run once (because it's lossy) and should only be run once (because its parameterization allows near infinite customization to get a precise outcome in only one run). The
simplify_graph
function handles this gracefully by marked a graph as "simplified" and then raising an interpretable error if it's run again.This PR makes the
consolidate_intersections
consistent with the behavior of thesimplify_graph
function so its behavior is clearer for users:consolidate_intersections
function is run in topological mode (i.e., you rebuilt the graph)consolidate_intersections
function run in topological mode again, it raises an error with a clearer message: "GraphSimplificationError: This graph has already been consolidated, cannot consolidate it again."io
module gracefully handles the "consolidated" graph-level attribute when loading to/from file.consolidate_intersections
would mutate the passed-in graph itself.