def read_rawcells_example(): cell1 = gdstk.Cell("CELL_1") cell1.add(gdstk.rectangle((0, 0), (2, 1))) cell2 = gdstk.Cell("CELL_2") cell2.add(gdstk.Reference(cell1, (-1, 0))) library = gdstk.Library() library.add(cell1, cell2) library.write_gds("test.gds") raw_cells = gdstk.read_rawcells("test.gds") print(raw_cells.keys()) print(len(raw_cells["CELL_1"].dependencies(True))) print(len(raw_cells["CELL_2"].dependencies(True))) deps = raw_cells["CELL_2"].dependencies(True) print(deps[0] is raw_cells["CELL_1"])
def read_rawcells_example(): cell1 = gdstk.Cell("CELL_1") cell1.add(gdstk.rectangle((0, 0), (2, 1))) cell2 = gdstk.Cell("CELL_2") cell2.add(gdstk.Reference(cell1, (-1, 0))) library = gdstk.Library() library.add(cell1, cell2) library.write_gds("test.gds") raw_cells = gdstk.read_rawcells("test.gds") assert tuple(sorted(raw_cells.keys())) == ("CELL_1", "CELL_2") assert len(raw_cells["CELL_1"].dependencies(True)) == 0 assert len(raw_cells["CELL_2"].dependencies(True)) == 1 deps = raw_cells["CELL_2"].dependencies(True) assert deps[0] is raw_cells["CELL_1"]
def test_replace(tree, tmpdir): lib, c = tree fname = str(tmpdir.join("tree.gds")) lib.write_gds(fname) rc = gdstk.read_rawcells(fname) c3 = gdstk.Cell(c[3].name) c2 = rc[c[2].name] lib.replace(c2, c3) assert c[2] not in lib.cells assert c[3] not in lib.cells assert c2 in lib.cells assert c3 in lib.cells assert c[0].references[1].cell is c3 assert c[1].references[0].cell is c2 assert c[1].references[1].cell is c2 assert c[1].references[2].cell is c3 assert c[4].references[0].cell is c3
def bench_gdstk(): d = gdstk.read_rawcells("tests/proof_lib.gds")
from tutorial_images import draw import pathlib import numpy import gdstk import pcell if __name__ == "__main__": path = pathlib.Path(__file__).parent.absolute() # Check library units. In this case it is using the default units. units = gdstk.gds_units(path / "photonics.gds") print(f"Using unit = {units[0]}, precision = {units[1]}") # Load the library as a dictionary of RawCell pdk = gdstk.read_rawcells(path / "photonics.gds") # Cell holding a single device (MZI) dev_cell = gdstk.Cell("Device") dev_cell.add(gdstk.Reference(pdk["MZI"], (-40, 0))) # Create a grating coupler using the function imported from the # pcell module (pcell.py) created earlier. grating = pcell.grating(0.62, layer=2) # Add 4 grating couplers to the device cell: one for each port. dev_cell.add( gdstk.Reference(grating, (-200, -150), rotation=numpy.pi / 2, columns=2, spacing=(300, 0)), gdstk.Reference(grating, (200, 150),