Skip to content

Commit

Permalink
add missing models and cells
Browse files Browse the repository at this point in the history
  • Loading branch information
flaport committed Mar 7, 2024
1 parent 7efa69b commit 825e1d3
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 74 deletions.
78 changes: 49 additions & 29 deletions cspdk/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,80 @@
################
# Waveguides
################
_straight = gf.components.straight
straight_sc = partial(_straight, cross_section=xs_sc, info={"model": "straight_sc"})
straight_so = partial(_straight, cross_section=xs_so, info={"model": "straight_so"})
straight_rc = partial(_straight, cross_section=xs_rc, info={"model": "straight_rc"})
straight_ro = partial(_straight, cross_section=xs_ro, info={"model": "straight_ro"})
straight_nc = partial(_straight, cross_section=xs_nc, info={"model": "straight_nc"})
straight_no = partial(_straight, cross_section=xs_no, info={"model": "straight_no"})

straight = gf.components.straight
straight_sc = partial(straight, cross_section=xs_sc, info={"model": "straight_sc"})
straight_so = partial(straight, cross_section=xs_so, info={"model": "straight_so"})
straight_rc = partial(straight, cross_section=xs_rc, info={"model": "straight_rc"})
straight_ro = partial(straight, cross_section=xs_ro, info={"model": "straight_ro"})
straight_nc = partial(straight, cross_section=xs_nc, info={"model": "straight_nc"})
straight_no = partial(straight, cross_section=xs_no, info={"model": "straight_no"})


@wraps(gf.components.bend_euler)
def _bend_euler(info=None, **kwargs):
def bend_euler(info=None, **kwargs):
c = gf.components.bend_euler(**kwargs)
if info is not None:
c.info.update(info)
return c


bend_sc = partial(_bend_euler, cross_section=xs_sc, info={"model": "bend_sc"})
bend_so = partial(_bend_euler, cross_section=xs_so, info={"model": "bend_so"})
bend_rc = partial(_bend_euler, cross_section=xs_rc, info={"model": "bend_rc"})
bend_ro = partial(_bend_euler, cross_section=xs_ro, info={"model": "bend_ro"})
bend_nc = partial(_bend_euler, cross_section=xs_nc, info={"model": "bend_nc"})
bend_no = partial(_bend_euler, cross_section=xs_no, info={"model": "bend_no"})
bend_sc = partial(bend_euler, cross_section=xs_sc, info={"model": "bend_sc"})
bend_so = partial(bend_euler, cross_section=xs_so, info={"model": "bend_so"})
bend_rc = partial(bend_euler, cross_section=xs_rc, info={"model": "bend_rc"})
bend_ro = partial(bend_euler, cross_section=xs_ro, info={"model": "bend_ro"})
bend_nc = partial(bend_euler, cross_section=xs_nc, info={"model": "bend_nc"})
bend_no = partial(bend_euler, cross_section=xs_no, info={"model": "bend_no"})

################
# Transitions
################

taper = gf.components.taper
taper_cross_section = gf.c.taper_cross_section

trans_sc_rc10 = partial(
gf.c.taper_cross_section_linear,
taper_cross_section,
cross_section1=xs_rc_tip,
cross_section2=xs_rc,
length=10,
linear=True,
npoints=2,
info={"model": "trans_sc_rc10"},
)
trans_sc_rc20 = partial(
gf.c.taper_cross_section_linear,
taper_cross_section,
cross_section1=xs_rc_tip,
cross_section2=xs_rc,
length=20,
linear=True,
npoints=2,
info={"model": "trans_sc_rc20"},
)
trans_sc_rc50 = partial(
gf.c.taper_cross_section_linear,
taper_cross_section,
cross_section1=xs_rc_tip,
cross_section2=xs_rc,
length=50,
linear=True,
npoints=2,
info={"model": "trans_sc_rc50"},
)

################
# MMIs
################

mmi1x2 = gf.components.mmi1x2
mmi2x2 = gf.components.mmi2x2

_mmi1x2 = partial(
gf.components.mmi1x2,
width_mmi=6,
length_taper=20,
width_taper=1.5,
)

_mmi2x2 = partial(
gf.components.mmi2x2,
width_mmi=6,
Expand Down Expand Up @@ -213,7 +229,7 @@ def _bend_euler(info=None, **kwargs):


@gf.cell
def _gc_rectangular(
def gc_rectangular(
n_periods=30,
fill_factor=0.5,
length_taper=350,
Expand All @@ -239,38 +255,38 @@ def _gc_rectangular(


gc_rectangular_so = partial(
_gc_rectangular,
gc_rectangular,
period=0.5,
cross_section=xs_so,
n_periods=80,
info={"model": "gc_rectangular_so"},
)
gc_rectangular_ro = partial(
_gc_rectangular,
gc_rectangular,
period=0.5,
cross_section=xs_ro,
n_periods=80,
info={"model": "gc_rectangular_ro"},
)

gc_rectangular_sc = partial(
_gc_rectangular,
gc_rectangular,
period=0.63,
cross_section=xs_sc,
fiber_angle=10,
n_periods=60,
info={"model": "gc_rectangular_sc"},
)
gc_rectangular_rc = partial(
_gc_rectangular,
gc_rectangular,
period=0.5,
cross_section=xs_rc,
n_periods=60,
info={"model": "gc_rectangular_rc"},
)

gc_rectangular_nc = partial(
_gc_rectangular,
gc_rectangular,
period=0.66,
cross_section=xs_nc,
length_taper=200,
Expand All @@ -281,7 +297,7 @@ def _gc_rectangular(
info={"model": "gc_rectangular_nc"},
)
gc_rectangular_no = partial(
_gc_rectangular,
gc_rectangular,
period=0.964,
cross_section=xs_no,
length_taper=200,
Expand All @@ -296,29 +312,31 @@ def _gc_rectangular(
# MZI
################

mzi = gf.c.mzi

mzi_sc = partial(
gf.c.mzi,
mzi,
straight=straight_sc,
cross_section=xs_sc,
combiner=mmi1x2_sc,
splitter=mmi1x2_sc,
)
mzi_so = partial(
gf.c.mzi,
mzi,
straight=straight_so,
cross_section=xs_so,
combiner=mmi1x2_so,
splitter=mmi1x2_so,
)
mzi_rc = partial(
gf.c.mzi,
mzi,
straight=straight_rc,
cross_section=xs_rc,
combiner=mmi1x2_rc,
splitter=mmi1x2_rc,
)
mzi_ro = partial(
gf.c.mzi,
mzi,
straight=straight_ro,
cross_section=xs_ro,
combiner=mmi1x2_ro,
Expand Down Expand Up @@ -466,7 +484,9 @@ def die_nc(
@gf.cell
def heater() -> gf.Component:
"""Returns Heater fixed cell."""
return _import_gds("Heater.gds")
heater = _import_gds("Heater.gds")
heater.name = "heater"
return heater


@gf.cell
Expand Down
82 changes: 37 additions & 45 deletions cspdk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sax
from gplugins.sax.models import bend, grating_coupler, straight

from cspdk.tech import LAYER
from cspdk.tech import check_cross_section

nm = 1e-3

Expand Down Expand Up @@ -73,57 +73,24 @@ def _4port(wl=1.5):
straight_no = partial(straight, wl0=1.31, neff=2.4, ng=4.2)


def _layer_eq(layer1, layer2):
return (int(layer1[0]) == int(layer2[0])) and (int(layer1[1]) == int(layer2[1]))


def _check_cross_section(cross_section):
if isinstance(cross_section, str):
return cross_section
err = ValueError(f"Unknown cross section {cross_section}")
if _layer_eq(cross_section["sections"][0]["layer"], LAYER.WG):
if len(cross_section["sections"]) > 1:
if cross_section["sections"][0]["width"] == 0.45:
return "xs_rc"
elif cross_section["sections"][0]["width"] == 0.40:
return "xs_ro"
else:
raise err
elif cross_section["sections"][0]["width"] == 0.45:
return "xs_sc"
elif cross_section["sections"][0]["width"] == 0.40:
return "xs_so"
else:
raise err
elif _layer_eq(cross_section["sections"][0]["layer"], LAYER.NITRIDE):
if cross_section["sections"][0]["width"] == 1.20:
return "xs_nc"
elif cross_section["sections"][0]["width"] == 0.95:
return "xs_no"
else:
raise err
else:
raise err


def _straight(
*,
wl: float = 1.55,
length: float = 10.0,
loss: float = 0.0,
cross_section="xs_sc",
):
if _check_cross_section(cross_section) == "xs_sc":
if check_cross_section(cross_section) == "xs_sc":
return straight_sc(wl=wl, length=length, loss=loss)
elif _check_cross_section(cross_section) == "xs_so":
elif check_cross_section(cross_section) == "xs_so":
return straight_so(wl=wl, length=length, loss=loss)
elif _check_cross_section(cross_section) == "xs_rc":
elif check_cross_section(cross_section) == "xs_rc":
return straight_rc(wl=wl, length=length, loss=loss)
elif _check_cross_section(cross_section) == "xs_ro":
elif check_cross_section(cross_section) == "xs_ro":
return straight_ro(wl=wl, length=length, loss=loss)
elif _check_cross_section(cross_section) == "xs_nc":
elif check_cross_section(cross_section) == "xs_nc":
return straight_nc(wl=wl, length=length, loss=loss)
elif _check_cross_section(cross_section) == "xs_no":
elif check_cross_section(cross_section) == "xs_no":
return straight_no(wl=wl, length=length, loss=loss)
else:
raise ValueError(f"Invalid cross section: Got: {cross_section}")
Expand Down Expand Up @@ -189,13 +156,15 @@ def mmi2x2(wl=1.55, wl0=1.55, fwhm=0.2, loss_dB=0.3, shift=0.005):
)


mmi1x2 = mmi1x2
mmi1x2_rc = mmi1x2
mmi1x2_sc = mmi1x2
mmi1x2_ro = mmi1x2
mmi1x2_so = mmi1x2
mmi1x2_no = mmi1x2
mmi1x2_nc = mmi1x2

mmi2x2 = mmi2x2
mmi2x2_nc = mmi2x2
mmi2x2_no = mmi2x2
mmi2x2_so = mmi2x2
Expand All @@ -209,6 +178,22 @@ def mmi2x2(wl=1.55, wl0=1.55, fwhm=0.2, loss_dB=0.3, shift=0.005):

_gco = partial(grating_coupler, loss=6, bandwidth=35 * nm, wl0=1.31)
_gcc = partial(grating_coupler, loss=6, bandwidth=35 * nm, wl0=1.55)


def _gc(
*,
wl: float = 1.55,
reflection: float = 0.0,
reflection_fiber: float = 0.0,
cross_section="xs_so",
):
cross_section = check_cross_section(cross_section)
if cross_section.endswith("o"):
return _gco(wl=wl, reflection=reflection, reflection_fiber=reflection_fiber)
else:
return _gcc(wl=wl, reflection=reflection, reflection_fiber=reflection_fiber)


gc_rectangular_so = _gco
gc_rectangular_ro = _gco
gc_rectangular_no = _gco
Expand All @@ -220,6 +205,8 @@ def mmi2x2(wl=1.55, wl0=1.55, fwhm=0.2, loss_dB=0.3, shift=0.005):
################
# Crossings
################


@jax.jit
def _crossing(wl=1.5):
wl = jnp.asarray(wl)
Expand Down Expand Up @@ -247,6 +234,7 @@ def _crossing(wl=1.5):
_2port=_2port("o1", "o2"),
_3port=_3port("o1", "o2", "o3"),
_4port=_4port("o1", "o2", "o3", "o4"),
taper=_straight,
straight=_straight,
straight_sc=straight_sc,
straight_so=straight_so,
Expand All @@ -264,24 +252,28 @@ def _crossing(wl=1.5):
trans_sc_rc10=trans_sc_rc10,
trans_sc_rc20=trans_sc_rc20,
trans_sc_rc50=trans_sc_rc50,
mmi1x2=mmi1x2,
mmi1x2_rc=mmi1x2_rc,
mmi2x2_rc=mmi2x2_rc,
mmi1x2_sc=mmi1x2_sc,
mmi2x2_sc=mmi2x2_sc,
mmi1x2_ro=mmi1x2_ro,
mmi2x2_ro=mmi2x2_ro,
mmi1x2_so=mmi1x2_so,
mmi2x2_so=mmi2x2_so,
mmi1x2_no=mmi1x2_no,
mmi2x2_no=mmi2x2_no,
mmi1x2_nc=mmi1x2_nc,
mmi2x2=mmi2x2,
mmi2x2_rc=mmi2x2_rc,
mmi2x2_sc=mmi2x2_sc,
mmi2x2_ro=mmi2x2_ro,
mmi2x2_so=mmi2x2_so,
mmi2x2_no=mmi2x2_no,
mmi2x2_nc=mmi2x2_nc,
gc_rectangular=_gc,
gc_rectangular_so=gc_rectangular_so,
gc_rectangular_ro=gc_rectangular_ro,
gc_rectangular_no=gc_rectangular_no,
gc_rectangular_sc=gc_rectangular_sc,
gc_rectangular_rc=gc_rectangular_rc,
gc_rectangular_nc=gc_rectangular_nc,
crossing=_crossing,
crossing_so=crossing_so,
crossing_rc=crossing_rc,
crossing_sc=crossing_sc,
Expand Down
Loading

0 comments on commit 825e1d3

Please sign in to comment.