jcmgray / quimb

A python library for quantum information and many-body calculations including tensor networks.
http://quimb.readthedocs.io
Other
455 stars 107 forks source link

forceatlas2_networkx_layout() in drawing.py returns error #126

Closed SnehalRaj closed 2 years ago

SnehalRaj commented 2 years ago

What happened?

I was working with the Sycamore Quantum Circuit example on Cotengra link and ran into this error while drawing the tensor network graph

Code tn.graph(iterations=20, color=circ.psi.site_tags, legend=False, figsize=(3, 3)) Error

TypeError                                 Traceback (most recent call last)
[<ipython-input-19-be4976cfc81b>](https://localhost:8080/#) in <module>()
----> 1 tn.graph(iterations=20, color=circ.psi.site_tags, legend=False, figsize=(3, 3))
[/usr/local/lib/python3.7/dist-packages/quimb/tensor/drawing.py](https://localhost:8080/#) in get_positions(tn, G, fix, initial_layout, k, iterations, use_forceatlas2, use_spring_weight)
    759             from fa2 import ForceAtlas2
    760             pos = ForceAtlas2(verbose=False).forceatlas2_networkx_layout(
--> 761                 G, pos=pos0, iterations=iterations)
    762         else:
    763             pos = nx.spring_layout(

TypeError: forceatlas2_networkx_layout() got an unexpected keyword argument 'weight_attr'

I assume it is because the forceatlas2_networkx_layout(G, pos, iterations) doesn't take weight_attr as input?

A quick look through forceatlas2 shows that forceatlas2_igraph_layout(G, pos, iterations, weight_attr) uses the 'weight_attr' argument

What did you expect to happen?

No response

Minimal Complete Verifiable Example

https://github.com/jcmgray/cotengra/blob/c3d7d345ef6ef7c61d2c2b5c86e9de8e73db4286/examples/Quantum%20Circuit%20Example.ipynb

Relevant log output

No response

Anything else we need to know?

No response

Environment

Yes, quimb-1.4.0

jcmgray commented 2 years ago

Yes, its a bit odd as it looks like forceatlas2_networkx_layout should also support the weight_attr arg:

https://github.com/bhargavchippada/forceatlas2/blob/da3ece0b559efcc1cee51bd0f1d56db4732ce50c/fa2/forceatlas2.py#L235-L237

But I have also run into this bug, and since the weights likely don't add much, probably easiest just to remove it.

jcmgray commented 2 years ago

Should be fixed by https://github.com/jcmgray/quimb/commit/08ab4805df6be023e1027503b8c0915e1bf50b34.