google / TensorNetwork

A library for easy and efficient manipulation of tensor networks.
Apache License 2.0
1.82k stars 357 forks source link

Visualization of network #109

Closed imatsuzaki closed 4 years ago

imatsuzaki commented 5 years ago

Is there any way to visualize network ?

This library based on TensoFlow, so it may be suitable to use tensorboard. However I think we need to implement visualization code for tensoboard, and it will be hard.

chaserileyroberts commented 5 years ago

Not yet, but we definitely should add one soon!

We plan on integrating with networkx for now. That way you can easily view the network visualization inside of a colab/Jupiter notebook. We have a PR from a (recently) exintern who did network visualization of "tree like" networks, but we should definitely extend it to arbitrary networks.

Doing an integration into tensorboard would be great, but we have no plans of doing that yet.

imatsuzaki commented 5 years ago

We plan on integrating with nxgraph for now. That way you can easily view the network visualization inside of a colab/Jupiter notebook.

That's great! It will be helpful to construct tensor network! Looking forward to PR and release. I think integrating with nxgraph will be enough.

Should I close this issue?

chaserileyroberts commented 5 years ago

Keep it open, we'll use it to track progress

stavros11 commented 5 years ago

Thanks for raising this issue, I also think should stay open until a general solution is found. Regarding the networkx visualization, I have a jupyter notebook with some example visualizations on my PR that you can check if you like.

A problem with this implementation is that I code explicitly the coordinates of each node in the graph which might be hard to do for arbitrary networks. For trees it is possible to find the levels with a BFS but I cannot think of a general way to define coordinates. I do not have much experience on graph plotting but perhaps there are ways or libraries to do a plot that looks reasonably well automatically, without having to code every coordinate. This might be worth checking. Also, I would find nice to have interactive graphs, where you can click a node and hide/show the nodes connected to it. I think that Tensorboard might be able to do this.

chaserileyroberts commented 5 years ago

*nxgraph-> networkx.

Sorry, I wrote the wrong name

imatsuzaki commented 5 years ago

I appreciate discussing about visualization, and also looking forward to PR.

I do not also have much experience on graph, but graphviz can be helpful to create interactive tensor network visualization.

Implementing tensorboard visualization may be hard because it is based on tensorflow graph, and it is not suitable to this library because of other runtime, like JAX.

stared commented 5 years ago

I would be happy to help with working on a tensor viz (vide my interest in tensor diagrams).

There is a super-simple thing in JSFiddle, with D3.js (https://jsfiddle.net/stared/8huz5gy7/):

Screenshot 2019-06-14 12 58 41

However, for a general one I would like to make sure:

chaserileyroberts commented 5 years ago

Hey that'd be awesome! We'd welcome a PR for this. I'm not a JS developer, so really anything that looks nice would be ok by me.

If you want to make a JS visualization tool, go ahead and make a new directory under visualization/js/.

chaserileyroberts commented 5 years ago

Ok cool so we have a TensorNetwork -> graphviz.Graph shim working. I think this will be a good enough for now.

It would also be cool to have a gif generator so you can visualize the contraction order of the network.

chaserileyroberts commented 5 years ago

0.0.4 is out now. You can use g = tensornetwork.to_graphviz(net) to create an isomorphic graphviz object. From there you can pretty easily see the visualization.

AdrianFRadulescu commented 4 years ago

The current version does not seem to support net = tensornetwork.TensorNetwork(), so how can I visualize the network from a set of nodes I created?

chaserileyroberts commented 4 years ago

Sorry for the late response!

To visialize the graph in the latest API, you can simple do

tn.to_graphvis(list_of_nodes)