qiime2 / provenance-lib

QIIME 2 Provenance Replay Tools
BSD 3-Clause "New" or "Revised" License
3 stars 4 forks source link

ProvDAG constructor may not support some inherited functions #25

Closed ChrisKeefe closed 3 years ago

ChrisKeefe commented 3 years ago

summary

Some nx functions fail with ProvDAGs. (probably those which create new graphs based on an existing graph object)

details

I suspect this is an issue with the way we've reimplemented __init__. I suspect these functions are attempting to create new graphs/graphviews of the same type as the "parent" and then fill in the data, but are choking on the way ProvDAG is initialized. A few quick attempts didn't yield results.

None of these functions are quite critical at this time, but I'll have to come back to this. Union may also be affected if we're asking nx to create a new ProvDAG on its own. If addressing this directly proves problematic, we may be able to sidestep the issue by making ProvDAGs (or something with a better name) that simply have a DiGraph, and implement helpers that call DiGraph functions.

examples

Call:

nx.subgraph_view(dag, filter_node = lambda x: x in nested_nodes)

traceback:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-e778f4be6599> in <module>
----> 1 nx.subgraph_view(dag, filter_node = lambda x: x in nested_nodes)
      2 nx.draw(dag, with_labels=True, font_weight="bold")

~/miniconda/envs/prov/lib/python3.8/site-packages/networkx/classes/graphviews.py in subgraph_view(G, filter_node, filter_edge)
    142     EdgeView([(0, 1), (1, 2), (2, 3)])
    143     """
--> 144     newG = nx.freeze(G.__class__())
    145     newG._NODE_OK = filter_node
    146     newG._EDGE_OK = filter_edge

TypeError: __init__() missing 1 required positional argument: 'archive_fp'

Call:

dag = ProvDAG(archive_fp=qzv)
reversed = nx.reverse_view(dag)

Traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-a11c5f1b7b87> in <module>
      6 contents = dag.parser_results.archive_contents
      7 nodes = list(contents.values())
----> 8 reversed = nx.reverse_view(dag)

<decorator-gen-128> in reverse_view(G)

~/miniconda/envs/prov/lib/python3.8/site-packages/networkx/utils/decorators.py in _not_implemented_for(not_implement_for_func, *args, **kwargs)
     76             raise nx.NetworkXNotImplemented(msg)
     77         else:
---> 78             return not_implement_for_func(*args, **kwargs)
     79 
     80     return _not_implemented_for

~/miniconda/envs/prov/lib/python3.8/site-packages/networkx/classes/graphviews.py in reverse_view(G)
    201     OutEdgeView([(2, 1), (3, 2)])
    202     """
--> 203     newG = generic_graph_view(G)
    204     newG._succ, newG._pred = G._pred, G._succ
    205     newG._adj = newG._succ

~/miniconda/envs/prov/lib/python3.8/site-packages/networkx/classes/graphviews.py in generic_graph_view(G, create_using)
     42 def generic_graph_view(G, create_using=None):
     43     if create_using is None:
---> 44         newG = G.__class__()
     45     else:
     46         newG = nx.empty_graph(0, create_using)

~/src/provenance_py/provenance_lib/parse.py in __init__(self, cfg, archive_fp)
    129                         type = tuple(parent.keys())[0]
    130                         parent_uuid = tuple(parent.values())[0]
--> 131                         ebunch.append((parent_uuid, node_id,
    132                                        {'type': type}))
    133             self.add_edges_from(ebunch)

~/miniconda/envs/prov/lib/python3.8/zipfile.py in __init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps)
   1267         try:
   1268             if mode == 'r':
-> 1269                 self._RealGetContents()
   1270             elif mode in ('w', 'x'):
   1271                 # set the modified flag so central directory gets written

~/miniconda/envs/prov/lib/python3.8/zipfile.py in _RealGetContents(self)
   1330         fp = self.fp
   1331         try:
-> 1332             endrec = _EndRecData(fp)
   1333         except OSError:
   1334             raise BadZipFile("File is not a zip file")

~/miniconda/envs/prov/lib/python3.8/zipfile.py in _EndRecData(fpin)
    262 
    263     # Determine file size
--> 264     fpin.seek(0, 2)
    265     filesize = fpin.tell()
    266 

AttributeError: 'NoneType' object has no attribute 'seek'

References

The DiGraph source has a subclassing example near the end of the docstring