nengo / nengo-extras

Extra utilities and add-ons for Nengo
https://www.nengo.ai/nengo-extras
Other
5 stars 8 forks source link

GEXF conversion #54

Closed jgosmann closed 6 years ago

jgosmann commented 6 years ago

(based on PR #56)

This PR adds a conversion of Nengo model to the GEXF format, which can be opened with Gephi, a visualization and explanatory analysis software for graphs. The motivation behind this is that Nengo GUI currently is not powerful enough to get a good overview over complex models (e.g., no support to color or temporarily hide objects, no possibility to identify inhibitory or modulatory connections).

A screenshot from a Nengo model visualized in Gephi: screenshot_125402

The main class is GexfConverter, doing the basic conversion of a model. But usually there is a bunch of networks (like spa.State) where all the detail is too much. CollapsingGexfConverter thus extends GexfConverter to keep certain networks collapsed. Both classes use the DispatchTable descriptor to define conversion methods for different types of Nengo objects. This descriptor allows to overwrite methods in derived classes or on instances to customize the conversion.

Furthermore, there is a InspectiveLabeler class to obtain the labels for the graph nodes. This is done by going through the referrers of an object and looking for dictionaries where the key could be used as name and stack frames that contain the object. This might be mildly interesting for Nengo GUI (@tcstewar @tbekolay) as an alternate way to obtain names, but is probably a worse approach. Getting the referrers is a slow operation (because Python has to scan all objects). Also, we cannot get the name for objects that have been created in a function that finished excuting without assigning the object as an attribute. Even worse, those objects get a name like 'o' (depending on the context in which the labeler is executed). Currently, this affects only a few nodes in my model (so I won't spend time on this for now), but might be a limitation for other models.

The GEXF format supports a hierarchical graph representation that can be activated with the hierarchical=True flag. However, in the current Gephi version support for hierarchical graphs has been removed (last version with that support is 0.8.x which can still be run with JRE <= 1.7). Thus, it will flatten a hierarchical graph and leave an unconnected node for every network. The default hierarchical=False will write a flat graph and avoid those unconnected nodes.

jgosmann commented 6 years ago

Could you put an example of how to visualize a model using Gephi in the examples?

I'm hoping to do a presentation in a lab meeting on this. Though, having an example in writing would certainly be nice, but also a bit of effort ...

hunse commented 6 years ago

I'm hoping to do a presentation in a lab meeting on this. Though, having an example in writing would certainly be nice, but also a bit of effort ...

I think that effort is worth it. Whether you prepare the example now, or for the lab meeting in the future, an example is necessary if you want others to use this, IMO. The problem with only presenting it in a lab meeting is that a) the people who saw the presentation will forget the details, and not have anything to reference, b) anybody who didn't see the presentation (whether they were away, or someone outside our immediate lab group) won't have anything to work from. Examples become especially useful when things like the Nengo summer school come up, and we want to help introduce these extra tools to new people.

I'm fine to merge this without an example for now, so that it's easier for you to use and maintain, as long as the plan is to add an example eventually.

jgosmann commented 6 years ago

I think that effort is worth it.

Yes, I completely agree. I just have to find the time ...

jgosmann commented 6 years ago

Rebased this PR onto #56 (setting up documentation for nengo_extras) and added a tutorial on Nengo+Gephi.

jgosmann commented 6 years ago

Sounds good to me. It'd be nice if building the documentation with the images somewhere else does not involve much more effort and if it is clear how to change/update them.

tbekolay commented 6 years ago

It'd be nice if building the documentation with the images somewhere else does not involve much more effort and if it is clear how to change/update them.

I was going to just upload them to imgur and include them with IPython.display.Image. Any objection to that, or alternatives?

jgosmann commented 6 years ago

Doesn't imgur delete images after a while? I feel like it is not uncommon to come along broken imgur links. But that's just anecdotal evidence (at best).

tbekolay commented 6 years ago

As of Feb 2015 images are only deleted upon request, as long as they're uploaded by a logged in user (which I would be).