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

Trying to upload design using python script with GDS Factory #172

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions .github/workflows/gdsfactory-to-gds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Run Python Files

on:
workflow_dispatch:
push:
paths:
- "submissions/gdsfactory/**.py"
branches:
- '**'
pull_request:
paths:
- "submissions/gdsfactory/**.py"
branches:
- '**'

jobs:
run-python:
runs-on: ubuntu-latest

steps:
- name: checkout repo content
uses: actions/checkout@v4
with:
fetch-depth: 0

# can also specify python version if needed
- name: setup python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: install python packages
run: |
pip install klayout SiEPIC siepic_ebeam_pdk packaging gdsfactory ubcpdk

- name: run python scripts and get output gds file
run: |

# get added/modified py files
if [ "${{ github.event_name }}" == "push" ]; then
FILES=$(git diff --name-only --diff-filter=ACM ${{ github.event.before }} ${{ github.sha }} -- "submissions/gdsfactory" | grep -E '\.py$' | sed 's|^submissions/gdsfactory/||')
else
FILES=$(git diff --name-only --diff-filter=ACM FETCH_HEAD -- "submissions/gdsfactory" | grep -i -E '\.py$' | sed 's|^submissions/gdsfactory/||')
fi


echo "Added / modified Python files; $FILES"

# delete .oas and .gds files in the runner's submissions folder
# this is needed in the case where someone already has file_name.gds and is now trying to generate file_name.oas (or vice versa)
rm -rf submissions/*.gds submissions/*.oas

IFS=$'\n'

OUTPUT_FILES=""

for file in $FILES; do

echo "Getting oas/gds output for $file"

# run file and generate a gds / oas output
python "submissions/gdsfactory/$file"

# get output and save to OUTPUT_FILES
gds_files=$(find submissions -type f -name "*.gds" -exec basename {} .gds \;)
oas_files=$(find submissions -type f -name "*.oas" -exec basename {} .oas \;)

file_name=$(basename "$file")
file_name_no_py=$(basename "$file_name" .py)

output_files=""
if echo "$gds_files" | grep -q "$file_name_no_py"; then
output_file="${file_name_no_py}.gds"
else
output_file="${file_name_no_py}.oas"
fi

OUTPUT_FILES+="$output_file "

echo "Done for $file"

done

echo "output files; $OUTPUT_FILES"

echo "OUTPUT_FILES=$OUTPUT_FILES" >> $GITHUB_ENV

- name: move oas and gds files to a new folder
run: |
mkdir -p python_to_oas_gds

for file in $OUTPUT_FILES; do
cp "submissions/$file" python_to_oas_gds/
done

- name: upload .oas and .gds as an artifact
uses: actions/upload-artifact@v4
with:
name: python-to-oas-gds
path: python_to_oas_gds/

- name: commit outputted oas and gds files into repository
run: |
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"

# git add all produced oas/gds files
for file in $OUTPUT_FILES; do
git add "submissions/$file"
echo "done: git add $file"
done

git commit -m "Add gds files produced from .py files"
echo "done: git commit"
git push
echo "done: git push"
if: github.event_name != 'pull_request'

2 changes: 1 addition & 1 deletion .github/workflows/python-to-oas_gds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- name: install python packages
run: |
pip install klayout SiEPIC siepic_ebeam_pdk packaging
pip install klayout SiEPIC siepic_ebeam_pdk packaging gdsfactory

- name: run python scripts and get output gds / oas file
run: |
Expand Down
Binary file removed submissions/EBeam_lbelangers2.gds
Binary file not shown.
65 changes: 65 additions & 0 deletions submissions/gdsfactory/EBeam_lbelangers2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import gdsfactory as gf
import ubcpdk
import numpy as np

@gf.cell
def variable_delta_mzi(splitter=ubcpdk.components.ebeam_y_1550(),
delta_length: float = 0,
length_x: float = 37,
length_y: float = 15,
**kwargs) -> gf.Component:
"""Create variable delta L MZI"""
mzi = ubcpdk.components.mzi(splitter,
delta_length=delta_length,
length_x=length_x,
length_y=length_y,
**kwargs)

return gf.add_pins.add_pins_container(mzi, layer=ubcpdk.LAYER.PORT)

@gf.cell
def variable_delta_mzi_with_gc(delta_lengths: list[float] = [0]) -> gf.Component:
"""Create variabable delta L MZIs with gratings couplers"""
cell = gf.Component()

cell << gf.components.rectangle(size=(605, 410), layer=(99, 0))

cum_lengths = np.cumsum(delta_lengths[1::2]) / 2
cum_lengths -= cum_lengths[0]

for i, delta_length in enumerate(delta_lengths):
single_circuit = gf.Component(name=f"mzi_circuit_{i}")

x_offset = cum_lengths[i // 2] + 70 * (i // 2)
y_offset = 2 * 127 * (i % 2)

mzi = single_circuit << variable_delta_mzi(delta_length=delta_length)

mzi.drotate(90)
mzi.dy += y_offset + 31
mzi.dx += x_offset + 50

gc = single_circuit << gf.components.grating_coupler_array(grating_coupler=ubcpdk.components.gc_te1550(),
n=2,)
gc.drotate(angle=-90)
gc.dy += y_offset + 77
gc.dx += x_offset + 37

gf.routing.route_bundle(single_circuit, ports1=mzi.ports, ports2=list(gc.ports)[::-1])

single_circuit.add_label(text=f"opt_in_TE_1550_device_LouisBelangerSansoucy_MZI{i}",
position=gc.ports[0].dcenter, layer=ubcpdk.LAYER.TEXT)

cell.add_port(f'o{i * 2}', port=gc.ports['o0'])
cell.add_port(f'o{i * 2 + 1}', port=gc.ports['o1'])

cell << single_circuit

#port_layers = (ubcpdk.LAYER.PORT, ubcpdk.LAYER.PORTE)
#extract = cell.extract(layers=port_layers)
#_ = extract.remove_layers(layers=port_layers)

return cell

if __name__ == "__main__":
variable_delta_mzi_with_gc(delta_lengths=list(np.linspace(0, 112.5, 10))).write_gds("./submissions/EBeam_lbelangers2.gds")
Loading