diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cbeda8ee..4a16535f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.2.2" + rev: "v0.3.3" hooks: - id: ruff - id: ruff-format @@ -26,7 +26,7 @@ repos: # - id: shellcheck - repo: https://github.com/PyCQA/bandit - rev: 1.7.7 + rev: 1.7.8 hooks: - id: bandit args: [--exit-zero] diff --git a/gplugins/common/utils/add_simulation_markers.py b/gplugins/common/utils/add_simulation_markers.py index 47814b03..56112ad1 100644 --- a/gplugins/common/utils/add_simulation_markers.py +++ b/gplugins/common/utils/add_simulation_markers.py @@ -1,4 +1,5 @@ """Returns component with simulation markers.""" + from __future__ import annotations import warnings diff --git a/gplugins/common/utils/async_helpers.py b/gplugins/common/utils/async_helpers.py index f28fff48..fc172727 100644 --- a/gplugins/common/utils/async_helpers.py +++ b/gplugins/common/utils/async_helpers.py @@ -18,9 +18,11 @@ async def handle_return( append: bool = False, ) -> None: """Reads through a :class:`StreamReader` and tees content to ``out_stream`` and ``log_file``.""" - with open( - log_file, "a" if append else "w", encoding="utf-8", buffering=1 - ) if log_file else nullcontext(None) as f: + with ( + open(log_file, "a" if append else "w", encoding="utf-8", buffering=1) + if log_file + else nullcontext(None) as f + ): while True: # Without this sleep, the program won't exit await asyncio.sleep(0) diff --git a/gplugins/common/utils/disable_print.py b/gplugins/common/utils/disable_print.py index 591124c0..b673a16a 100644 --- a/gplugins/common/utils/disable_print.py +++ b/gplugins/common/utils/disable_print.py @@ -1,4 +1,5 @@ """Disable print statements for overly verbose simulators.""" + from __future__ import annotations import os diff --git a/gplugins/common/utils/get_component_with_net_layers.py b/gplugins/common/utils/get_component_with_net_layers.py index 6b3a7171..47d48fb1 100644 --- a/gplugins/common/utils/get_component_with_net_layers.py +++ b/gplugins/common/utils/get_component_with_net_layers.py @@ -88,9 +88,9 @@ def get_component_with_net_layers( new_layers_init[0] + i, new_layers_init[1] + j, ) - layer_stack.layers[ - f"{old_layername}{delimiter}{portname}" - ] = new_layer + layer_stack.layers[f"{old_layername}{delimiter}{portname}"] = ( + new_layer + ) net_component.add_polygon(polygon, layer=new_layer_number) # Otherwise put the polygon back on the same layer else: diff --git a/gplugins/common/utils/optical_constants.py b/gplugins/common/utils/optical_constants.py index fb5f01d3..7c462a26 100644 --- a/gplugins/common/utils/optical_constants.py +++ b/gplugins/common/utils/optical_constants.py @@ -1,4 +1,5 @@ """Useful optical constant manipulations.""" + import numpy as np diff --git a/gplugins/common/utils/parse_layer_stack.py b/gplugins/common/utils/parse_layer_stack.py index 71c0c776..6941015e 100644 --- a/gplugins/common/utils/parse_layer_stack.py +++ b/gplugins/common/utils/parse_layer_stack.py @@ -1,4 +1,5 @@ """Preprocessing involving only the LayerStack.""" + from __future__ import annotations import numpy as np diff --git a/gplugins/devsim/get_simulation_xsection.py b/gplugins/devsim/get_simulation_xsection.py index 592f7a10..5cd056da 100644 --- a/gplugins/devsim/get_simulation_xsection.py +++ b/gplugins/devsim/get_simulation_xsection.py @@ -8,7 +8,6 @@ """ - from __future__ import annotations import warnings @@ -57,8 +56,8 @@ def dn_carriers(wavelength: float, dN: float, dP: float) -> float: else: wavelength *= 1e-6 return ( - -3.64 * 1e-10 * wavelength**2 * dN - - 3.51 * 1e-6 * wavelength**2 * np.power(dP, 0.8) + -3.64 * 1e-10 * wavelength** 2 * dN + - 3.51 * 1e-6 * wavelength** 2 * np.power(dP, 0.8) ) diff --git a/gplugins/femwell/solve_thermal.py b/gplugins/femwell/solve_thermal.py index fab6c32d..24cd3ff9 100644 --- a/gplugins/femwell/solve_thermal.py +++ b/gplugins/femwell/solve_thermal.py @@ -45,16 +45,16 @@ def get_thermal_conductivities(basis): # adding the layer to the thermal_conductivities dict. Check for that # case if domain in thermal_conductivities: - thermal_conductivity[ - basis.get_dofs(elements=domain) - ] = thermal_conductivities[domain] + thermal_conductivity[basis.get_dofs(elements=domain)] = ( + thermal_conductivities[domain] + ) else: for material, labels in materials_dict.items(): if domain in labels: # Assign the right values - thermal_conductivity[ - basis.get_dofs(elements=domain) - ] = thermal_conductivities[material] + thermal_conductivity[basis.get_dofs(elements=domain)] = ( + thermal_conductivities[material] + ) break thermal_conductivity *= 1e-12 # 1e-12 -> conversion from 1/m^2 -> 1/um^2 diff --git a/gplugins/gmeep/get_simulation.py b/gplugins/gmeep/get_simulation.py index aa4b898c..447b77b0 100644 --- a/gplugins/gmeep/get_simulation.py +++ b/gplugins/gmeep/get_simulation.py @@ -1,4 +1,5 @@ """Returns simulation from component.""" + from __future__ import annotations import inspect diff --git a/gplugins/gmeep/get_simulation_grating_farfield.py b/gplugins/gmeep/get_simulation_grating_farfield.py index de262b73..cbf0da6e 100644 --- a/gplugins/gmeep/get_simulation_grating_farfield.py +++ b/gplugins/gmeep/get_simulation_grating_farfield.py @@ -7,6 +7,7 @@ - add tests """ + from __future__ import annotations from typing import Any diff --git a/gplugins/gmeep/write_sparameters_grating.py b/gplugins/gmeep/write_sparameters_grating.py index 9c1a5ffa..6f1ed8ae 100644 --- a/gplugins/gmeep/write_sparameters_grating.py +++ b/gplugins/gmeep/write_sparameters_grating.py @@ -6,6 +6,7 @@ - 9.2 for Oband """ + from __future__ import annotations import hashlib diff --git a/gplugins/gmsh/parse_component.py b/gplugins/gmsh/parse_component.py index a9342fb9..44f69c83 100644 --- a/gplugins/gmsh/parse_component.py +++ b/gplugins/gmsh/parse_component.py @@ -1,4 +1,5 @@ """Preprocessing involving both the GDS and the LayerStack, or the resulting simulation polygons.""" + from __future__ import annotations import numpy as np @@ -75,15 +76,15 @@ def process_buffers(layer_polygons_dict: dict, layer_stack: LayerStack): layer_stack.layers[layername].thickness * zs[z_ind + 1] - layer_stack.layers[layername].thickness * z ) - extended_layer_stack_layers[ - f"{layername}_{poly_ind}_{z}" - ] = LayerLevel( - layer=layer_stack.layers[layername].layer, - thickness=new_thickness, - zmin=new_zmin, - material=layer_stack.layers[layername].material, - info=layer_stack.layers[layername].info, - mesh_order=layer_stack.layers[layername].mesh_order, + extended_layer_stack_layers[f"{layername}_{poly_ind}_{z}"] = ( + LayerLevel( + layer=layer_stack.layers[layername].layer, + thickness=new_thickness, + zmin=new_zmin, + material=layer_stack.layers[layername].material, + info=layer_stack.layers[layername].info, + mesh_order=layer_stack.layers[layername].mesh_order, + ) ) extended_layer_polygons_dict[f"{layername}_{poly_ind}_{z}"] = ( f"{layername}", @@ -91,16 +92,16 @@ def process_buffers(layer_polygons_dict: dict, layer_stack: LayerStack): polygon.buffer(width_buffer), polygon.buffer(width_buffers[z_ind + 1]), ) - extended_layer_stack_layers[ - f"{layername}_{poly_ind}_{zs[-1]}" - ] = LayerLevel( - layer=layer_stack.layers[layername].layer, - thickness=0, - zmin=layer_stack.layers[layername].zmin - + layer_stack.layers[layername].thickness, - material=layer_stack.layers[layername].material, - info=layer_stack.layers[layername].info, - mesh_order=layer_stack.layers[layername].mesh_order, + extended_layer_stack_layers[f"{layername}_{poly_ind}_{zs[-1]}"] = ( + LayerLevel( + layer=layer_stack.layers[layername].layer, + thickness=0, + zmin=layer_stack.layers[layername].zmin + + layer_stack.layers[layername].thickness, + material=layer_stack.layers[layername].material, + info=layer_stack.layers[layername].info, + mesh_order=layer_stack.layers[layername].mesh_order, + ) ) return extended_layer_polygons_dict, LayerStack(layers=extended_layer_stack_layers) diff --git a/gplugins/gmsh/parse_gds.py b/gplugins/gmsh/parse_gds.py index bb4c7c31..535e13fc 100644 --- a/gplugins/gmsh/parse_gds.py +++ b/gplugins/gmsh/parse_gds.py @@ -1,4 +1,5 @@ """Preprocessing involving mostly the GDS polygons.""" + from __future__ import annotations import gdsfactory as gf diff --git a/gplugins/klayout/drc/samples/drc_errors.py b/gplugins/klayout/drc/samples/drc_errors.py index 624b3cca..c09618e7 100644 --- a/gplugins/klayout/drc/samples/drc_errors.py +++ b/gplugins/klayout/drc/samples/drc_errors.py @@ -1,4 +1,5 @@ """Write GDS with sample errors.""" + from __future__ import annotations import gdsfactory as gf diff --git a/gplugins/lumerical/write_sparameters_lumerical.py b/gplugins/lumerical/write_sparameters_lumerical.py index 1d36f1a7..28137cff 100644 --- a/gplugins/lumerical/write_sparameters_lumerical.py +++ b/gplugins/lumerical/write_sparameters_lumerical.py @@ -1,4 +1,5 @@ """Write Sparameters with Lumerical FDTD.""" + from __future__ import annotations import shutil diff --git a/gplugins/lumerical/write_sparameters_lumerical_components.py b/gplugins/lumerical/write_sparameters_lumerical_components.py index 12317355..70106594 100644 --- a/gplugins/lumerical/write_sparameters_lumerical_components.py +++ b/gplugins/lumerical/write_sparameters_lumerical_components.py @@ -1,4 +1,5 @@ """Write Sparameters with for different components.""" + from __future__ import annotations import gdsfactory as gf diff --git a/gplugins/modes/find_modes.py b/gplugins/modes/find_modes.py index 2ce6fc54..9b395027 100644 --- a/gplugins/modes/find_modes.py +++ b/gplugins/modes/find_modes.py @@ -10,6 +10,7 @@ 1/1.5 = 0.6667. """ + import json import pathlib import pickle diff --git a/gplugins/modes/find_modes_cross_section.py b/gplugins/modes/find_modes_cross_section.py index 91c89292..b22eedeb 100755 --- a/gplugins/modes/find_modes_cross_section.py +++ b/gplugins/modes/find_modes_cross_section.py @@ -10,6 +10,7 @@ 1/1.5 = 0.6667. """ + from __future__ import annotations import pathlib diff --git a/gplugins/modes/neff_convergence_test.py b/gplugins/modes/neff_convergence_test.py index 4c50c237..59e5a63f 100644 --- a/gplugins/modes/neff_convergence_test.py +++ b/gplugins/modes/neff_convergence_test.py @@ -6,6 +6,7 @@ hyperparameters that allowed convergence. """ + from __future__ import annotations import meep as mp diff --git a/gplugins/process/implant_tables.py b/gplugins/process/implant_tables.py index e5b43217..85835a91 100644 --- a/gplugins/process/implant_tables.py +++ b/gplugins/process/implant_tables.py @@ -1,6 +1,7 @@ """ Reference: Selberherr, S. (1984). Process Modeling. In: Analysis and Simulation of Semiconductor Devices. Springer, Vienna. https://doi.org/10.1007/978-3-7091-8752-4_3 """ + from pathlib import Path import numpy as np diff --git a/gplugins/process/pysrim.py b/gplugins/process/pysrim.py index f4d1d10d..a1d87630 100644 --- a/gplugins/process/pysrim.py +++ b/gplugins/process/pysrim.py @@ -50,9 +50,7 @@ def run_fragmented_calculation( for i, num_ions in enumerate(fragment(step, number_ions)): print( - "total ions completed: {:06d}\tion: {}\tions in step: {:06d}".format( - i * step, ion.symbol, num_ions - ) + f"total ions completed: {i * step:06d}\tion: {ion.symbol}\tions in step: {num_ions:06d}" ) trim_settings = trim_settings or {"calculation": 2} trim = TRIM(target, ion, number_ions=num_ions, **trim_settings) diff --git a/gplugins/process/silicon.py b/gplugins/process/silicon.py index 66f16121..f9989962 100644 --- a/gplugins/process/silicon.py +++ b/gplugins/process/silicon.py @@ -4,6 +4,7 @@ Material class Pint for units """ + import numpy as np kB = 1.380649e-23 # m2 kg s-2 K-1, boltzmann constant diff --git a/gplugins/sax/read.py b/gplugins/sax/read.py index 71521a5a..ad9b5e10 100644 --- a/gplugins/sax/read.py +++ b/gplugins/sax/read.py @@ -1,4 +1,5 @@ """read Sparameters from CSV file and returns sax model.""" + from __future__ import annotations import pathlib diff --git a/gplugins/sax/tests/test_mzi.py b/gplugins/sax/tests/test_mzi.py index 040bc057..68522123 100644 --- a/gplugins/sax/tests/test_mzi.py +++ b/gplugins/sax/tests/test_mzi.py @@ -1,4 +1,5 @@ """Demo of non-hierarchical circuit simulations.""" + from __future__ import annotations import gdsfactory as gf diff --git a/gplugins/sax/tests/test_mzi_lattice.py b/gplugins/sax/tests/test_mzi_lattice.py index 2c371a07..4f3181fd 100644 --- a/gplugins/sax/tests/test_mzi_lattice.py +++ b/gplugins/sax/tests/test_mzi_lattice.py @@ -1,4 +1,5 @@ """Test hierarchical circuit simulations.""" + from __future__ import annotations import gdsfactory as gf diff --git a/gplugins/tidy3d/component.py b/gplugins/tidy3d/component.py index cfa575bb..f0ed65bf 100644 --- a/gplugins/tidy3d/component.py +++ b/gplugins/tidy3d/component.py @@ -611,14 +611,14 @@ def write_sparameters( for port_out in s.port_out.values: for mode_index_in in s.mode_index_in.values: for mode_index_out in s.mode_index_out.values: - sp[ - f"{port_in}@{mode_index_in},{port_out}@{mode_index_out}" - ] = s.sel( - port_in=port_in, - port_out=port_out, - mode_index_in=mode_index_in, - mode_index_out=mode_index_out, - ).values + sp[f"{port_in}@{mode_index_in},{port_out}@{mode_index_out}"] = ( + s.sel( + port_in=port_in, + port_out=port_out, + mode_index_in=mode_index_in, + mode_index_out=mode_index_out, + ).values + ) frequency = s.f.values sp["wavelengths"] = td.constants.C_0 / frequency diff --git a/gplugins/tidy3d/get_simulation_grating_coupler.py b/gplugins/tidy3d/get_simulation_grating_coupler.py index ecec2596..042bb63c 100644 --- a/gplugins/tidy3d/get_simulation_grating_coupler.py +++ b/gplugins/tidy3d/get_simulation_grating_coupler.py @@ -1,4 +1,5 @@ """Returns tidy3d simulation from gdsfactory Component.""" + from __future__ import annotations import warnings