Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interactive netlist plotting #199

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

install:
pip install -e .[dev,docs,devsim,femwell,gmsh,meow,meshwell,ray,sax,schematic,tidy3d,web,vlsir]
pip install -e .[dev,docs,devsim,femwell,gmsh,klayout,meow,meshwell,ray,sax,schematic,tidy3d,web,vlsir]
pre-commit install

dev: test-data gmsh elmer install
Expand Down
43 changes: 31 additions & 12 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.
filepath: Path to the KLayout netlist 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[klayout]`"
) 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
27 changes: 27 additions & 0 deletions gplugins/klayout/tests/test_plot_nets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pathlib import Path

import pytest
from gdsfactory.samples.demo.lvs import pads_correct

from gplugins.klayout.get_netlist import get_l2n
from gplugins.klayout.plot_nets import plot_nets


@pytest.fixture
def klayout_netlist(tmp_path):
c = pads_correct()

gdspath = c.write_gds(gdsdir=tmp_path)
l2n = get_l2n(gdspath)
netlist_path = str(Path(tmp_path) / f"{c.name}.txt")
l2n.write_l2n(netlist_path)
return netlist_path


def test_plot_nets(klayout_netlist):
plot_nets(klayout_netlist)


def test_plot_nets_interactive(klayout_netlist):
plot_nets(klayout_netlist, interactive=True)
assert Path("connectivity.html").exists()
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ gmsh = [
"meshwell>=1.0.0,<1.1.0"
]
klayout = [
"kfactory[git,ipy]>=0.9.3,<0.10"
"kfactory[git,ipy]>=0.9.3,<0.10",
"pyvis<=0.3.1"
]
meow = [
"jaxlib",
Expand Down