From a92d01e2a111740030ef4b81fd1440684b76d054 Mon Sep 17 00:00:00 2001 From: Joaquin Matres <4514346+joamatab@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:57:57 -0700 Subject: [PATCH] add ruff --- .pre-commit-config.yaml | 3 ++- notebooks/21_schematic_driven_layout_lumerical.ipynb | 1 - notebooks/elmer_01_electrostatic.ipynb | 3 --- notebooks/fdtdz_01.ipynb | 2 +- notebooks/femwell_01_modes.ipynb | 12 ++++++------ notebooks/lumerical_1_fdtd_sparameters.ipynb | 1 - notebooks/meep_01_sparameters.ipynb | 8 ++------ notebooks/path_length_analysis.ipynb | 5 +++-- notebooks/sax_01_sax.ipynb | 10 +++++----- notebooks/tcad_02_analytical_process.ipynb | 2 +- notebooks/tidy3d_00_tidy3d.ipynb | 5 ++--- notebooks/workflow_1_mzi.ipynb | 1 - notebooks/workflow_2_ring.ipynb | 3 --- pyproject.toml | 2 +- 14 files changed, 23 insertions(+), 35 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7845ec3c..dfae6ddc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,9 +16,10 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.5.7" + rev: "v0.6.9" hooks: - id: ruff + args: [--fix, --exit-non-zero-on-fix] - id: ruff-format # - repo: https://github.com/shellcheck-py/shellcheck-py diff --git a/notebooks/21_schematic_driven_layout_lumerical.ipynb b/notebooks/21_schematic_driven_layout_lumerical.ipynb index ee2ba252..b9e272f5 100644 --- a/notebooks/21_schematic_driven_layout_lumerical.ipynb +++ b/notebooks/21_schematic_driven_layout_lumerical.ipynb @@ -33,7 +33,6 @@ "from gplugins.spice.spice_to_yaml import spice_to_yaml\n", "from gplugins.spice.tests.test_interconnect import spice_netlist_interconnect\n", "\n", - "\n", "netlist_path = GDSDIR_TEMP / \"test_interconnect.sp\"\n", "netlist_path.write_text(spice_netlist_interconnect)\n", "picyaml_path = GDSDIR_TEMP / \"test_interconnect.sp\"\n", diff --git a/notebooks/elmer_01_electrostatic.ipynb b/notebooks/elmer_01_electrostatic.ipynb index 50cf5ae6..5454bbfe 100644 --- a/notebooks/elmer_01_electrostatic.ipynb +++ b/notebooks/elmer_01_electrostatic.ipynb @@ -37,9 +37,7 @@ }, "outputs": [], "source": [ - "import os\n", "from math import inf\n", - "from pathlib import Path\n", "\n", "import gdsfactory as gf\n", "import pyvista as pv\n", @@ -49,7 +47,6 @@ "from gdsfactory.generic_tech import LAYER, get_generic_pdk\n", "from gdsfactory.technology import LayerStack\n", "from gdsfactory.technology.layer_stack import LayerLevel\n", - "from IPython.display import display\n", "\n", "from gplugins.elmer import run_capacitive_simulation_elmer\n", "\n", diff --git a/notebooks/fdtdz_01.ipynb b/notebooks/fdtdz_01.ipynb index fc18a937..4e0f0a2b 100644 --- a/notebooks/fdtdz_01.ipynb +++ b/notebooks/fdtdz_01.ipynb @@ -76,7 +76,7 @@ "c = gf.Component()\n", "waveguide_rib = c << gf.components.straight(length=length, cross_section=rib)\n", "nitride_feature = c << gf.components.circle(radius=2, layer=LAYER.WGN)\n", - "nitride_feature.dx= 5\n", + "nitride_feature.dx = 5\n", "padding = c << gf.components.bbox(\n", " waveguide_rib.bbox, top=2, bottom=2, layer=LAYER.WAFER\n", ")\n", diff --git a/notebooks/femwell_01_modes.ipynb b/notebooks/femwell_01_modes.ipynb index b34dfd9e..5a0c63e7 100644 --- a/notebooks/femwell_01_modes.ipynb +++ b/notebooks/femwell_01_modes.ipynb @@ -66,13 +66,13 @@ " }\n", ")\n", "\n", - "filtered_layer_stack.layers[\"core\"].thickness = (\n", - " 0.22 # Perturb the layer_stack before simulating\n", - ")\n", + "filtered_layer_stack.layers[\n", + " \"core\"\n", + "].thickness = 0.22 # Perturb the layer_stack before simulating\n", "\n", - "filtered_layer_stack.layers[\"slab90\"].thickness = (\n", - " 0.09 # Perturb the layer_stack before simulating\n", - ")\n", + "filtered_layer_stack.layers[\n", + " \"slab90\"\n", + "].thickness = 0.09 # Perturb the layer_stack before simulating\n", "\n", "resolutions = {\n", " \"core\": {\"resolution\": 0.02, \"distance\": 1, \"SizeMax\": 0.2},\n", diff --git a/notebooks/lumerical_1_fdtd_sparameters.ipynb b/notebooks/lumerical_1_fdtd_sparameters.ipynb index a776ce5e..beafae4c 100644 --- a/notebooks/lumerical_1_fdtd_sparameters.ipynb +++ b/notebooks/lumerical_1_fdtd_sparameters.ipynb @@ -414,7 +414,6 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "c = gf.components.straight()\n", "s = sim.write_sparameters_lumerical(c, layer_stack=layer_stack, run=False, session=s)" ] diff --git a/notebooks/meep_01_sparameters.ipynb b/notebooks/meep_01_sparameters.ipynb index 5e176fa3..a9e265f1 100644 --- a/notebooks/meep_01_sparameters.ipynb +++ b/notebooks/meep_01_sparameters.ipynb @@ -1001,7 +1001,7 @@ "import gdsfactory as gf\n", "import meep as mp\n", "\n", - "from gplugins.gmeep.get_simulation import get_simulation\n" + "from gplugins.gmeep.get_simulation import get_simulation" ] }, { @@ -1030,8 +1030,6 @@ "metadata": {}, "outputs": [], "source": [ - "import matplotlib.pyplot as plt\n", - "\n", "component = gf.add_padding_container(\n", " c,\n", " default=0,\n", @@ -1060,7 +1058,7 @@ "outputs": [], "source": [ "sim.init_sim()\n", - "sim.solve_cw(1e-6, 10000, 10)\n" + "sim.solve_cw(1e-6, 10000, 10)" ] }, { @@ -1084,7 +1082,6 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "import numpy as np\n", "\n", "eps_data = sim.get_array(vol=nonpml_vol, component=mp.Dielectric)\n", @@ -1112,7 +1109,6 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "sim.run(until=400)" ] }, diff --git a/notebooks/path_length_analysis.ipynb b/notebooks/path_length_analysis.ipynb index ea976c98..08cc8e93 100644 --- a/notebooks/path_length_analysis.ipynb +++ b/notebooks/path_length_analysis.ipynb @@ -23,8 +23,9 @@ "metadata": {}, "outputs": [], "source": [ - "import gplugins.path_length_analysis.path_length_analysis_from_gds as pl\n", - "import gdsfactory as gf" + "import gdsfactory as gf\n", + "\n", + "import gplugins.path_length_analysis.path_length_analysis_from_gds as pl" ] }, { diff --git a/notebooks/sax_01_sax.ipynb b/notebooks/sax_01_sax.ipynb index ef3ec43e..9f97cf28 100644 --- a/notebooks/sax_01_sax.ipynb +++ b/notebooks/sax_01_sax.ipynb @@ -44,7 +44,7 @@ "from rich.logging import RichHandler\n", "from scipy import constants\n", "from sklearn.linear_model import LinearRegression\n", - "from tqdm.notebook import trange, tqdm\n", + "from tqdm.notebook import tqdm, trange\n", "\n", "import gplugins.sax as gs\n", "import gplugins.tidy3d as gt\n", @@ -788,7 +788,7 @@ " mmi_in = gf.components.mmi1x2()\n", " mmi_out = gf.components.mmi2x2()\n", " bend = gf.components.bend_euler()\n", - " half_delay_straight = gf.components.straight(length=delta_length/2)\n", + " half_delay_straight = gf.components.straight(length=delta_length / 2)\n", "\n", " # references\n", " mmi_in = c.add_ref(mmi_in, name=\"mmi_in\")\n", @@ -1061,17 +1061,17 @@ " fn = f\"{wl=:.2f}-{n_box=:.2f}-{n_clad=:.2f}-{n_core=:.2f}-{t_slab=:.3f}-{t_soi=:.3f}-{w_core=:.3f}-{du=:.3f}-{n_modes=}.json\"\n", " path = os.path.join(cache_path, fn)\n", " if not replace_cached and os.path.exists(path):\n", - " return [mw.Mode.parse_obj(mode) for mode in json.load(open(path, \"r\"))]\n", + " return [mw.Mode.parse_obj(mode) for mode in json.load(open(path))]\n", "\n", " # fmt: off\n", " m_core = mw.SampledMaterial(name=\"slab\", n=np.asarray([n_core, n_core]), params={\"wl\": np.asarray([1.0, 2.0])}, meta={\"color\": (0.9, 0, 0, 0.9)})\n", - " m_clad = mw.SampledMaterial(name=\"clad\", n=np.asarray([n_clad, n_clad]), params={\"wl\": np.asarray([1.0, 2.0])}) \n", + " m_clad = mw.SampledMaterial(name=\"clad\", n=np.asarray([n_clad, n_clad]), params={\"wl\": np.asarray([1.0, 2.0])})\n", " m_box = mw.SampledMaterial(name=\"box\", n=np.asarray([n_box, n_box]), params={\"wl\": np.asarray([1.0, 2.0])})\n", " box = mw.Structure(material=m_box, geometry=mw.Box(x_min=- 2 * w_core - delta, x_max= 2 * w_core + delta, y_min=- 2 * t_soi - delta, y_max=0.0, z_min=0.0, z_max=length))\n", " slab = mw.Structure(material=m_core, geometry=mw.Box(x_min=-2 * w_core - delta, x_max=2 * w_core + delta, y_min=0.0, y_max=t_slab, z_min=0.0, z_max=length))\n", " clad = mw.Structure(material=m_clad, geometry=mw.Box(x_min=-2 * w_core - delta, x_max=2 * w_core + delta, y_min=0, y_max=3 * t_soi + delta, z_min=0.0, z_max=length))\n", " core = mw.Structure(material=m_core, geometry=mw.Box(x_min=-w_core / 2, x_max=w_core / 2, y_min=0.0, y_max=t_soi, z_min=0.0, z_max=length))\n", - " \n", + "\n", " cell = mw.Cell(structures=[box, clad, slab, core], mesh=mw.Mesh2D( x=np.arange(-2*w_core, 2*w_core, du), y=np.arange(-2*t_soi, 3*t_soi, du), ), z_min=0.0, z_max=10.0)\n", " cross_section = mw.CrossSection.from_cell(cell=cell, env=env)\n", " modes = mw.compute_modes(cross_section, num_modes=n_modes)\n", diff --git a/notebooks/tcad_02_analytical_process.ipynb b/notebooks/tcad_02_analytical_process.ipynb index ae8e4d7a..567b87ac 100644 --- a/notebooks/tcad_02_analytical_process.ipynb +++ b/notebooks/tcad_02_analytical_process.ipynb @@ -30,7 +30,7 @@ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", - "from gplugins.process.implant_tables import *\n" + "from gplugins.process.implant_tables import *" ] }, { diff --git a/notebooks/tidy3d_00_tidy3d.ipynb b/notebooks/tidy3d_00_tidy3d.ipynb index 6af2084e..6459f6ec 100644 --- a/notebooks/tidy3d_00_tidy3d.ipynb +++ b/notebooks/tidy3d_00_tidy3d.ipynb @@ -390,7 +390,6 @@ "source": [ "sp = gt.write_sparameters(\n", " component,\n", - " filepath=PATH.sparameters_repo / \"coupler_ring_2d.npz\",\n", " sim_size_z=0,\n", " layer_stack=LAYER_STACK,\n", " plot_simulation_layer_name=\"core\",\n", @@ -408,7 +407,7 @@ "component = gf.components.straight()\n", "sp = gt.write_sparameters(\n", " component,\n", - " filepath=PATH.sparameters_repo / \"straight_2d.npz\",\n", + " # filepath=PATH.sparameters_repo / \"straight_2d.npz\",\n", " sim_size_z=0,\n", " center_z=\"core\",\n", ")" @@ -1166,7 +1165,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.8" } }, "nbformat": 4, diff --git a/notebooks/workflow_1_mzi.ipynb b/notebooks/workflow_1_mzi.ipynb index 807e169d..b3a74c35 100644 --- a/notebooks/workflow_1_mzi.ipynb +++ b/notebooks/workflow_1_mzi.ipynb @@ -25,7 +25,6 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "import gdsfactory as gf\n", "import numpy as np\n", "from gdsfactory.generic_tech import get_generic_pdk\n", diff --git a/notebooks/workflow_2_ring.ipynb b/notebooks/workflow_2_ring.ipynb index eaf48006..f40fcc57 100644 --- a/notebooks/workflow_2_ring.ipynb +++ b/notebooks/workflow_2_ring.ipynb @@ -127,9 +127,6 @@ "metadata": {}, "outputs": [], "source": [ - "import gdsfactory as gf\n", - "import toolz\n", - "\n", "c = gf.components.ring_single_heater(gap=0.2, radius=10, length_x=4)\n", "c.plot()" ] diff --git a/pyproject.toml b/pyproject.toml index c81cfbab..3abac54a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -123,7 +123,7 @@ ignore-words-list = 'te, te/tm, te, ba, fpr, fpr_spacing, ro, nd, donot, schem, skip = 'notebooks/palace_02_fullwave.ipynb' [tool.mypy] -python_version = "3.10" +python_version = "3.11" strict = true [tool.pylsp-mypy]