Skip to content

Commit

Permalink
Add interactive netlist plotting
Browse files Browse the repository at this point in the history
Implemented with `pyvis` on top of `networkx`
  • Loading branch information
nikosavola committed Oct 18, 2023
1 parent 53333aa commit b5e56d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
41 changes: 30 additions & 11 deletions gplugins/klayout/plot_nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import networkx as nx


def plot_nets(filepath: str | Path, fully_connected: bool = False) -> None:
def plot_nets(
filepath: str | Path, fully_connected: bool = False, interactive: bool = False
) -> None:
"""Plots the connectivity between the components in the GDS file.
Args:
filepath: Path to the GDS file.
fully_connected: Whether to plot the graph as elements fully connected to all other ones (True) or
going through other elements (False).
interactive: Whether to plot an interactive graph with `pyvis` or not.
"""
filepath = Path(filepath)
code = filepath.read_text()
Expand All @@ -32,16 +35,32 @@ def plot_nets(filepath: str | Path, fully_connected: bool = False) -> None:
)

# Plotting the graph
plt.figure(figsize=(8, 6))
nx.draw(
G_connectivity,
with_labels=True,
node_size=2000,
node_color="lightpink",
font_size=12,
)
plt.title("Connectivity")
plt.show()
if interactive:
try:
from pyvis.network import Network
except ModuleNotFoundError as e:
raise UserWarning(
"You need to `pip install pyvis` or `gplugins[schematic]`"
) from e

net = Network(
select_menu=True,
filter_menu=True,
)
net.show_buttons()
net.from_nx(G_connectivity)
net.show("connectivity.html")
else:
plt.figure(figsize=(8, 6))
nx.draw(
G_connectivity,
with_labels=True,
node_size=2000,
node_color="lightpink",
font_size=12,
)
plt.title("Connectivity")
plt.show()


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ sax = [
]
schematic = [
"bokeh",
"natsort"
"natsort",
"pyvis<=0.3.1"
]
tidy3d = [
"tidy3d>=2.4.0,<2.5.0"
Expand Down

0 comments on commit b5e56d4

Please sign in to comment.