Netlist extractor SPICE

Contents

Netlist extractor SPICE#

This notebook demonstrates how to extract the SPICE netlist of a Component or a GDS file using gdsfactory. It uses the :func:~get_netlist and :func:~get_l2n functions from the gplugins.klayout module to extract the netlist and connectivity mapping, respectively. It also uses the plot_nets function to visualize the connectivity.

import pathlib

from gdsfactory.samples.demo.lvs import pads_correct, pads_shorted

from gplugins.klayout.get_netlist import get_l2n, get_netlist
from gplugins.klayout.netlist_spice_reader import (
    GdsfactorySpiceReader,
)
from gplugins.klayout.plot_nets import plot_nets

Sample layouts#

We generate a sample layout using pads_correct and write a GDS file.

c = pads_correct()
gdspath = c.write_gds()
c.show()
c.plot()
../_images/ce6bae2f33a6de33237b877e74f5cbf98012281321457731dd01ff006e62f64c.png

We obtain the netlist using KLayout by simply calling the :func:~get_netlist function from the gplugins.klayout module. The function takes the path to the GDS file as an argument and returns the netlist as a kdb.Netlist object.

netlist = get_netlist(gdspath)
print(netlist)
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/layers.lyp'
/home/runner/work/gplugins/gplugins/gplugins/klayout/d25/generic.lyd25
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/tech.lyt'
circuit straight_L387_N2_CSmetal3_W10 ($1=$1);
end;
circuit straight_L190_N2_CSmetal3_W10 ($1=$1);
end;
circuit straight_L3_N2_CSmetal3_W10 ($1=$1);
end;
circuit wire_corner_CSmetal3_RNone ($1=$1);
end;
circuit straight_L400_N2_CSmetal3_W10 ($1=$1);
end;
circuit pad_S100_100_LMTOP_BLNo_8d51f10c ($1=$1,$2=$2);
end;
circuit pads_correct_Ppad_CSmetal3 ();
  subcircuit pad_S100_100_LMTOP_BLNo_8d51f10c $1 ($1='tl,tr',$2=tl);
  subcircuit pad_S100_100_LMTOP_BLNo_8d51f10c $2 ($1='tl,tr',$2=tr);
  subcircuit pad_S100_100_LMTOP_BLNo_8d51f10c $3 ($1='bl,br',$2=br);
  subcircuit pad_S100_100_LMTOP_BLNo_8d51f10c $4 ($1='bl,br',$2=bl);
  subcircuit straight_L3_N2_CSmetal3_W10 $5 ($1='tl,tr');
  subcircuit wire_corner_CSmetal3_RNone $6 ($1='tl,tr');
  subcircuit straight_L190_N2_CSmetal3_W10 $7 ($1='tl,tr');
  subcircuit wire_corner_CSmetal3_RNone $8 ($1='tl,tr');
  subcircuit straight_L387_N2_CSmetal3_W10 $9 ($1='tl,tr');
  subcircuit straight_L400_N2_CSmetal3_W10 $10 ($1='bl,br');
end;

The connectivity between the components in the GDS file can be visualized using the :func:~plot_nets function from the gplugins.klayout module. The function takes the path to the GDS file as an argument and plots the connectivity between the components in the GDS file.

l2n = get_l2n(gdspath)
cwd = pathlib.Path.cwd()
filepath = cwd / f"{c.name}.txt"
l2n.write_l2n(str(filepath))
plt = plot_nets(
    filepath, spice_reader=GdsfactorySpiceReader(components_as_subcircuits=[c.name])
)
plt.savefig(f"{c.name}.png")
plt.show()
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/layers.lyp'
/home/runner/work/gplugins/gplugins/gplugins/klayout/d25/generic.lyd25
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/tech.lyt'
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 47
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 53
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 59
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 65
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 71
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 77
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 83
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 89
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 95
Warning: Element type 'X' ignored in /tmp/tmp4g3rqfu3.sp, line 101
../_images/fba2bdcfef8ccee70a07b439acc24b4f31ebba6d018e99f3ab82bd26a52719c1.png

The same steps as above are done for a shorted case.

c = pads_shorted()
gdspath = c.write_gds()
c.plot()
../_images/dc4c0fb8256046c980c5e6026f18ff59cb22c7f71c9e04ffe4fc898ad30bf123.png
netlist = get_netlist(gdspath)
print(netlist)
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/layers.lyp'
/home/runner/work/gplugins/gplugins/gplugins/klayout/d25/generic.lyd25
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/tech.lyt'
circuit straight_L387_N2_CSmetal3_W10 ($1=$1);
end;
circuit straight_L190_N2_CSmetal3_W10 ($1=$1);
end;
circuit straight_L3_N2_CSmetal3_W10 ($1=$1);
end;
circuit wire_corner_CSmetal3_RNone ($1=$1);
end;
circuit straight_L400_N2_CSmetal3_W10 ($1=$1);
end;
circuit pad_S100_100_LMTOP_BLNo_8d51f10c ($1=$1,$2=$2);
end;
circuit pads_shorted_Ppad_CSmetal3 ();
  subcircuit pad_S100_100_LMTOP_BLNo_8d51f10c $1 ($1='bl,br,tl,tr',$2=tl);
  subcircuit pad_S100_100_LMTOP_BLNo_8d51f10c $2 ($1='bl,br,tl,tr',$2=tr);
  subcircuit pad_S100_100_LMTOP_BLNo_8d51f10c $3 ($1='bl,br,tl,tr',$2=br);
  subcircuit pad_S100_100_LMTOP_BLNo_8d51f10c $4 ($1='bl,br,tl,tr',$2=bl);
  subcircuit straight_L3_N2_CSmetal3_W10 $5 ($1='bl,br,tl,tr');
  subcircuit wire_corner_CSmetal3_RNone $6 ($1='bl,br,tl,tr');
  subcircuit straight_L190_N2_CSmetal3_W10 $7 ($1='bl,br,tl,tr');
  subcircuit wire_corner_CSmetal3_RNone $8 ($1='bl,br,tl,tr');
  subcircuit straight_L387_N2_CSmetal3_W10 $9 ($1='bl,br,tl,tr');
  subcircuit straight_L400_N2_CSmetal3_W10 $10 ($1='bl,br,tl,tr');
end;
l2n = get_l2n(gdspath)
filepath = cwd / f"{c.name}.txt"
l2n.write_l2n(str(filepath))
plt = plot_nets(
    filepath, spice_reader=GdsfactorySpiceReader(components_as_subcircuits=[c.name])
)
plt.savefig(f"{c.name}.png")
plt.show()
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/layers.lyp'
/home/runner/work/gplugins/gplugins/gplugins/klayout/d25/generic.lyd25
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/tech.lyt'
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 47
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 53
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 59
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 65
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 71
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 77
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 83
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 89
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 95
Warning: Element type 'X' ignored in /tmp/tmpima7xv0d.sp, line 101
../_images/1f610e255514fdb50980935f8b66f540bfe79bde59a8e2ebed540b2d2d3dacac.png