Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ruff version #503

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.4"
rev: "v0.8.0"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -28,7 +28,7 @@ repos:
# - id: shellcheck

- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
rev: 1.8.0
hooks:
- id: bandit
args: [--exit-zero]
Expand Down
2 changes: 1 addition & 1 deletion gplugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ class Paths:

PATH = Paths()

__all__ = ["plot", "get_effective_indices", "port_symmetries"]
__all__ = ["get_effective_indices", "plot", "port_symmetries"]
10 changes: 5 additions & 5 deletions gplugins/devsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
logger.info(f"DEVSIM {tcad.__version__!r} installed at {tcad.__path__!r}")

__all__ = [
"dn_carriers",
"dalpha_carriers",
"alpha_to_k",
"k_to_alpha",
"PINWaveguide",
"DDComponent",
"PINWaveguide",
"alpha_to_k",
"clear_devsim_cache",
"dalpha_carriers",
"dn_carriers",
"k_to_alpha",
]
__version__ = "0.0.1"
2 changes: 1 addition & 1 deletion gplugins/femwell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from .mode_solver import compute_component_slice_modes, compute_cross_section_modes

__all__ = ("compute_cross_section_modes", "compute_component_slice_modes")
__all__ = ("compute_component_slice_modes", "compute_cross_section_modes")
16 changes: 8 additions & 8 deletions gplugins/gmeep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@
"get_meep_adjoint_optimizer",
"get_simulation",
"get_sparameters_data_meep",
"plot",
"port_symmetries",
"run_meep_adjoint_optimizer",
"write_sparameters_grating",
"write_sparameters_grating_batch",
"write_sparameters_grating_mpi",
"write_sparameters_meep",
"write_sparameters_meep_1x1",
"write_sparameters_meep_1x1_bend90",
"write_sparameters_meep_mpi",
"write_sparameters_meep_mpi_1x1",
"write_sparameters_meep_mpi_1x1_bend90",
"write_sparameters_meep_batch",
"write_sparameters_meep_batch_1x1",
"write_sparameters_meep_batch_1x1_bend90",
"write_sparameters_grating",
"write_sparameters_grating_mpi",
"write_sparameters_grating_batch",
"plot",
"port_symmetries",
"write_sparameters_meep_mpi",
"write_sparameters_meep_mpi_1x1",
"write_sparameters_meep_mpi_1x1_bend90",
]
__version__ = "0.0.3"
4 changes: 2 additions & 2 deletions gplugins/gmsh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
from gplugins.gmsh.xy_xsection_mesh import xy_xsection_mesh

__all__ = [
"create_physical_mesh",
"get_layer_overlaps_z",
"get_layers_at_z",
"get_mesh",
"get_u_bounds_layers",
"get_u_bounds_polygons",
"get_uz_bounds_layers",
"get_mesh",
"list_unique_layer_stack_z",
"map_unique_layer_stack_z",
"order_layer_stack",
"uz_xsection_mesh",
"xy_xsection_mesh",
"create_physical_mesh",
]
__version__ = "0.0.2"
2 changes: 1 addition & 1 deletion gplugins/lumerical/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

__all__ = [
"read_sparameters_lumerical",
"run_wavelength_sweep",
"write_sparameters_lumerical",
"write_sparameters_lumerical_components",
"run_wavelength_sweep",
]
12 changes: 6 additions & 6 deletions gplugins/modes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
)

__all__ = [
"find_modes_waveguide",
"find_modes_coupler",
"find_neff_vs_width",
"find_mode_dispersion",
"coupler",
"find_coupling_vs_gap",
"find_mode_dispersion",
"find_modes_coupler",
"find_modes_waveguide",
"find_neff_ng_dw_dh",
"find_neff_vs_width",
"plot_coupling_vs_gap",
"plot_neff_ng_dw_dh",
"plot_neff_vs_width",
"plot_coupling_vs_gap",
"coupler",
"waveguide",
]
__version__ = "0.0.2"
2 changes: 1 addition & 1 deletion gplugins/sax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from gplugins.sax import models, read
from gplugins.sax.plot_model import plot_model

__all__ = ["read", "plot_model", "models"]
__all__ = ["models", "plot_model", "read"]
38 changes: 15 additions & 23 deletions gplugins/spice/spice_to_yaml.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import os
import pathlib
import re
Expand Down Expand Up @@ -420,17 +421,15 @@ def get_instances(netlist: str, models: dict) -> list:
grouped_instances = group_instance_str(netlist)
instances = []
non_pdk = []
model_names = []
for model in models:
model_names.append(str(model))
model_names = [str(model) for model in models]
# Get params using regular expressions
pattern = r'(\w+|"[^"]*")\s*=\s*({.*?}|-[0-9.]+|[0-9.]+|f+|y+|x+|"[^"]*")'
for inst_line in grouped_instances:
instance = {}
# Get preamble before parameters (instance name, nets, model name)
fields = inst_line.split(" ")
instance["name"] = fields[0]

# Get params using regular expressions
pattern = r'(\w+|"[^"]*")\s*=\s*({.*?}|-[0-9.]+|[0-9.]+|f+|y+|x+|"[^"]*")'
matches = re.findall(pattern, inst_line)

# Get fields before params
Expand Down Expand Up @@ -459,7 +458,7 @@ def get_instances(netlist: str, models: dict) -> list:
match = re.match(r"([\d.]+)([un])", value)
if match:
instance["params"][param] = (
float(match.group(1)) * CONVERSION[match.group(2)]
float(match[1]) * CONVERSION[match.group(2)]
)
Comment on lines 460 to 462
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Replace m.group(x) with m[x] for re.Match objects (use-getitem-for-re-match-groups)

Suggested change
instance["params"][param] = (
float(match.group(1)) * CONVERSION[match.group(2)]
float(match[1]) * CONVERSION[match.group(2)]
)
instance["params"][param] = float(match[1]) * CONVERSION[match[2]]

else:
try:
Expand All @@ -477,12 +476,10 @@ def get_instances(netlist: str, models: dict) -> list:
instances.append(instance)
except KeyError:
non_pdk.append(instance["name"])
pass

if len(non_pdk) > 0:
if non_pdk:
print(
"LOG: Non-PDK elements detected! Removing instances {"
+ ", ".join(x for x in non_pdk)
+ ", ".join(non_pdk)
+ "} from netlist."
)
return instances
Expand Down Expand Up @@ -540,6 +537,7 @@ def get_instances_info(
.
}
}
ignore_electrical: Flag to ignore electrical routes and bundles.
ignored_info: Ignored param names that will not be put into the 'settings' or 'info' fields (list of str)

Returns:
Expand Down Expand Up @@ -671,19 +669,13 @@ def group_instance_str(netlist: str) -> list:
i
].strip().startswith("+"):
instances.append(lines[i].strip())
i = i + 1
i += 1

while i < len(lines) and lines[i].strip().startswith("+") and instances:
instances[-1] = instances[-1] + lines[i].strip()[1:-1]
i = i + 1

# Check that each instance has params. If not, remove them
filtered_instances = []
for inst in instances:
if "=" in inst:
filtered_instances.append(inst)
i += 1

return filtered_instances
return [inst for inst in instances if "=" in inst]


def get_placements(instances: list, mapping: dict, ignore_electrical: bool) -> dict:
Expand Down Expand Up @@ -921,10 +913,10 @@ def get_routes(instances, mapping, layers, ignore_electrical):
"""Extract routing information from instances using provided mapping and layers.

Args:
- instances: list of instance dictionaries with port and net information.
- mapping: dictionary mapping model names to layout cells and their properties.
- layers: dictionary defining parameters for different routing layers.
- ignore_electrical: boolean indicating whether to ignore electrical routes.
instances: list of instance dictionaries with port and net information.
mapping: dictionary mapping model names to layout cells and their properties.
layers: dictionary defining parameters for different routing layers.
ignore_electrical: boolean indicating whether to ignore electrical routes.

Returns:
- A dictionary of routes organized by bundle types.
Expand Down
6 changes: 3 additions & 3 deletions gplugins/tidy3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

__all__ = [
"Tidy3DComponent",
"get_simulation_grating_coupler",
"material_name_to_medium",
"modes",
"materials",
"get_simulation_grating_coupler",
"modes",
"plot_simulation",
"write_sparameters",
"write_sparameters_batch",
"write_sparameters_grating_coupler",
"write_sparameters_grating_coupler_batch",
"plot_simulation",
]
Loading
Loading