question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Layouts fail for directed graphs

See original GitHub issue

Expected Behavior

Layouts should work with directed graphs (IMO) Perhaps not a bug in the sense that I’m not sure we promise this works for directed, but still. If we decided to only support undirected maybe a clearer error is warranted.

Actual Behavior

NetworkXNotImplemented: not implemented for directed type

Example Code

import networkx as nx
from graspologic.layouts import layout_umap

g = nx.erdos_renyi_graph(10, 0.7, directed=True)
layout_umap(g)

Full Traceback

---------------------------------------------------------------------------
NetworkXNotImplemented                    Traceback (most recent call last)
~/JHU_code/maggot/maggot_connectome/scripts/what_is_flow_rank.py in 
      3 
      4 g = nx.erdos_renyi_graph(10, 0.7, directed=True)
----> 5 layout_umap(g)

~/miniconda3/envs/maggot-revamp/lib/python3.8/site-packages/graspologic/layouts/auto.py in layout_umap(graph, min_dist, n_neighbors, max_edges, random_seed)
    173     """
    174 
--> 175     lcc_graph, tensors, labels = _node2vec_for_layout(graph, max_edges, random_seed)
    176     points = umap.UMAP(
    177         min_dist=min_dist, n_neighbors=n_neighbors, random_state=random_seed

~/miniconda3/envs/maggot-revamp/lib/python3.8/site-packages/graspologic/layouts/auto.py in _node2vec_for_layout(graph, max_edges, random_seed)
    214 ) -> Tuple[nx.Graph, np.ndarray, np.ndarray]:
    215     graph = _approximate_prune(graph, max_edges)
--> 216     graph = _largest_connected_component(graph)
    217 
    218     start = time.time()

~/miniconda3/envs/maggot-revamp/lib/python3.8/site-packages/graspologic/layouts/auto.py in _largest_connected_component(graph)
    182 
    183 def _largest_connected_component(graph: nx.Graph) -> nx.Graph:
--> 184     largest_component = max(nx.connected_components(graph), key=len)
    185     return graph.subgraph(largest_component).copy()
    186 

 in connected_components(G)

~/miniconda3/envs/maggot-revamp/lib/python3.8/site-packages/networkx/utils/decorators.py in _not_implemented_for(not_implement_for_func, *args, **kwargs)
     74         if match:
     75             msg = f"not implemented for {' '.join(graph_types)} type"
---> 76             raise nx.NetworkXNotImplemented(msg)
     77         else:
     78             return not_implement_for_func(*args, **kwargs)

NetworkXNotImplemented: not implemented for directed type

Your Environment

  • Python version: 3.8
  • graspologic version: dev

Additional Details

183 def _largest_connected_component(graph: nx.Graph) -> nx.Graph:
--> 184     largest_component = max(nx.connected_components(graph), key=len)

Just from these 2 lines on the traceback, I suspect this just needs to be adapted to check for weakly connected components. Or, use graspologic.utils.is_fully_connected from our own codebase. However in #112 we are talking about replacing the networkx-based check with a faster one from scipy. Not sure if the layouts code will always assume networkx input going forward. AFAIK there is nothing that inherently needs to be undirected for the layouts process, or am I missing something?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bdpedigocommented, Feb 8, 2021

FYI @kareef928 has been working on the conversion stuff so we’ll keep him in the loop too!

1reaction
daxprycecommented, Feb 8, 2021

Would be interesting to see if the time-to-convert an nx graph into a csr matrix and run that lcc check is faster than doing it all in networkx. I’ll keep you guys posted after I crunch some numbers 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Force Directed Graph Error, "Cannot Read Property 'Push' of ...
However, when I explicitly list the nodes I receive the error "Uncaught TypeError: Cannot read property 'push' of undefined (d3.v3.min.js)". I ...
Read more >
Error when plotting a small digraph - MATLAB Answers
Using (e.g.) the circle layout works fine. Is there a workaround that lets me use the default/force layout or must I resort to...
Read more >
Cairo-Error when attempting ARF layout of graph (#239) - GitLab
I am currently facing a problem similar to the one reported a few months ago (Crash when generating arf_layout for a directed twitter...
Read more >
Commerce Bug 2.5: One Click Layout Graph - Alan Storm
There's lots of libraries that model directed graphs (nodes, edges, the relationships between them) without actually providing a visualization ...
Read more >
Network Analysis and Visualization with R and igraph
rm(z) # Remove z: deletes the object. z # Error! ... The code below generates an undirected graph with three edges. The numbers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found