Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CycleError: Report all nodes #159

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

matthiasdiener
Copy link
Contributor

No description provided.

pytools/graph.py Outdated
def __init__(self, node: T) -> None:
self.node = node
def __init__(self, nodes: List[T]) -> None:
self.nodes = nodes
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks backward compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I avoid that - maybe by providing a nodes parameter (with a default of None) in addition to the node parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of c39afca?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better approach would be to make node a @property that spews a DeprecationWarning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 8823bca

pytools/graph.py Outdated Show resolved Hide resolved
pytools/graph.py Outdated
Comment on lines 302 to 303
raise CycleError(list(n for n, num_preds in
nodes_to_num_predecessors.items() if num_preds != 0))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to provide this in traversable (rather than arbitrary) order, which is doable at $O(n)$ cost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to do that - how would we provide this in case there are multiple cycles in the graph?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#167 has some work in this direction

@inducer
Copy link
Owner

inducer commented Nov 17, 2022

Unsubscribing... @-mention or request review once it's ready for a look or needs attention.

@kaushikcfd
Copy link
Collaborator

Also worth referring to the suggestions in this PR: https://gitlab.tiker.net/inducer/pytools/-/merge_requests/37.

pytools/graph.py Outdated
def __init__(self, node: T) -> None:
self.node = node
def __init__(self, nodes: List[T]) -> None:
self.nodes = nodes
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better approach would be to make node a @property that spews a DeprecationWarning.

pytools/graph.py Outdated
@@ -213,9 +213,17 @@ class CycleError(Exception):
Raised when a topological ordering cannot be computed due to a cycle.

:attr node: Node in a directed graph that is part of a cycle.

:attr nodes: List of nodes in a directed graph that are part of a cycle.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe path is a better name. Also state that we claim that node[i+1] in path is a successor of node[i] (and test that!).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to paths and added comment regarding the successors in 47aa316.
Testing this is done in #167 right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants