From b51116940cb1695f441bbb0aef0f85da741855fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:59:03 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.6 → v0.9.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.6...v0.9.1) - [github.com/PyCQA/bandit: 1.8.0 → 1.8.2](https://github.com/PyCQA/bandit/compare/1.8.0...1.8.2) - [github.com/astral-sh/uv-pre-commit: 0.5.14 → 0.5.18](https://github.com/astral-sh/uv-pre-commit/compare/0.5.14...0.5.18) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 81593162..d2df878a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.8.6" + rev: "v0.9.1" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -28,7 +28,7 @@ repos: # - id: shellcheck - repo: https://github.com/PyCQA/bandit - rev: 1.8.0 + rev: 1.8.2 hooks: - id: bandit args: [--exit-zero] @@ -61,6 +61,6 @@ repos: additional_dependencies: - tomli - repo: https://github.com/astral-sh/uv-pre-commit - rev: 0.5.14 + rev: 0.5.18 hooks: - id: uv-lock From 110369a059e789119641f28da7b53383bc80774f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:59:17 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- gplugins/common/utils/add_simulation_markers.py | 6 +++--- gplugins/common/utils/convert_sparameters.py | 6 +++--- .../utils/tests/test_get_component_with_new_port_layers.py | 6 +++--- gplugins/devsim/get_simulation_xsection.py | 4 ++-- gplugins/elmer/get_capacitance.py | 2 +- gplugins/fdtdz/get_sparameters_fdtdz.py | 6 +++--- gplugins/gmeep/get_simulation.py | 6 +++--- gplugins/gmsh/parse_component.py | 2 +- gplugins/klayout/drc/write_drc.py | 2 +- gplugins/klayout/tests/test_global_density.py | 6 +++--- gplugins/lumerical/interconnect.py | 4 ++-- gplugins/lumerical/tests/test_netlist_get_routes.py | 6 +++--- gplugins/lumerical/write_sparameters_lumerical.py | 7 +++---- gplugins/photonic_circuit_models/ring.py | 2 +- gplugins/sax/models.py | 2 +- gplugins/sentaurus/sprocess.py | 6 +++--- gplugins/spice/spice_to_yaml.py | 6 +++--- gplugins/tidy3d/types.py | 6 +++--- gplugins/vlsir/tests/test_vlsir.py | 6 +++--- notebooks/workflow_2_ring.ipynb | 2 +- 20 files changed, 46 insertions(+), 47 deletions(-) diff --git a/gplugins/common/utils/add_simulation_markers.py b/gplugins/common/utils/add_simulation_markers.py index ce147be1..c8681d8b 100644 --- a/gplugins/common/utils/add_simulation_markers.py +++ b/gplugins/common/utils/add_simulation_markers.py @@ -91,9 +91,9 @@ def add_simulation_markers( port_source_name = port_source.name warnings.warn(f"Selecting port_source_name={port_source_name!r} instead.") - assert isinstance( - component, Component - ), f"component needs to be a gf.Component, got Type {type(component)}" + assert isinstance(component, Component), ( + f"component needs to be a gf.Component, got Type {type(component)}" + ) # Add port monitors for port_name in port_names: diff --git a/gplugins/common/utils/convert_sparameters.py b/gplugins/common/utils/convert_sparameters.py index c1a8c977..700b0d90 100644 --- a/gplugins/common/utils/convert_sparameters.py +++ b/gplugins/common/utils/convert_sparameters.py @@ -46,9 +46,9 @@ def pandas_to_numpy(df: pd.DataFrame, port_map=None) -> np.ndarray: if port_map is None: port_map = {f"o{i}@0": i for i in idxs} rev_port_map = {i: p for p, i in port_map.items()} - assert len(rev_port_map) == len( - port_map - ), "Duplicate port indices found in port_map" + assert len(rev_port_map) == len(port_map), ( + "Duplicate port indices found in port_map" + ) s_map = { s: tuple(rev_port_map[i] for i in _s_header_to_port_idxs(s)) for s in s_headers diff --git a/gplugins/common/utils/tests/test_get_component_with_new_port_layers.py b/gplugins/common/utils/tests/test_get_component_with_new_port_layers.py index c041e505..3b2db566 100644 --- a/gplugins/common/utils/tests/test_get_component_with_new_port_layers.py +++ b/gplugins/common/utils/tests/test_get_component_with_new_port_layers.py @@ -21,9 +21,9 @@ def test_component_with_new_port_layers() -> None: layernames_after = set(layer_stack.layers.keys()) # Check we have two new layers in the LayerStack - assert ( - len(layernames_after - layernames_before) == 2 - ), "Two new layers should be added to the LayerStack" + assert len(layernames_after - layernames_before) == 2, ( + "Two new layers should be added to the LayerStack" + ) # Check we have one new layer in Component (all metal3 is removed by these operations) # assert len(new_component.get_layers()) == len(original_component.get_layers()) + 1 diff --git a/gplugins/devsim/get_simulation_xsection.py b/gplugins/devsim/get_simulation_xsection.py index 5cd056da..d3c812e0 100644 --- a/gplugins/devsim/get_simulation_xsection.py +++ b/gplugins/devsim/get_simulation_xsection.py @@ -306,7 +306,7 @@ def set_net_doping(self, device) -> None: device, "slab", "Acceptors", - f"{self.p_conc:1.3e}*step({-1*self.p_offset / cm:1.3e}-x) + {self.ppp_conc:1.3e}*step({self.xppp / cm:1.3e}-x)", + f"{self.p_conc:1.3e}*step({-1 * self.p_offset / cm:1.3e}-x) + {self.ppp_conc:1.3e}*step({self.xppp / cm:1.3e}-x)", ) model_create.CreateNodeModel( device, @@ -319,7 +319,7 @@ def set_net_doping(self, device) -> None: device, "core", "Acceptors", - f"{self.p_conc:1.1e}*step({-1*self.p_offset / cm:1.6e}-x)", + f"{self.p_conc:1.1e}*step({-1 * self.p_offset / cm:1.6e}-x)", ) model_create.CreateNodeModel( device, diff --git a/gplugins/elmer/get_capacitance.py b/gplugins/elmer/get_capacitance.py index 932d4c7b..d0ce4acb 100644 --- a/gplugins/elmer/get_capacitance.py +++ b/gplugins/elmer/get_capacitance.py @@ -153,7 +153,7 @@ def _read_elmer_results( field_file_location=simulation_folder / raw_name / "results" - / f'{raw_name}_t0001.{"pvtu" if n_processes > 1 else "vtu"}', + / f"{raw_name}_t0001.{'pvtu' if n_processes > 1 else 'vtu'}", ) ), ) diff --git a/gplugins/fdtdz/get_sparameters_fdtdz.py b/gplugins/fdtdz/get_sparameters_fdtdz.py index 77e4e593..6af60996 100644 --- a/gplugins/fdtdz/get_sparameters_fdtdz.py +++ b/gplugins/fdtdz/get_sparameters_fdtdz.py @@ -98,9 +98,9 @@ def get_sparameters_fdtdz( optical_port_names = list(component_ref.get_ports_dict(port_type="optical").keys()) - assert isinstance( - component, Component - ), f"component needs to be a gf.Component, got Type {type(component)}" + assert isinstance(component, Component), ( + f"component needs to be a gf.Component, got Type {type(component)}" + ) component_extended = ( gf.components.extension.extend_ports( diff --git a/gplugins/gmeep/get_simulation.py b/gplugins/gmeep/get_simulation.py index f94aae7f..345c0f3a 100644 --- a/gplugins/gmeep/get_simulation.py +++ b/gplugins/gmeep/get_simulation.py @@ -158,9 +158,9 @@ def get_simulation( port_source_name = port_source.name warnings.warn(f"Selecting port_source_name={port_source_name!r} instead.") - assert isinstance( - component, Component - ), f"component needs to be a gf.Component, got Type {type(component)}" + assert isinstance(component, Component), ( + f"component needs to be a gf.Component, got Type {type(component)}" + ) component_extended = ( gf.c.extend_ports( diff --git a/gplugins/gmsh/parse_component.py b/gplugins/gmsh/parse_component.py index 44f69c83..9140083d 100644 --- a/gplugins/gmsh/parse_component.py +++ b/gplugins/gmsh/parse_component.py @@ -88,7 +88,7 @@ def process_buffers(layer_polygons_dict: dict, layer_stack: LayerStack): ) extended_layer_polygons_dict[f"{layername}_{poly_ind}_{z}"] = ( f"{layername}", - f"{layername}_{poly_ind}_{zs[z_ind+1]}", + f"{layername}_{poly_ind}_{zs[z_ind + 1]}", polygon.buffer(width_buffer), polygon.buffer(width_buffers[z_ind + 1]), ) diff --git a/gplugins/klayout/drc/write_drc.py b/gplugins/klayout/drc/write_drc.py index 8866f27a..d3e19b22 100644 --- a/gplugins/klayout/drc/write_drc.py +++ b/gplugins/klayout/drc/write_drc.py @@ -121,7 +121,7 @@ def check_not_inside( """ if size is None: error = f"{layer} not inside {not_inside}" - return f"{layer}.not_inside({not_inside})" f".output({error!r}, {error!r})" + return f"{layer}.not_inside({not_inside}).output({error!r}, {error!r})" else: error = f"{layer} sized by {size} not inside {not_inside}" script = f"{layer}_sized = {layer}.size({size})\n " diff --git a/gplugins/klayout/tests/test_global_density.py b/gplugins/klayout/tests/test_global_density.py index b549c23a..fd8036bb 100644 --- a/gplugins/klayout/tests/test_global_density.py +++ b/gplugins/klayout/tests/test_global_density.py @@ -105,6 +105,6 @@ def test_estimate_weighted_global_density( estimated_density = estimate_weighted_global_density( Xi=Xi, Yi=Yi, Zi=Zi, bbox=get_gds_bbox(gdspath) ) - assert np.isclose( - estimated_density, expected_global_density - ), f"{estimated_density=}, {expected_global_density=}" + assert np.isclose(estimated_density, expected_global_density), ( + f"{estimated_density=}, {expected_global_density=}" + ) diff --git a/gplugins/lumerical/interconnect.py b/gplugins/lumerical/interconnect.py index 1c5f8f40..f06ab09c 100644 --- a/gplugins/lumerical/interconnect.py +++ b/gplugins/lumerical/interconnect.py @@ -404,14 +404,14 @@ def run_wavelength_sweep( session.connect(ona.name, "output", component.name, name) for i, port in enumerate(ports_out.keys()): name = port if is_top_level else f"{port}.{ports_out[port]}" - session.connect(ona.name, f"input {i+1}", component.name, name) + session.connect(ona.name, f"input {i + 1}", component.name, name) session.run() # inc.close() return { result: { - port: session.getresult(ona.name, f"input {i+1}/mode {mode}/{result}") + port: session.getresult(ona.name, f"input {i + 1}/mode {mode}/{result}") for i, port in enumerate(ports_out) } for result in results diff --git a/gplugins/lumerical/tests/test_netlist_get_routes.py b/gplugins/lumerical/tests/test_netlist_get_routes.py index 5486d5de..183dcc97 100644 --- a/gplugins/lumerical/tests/test_netlist_get_routes.py +++ b/gplugins/lumerical/tests/test_netlist_get_routes.py @@ -48,9 +48,9 @@ def mock_get_connections(instances, mapping): routes = get_routes(instances, mapping, layers, True) assert "electrical_bundle_00" not in routes - assert all( - "electrical" not in key for key in routes.keys() - ), "Electrical routes should be ignored" + assert all("electrical" not in key for key in routes.keys()), ( + "Electrical routes should be ignored" + ) # def test_electrical_routing_with_parameters(setup_routing_data): diff --git a/gplugins/lumerical/write_sparameters_lumerical.py b/gplugins/lumerical/write_sparameters_lumerical.py index 7261c653..b3a921dc 100644 --- a/gplugins/lumerical/write_sparameters_lumerical.py +++ b/gplugins/lumerical/write_sparameters_lumerical.py @@ -274,8 +274,7 @@ def write_sparameters_lumerical( ] if not layers_thickness: raise ValueError( - f"no layers for component {component.layers}" - f"in layer stack {layer_stack}" + f"no layers for component {component.layers}in layer stack {layer_stack}" ) layers_zmin = [ layer_to_zmin[layer] @@ -300,7 +299,7 @@ def write_sparameters_lumerical( ) logger.info( - f"Simulation size = {x_span*1e6:.3f}, {y_span*1e6:.3f}, {z_span*1e6:.3f} um" + f"Simulation size = {x_span * 1e6:.3f}, {y_span * 1e6:.3f}, {z_span * 1e6:.3f} um" ) # from pprint import pprint @@ -393,7 +392,7 @@ def write_sparameters_lumerical( zspan = 2 * ss.port_margin + thickness s.addport() - p = f"FDTD::ports::port {i+1}" + p = f"FDTD::ports::port {i + 1}" s.setnamed(p, "x", port.dx * 1e-6) s.setnamed(p, "y", port.dy * 1e-6) s.setnamed(p, "z", z * 1e-6) diff --git a/gplugins/photonic_circuit_models/ring.py b/gplugins/photonic_circuit_models/ring.py index c60f2377..b56df8ed 100644 --- a/gplugins/photonic_circuit_models/ring.py +++ b/gplugins/photonic_circuit_models/ring.py @@ -66,7 +66,7 @@ def ring( coupling=coupling, loss=loss, ) - plt.plot(wl, p, label=f"{int(width*1e3)}nm") + plt.plot(wl, p, label=f"{int(width * 1e3)}nm") # for thickness, ng in zip(thicknesses, ngs): # p = ring( diff --git a/gplugins/sax/models.py b/gplugins/sax/models.py index 5d00e455..06a0748d 100644 --- a/gplugins/sax/models.py +++ b/gplugins/sax/models.py @@ -367,7 +367,7 @@ def _mmi_nxn( splitting_matrix[i][j] ) # Convert power ratio to amplitude loss_factor = 10 ** (-loss_dB[j] / 20) - S[(f"o{i+1}", f"o{j+1}")] = amplitude * loss_factor + S[(f"o{i + 1}", f"o{j + 1}")] = amplitude * loss_factor return sax.reciprocal(S) diff --git a/gplugins/sentaurus/sprocess.py b/gplugins/sentaurus/sprocess.py index 2468f2f8..4ef53c9f 100644 --- a/gplugins/sentaurus/sprocess.py +++ b/gplugins/sentaurus/sprocess.py @@ -309,7 +309,7 @@ def write_sprocess( ) if split_steps: f.write( - f"struct tdr={relative_save_directory!s}/{struct_prefix}{i+1}_{step.name}_litho.tdr\n" + f"struct tdr={relative_save_directory!s}/{struct_prefix}{i + 1}_{step.name}_litho.tdr\n" ) if isinstance(step, Etch): @@ -350,7 +350,7 @@ def write_sprocess( if split_steps: f.write( - f"struct tdr={relative_save_directory!s}/{struct_prefix}{i+1}_{step.name}.tdr" + f"struct tdr={relative_save_directory!s}/{struct_prefix}{i + 1}_{step.name}.tdr" ) f.write("\n") @@ -632,7 +632,7 @@ def cut_tdr( ) contact_str = f"""contact name=cathode aluminum silicon xlo=0.0 xhi=0.2 ylo=0.0 yhi=1 zlo=0 zhi=0 -contact name=anode aluminum silicon xlo=0.0 xhi=0.2 ylo={c.dysize-1:1.3f} yhi={c.dysize:1.3f} zlo=0 zhi=0 +contact name=anode aluminum silicon xlo=0.0 xhi=0.2 ylo={c.dysize - 1:1.3f} yhi={c.dysize:1.3f} zlo=0 zhi=0 contact name=substrate box silicon xlo=4.2 xhi=4.3 ylo=0.0 yhi={c.dysize:1.3f} zlo=0 zhi=0 """ diff --git a/gplugins/spice/spice_to_yaml.py b/gplugins/spice/spice_to_yaml.py index 576e94e7..7c226acf 100644 --- a/gplugins/spice/spice_to_yaml.py +++ b/gplugins/spice/spice_to_yaml.py @@ -834,13 +834,13 @@ def get_ports(netlist: str, instances: list, model: dict, mapping: dict) -> dict # Ex. [a,o1: b,o1] is same as [b,o1: a,o1]; remove this permutation if ( "$" not in inst1["nets"][i] - and f'{inst1["name"]},{inst1["ports"][i]}' not in connections + and f"{inst1['name']},{inst1['ports'][i]}" not in connections ): - side1 = f'{inst1["name"]},{inst1["ports"][i]}' + side1 = f"{inst1['name']},{inst1['ports'][i]}" connections.append(side1) # Map instance port name to layout port name - side1 = f'{inst1["name"]},{mapping[inst1["model"]]["ports"][inst1["ports"][i]]}' + side1 = f"{inst1['name']},{mapping[inst1['model']]['ports'][inst1['ports'][i]]}" j = ctk_ports.index(inst1["nets"][i]) ports[model["ports"][j]] = side1 diff --git a/gplugins/tidy3d/types.py b/gplugins/tidy3d/types.py index ddc64526..96e76a86 100644 --- a/gplugins/tidy3d/types.py +++ b/gplugins/tidy3d/types.py @@ -9,9 +9,9 @@ # Function to validate the medium def validate_medium(v): # Check if the input is an instance of td.Medium - assert isinstance( - v, td.AbstractMedium - ), f"Input should be a tidy3d medium, but got {type(v)} instead" + assert isinstance(v, td.AbstractMedium), ( + f"Input should be a tidy3d medium, but got {type(v)} instead" + ) return v diff --git a/gplugins/vlsir/tests/test_vlsir.py b/gplugins/vlsir/tests/test_vlsir.py index 222eb91c..b7dced00 100644 --- a/gplugins/vlsir/tests/test_vlsir.py +++ b/gplugins/vlsir/tests/test_vlsir.py @@ -29,9 +29,9 @@ def test_kdb_vlsir(pkg) -> None: assert pkg is not None, "Package should not be None" assert len(pkg.modules) == 3, "Expected 3 modules in the package" for i in range(3): - assert ( - pkg.modules[i].name == packages[i] - ), f"Module[{i}] name should be {packages[i]}" + assert pkg.modules[i].name == packages[i], ( + f"Module[{i}] name should be {packages[i]}" + ) @pytest.mark.parametrize("spice_format", ["spice", "spectre", "xyce", "verilog"]) diff --git a/notebooks/workflow_2_ring.ipynb b/notebooks/workflow_2_ring.ipynb index 598da995..d3f9a2a8 100644 --- a/notebooks/workflow_2_ring.ipynb +++ b/notebooks/workflow_2_ring.ipynb @@ -96,7 +96,7 @@ " coupling=coupling,\n", " loss=loss,\n", " )\n", - " plt.plot(wl, p, label=f\"{int(width*1e3)}nm\")\n", + " plt.plot(wl, p, label=f\"{int(width * 1e3)}nm\")\n", "\n", " plt.title(\"ring resonator vs waveguide width\")\n", " plt.xlabel(\"wavelength (um)\")\n",