Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alibillalhammoud committed Aug 16, 2023
1 parent 31d22d7 commit d310c39
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 19 deletions.
156 changes: 156 additions & 0 deletions openfasoc/generators/gdsfactory-gen/pygen/README.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 28 additions & 15 deletions openfasoc/generators/gdsfactory-gen/pygen/pdk/mappedpdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ class MappedPDK(Pdk):
"capmet",
)

glayers: dict[StrictStr, StrictStr]
glayers: dict[StrictStr, Union[StrictStr, tuple[int,int]]]
# friendly way to implement a graph
grules: dict[StrictStr, dict[StrictStr, Optional[dict[StrictStr, Any]]]]
klayout_lydrc_file: Optional[Path] = None

@validator("glayers")
def glayers_check_keys(cls, glayers_obj: dict[StrictStr, StrictStr]):
def glayers_check_keys(cls, glayers_obj: dict[StrictStr, Union[StrictStr, tuple[int,int]]]):
"""force people to pick glayers from a finite set of string layers that you define
checks glayers to ensure valid keys,type. Glayers must be passed as dict[str,str]
if someone tries to pass a glayers dict that has a bad key, throw an error"""
for glayer, mapped_layer in glayers_obj.items():
if (not isinstance(glayer, str)) or (not isinstance(mapped_layer, str)):
raise TypeError("glayers should be passed as dict[str, str]")
if (not isinstance(glayer, str)) or (not isinstance(mapped_layer, Union[str, tuple])):
raise TypeError("glayers should be passed as dict[str, Union[StrictStr, tuple[int,int]]]")
if glayer not in cls.valid_glayers:
raise ValueError(
"glayers keys must be one of generic layers listed in class variable valid_glayers"
Expand Down Expand Up @@ -147,7 +147,11 @@ def has_required_glayers(self, layers_required: list[str]):
raise ValueError(
f"{layer!r} not in self.glayers {list(self.glayers.keys())}"
)
self.validate_layers([self.glayers[layer]])
if isinstance(self.glayers[layer], str):
self.validate_layers([self.glayers[layer]])
elif not isinstance(self.glayers[layer], tuple):
raise TypeError("glayer mapped value should be str or tuple[int,int]")


@validate_arguments
def layer_to_glayer(self, layer: tuple[int, int]) -> str:
Expand All @@ -156,23 +160,32 @@ def layer_to_glayer(self, layer: tuple[int, int]) -> str:
takes layer as a tuple(int,int)"""
# lambda for finding last matching key in dict from val
find_last = lambda val, d: [x for x, y in d.items() if y == val].pop()
# find glayer verfying presence along the way
pdk_real_layers = self.layers.values()
if layer in pdk_real_layers:
layer_name = find_last(layer, self.layers)
if layer_name in self.glayers.values():
glayer_name = find_last(layer_name, self.glayers)
if layer in self.glayers.values():
return find_last(layer)
elif self.layers is not None:
# find glayer verfying presence along the way
pdk_real_layers = self.layers.values()
if layer in pdk_real_layers:
layer_name = find_last(layer, self.layers)
if layer_name in self.glayers.values():
glayer_name = find_last(layer_name, self.glayers)
else:
raise ValueError("layer does not correspond to a glayer")
else:
raise ValueError("layer does not correspond to a glayer")
raise ValueError("layer is not a layer present in the pdk")
return glayer_name
else:
raise ValueError("layer is not a layer present in the pdk")
return glayer_name
raise ValueError("layer might not be a layer present in the pdk")

# TODO: implement LayerSpec type
@validate_arguments
def get_glayer(self, layer: str) -> Layer:
"""Returns the pdk layer from the generic layer name"""
return self.get_layer(self.glayers[layer])
direct_mapping = self.glayers[layer]
if isinstance(direct_mapping, tuple):
return direct_mapping
else:
return self.get_layer(direct_mapping)

@validate_arguments
def get_grule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import math
from gdsfactory.pdk import Pdk
from pathlib import Path

from typing import Union

def get_files_with_extension(directory, extension):
file_list = []
Expand All @@ -15,7 +15,7 @@ def get_files_with_extension(directory, extension):
return file_list


def write_opamp_matrix(opamps_dir: Union[str,Path]="./"):
def write_opamp_matrix(opamps_dir: Union[str,Path]="./", xspace=400,yspace=300):
"""Use the write_opamp_matrix function to create a matrix of many different opamps
reads the different opamps from all gds files in opamps_dir
"""
Expand All @@ -28,9 +28,11 @@ def write_opamp_matrix(opamps_dir: Union[str,Path]="./"):
opamp_comp_list = list()

for i,filev in enumerate(opamp_files_list):
if "big_gds_here" in str(filev):
continue
tempcomp = import_gds(filev)
tempcomp.name = "opamp"+str(i)
opamp_comp_list.append()
opamp_comp_list.append(tempcomp)

col_len = round(math.sqrt(len(opamp_comp_list)))
col_index = 0
Expand All @@ -40,7 +42,7 @@ def write_opamp_matrix(opamps_dir: Union[str,Path]="./"):
if opamp_v is None:
continue
opref = big_comp << opamp_v
opref.movex(col_index * 200).movey(row_index*200)
opref.movex(col_index * xspace).movey(row_index*yspace)
col_index += 1
if not col_index % col_len:
col_index=0
Expand Down

0 comments on commit d310c39

Please sign in to comment.