.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_openfpga_tiling/01_netlist_to_graph.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_openfpga_tiling_01_netlist_to_graph.py: ============================== Netlist to graph (networkx) ============================== This example demonstrate how to convert a netlist to a netowrkx graph. By default each node is assigned weight 1 and each edge is assigned weight based on how many wires it represents. In case of bus connected single edge with weight equal to length of bus is assigned. **Graph representation** .. image:: ../../../examples/OpenFPGA_tiling/_nx_graph.svg :align: center :width: 40% .. GENERATED FROM PYTHON SOURCE LINES 18-39 .. code-block:: Python import matplotlib.pyplot as plt import networkx as nx import spydrnet as sdn import spydrnet_physical as sdnphy from networkx.drawing.nx_pydot import to_pydot netlist = sdnphy.load_netlist_by_name('basic_hierarchy') top: sdn.Netlist = netlist.top_instance.reference graph = top.get_connectivity_network() nodes = graph.nodes graph_dot = to_pydot(graph) graph_dot.write_svg('_nx_graph.svg') print(" ========== Nodes ==========") print("\n".join([f"{node:2} {nodes[node]['label']:15} {nodes[node]}" for node in nodes])) print(" ========== Edges ==========") print("\n".join(nx.generate_edgelist(graph, data=True))) .. GENERATED FROM PYTHON SOURCE LINES 40-45 **Regenerated graph with ports splits into individual nodes** .. image:: ../../../examples/OpenFPGA_tiling/_nx_graph_split.svg :align: center :width: 50% .. GENERATED FROM PYTHON SOURCE LINES 45-56 .. code-block:: Python graph = top.get_connectivity_network(split_ports=True) nodes = graph.nodes graph_dot = to_pydot(graph) graph_dot.write_svg('_nx_graph_split.svg') print(" ========== Nodes ==========") print("\n".join([f"{node:2} {nodes[node]['label']:15} {nodes[node]}" for node in nodes])) print(" ========== Edges ==========") print("\n".join(nx.generate_edgelist(graph, data=True))) .. _sphx_glr_download_auto_openfpga_tiling_01_netlist_to_graph.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_netlist_to_graph.ipynb <01_netlist_to_graph.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_netlist_to_graph.py <01_netlist_to_graph.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01_netlist_to_graph.zip <01_netlist_to_graph.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_