From 4a0d9dea984353c3dd801f9f7d6be44ba99cfe3c Mon Sep 17 00:00:00 2001 From: chetanyagoyal Date: Fri, 7 Jun 2024 19:09:14 +0530 Subject: [PATCH 1/2] fix relational imports, fix glayout tests in ci --- .github/workflows/glayout_opamp_sim.yml | 1 + .github/workflows/glayout_sky130.yml | 5 ++++ .../CrossCoupledInverters_cell.py | 2 +- .../glayout/glayout/flow/pdk/mappedpdk.py | 4 +-- .../glayout/glayout/syntaxer/relational.py | 25 ++++++++++++++----- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/workflows/glayout_opamp_sim.yml b/.github/workflows/glayout_opamp_sim.yml index 64f1707ad..cf9eb9fcf 100644 --- a/.github/workflows/glayout_opamp_sim.yml +++ b/.github/workflows/glayout_opamp_sim.yml @@ -37,6 +37,7 @@ jobs: $IMAGE_NAME \ bash -c "\ cp ./.github/scripts/test_glayout_ci.py ./openfasoc/generators/glayout/tapeout/tapeout_and_RL/. &&\ + pip uninstall glayout -y &&\ pip3 install -r requirements.txt &&\ cd ./openfasoc/generators/glayout/tapeout/tapeout_and_RL/ &&\ pip3 install prettyprint prettyprinttree gdstk &&\ diff --git a/.github/workflows/glayout_sky130.yml b/.github/workflows/glayout_sky130.yml index a11c15233..804087e31 100644 --- a/.github/workflows/glayout_sky130.yml +++ b/.github/workflows/glayout_sky130.yml @@ -37,6 +37,7 @@ jobs: -w $PWD \ $IMAGE_NAME \ bash -c "\ + pip uninstall glayout -y &&\ cp ./.github/scripts/test_glayout_ci.py ./openfasoc/generators/glayout/. &&\ cd ./openfasoc/generators/glayout &&\ pip3 install gdsfactory==7.7.0 prettyprint prettyprinttree gdstk &&\ @@ -57,6 +58,7 @@ jobs: -w $PWD \ $IMAGE_NAME \ bash -c "\ + pip uninstall glayout -y &&\ cp ./.github/scripts/test_glayout_ci.py ./openfasoc/generators/glayout/. &&\ cd ./openfasoc/generators/glayout &&\ pip3 install gdsfactory==7.7.0 prettyprint prettyprinttree gdstk &&\ @@ -76,6 +78,7 @@ jobs: -w $PWD \ $IMAGE_NAME \ bash -c "\ + pip uninstall glayout -y &&\ cp ./.github/scripts/test_glayout_ci.py ./openfasoc/generators/glayout/. &&\ cd ./openfasoc/generators/glayout &&\ pip3 install gdsfactory==7.7.0 prettyprint prettyprinttree gdstk &&\ @@ -95,6 +98,7 @@ jobs: -w $PWD \ $IMAGE_NAME \ bash -c "\ + pip uninstall glayout -y &&\ cp ./.github/scripts/test_glayout_ci.py ./openfasoc/generators/glayout/. &&\ cd ./openfasoc/generators/glayout &&\ pip3 install gdsfactory==7.7.0 prettyprint prettyprinttree gdstk &&\ @@ -114,6 +118,7 @@ jobs: -w $PWD \ $IMAGE_NAME \ bash -c "\ + pip uninstall glayout -y &&\ cp ./.github/scripts/test_glayout_ci.py ./openfasoc/generators/glayout/. &&\ cd ./openfasoc/generators/glayout &&\ pip3 install gdsfactory==7.7.0 prettyprint prettyprinttree gdstk &&\ diff --git a/openfasoc/generators/glayout/glayout/flow/blocks/cross_coupled_inverter/CrossCoupledInverters_cell.py b/openfasoc/generators/glayout/glayout/flow/blocks/cross_coupled_inverter/CrossCoupledInverters_cell.py index 73c280203..d1b106f5d 100644 --- a/openfasoc/generators/glayout/glayout/flow/blocks/cross_coupled_inverter/CrossCoupledInverters_cell.py +++ b/openfasoc/generators/glayout/glayout/flow/blocks/cross_coupled_inverter/CrossCoupledInverters_cell.py @@ -19,7 +19,7 @@ from glayout.flow.placement.two_transistor_interdigitized import two_nfet_interdigitized from glayout.flow.placement.four_transistor_interdigitized import generic_4T_interdigitzed from glayout.flow.placement.two_transistor_interdigitized import two_pfet_interdigitized -from glayout.flow.components.diff_pair import diff_pair_generic +from glayout.flow.blocks.diff_pair import diff_pair_generic from glayout.flow.routing.smart_route import smart_route from glayout.flow.routing.L_route import L_route from glayout.flow.routing.c_route import c_route diff --git a/openfasoc/generators/glayout/glayout/flow/pdk/mappedpdk.py b/openfasoc/generators/glayout/glayout/flow/pdk/mappedpdk.py index db58e17b3..ad0994e67 100644 --- a/openfasoc/generators/glayout/glayout/flow/pdk/mappedpdk.py +++ b/openfasoc/generators/glayout/glayout/flow/pdk/mappedpdk.py @@ -514,7 +514,7 @@ def create_magic_commands_file(temp_dir): dir_name = design_name path_to_dir = path_to_regression_drc / dir_name if not path_to_dir.exists(): - path_to_dir.mkdir() + path_to_dir.mkdir(parents=True, exist_ok=False) new_output_file_path = path_to_dir / output_file if not new_output_file_path.exists(): shutil.copy(report_path, path_to_dir / output_file) @@ -769,7 +769,7 @@ def write_spice(input_cdl, output_spice, lvs_schematic_ref_file): dir_name = design_name path_to_dir = Path(__file__).resolve().parents[1] / "regression" / "lvs" / dir_name if not path_to_dir.exists(): - path_to_dir.mkdir() + path_to_dir.mkdir(parents=True, exist_ok=False) new_output_file_path = path_to_dir / output_file_path if not new_output_file_path.exists(): shutil.copy(report_path, path_to_dir / output_file_path) diff --git a/openfasoc/generators/glayout/glayout/syntaxer/relational.py b/openfasoc/generators/glayout/glayout/syntaxer/relational.py index cdf0d368e..4b5a3fa26 100644 --- a/openfasoc/generators/glayout/glayout/syntaxer/relational.py +++ b/openfasoc/generators/glayout/glayout/syntaxer/relational.py @@ -300,24 +300,26 @@ def __init__(self, component_identifiers: list[str], component_name: str, module # try to find an os path to the desired module by looking in Glayout if module_path is None: # try to resolve path of glayout package - matching_files = list(Path("./").resolve().rglob("glayout")) - if len(matching_files)>0: - glayout_path = (matching_files[0].resolve() / "flow").resolve() + matching_files = Path(__file__).resolve().parents[1] + # matching_files = list(Path("./").resolve().rglob("glayout")) + if matching_files.is_dir(): + glayout_path = (matching_files.resolve() / "flow").resolve() else: raise FileNotFoundError("Glayout.flow package not found in a sub folder of ../ directory") # try to resolve path of user module in Glayout package # this will look for the file which starts with "component_name" ANYWHERE in the glayout.flow package matching_files = list(glayout_path.rglob(str(component_name)+".py")) + matching_files += list(glayout_path.rglob(str(component_name)+"_cell.py")) matching_files += list(glayout_path.rglob(str(component_name)+".convo")) # also check the test_cases directory for convo files - matching_files += list((glayout_path / "../llm/syntax_data/convos").rglob(str(component_name)+".convo")) + # matching_files += list((glayout_path / "../llm/syntax_data/convos").rglob(str(component_name)+".convo")) if len(matching_files)>0: module_path = matching_files[-1].resolve() else: raise FileNotFoundError("Could not find a module called "+str(component_name)+" in Glayout") # copy convo file into glayout Components and then create a python file and copy it into glayout components if str(module_path).endswith(".convo"): - components_directory = glayout_path / "components" + components_directory = glayout_path / "blocks" if module_path.parent != components_directory: shutil.copy(module_path, components_directory) glayoutcode = glayout.syntaxer.dynamic_load.run_session(module_path,True) @@ -360,7 +362,18 @@ def from_module_import(cls, module: str, nameofobjtoimport: str): Returns: the object that was imported """ module_object = import_module(module) - return getattr(module_object, nameofobjtoimport) + if module_object is None: + raise ImportError("could not import module, maybe cell's __init__.py is missing?") + try: + return getattr(module_object, nameofobjtoimport) + except AttributeError: + # Try appending "_cell" if the direct attribute fetch failed + cell_attr_name = f"{nameofobjtoimport}_cell" + try: + return getattr(module_object, cell_attr_name) + except AttributeError: + error_msg = (f"Could not find '{nameofobjtoimport}' or '{cell_attr_name}' in module '{module_object}'.") + raise AttributeError(error_msg) from None def get_code(self) -> str: """returns as str a whole import line of code""" From 07fe55a58d98cf1bd23d9bfb8390556e00adfab4 Mon Sep 17 00:00:00 2001 From: chetanyagoyal Date: Sat, 8 Jun 2024 00:14:21 +0530 Subject: [PATCH 2/2] make regression folder ephemeral --- openfasoc/generators/glayout/glayout/flow/regression/.gitkeep | 0 openfasoc/generators/glayout/glayout/flow/regression/drc/.gitkeep | 0 openfasoc/generators/glayout/glayout/flow/regression/lvs/.gitkeep | 0 .../generators/glayout/glayout/flow/regression/testbench/.gitkeep | 0 4 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 openfasoc/generators/glayout/glayout/flow/regression/.gitkeep delete mode 100644 openfasoc/generators/glayout/glayout/flow/regression/drc/.gitkeep delete mode 100644 openfasoc/generators/glayout/glayout/flow/regression/lvs/.gitkeep delete mode 100644 openfasoc/generators/glayout/glayout/flow/regression/testbench/.gitkeep diff --git a/openfasoc/generators/glayout/glayout/flow/regression/.gitkeep b/openfasoc/generators/glayout/glayout/flow/regression/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/openfasoc/generators/glayout/glayout/flow/regression/drc/.gitkeep b/openfasoc/generators/glayout/glayout/flow/regression/drc/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/openfasoc/generators/glayout/glayout/flow/regression/lvs/.gitkeep b/openfasoc/generators/glayout/glayout/flow/regression/lvs/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/openfasoc/generators/glayout/glayout/flow/regression/testbench/.gitkeep b/openfasoc/generators/glayout/glayout/flow/regression/testbench/.gitkeep deleted file mode 100644 index e69de29bb..000000000