From b5e314f9c709db8390da0214ecd89599ffefbc56 Mon Sep 17 00:00:00 2001 From: Joaquin Matres <4514346+joamatab@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:33:06 -0800 Subject: [PATCH 1/3] update ruff --- .pre-commit-config.yaml | 2 +- gplugins/__init__.py | 2 +- gplugins/devsim/__init__.py | 10 ++-- gplugins/femwell/__init__.py | 2 +- gplugins/gmeep/__init__.py | 16 +++--- gplugins/gmsh/__init__.py | 4 +- gplugins/lumerical/__init__.py | 2 +- gplugins/modes/__init__.py | 12 ++-- gplugins/sax/__init__.py | 2 +- gplugins/tidy3d/__init__.py | 6 +- notebooks/tcad_02_analytical_process.ipynb | 56 +++++++++++-------- .../tcad_03_numerical_implantation.ipynb | 3 + 12 files changed, 66 insertions(+), 51 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6bdcb402..3b93767c 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.7.4" + rev: "v0.8.0" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/gplugins/__init__.py b/gplugins/__init__.py index 51250094..85f6aedf 100644 --- a/gplugins/__init__.py +++ b/gplugins/__init__.py @@ -20,4 +20,4 @@ class Paths: PATH = Paths() -__all__ = ["plot", "get_effective_indices", "port_symmetries"] +__all__ = ["get_effective_indices", "plot", "port_symmetries"] diff --git a/gplugins/devsim/__init__.py b/gplugins/devsim/__init__.py index 899d2d06..2f56917f 100644 --- a/gplugins/devsim/__init__.py +++ b/gplugins/devsim/__init__.py @@ -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" diff --git a/gplugins/femwell/__init__.py b/gplugins/femwell/__init__.py index a845f952..eb60c523 100644 --- a/gplugins/femwell/__init__.py +++ b/gplugins/femwell/__init__.py @@ -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") diff --git a/gplugins/gmeep/__init__.py b/gplugins/gmeep/__init__.py index 06df2325..2bd8cacb 100644 --- a/gplugins/gmeep/__init__.py +++ b/gplugins/gmeep/__init__.py @@ -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" diff --git a/gplugins/gmsh/__init__.py b/gplugins/gmsh/__init__.py index 0fd0e37c..56833f1f 100644 --- a/gplugins/gmsh/__init__.py +++ b/gplugins/gmsh/__init__.py @@ -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" diff --git a/gplugins/lumerical/__init__.py b/gplugins/lumerical/__init__.py index b84d7d36..351eda62 100644 --- a/gplugins/lumerical/__init__.py +++ b/gplugins/lumerical/__init__.py @@ -11,7 +11,7 @@ __all__ = [ "read_sparameters_lumerical", + "run_wavelength_sweep", "write_sparameters_lumerical", "write_sparameters_lumerical_components", - "run_wavelength_sweep", ] diff --git a/gplugins/modes/__init__.py b/gplugins/modes/__init__.py index 805e72aa..fff55ac4 100644 --- a/gplugins/modes/__init__.py +++ b/gplugins/modes/__init__.py @@ -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" diff --git a/gplugins/sax/__init__.py b/gplugins/sax/__init__.py index d21431fe..a8928d32 100644 --- a/gplugins/sax/__init__.py +++ b/gplugins/sax/__init__.py @@ -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"] diff --git a/gplugins/tidy3d/__init__.py b/gplugins/tidy3d/__init__.py index 3153359f..3ae891a7 100644 --- a/gplugins/tidy3d/__init__.py +++ b/gplugins/tidy3d/__init__.py @@ -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", ] diff --git a/notebooks/tcad_02_analytical_process.ipynb b/notebooks/tcad_02_analytical_process.ipynb index 567b87ac..fd9083a2 100644 --- a/notebooks/tcad_02_analytical_process.ipynb +++ b/notebooks/tcad_02_analytical_process.ipynb @@ -30,7 +30,14 @@ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", - "from gplugins.process.implant_tables import *" + "from gplugins.process.diffusion import D, silicon_diffused_gaussian_profile\n", + "from gplugins.process.implant_tables import (\n", + " depth_in_silicon,\n", + " silicon_gaussian_profile,\n", + " silicon_skewed_gaussian_profile,\n", + " skew_in_silicon,\n", + " straggle_in_silicon,\n", + ")" ] }, { @@ -87,7 +94,6 @@ "energies = [20, 40, 60, 80, 100, 120, 140, 160]\n", "z = np.linspace(0, 0.25, 1000)\n", "\n", - "import matplotlib.pyplot as plt\n", "\n", "lower_lim = 0\n", "for E in energies:\n", @@ -146,7 +152,6 @@ "energies = [20, 40, 60, 80, 100, 120, 140, 160]\n", "z = np.linspace(0, 0.25, 1000)\n", "\n", - "import matplotlib.pyplot as plt\n", "\n", "lower_lim = 0\n", "for E in energies:\n", @@ -187,16 +192,6 @@ "id": "12", "metadata": {}, "outputs": [], - "source": [ - "from gplugins.process.diffusion import *" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "13", - "metadata": {}, - "outputs": [], "source": [ "Ts = np.linspace(800, 1100, 100)\n", "\n", @@ -211,7 +206,7 @@ }, { "cell_type": "markdown", - "id": "14", + "id": "13", "metadata": {}, "source": [ "In this low-doping regime, the diffusivity can be taken as constant, and there exist an analytical solution for initially Gaussian doping profiles:" @@ -220,7 +215,7 @@ { "cell_type": "code", "execution_count": null, - "id": "15", + "id": "14", "metadata": {}, "outputs": [], "source": [ @@ -249,7 +244,7 @@ }, { "cell_type": "markdown", - "id": "16", + "id": "15", "metadata": {}, "source": [ "This can be extended to many dimensions." @@ -257,7 +252,7 @@ }, { "cell_type": "markdown", - "id": "17", + "id": "16", "metadata": {}, "source": [ "### Concentration-dependent diffusion\n", @@ -268,7 +263,7 @@ { "cell_type": "code", "execution_count": null, - "id": "18", + "id": "17", "metadata": {}, "outputs": [], "source": [ @@ -287,7 +282,7 @@ { "cell_type": "code", "execution_count": null, - "id": "19", + "id": "18", "metadata": {}, "outputs": [], "source": [ @@ -303,7 +298,7 @@ { "cell_type": "code", "execution_count": null, - "id": "20", + "id": "19", "metadata": {}, "outputs": [], "source": [ @@ -319,7 +314,7 @@ { "cell_type": "code", "execution_count": null, - "id": "21", + "id": "20", "metadata": {}, "outputs": [], "source": [ @@ -334,7 +329,7 @@ }, { "cell_type": "markdown", - "id": "22", + "id": "21", "metadata": {}, "source": [ "The most generic solution considers the local forms of these concentration-dependent diffusivities for the diffusion equation of each dopant, as well as the electrostatic potential, in a finite-element scheme." @@ -346,6 +341,23 @@ "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" + }, + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.8" } }, "nbformat": 4, diff --git a/notebooks/tcad_03_numerical_implantation.ipynb b/notebooks/tcad_03_numerical_implantation.ipynb index 664c6af8..a70348ed 100644 --- a/notebooks/tcad_03_numerical_implantation.ipynb +++ b/notebooks/tcad_03_numerical_implantation.ipynb @@ -267,6 +267,9 @@ "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" + }, + "language_info": { + "name": "python" } }, "nbformat": 4, From 72b4369a80a968e3eaf7ace3957a71848560ad13 Mon Sep 17 00:00:00 2001 From: Joaquin Matres <4514346+joamatab@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:36:55 -0800 Subject: [PATCH 2/3] fix ruff --- gplugins/spice/spice_to_yaml.py | 38 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/gplugins/spice/spice_to_yaml.py b/gplugins/spice/spice_to_yaml.py index 7e12bd49..576e94e7 100644 --- a/gplugins/spice/spice_to_yaml.py +++ b/gplugins/spice/spice_to_yaml.py @@ -1,3 +1,4 @@ +# type: ignore import os import pathlib import re @@ -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 @@ -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)] ) else: try: @@ -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 @@ -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: @@ -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: @@ -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. From 5be5e67c61be696ecbcc17de5587190eed0f7664 Mon Sep 17 00:00:00 2001 From: Joaquin Matres <4514346+joamatab@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:38:38 -0800 Subject: [PATCH 3/3] update bandig --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b93767c..8772b5f0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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]