Skip to content

Commit

Permalink
opics fixes WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasc-ubc committed Mar 24, 2024
1 parent 077a2ba commit 87faff8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions klayout_dot_config/pymacros/SiEPIC - Test Environment.lym
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ if 1:
SiEPIC.verification = reload(SiEPIC.verification)
# import SiEPIC.opics_netlist_sim
# SiEPIC.opics_netlist_sim = reload(SiEPIC.opics_netlist_sim)
# import SiEPIC.opics
# SiEPIC.opics.utils = reload(SiEPIC.opics.utils)
import SiEPIC.opics
SiEPIC.opics.utils = reload(SiEPIC.opics.utils)
# SiEPIC.opics.network = reload(SiEPIC.opics.network)
# SiEPIC.opics.components = reload(SiEPIC.opics.components)
#SiEPIC.netlist = reload(SiEPIC.netlist)
Expand Down
6 changes: 4 additions & 2 deletions klayout_dot_config/python/SiEPIC/opics/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def __init__(
self.sparam_file = filename

for key, value in kwargs.items():
self.componentParameters.append([key, str(value)])
self.componentParameters.append([key, value])

def load_sparameters(self, data_folder: PosixPath, filename: str) -> ndarray:
def load_sparameters(self, data_folder: PosixPath, filename: str,
verbose: bool = True) -> ndarray:
"""
Loads sparameters either from an npz file or from a raw sparam\
file using a look-up table.
Expand All @@ -90,6 +91,7 @@ def load_sparameters(self, data_folder: PosixPath, filename: str) -> ndarray:
self.componentParameters,
self.nports,
self.sparam_attr,
verbose = verbose
)
return self.interpolate_sparameters(
self.f, componentData[0], componentData[1]
Expand Down
13 changes: 10 additions & 3 deletions klayout_dot_config/python/SiEPIC/opics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,13 @@ def LUT_reader(filedir: PosixPath, lutfilename: str, lutdata: List[List[str]]):
xml = parse(filedir / lutfilename)
root = xml.getroot()

if "contraDC" in lutfilename:
print(1)

for node in root.iter("association"):
sample = [[each.attrib["name"], each.text] for each in node.iter("value")]
# sample = [[each.attrib["name"], each.text] for each in node.iter("value")]
sample = [[each.attrib["name"], float(each.text) if each.attrib["type"]=='double' else int(each.text) if each.attrib["type"]=='int' else bool(each.text) if each.attrib["type"]=='bool' else each.text] for each in node.iter("value")]

if sorted(sample[0:-1]) == sorted(lutdata):
break
sparam_file = sample[-1][1].split(";")
Expand All @@ -208,6 +213,8 @@ def LUT_processor(
start = time.time()
sparam_file, xml, node = LUT_reader(filedir, lutfilename, lutdata)

print(' - LUT_processor: file: %s' % sparam_file)

# read data
if ".npz" in sparam_file[0] or ".npz" in sparam_file[-1]:
npzfile = [each for each in sparam_file if ".npz" in each][0]
Expand All @@ -217,11 +224,11 @@ def LUT_processor(

else:
if verbose:
print("numpy datafile not found. reading sparam file instead..")
print("numpy datafile not found. reading sparam file instead.. %s " % sparam_file)

sdata = universal_sparam_filereader(nports, sparam_file[-1], filedir, "auto")
# create npz file name
npz_file = sparam_file[-1].split(".")[0]
npz_file = sparam_file[-1].split(".dat")[0]

# save as npz file
np.savez(filedir / npz_file, f=sdata[0], s=sdata[1])
Expand Down

0 comments on commit 87faff8

Please sign in to comment.