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

Improve error message when the graph contains cyclic dependencies #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JeremyIV
Copy link

Creates a more helpful exception when trying to compose a graph with cyclic dependencies.

Example message: (helpful part at the bottom)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'op3' is not defined
>>> graph = compose(name="graph")(op1, op2, op4)
Traceback (most recent call last):
  File "/home/jeremyiv/Documents/graphkit-1/graphkit/network.py", line 119, in compile
    ordered_nodes = list(nx.dag.topological_sort(self.graph))
  File "/home/jeremyiv/anaconda3/lib/python3.8/site-packages/networkx/algorithms/dag.py", line 210, in topological_sort
    raise nx.NetworkXUnfeasible("Graph contains a cycle or graph changed "
networkx.exception.NetworkXUnfeasible: Graph contains a cycle or graph changed during iteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jeremyiv/Documents/graphkit-1/graphkit/functional.py", line 209, in __call__
    net.compile()
  File "/home/jeremyiv/Documents/graphkit-1/graphkit/network.py", line 126, in compile
    raise Exception(f"Cyclic dependency in graph:\n{_format_cycle(cycle)}")
Exception: Cyclic dependency in graph:
op1 needs "a" from op4.
op4 needs "c" from op1.

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@ankostis
Copy link

Great!

I would raise the same exception type `networkx.exception.NetworkXUnfeasible.

@JeremyIV
Copy link
Author

Ok, made the change. It throws the same NetworkXUnfeasible exception now.

@ankostis
Copy link

Just to be lcear, have no saying i this project.

@JeremyIV
Copy link
Author

Ah... Is this project maintained anymore? Are there better maintained alternatives?

@ankostis
Copy link

I submitted a lot of fixes and enhancements in #22 (and other issues) a couple of years ago, that were not addressed.
Eentually i forked it into https://graphtik.readthedocs.io/.

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.

2 participants