Skip to content

Commit

Permalink
Merge pull request #357 from gdsfactory/add_models
Browse files Browse the repository at this point in the history
Add models
  • Loading branch information
joamatab authored Mar 11, 2024
2 parents d5a3dd4 + de0494c commit 21da3ee
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 23 deletions.
42 changes: 23 additions & 19 deletions gplugins/klayout/drc/samples/drc_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
from __future__ import annotations

import gdsfactory as gf
import numpy as np
from gdsfactory.component import Component
from gdsfactory.typings import Float2, Layer
from gdsfactory.typings import Layer

layer = (1, 0)


@gf.cell
def width_min(size: Float2 = (0.1, 0.1)) -> Component:
return gf.components.rectangle(size=size, layer=layer)
def width_min(width: float = 0.1) -> Component:
return gf.components.rectangle(size=(width, width), layer=layer)


@gf.cell
def area_min() -> Component:
size = (0.2, 0.2)
return gf.components.rectangle(size=size, layer=layer)
def area_min(width: float = 0.2) -> Component:
return gf.components.rectangle(size=(width, width), layer=layer)


@gf.cell
Expand Down Expand Up @@ -46,8 +46,13 @@ def enclosing(
enclosing: float = 0.1, layer1: Layer = (40, 0), layer2: Layer = (41, 0)
) -> Component:
"""Layer1 must be enclosed by layer2 by value.
checks if layer1 encloses (is bigger than) layer2 by value
Args:
enclosing: value to enclose layer1 by layer2.
layer1: layer to enclose.
layer2: layer to enclose by.
"""
w1 = 1
w2 = w1 + enclosing
Expand All @@ -69,18 +74,17 @@ def snapping_error(gap: float = 1e-3) -> Component:


@gf.cell
def errors() -> Component:
"""Write a GDS with sample errors."""
components = [width_min(), gap_min(), separation(), enclosing()]
c = gf.pack(components, spacing=1.5)
return gf.add_padding_container(c[0], layers=((64, 0),), default=5)


@gf.cell
def errors2() -> Component:
def errors(n: int = 20) -> Component:
"""Write a GDS with sample errors."""
components = 2 * [width_min(), gap_min(), separation(), enclosing()]
c = gf.pack(components, spacing=1.5)
wmin = 0.1
# components = [width_min(), gap_min(), separation(), enclosing()]
cs = []
cs += [width_min(wmin * np.random.rand()) for _ in range(n)]
cs += [gap_min(gap=0.1 * np.random.rand()) for _ in range(n)]
cs += [separation(gap=0.1 * np.random.rand()) for _ in range(n)]
cs += [enclosing(enclosing=0.1 * np.random.rand()) for _ in range(n)]

c = gf.pack(cs, spacing=1.5)
return gf.add_padding_container(c[0], layers=((64, 0),), default=5)


Expand All @@ -92,6 +96,6 @@ def errors2() -> Component:
# c = snapping_error()
# c.write_gds("snap.gds")

c = errors2()
c = errors()
c.write_gds("errors.gds")
c.show(show_ports=True)
53 changes: 53 additions & 0 deletions gplugins/sax/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,64 @@
from __future__ import annotations

from functools import cache

import jax
import jax.numpy as jnp
import sax
from sax import SDict
from sax.utils import reciprocal

nm = 1e-3

################
# PassThrus
################


@cache
def _2port(p1, p2):
@jax.jit
def _2port(wl=1.5):
wl = jnp.asarray(wl)
return sax.reciprocal({(p1, p2): jnp.ones_like(wl)})

return _2port


@cache
def _3port(p1, p2, p3):
@jax.jit
def _3port(wl=1.5):
wl = jnp.asarray(wl)
thru = jnp.ones_like(wl) / jnp.sqrt(2)
return sax.reciprocal(
{
(p1, p2): thru,
(p1, p3): thru,
}
)

return _3port


@cache
def _4port(p1, p2, p3, p4):
@jax.jit
def _4port(wl=1.5):
wl = jnp.asarray(wl)
thru = jnp.ones_like(wl) / jnp.sqrt(2)
cross = 1j * thru
return sax.reciprocal(
{
(p1, p4): thru,
(p2, p3): thru,
(p1, p3): cross,
(p2, p4): cross,
}
)

return _4port


def straight(
*,
Expand Down
4 changes: 2 additions & 2 deletions notebooks/sdl_demo.pic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ instances:
settings: {gap_mmi: 0.7}
s1:
component: straight
settings: {length: 20, npoints: 2, cross_section: xs_sc, post_process: null, info: null}
settings: {length: 20, npoints: 2, cross_section: xs_sc}
s2:
component: straight
settings: {length: 40, npoints: 2, cross_section: xs_sc, post_process: null, info: null}
settings: {length: 40, npoints: 2, cross_section: xs_sc}
placements:
mmi1: {x: null, y: null, port: null, rotation: 0.0, dx: -22.832156230736544, dy: -0.9358105716724547,
mirror: null}
Expand Down
4 changes: 2 additions & 2 deletions notebooks/test.schem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ instances:
settings: {gap_mmi: 0.7}
s1:
component: straight
settings: {length: 20, npoints: 2, cross_section: xs_sc, post_process: null, info: null}
settings: {length: 20, npoints: 2, cross_section: xs_sc}
s2:
component: straight
settings: {length: 40, npoints: 2, cross_section: xs_sc, post_process: null, info: null}
settings: {length: 40, npoints: 2, cross_section: xs_sc}
schematic_placements:
mmi1: {x: null, y: null, port: null, rotation: 0.0, dx: -22.832156230736544, dy: -0.9358105716724547,
mirror: null}
Expand Down

0 comments on commit 21da3ee

Please sign in to comment.