From 6847ac01bd18e02a4a57276bd5994ee74c2aeae2 Mon Sep 17 00:00:00 2001 From: Joaquin Matres <4514346+joamatab@users.noreply.github.com> Date: Sun, 10 Nov 2024 09:08:49 -0800 Subject: [PATCH] fix errors --- .pre-commit-config.yaml | 8 +++--- docs/notebooks/00_layout.ipynb | 21 ++++++-------- docs/notebooks/11_sparameters_gratings.ipynb | 2 +- docs/notebooks/12_sim_plugins_tidy3d.ipynb | 2 -- ubcpdk/components.py | 29 +++++++++++++------- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9ef64982..07f9f182 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/kynan/nbstripout - rev: 0.7.1 + rev: 0.8.0 hooks: - id: nbstripout files: ".ipynb" @@ -20,14 +20,14 @@ repos: - tomli - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.2" + rev: "v0.7.2" hooks: - id: ruff - args: [ --fix, --exit-non-zero-on-fix ] + args: [--fix, --exit-non-zero-on-fix] - id: ruff-format - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.13.0 + rev: v2.14.0 hooks: - id: pretty-format-toml args: [--autofix] diff --git a/docs/notebooks/00_layout.ipynb b/docs/notebooks/00_layout.ipynb index b5b34361..1680c848 100644 --- a/docs/notebooks/00_layout.ipynb +++ b/docs/notebooks/00_layout.ipynb @@ -19,7 +19,6 @@ "source": [ "import gdsfactory as gf\n", "\n", - "import ubcpdk\n", "import ubcpdk.components as uc" ] }, @@ -239,7 +238,7 @@ "outputs": [], "source": [ "c = uc.mzi_heater()\n", - "c = uc.add_fiber_array_pads_rf(c, optical_routing_type=2)\n", + "c = uc.add_fiber_array_pads_rf(c)\n", "c.plot()" ] }, @@ -278,6 +277,7 @@ "outputs": [], "source": [ "from functools import partial\n", + "\n", "import gdsfactory as gf\n", "\n", "import ubcpdk.components as uc\n", @@ -354,9 +354,9 @@ " \"\"\"Contains mirror cavities and structures inside a resonator.\"\"\"\n", " e = []\n", " e += [add_gc(uc.ebeam_crossing4())]\n", - " e += [add_gc(uc.ebeam_adiabatic_te1550(), optical_routing_type=1)]\n", + " e += [add_gc(uc.ebeam_adiabatic_te1550())]\n", " e += [add_gc(uc.ebeam_bdc_te1550())]\n", - " e += [add_gc(uc.ebeam_y_1550(), optical_routing_type=1)]\n", + " e += [add_gc(uc.ebeam_y_1550())]\n", " e += [add_gc(uc.straight(), component_name=f\"straight_{i}\") for i in range(2)]\n", " c = gf.Component()\n", " _ = c << gf.pack(e, max_size=size, spacing=2)[0]\n", @@ -379,16 +379,11 @@ "def EBeam_JoaquinMatres_4() -> gf.Component:\n", " \"\"\"MZI interferometers.\"\"\"\n", " mzi = partial(gf.components.mzi, splitter=uc.ebeam_y_1550)\n", - " mzis = [mzi(delta_length=delta_length) for delta_length in [10, 40, 100]]\n", - " mzis_gc = [\n", - " uc.add_fiber_array(mzi, optical_routing_type=2, fanout_length=5) for mzi in mzis\n", - " ]\n", + " mzis = [mzi(delta_length=delta_length) for delta_length in [10, 40]]\n", + " mzis_gc = [uc.add_fiber_array(mzi, fanout_length=5) for mzi in mzis]\n", "\n", " mzis = [uc.mzi_heater(delta_length=delta_length) for delta_length in [40]]\n", - " mzis_heater_gc = [\n", - " uc.add_fiber_array_pads_rf(mzi, orientation=90, optical_routing_type=2)\n", - " for mzi in mzis\n", - " ]\n", + " mzis_heater_gc = [uc.add_fiber_array_pads_rf(mzi, orientation=90) for mzi in mzis]\n", "\n", " e = mzis_gc + mzis_heater_gc\n", " c = gf.Component()\n", @@ -457,7 +452,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.8" } }, "nbformat": 4, diff --git a/docs/notebooks/11_sparameters_gratings.ipynb b/docs/notebooks/11_sparameters_gratings.ipynb index 03e91307..0cc26dcf 100644 --- a/docs/notebooks/11_sparameters_gratings.ipynb +++ b/docs/notebooks/11_sparameters_gratings.ipynb @@ -174,7 +174,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.8" } }, "nbformat": 4, diff --git a/docs/notebooks/12_sim_plugins_tidy3d.ipynb b/docs/notebooks/12_sim_plugins_tidy3d.ipynb index 87c19d76..adb2342c 100644 --- a/docs/notebooks/12_sim_plugins_tidy3d.ipynb +++ b/docs/notebooks/12_sim_plugins_tidy3d.ipynb @@ -41,7 +41,6 @@ "metadata": {}, "outputs": [], "source": [ - "import gdsfactory as gf\n", "import gplugins as sim\n", "import gplugins.tidy3d as gt\n", "\n", @@ -116,7 +115,6 @@ "metadata": {}, "outputs": [], "source": [ - "import gdsfactory as gf\n", "import gplugins.sax as gsax\n", "import jax.numpy as jnp\n", "import matplotlib.pyplot as plt\n", diff --git a/ubcpdk/components.py b/ubcpdk/components.py index 694bc1bc..16ce6fca 100644 --- a/ubcpdk/components.py +++ b/ubcpdk/components.py @@ -9,7 +9,6 @@ ComponentSpec, CrossSectionSpec, Optional, - Port, ) from ubcpdk import tech @@ -433,8 +432,7 @@ def mzi_heater(delta_length=10.0, length_x=320) -> gf.Component: Args: delta_length: extra length for mzi arms. """ - c = _mzi_heater(delta_length=delta_length, length_x=length_x) - return c + return _mzi_heater(delta_length=delta_length, length_x=length_x) @gf.cell @@ -447,7 +445,6 @@ def via_stack_heater_mtop(size=(10, 10)) -> gf.Component: def get_input_label_text( - port: Port, gc: ComponentReference, component_name: Optional[str] = None, username: str = CONFIG.username, @@ -455,7 +452,6 @@ def get_input_label_text( """Return label for port and a grating coupler. Args: - port: component port. gc: grating coupler reference. component_name: optional component name. username: for the label. @@ -525,6 +521,11 @@ def add_fiber_array( ref.drotate(-90) c.add_ports(ref.ports) c.copy_child_info(component) + + component_name = component_name or component.name + grating_coupler = gf.get_component(grating_coupler) + label = get_input_label_text(gc=grating_coupler, component_name=component_name) + c.add_label(position=c.ports["o1"].dcenter, text=label, layer=LAYER.TEXT) return c @@ -812,6 +813,8 @@ def add_fiber_array_pads_rf( component: ComponentSpec = "ring_single_heater", username: str = CONFIG.username, orientation: float = 0, + pad_yspacing: float = 50, + component_name: Optional[str] = None, **kwargs, ) -> Component: """Returns fiber array with label and electrical pads. @@ -820,16 +823,21 @@ def add_fiber_array_pads_rf( component: to add fiber array and pads. username: for the label. orientation: for adding pads. + pad_yspacing: for adding pads. + component_name: for the label. kwargs: for add_fiber_array. """ + c0 = gf.get_component(component) - # text = f"elec_{username}-{clean_name(c0.name)}_G" - # add_label = partial(add_label_electrical, text=text) - c1 = add_pads_rf(component=c0, orientation=orientation) + component_name = component_name or c0.name + component_name = clean_name(component_name) + text = f"elec_{username}-{component_name}_G" + c1 = add_pads_rf(component=c0, orientation=orientation, spacing=(0, pad_yspacing)) + add_label_electrical(component=c1, text=text) # ports_names = [port.name for port in c0.ports if port.orientation == orientation] # c1 = add_pads_top(component=c0, port_names=ports_names) - return add_fiber_array(component=c1, **kwargs) + return add_fiber_array(component=c1, component_name=component_name, **kwargs) @cache @@ -874,7 +882,7 @@ def add_pads( # c = add_fiber_array(straight_heater_metal) # c.pprint_ports() # c = coupler_ring() - c = dbr_cavity_te() + # c = dbr_cavity_te() # c = dbr_cavity() # c = ring_single(radius=12) # c = bend_euler() @@ -888,4 +896,5 @@ def add_pads( # c = ring_double() # c = ring_double(radius=12, length_x=2, length_y=2) # c = straight() + c = add_fiber_array_pads_rf(component_name="ring_single_heater") c.show()