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.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.plot()
2024-05-10 10:16:51.656 | INFO | gdsfactory.component:_write_library:2003 - Wrote to '/tmp/gdsfactory/pads_correct.gds'
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'
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/d25/generic.lyd25'
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/tech.lyt'
circuit straight_41ebfd0f ($1=$1);
end;
circuit straight_5ac9171b ($1=$1);
end;
circuit straight_96ebe305 ($1=$1);
end;
circuit bend_euler_d6b78123 ($1=$1);
end;
circuit straight_eeb28574 ($1=$1);
end;
circuit pad ($1=$1,$2=$2);
end;
circuit pads_correct ();
subcircuit pad $1 ($1='tl,tr',$2=tl);
subcircuit pad $2 ($1='tl,tr',$2=tr);
subcircuit pad $3 ($1='bl,br',$2=br);
subcircuit pad $4 ($1='bl,br',$2=bl);
subcircuit straight_96ebe305 $5 ($1='tl,tr');
subcircuit bend_euler_d6b78123 $6 ($1='tl,tr');
subcircuit straight_5ac9171b $7 ($1='tl,tr');
subcircuit bend_euler_d6b78123 $8 ($1='tl,tr');
subcircuit straight_41ebfd0f $9 ($1='tl,tr');
subcircuit straight_eeb28574 $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))
plot_nets(filepath)
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/layers.lyp'
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/d25/generic.lyd25'
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/tech.lyt'
The same steps as above are done for a shorted case.
c = pads_shorted()
gdspath = c.write_gds()
c.plot()
2024-05-10 10:16:52.028 | INFO | gdsfactory.component:_write_library:2003 - Wrote to '/tmp/gdsfactory/pads_shorted.gds'
netlist = get_netlist(gdspath)
print(netlist)
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/layers.lyp'
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/d25/generic.lyd25'
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/tech.lyt'
circuit straight_41ebfd0f ($1=$1);
end;
circuit straight_5ac9171b ($1=$1);
end;
circuit straight_96ebe305 ($1=$1);
end;
circuit bend_euler_d6b78123 ($1=$1);
end;
circuit straight_eeb28574 ($1=$1);
end;
circuit pad ($1=$1,$2=$2);
end;
circuit pads_shorted ();
subcircuit pad $1 ($1='bl,br,tl,tr',$2=tl);
subcircuit pad $2 ($1='bl,br,tl,tr',$2=tr);
subcircuit pad $3 ($1='bl,br,tl,tr',$2=br);
subcircuit pad $4 ($1='bl,br,tl,tr',$2=bl);
subcircuit straight_96ebe305 $5 ($1='bl,br,tl,tr');
subcircuit straight_5ac9171b $6 ($1='bl,br,tl,tr');
subcircuit straight_eeb28574 $7 ($1='bl,br,tl,tr');
subcircuit bend_euler_d6b78123 $8 ($1='bl,br,tl,tr');
subcircuit straight_5ac9171b $9 ($1='bl,br,tl,tr');
subcircuit bend_euler_d6b78123 $10 ($1='bl,br,tl,tr');
subcircuit straight_41ebfd0f $11 ($1='bl,br,tl,tr');
end;
l2n = get_l2n(gdspath)
filepath = cwd / f"{c.name}.txt"
l2n.write_l2n(str(filepath))
plot_nets(filepath)
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/layers.lyp'
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/d25/generic.lyd25'
Wrote '/home/runner/work/gplugins/gplugins/gplugins/klayout/tech.lyt'