diff --git a/examples/tutorial/README.md b/examples/tutorial/README.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/tutorial/basic.py b/examples/tutorial/basic.py new file mode 100644 index 0000000..87548f7 --- /dev/null +++ b/examples/tutorial/basic.py @@ -0,0 +1,84 @@ +from typing import Tuple, Sequence + +import numpy # type: ignore +from numpy import pi + +from masque import layer_t, Pattern, SubPattern, Label +from masque.shapes import Circle, Arc +from masque.builder import Device, Port +from masque.library import Library, DeviceLibrary +import masque.file.klamath + +import pcgen + + +HOLE_SCALE: float = 1000 +""" Radius for the 'hole' cell. Should be significantly bigger than + 1 (minimum database unit) in order to have enough precision to + reasonably represent a polygonized circle (for GDS) +""" + + +def hole(radius: float = HOLE_SCALE, + layer: layer_t = (1, 0), + ) -> Pattern: + """ + Generate a pattern containing a single circular hole. + + Args: + layer: Layer to draw the circle on. + radius: Circle radius. + + Returns: + Pattern, named `'hole'` + """ + pat = Pattern('hole', shapes=[ + Circle(radius=radius, offset=(0, 0), layer=layer) + ]) + return pat + + +def smile(radius: float = HOLE_SCALE, + layer: layer_t = (1, 0), + secondary_layer: layer_t = (1, 2) + ) -> Pattern: + """ + Generate a pattern containing a single smiley face. + + Args: + radius: Boundary circle radius. + layer: Layer to draw the outer circle on. + secondary_layer: Layer to draw eyes and smile on. + + Returns: + Pattern, named `'smile'` + """ + # Make an empty pattern + pat = Pattern('smile') + + # Add all the shapes we want + pat.shapes += [ + Circle(radius=radius, offset=(0, 0), layer=layer), # Outer circle + Circle(radius=radius / 10, offset=(radius / 3, radius / 3), layer=secondary_layer), + Circle(radius=radius / 10, offset=(-radius / 3, radius / 3), layer=secondary_layer), + Arc(radii=(radius * 2 / 3, radius * 2 / 3), # Underlying ellipse radii + angles=(7 / 6 * pi, 11 / 6 * pi), # Angles limiting the arc + width=radius / 10, + offset=(0, 0), + layer=secondary_layer), + ] + + return pat + + +def _main() -> None: + hole_pat = hole() + smile_pat = smile() + + masque.file.klamath.writefile([hole_pat, smile_pat], 'basic.gds', 1e-9, 1e-3) + + smile_pat.visualize() + + +if __name__ == '__main__': + _main() diff --git a/examples/pcgen.py b/examples/tutorial/pcgen.py similarity index 100% rename from examples/pcgen.py rename to examples/tutorial/pcgen.py diff --git a/examples/phc.py b/examples/tutorial/phc.py similarity index 85% rename from examples/phc.py rename to examples/tutorial/phc.py index f214a5a..c1295f3 100644 --- a/examples/phc.py +++ b/examples/tutorial/phc.py @@ -10,31 +10,7 @@ from masque.library import Library, DeviceLibrary from masque.file.klamath import writefile import pcgen - - -HOLE_SCALE: float = 1000 -''' Radius for the 'hole' cell. Should be significantly bigger than - 1 (minimum database unit) in order to have enough precision to - reasonably represent a polygonized circle (for GDS) -''' - -def hole(layer: layer_t, - radius: float = HOLE_SCALE * 0.35, - ) -> Pattern: - """ - Generate a pattern containing a single circular hole. - - Args: - layer: Layer to draw the circle on. - radius: Circle radius. - - Returns: - Pattern, named `'hole'` - """ - pat = Pattern('hole', shapes=[ - Circle(radius=radius, offset=(0, 0), layer=layer, dose=1.0) - ]) - return pat +import basic def perturbed_l3(lattice_constant: float, @@ -152,13 +128,12 @@ def label_ports(device: Device, layer: layer_t = (3, 0)) -> Device: def main(): - hole_layer = (1, 2) a = 512 - hole_pat = hole(layer=hole_layer) - wg0 = label_ports(waveguide(lattice_constant=a, hole=hole_pat, length=10, mirror_periods=5)) - wg1 = label_ports(waveguide(lattice_constant=a, hole=hole_pat, length=5, mirror_periods=5)) - bend0 = label_ports(bend(lattice_constant=a, hole=hole_pat, mirror_periods=5)) - l3cav = label_ports(perturbed_l3(lattice_constant=a, hole=hole_pat, xy_size=(4, 10))) + hole= basic.smile() + wg0 = label_ports(waveguide(lattice_constant=a, hole=hole, length=10, mirror_periods=5)) + wg1 = label_ports(waveguide(lattice_constant=a, hole=hole, length=5, mirror_periods=5)) + bend0 = label_ports(bend(lattice_constant=a, hole=hole, mirror_periods=5)) + l3cav = label_ports(perturbed_l3(lattice_constant=a, hole=hole, xy_size=(4, 10))) dev = Device(name='my_bend', ports={}) dev.place(wg0, offset=(0, 0), port_map={'left': 'in', 'right': 'signal'}) diff --git a/masque/pattern.py b/masque/pattern.py index 7cbd06d..eb5f86e 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -958,6 +958,8 @@ class Pattern(LockableImpl, AnnotatableImpl, Mirrorable, metaclass=AutoSlots): line_color=line_color, fill_color=fill_color) if not overdraw: + pyplot.xlabel('x') + pyplot.ylabel('y') pyplot.show() @staticmethod