Skip to content

Commit

Permalink
unit testing, SiEPIC.utils
Browse files Browse the repository at this point in the history
SiEPIC.utils.load_layout
SiEPIC.utils.create_cell2
SiEPIC.utils.waveguide_length
  • Loading branch information
lukasc-ubc committed Jul 17, 2024
1 parent f029312 commit 6aae38b
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ def produce_impl(self):
t = Trans(angle, False, pts[0])
pts_txt = str([ [round(p.to_dtype(dbu).x,3), round(p.to_dtype(dbu).y,3)] for p in pts ]).replace(', ',',')
text = Text ( \
'Spice_param:wg_length=%.3fu wg_width=%.3fu points="%s" radius=%s' %\
(waveguide_length, self.width, pts_txt,self.radius ), t, 0.1*wg_width, -1 )
'Spice_param:wg_length=%.6f wg_width=%.3fu points="%s" radius=%s' %\
(waveguide_length*dbu, self.width, pts_txt,self.radius ), t, 0.1*wg_width, -1 )
text.halign=halign
shape = self.cell.shapes(LayerDevRecN).insert(text)
t = Trans(angle, False, pt4)
text = Text ( \
'Length=%.3fu' %(waveguide_length), t, 0.5*wg_width, -1 )
'Length=%.6f' %(waveguide_length*dbu), t, 0.5*wg_width, -1 )
text.halign=halign
shape = self.cell.shapes(LayerDevRecN).insert(text)
139 changes: 139 additions & 0 deletions klayout_dot_config/tech/GSiP/pymacros/tests/test_SiEPIC_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
'''
Unit testing for SiEPIC.utils.__init__
by Lukas Chrostowski, 2024
usage:
- run this script in KLayout Application, or in standalone Python
'''

from pya import *

def test_load_layout():
import pya
import SiEPIC
from SiEPIC._globals import Python_Env
from SiEPIC.scripts import connect_cell, connect_pins_with_waveguide, zoom_out, export_layout
from SiEPIC.utils.layout import new_layout, floorplan
from SiEPIC.extend import to_itype
from SiEPIC.verification import layout_check

tech_name = 'GSiP'

from packaging import version
if version.parse(SiEPIC.__version__) < version.parse('0.5.4'):
raise Exception("Errors", "This example requires SiEPIC-Tools version 0.5.4 or greater.")

# "path" is the folder where this script is located
import os
path = os.path.dirname(os.path.realpath(__file__))

if Python_Env == 'Script':
# Load the PDK from a folder, e.g, GitHub, when running externally from the KLayout Application
import sys
sys.path.insert(0,os.path.abspath(os.path.join(path, '../../..')))
import GSiP

# Create a new layout
topcell, ly = new_layout(tech_name, "UnitTesting", overwrite = True)

# Load layout from file
from SiEPIC.utils import load_layout
load_layout(ly,
os.path.abspath(os.path.join(path, '../../gds/building_blocks')),
'Germanium_Detector_Floating.GDS',
single_topcell = True, Verbose = False)


def test_create_cell2():
import pya
import SiEPIC
from SiEPIC._globals import Python_Env
from SiEPIC.scripts import connect_cell, connect_pins_with_waveguide, zoom_out, export_layout
from SiEPIC.utils.layout import new_layout, floorplan
from SiEPIC.extend import to_itype
from SiEPIC.verification import layout_check

tech_name = 'GSiP'

from packaging import version
if version.parse(SiEPIC.__version__) < version.parse('0.5.4'):
raise Exception("Errors", "This example requires SiEPIC-Tools version 0.5.4 or greater.")

# "path" is the folder where this script is located
import os
path = os.path.dirname(os.path.realpath(__file__))

if Python_Env == 'Script':
# Load the PDK from a folder, e.g, GitHub, when running externally from the KLayout Application
import sys
sys.path.insert(0,os.path.abspath(os.path.join(path, '../../..')))
import GSiP

# Create a new layout
topcell, ly = new_layout(tech_name, "UnitTesting", overwrite = True)

# Load a cell from the library
from SiEPIC.utils import create_cell2
cell_y = create_cell2(ly, 'YBranch_te1550', 'GSiP', load_check=True)

t = Trans(Trans.R0,0,0)
topcell.insert(CellInstArray(cell_y.cell_index(), t))


def test_waveguide_length():
import pya
import SiEPIC
from SiEPIC._globals import Python_Env
from SiEPIC.scripts import connect_cell, connect_pins_with_waveguide, zoom_out, export_layout
from SiEPIC.utils.layout import new_layout, floorplan
from SiEPIC.extend import to_itype
from SiEPIC.verification import layout_check

tech_name = 'GSiP'

from packaging import version
if version.parse(SiEPIC.__version__) < version.parse('0.5.4'):
raise Exception("Errors", "This example requires SiEPIC-Tools version 0.5.4 or greater.")

# "path" is the folder where this script is located
import os
path = os.path.dirname(os.path.realpath(__file__))

if Python_Env == 'Script':
# Load the PDK from a folder, e.g, GitHub, when running externally from the KLayout Application
import sys
sys.path.insert(0,os.path.abspath(os.path.join(path, '../../..')))
import GSiP

# Create a new layout
topcell, ly = new_layout(tech_name, "UnitTesting", overwrite = True)

# Create waveguide PCell
cell_wg = ly.create_cell('Waveguide', tech_name, {'layers':['Waveguide','DevRec'], 'widths':[0.5,2], 'offsets':[0,0]})
print(cell_wg)
if not cell_wg:
raise Exception('Waveguide not loaded')
t = Trans(Trans.R0,0,0)
topcell.insert(CellInstArray(cell_wg.cell_index(), t))

# Save
filename = os.path.splitext(os.path.basename(__file__))[0]
file_out = export_layout(topcell, path, filename, format='oas', screenshot=True)

# Display in KLayout
from SiEPIC._globals import Python_Env
if Python_Env == 'Script':
from SiEPIC.utils import klive
klive.show(file_out, technology=tech_name, keep_position=True)


from SiEPIC.utils import waveguide_length
wgl = waveguide_length(cell_wg)
print(wgl)

if __name__ == "__main__":
test_load_layout()
test_create_cell2()
test_waveguide_length()
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def test_all_library_cells():
import GSiP

# Create a new layout
from SiEPIC.scripts import instantiate_all_library_cells
topcell, ly = new_layout(tech_name, "UnitTesting", overwrite = True)

# Instantiate all cells
from SiEPIC.scripts import instantiate_all_library_cells
instantiate_all_library_cells(topcell)

# Check if there are any errors
Expand Down

0 comments on commit 6aae38b

Please sign in to comment.