Fixing the output positions in sfdp layout

Hi

I am trying to fix the layout that I get every time that I re-run my script.

I gave input pos to sfdp a propertymap that initializes all positions to
[1,1].
However, the output pos that I am getting is slightly different every time.

Any solutions? Thanks!

If you put all vertices on the same position, the repulsive force
between them will be undefined. What the algorithm does in this case, is
to push the vertices apart in random directions. To avoid this, you
should put them initially in different positions.

Furthermore, you should disable parallel processing with OpenMP which
will introduce another source of non-determinism. You can do this by
calling: openmp_set_num_threads(1)

Best,
Tiago

Hi Tiago,

Thanks for the reply. I still have the same issue. I am running the
following code in Jupyter

prop = g.new_vertex_property("vector<double>")
for i in xrange(n):
    prop[i] = [1 + i,1 + i]

#openmp_set_num_threads(1)

pos = sfdp_layout(g, gamma=10.0, mu=10.0, mu_p=10.0, verbose = False,
pos=prop)

I disabled the openmp command because it gives me an error that it's not
enabled anyway:
"OpenMP was not enabled during compilation".

Every time that I press shift + enter in Jupyter to re-run the above piece
of code (without running
anything else in-between) I get a different pos output.

Kimon

I cannot reproduce this. Can you please provide a short, complete and
self-contained example that shows the problem?

Best,
Tiago

Sure. I attached two files. A .pynb file for the code and senate.txt for the
data.

senate-unrolled.txt
<http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4026506/senate-unrolled.txt&gt;
test_kimon.ipynb
<http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4026506/test_kimon.ipynb&gt;

test_kimon.ipynb
<http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4026507/test_kimon.ipynb&gt;

senate-unrolled.txt
<http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4026507/senate-unrolled.txt&gt;

Any news in that front? I tried various things but every time I get different
result.
Is the method deterministic? If not how can I initialize its seed?

Kimon

It should be deterministic, but it is not. This is a bug and will be
fixed.

In the mean time you can make it deterministic by seeding the RNG before
calling graph_draw():

    numpy.random.seed(42)
    graph_tool.seed_rng(42)

Best,
Tiago

Ok thanks Tiago. I made a hack by saving the pos variable and loading it back
when I need.
I will try your solution which sounds easier.

Kimon

This is of course much faster, and makes a lot more sense if you just
need a single drawing for the same graph.

Best,
tiago