snorkel-team / snorkel

A system for quickly generating training data with weak supervision
https://snorkel.org
Apache License 2.0
5.81k stars 857 forks source link

Backwards-incompatible (2.3 -> 2.4) update to networkx #1491

Closed dataframing closed 5 years ago

dataframing commented 5 years ago

Issue description

As a result of a recent update to networkx, Graph objects no longer expose the node attribute. This causes code within the LabelModel to break, namely the call to fit, which calls self._create_tree, which calls (and ultimately fails at) snorkel/labeling/model/graph_utils.py::get_clique_tree.

Code example/repro steps

To test this, I created a new environment and only installed networkx==2.3.0 via pipenv:

>>> import networkx as nx
>>> nx.__version__
'2.3'
>>> g = nx.Graph()
>>> g.add_nodes_from(range(20))
>>> g.nodes
NodeView((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19))
>>> g.nodes[10]
{}
>>> g.node
NodeView((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19))
>>> g.node[10]
{}

Then, I tried the same code with networkx==2.4.0rc1, which is what pipenv installed (since I had allowed pipenv to also install packages tagged as prereleases):

>>> import networkx as nx
>>> nx.__version__
'2.4rc1'
>>> g = nx.Graph()
>>> g.add_nodes_from(range(20))
>>> g.nodes
NodeView((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19))
>>> g.nodes[10]
{}
>>> g.node
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Graph' object has no attribute 'node'

Obviously, you're biting the bullet when you allow for pre-release builds. However, given that 2.4.0rc1 will soon become 2.4.0, I suspect this would be an issue in the near future, regardless. Link to the NetworkX 2.4 release notes (in-progress) here, you can search for G.node --> use G.nodes.

Expected behavior

Given that snorkel's requirements.txt allows for networkx>=2.2,<3.0, I was surprised to see that networkx==2.4.0rc1 was causing the label model to fail.

Screenshots

N/A

System info

Additional context

I think a quick fix is to either update the dependency bounds within requirements.txt (e.g., networkx>=2.3,<2.4 or to update the calls that access networkx.Graph.node to networkx.Graph.nodes.

bhancock8 commented 5 years ago

Thanks for sharing! It's disappointing that networkx broke (or seems likely to break) backwards compatibility in a minor version update. I whipped up a PR (#1492) upper-bounding networkx version that should solve the issue.