Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 Automatic compilation of raw efabless PDKs into a gdsfactory-compatible PDK #92

Merged
merged 12 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
container: ghcr.io/gdsfactory/gdsfactory:main
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Install dependencies
run: |
make install
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,4 @@ cython_debug/
*.DS_Store
.DS_Store
*Thumbs.db
.idea/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "sky130/src/sky130_fd_pr"]
path = sky130/src/sky130_fd_pr
url = https://github.com/efabless/skywater-pdk-libs-sky130_fd_pr.git
[submodule "sky130/src/sky130_fd_sc_hd"]
path = sky130/src/sky130_fd_sc_hd
url = https://github.com/efabless/skywater-pdk-libs-sky130_fd_sc_hd.git
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sky130
14 changes: 0 additions & 14 deletions docs/notebooks/Makefile

This file was deleted.

3,106 changes: 3,106 additions & 0 deletions docs/notebooks/intro.ipynb
joamatab marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

78 changes: 0 additions & 78 deletions docs/notebooks/intro.py

This file was deleted.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ docs = [
"jupyter-book==1.0.0"
]

[tool.flit.sdist]
exclude = [
"**/.git/**"
]

[tool.mypy]
python_version = "3.10"
strict = true
Expand Down
119 changes: 119 additions & 0 deletions sky130/compile_components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import os

# Define the PDK directories
pdk_directories = ["src/sky130_fd_pr", "src/sky130_fd_sc_hd"]


# List to store gds file paths


def compile_components(pdk_directories=pdk_directories):
gds_files = []

# Walk through the PDK directories and collect GDS files
for pdk_dir in pdk_directories:
for subdir, _, files in os.walk(pdk_dir):
for file in files:
if file.endswith(".gds"):
gds_files.append(os.path.join(subdir, file))

# Function to create Python code for each gds file
def create_code(file_path):
file_name = os.path.basename(file_path)
raw_cell_name = os.path.splitext(file_name)[0]

for pdk_dir in pdk_directories:
prefix = pdk_dir.split("/")[-1] + "__"
if raw_cell_name.startswith(prefix):
cell_name = raw_cell_name[len(prefix) :]
break

# For old compatibility:
cell_name = raw_cell_name

code = f"""
@cell
def {cell_name}() -> gf.Component:
\"\"\"Returns {cell_name} fixed cell.

.. plot::
:include-source:

import sky130

c = sky130.components.{cell_name}()
c.plot()
\"\"\"
return import_gds("{file_path}", cellname="{raw_cell_name}")
"""
return code

# Prelude to add at the top of the file
prelude = """from functools import partial
import gdsfactory as gf
from gdsfactory.cell import cell

from sky130.config import PATH
from sky130.layers import LAYER

# add_ports_m1 = gf.partial(
# gf.add_ports.add_ports_from_markers_inside,
# pin_layer=LAYER.met1pin,
# port_layer=LAYER.met1drawing,
# port_type="electrical",
# )
# add_ports_m2 = gf.partial(
# gf.add_ports.add_ports_from_markers_inside,
# pin_layer=LAYER.met2pin,
# port_layer=LAYER.met2drawing,
# port_type="electrical",
# )

add_ports_m1 = gf.partial(
gf.add_ports.add_ports_from_labels,
port_layer=LAYER.met1drawing,
layer_label=LAYER.met1label,
port_type="electrical",
port_width=0.2,
get_name_from_label=True,
guess_port_orientation=False,
)
add_ports_m2 = gf.partial(
gf.add_ports.add_ports_from_labels,
port_layer=LAYER.met2drawing,
layer_label=LAYER.met2label,
port_type="electrical",
port_width=0.2,
get_name_from_label=True,
guess_port_orientation=False,
)
add_ports = gf.compose(add_ports_m1, add_ports_m2)

gdsdir = PATH.module
import_gds = partial(gf.import_gds, gdsdir=gdsdir, decorator=add_ports)
"""

# TODO delete old file automatically
# Write the code to a Python file
with open("components.py", "w") as f:
f.write(prelude)
for gds_file in gds_files:
print(gds_file)
# gds_file = os.path.dirname(str(pathlib.Path(gds_file)))
code = create_code(gds_file)
f.write(code)

print("Python file 'components.py' has been created.")


if __name__ == "__main__":
compile_components()
# # gf.write_cells.write_cells(gdspath=PATH.gdshd, dirpath="gds")
# # gf.write_cells.write_cells(gdspath=PATH.gdshs, dirpath="gds")
# # gf.write_cells.write_cells(gdspath=PATH.gdshvl, dirpath="gds")
# # print(gf.write_cells.get_import_gds_script(PATH.gds))
# # c = sky130_fd_sc_hvl__xor2_1()
# # c = sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_2()
# c = sky130_fd_sc_hd__conb_1()
# # c.show(show_ports=True)
# c.show()
Loading
Loading