Repository navigation
Forceatlas2 networkx implementation - #5392
cvanelteren wants to merge 26 commits into
Conversation
|
Small note. This implementation is not as fast as #5311. Running code without the cython dependency is not usable for larger graphs (in my opinion). Additionally, it does not contain the Barnes-Hut optimization yet. I may end up writing this in the future, or leave it up to the community. This is an initial implementation to get the layout out there. |
|
Before you put a lot more effort into this, NetworkX does not provide any cpp or pxd code. It should be pure python. |
|
@dschult code is in pure python with optional cython bindings. |
|
Rather than relying on code that needs to be compiled (which would be a blocker, even optionally), I wonder if this implementation could instead be recast in terms of sparse/vectorized operations. FWIW the current force-directed layouts provided by NetworkX (kamada-kawai, fruchterman-reingold) are implemented this way. |
|
@rossbar just pushed a vectorized implementation. This removes all the cython code. |
rossbar
left a comment
There was a problem hiding this comment.
I haven't had time to take a detailed look yet but yes it'd be great to add some tests. Ideally we could find some examples (perhaps from the paper) of the expected node positions (give or take scale factors) and verify that the results of the layout function against those. I skimmed the paper and didn't notice any obvious candidates. I'm also not a Gephi user so I have no idea if there's a good way to generate such test data. Any ideas?
|
I took the liberty of pushing up a minor change just to retrigger the CI. |
- Added gravity - Fixed swing update computation
2388aeb to
397ac4c
Compare
|
I wrote some code that calls gephi to run forceatlas2 starting from the same layout. I am not a gephi user unfortunately, and the gui does not run on my OS. It seems like the initial layout I give gephi through the cli is ignored. By eye, the layouts generated with the code above look similar, but not the same due to the different starting conditions. All other parameters are matched (code here). I also removed the sparse matrix conversion, as distance are less likely to be sparse anyway. This prohibits the vectorized approach for larger graphs. I'm open to an alternative that is not using for loops for this (or use the earlier cythonized commit). EDIT: I was going to use the gist in some form to generate ground truth positions and wrap those in a unittest (without the call to gephi ofcourse ;-)) |
|
Any comments on this PR or wanted changes? |
ff3b39d to
f5133cc
Compare
|
@dschult I believe the PR is ready for merging. The last check seems to be related to the build environment, not to the PR. Best, C |
|
I agree that this is ready for reviews/approvals... The tests seem to indicate a problem on the circle-ci build action with being unable to update apt-get. That has nothing to do with this PR. I will hopefully be able to get to this PR next week. |
dschult
left a comment
There was a problem hiding this comment.
This looks good!! Thanks!!
It needs tests. Your pictures look great and agree with Gephi. But as you know we need to make sure it keeps looking great. So tests are needed. Use pytest. Take a look at the other layout tests. If you have questions, ask.
I'm a little confused as to why the setup.py changes appear in this PR. I thought those changes were already merged into networkx. Why are they showing up in this PR?
|
I believe this is ready to be merged @dschult. |
There was a problem hiding this comment.
This looks good! Thanks!
I have a few very small comments below.
As a topic for another PR (unless you want t take it on), many of the layout functions set the initial conditions by default to a random layout. But they don't provide a way to control the random seed for that output. We should either let them provide a seed, or (my preference) add a phrase in the documentation for the pos argument which says that the default is a random layout. If they want to control the seed of that random layout they should generate it themselves and not use the default pos. I think this could be done with the kamada_kawai_layout doc_string too. I didn't see others, but there might be others.
|
Looks like a merge from main and a bunch of lint tweaks cleaned up the tests. You will need to pull it down to your local machine of course before making changes. |
d7654db to
21a7946
Compare
I think I messed up a pull somewhere, think I just restored it. |
|
@mbastian Hi Mathieu! We met last year in Leiden. I believe you have forceatlas2 in Gephi. If you have any time or interest, it would be great if you or someone on your team who is familiar with this layout could take a look. |
|
@jarrodmillman I used the official gephi code as a base for this code base in case that was any concerns. |
Sorry for the confusion - NetworkX requires approvals from two maintainers before merging. For cases like this one, where there has been a lot of back-and-forth, it is useful to verify that the suggestions of the reviewers are making it all the way into the code. Indeed it seems there are still some changes that have been "undone" by the latest pushes, so this is still not ready IMO. I will take a stab at manually resolving things to see if I can't get it over the finish line. |
|
Actually I take that back - looking at it more closely, it looks like most of the suggestions have been reverted... I think perhaps the last attempt to "fix" a missed pull may have actually made things worse. Did you perhaps force-push from a different local branch? |
hmm could be that I rebased wrong, could you push your latest changes, then I can merge them here locally. |
I'll hold off on making any changes - just ping me when you think you've got the PR in the state you want it! |
|
🔔 @rossbar 🔔 I see that the doc strings were old. I fixed it. I'm fine with the layout now, and have been using it for a while locally ;-). |
|
It's more than just the docstrings, many of @dschult's original comments still seem to not be addressed (though they were marked as resolved - I un-resolved them). |
|
I think it would be easier if someone can force push the local branch that contains the latest changes that are passable, it is currently for unclear what is not correct in this PR -- I don't have access to this older commit anymore, and this thread is spanning several years now. If there is anything needed on my part that requires changing, please ping me but from my side this PR is done. |
It sounds like some work may have been lost due to force pushing - in that case, I propose to resubmit the current commits in a new PR (to prevent unintentional force-pushes) so that we can finish polishing off the remaining issues. Re: attribution, the current commit history on this branch will be preserved. Does this sound okay to you @cvanelteren ? |
|
@rossabar, I made a new PR #7521, should we use this PR to merge the old commits? |

Implementation of forceatlas2 layout based on https://journals.plos.org/plosone/article/file?id=10.1371/journal.pone.0098679&type=printable
Example: