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

Fix ruff #535

Merged
merged 2 commits into from
Jan 11, 2025
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
3 changes: 1 addition & 2 deletions gplugins/sax/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,9 @@ def mmi2x2(
loss_dB: loss in dB.
shift: shift in wavelength for both cross and thru ports.
loss_dB_cross: loss in dB for the cross port.
loss_dB_bar: loss in dB for the bar port.
loss_dB_thru: loss in dB for the bar port.
splitting_ratio_cross: splitting ratio for the cross port.
splitting_ratio_thru: splitting ratio for the bar port.

"""
loss_dB_cross = loss_dB_cross or loss_dB
loss_dB_thru = loss_dB_thru or loss_dB
Expand Down
12 changes: 6 additions & 6 deletions gplugins/sentaurus/sdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ def write_sdevice_quasistationary_ramp_voltage_dd(
ramp_max_step: maximum ramping step.
ramp_min_step: minimum ramping step.
ramp_sample_voltages: list of voltages between 0V and ramp_final_voltage to report.
filepath: str = Path to the TLC file to be written.
file_settings: "File" field settings to add to the TCL file
output_settings: "Output" field settings to add to the TCL file
physics_settings: "Physics" field settings to add to the TCL file
math_settings: str = "Math" field settings to add to the TCL file
initialization_commands: in the solver, what to execute before the ramp
filename: name of the TCL file to save.
save_directory: directory to save the TCL file.
execution_directory: directory to execute the TCL file.
output_settings: "Plot" field settings to add to the TCL file.
physics_settings: "Physics" field settings to add to the TCL file.
math_settings: str = "Math" field settings to add to the TCL file.
"""
save_directory = (
Path("./sdevice/") if save_directory is None else Path(save_directory)
Expand Down
11 changes: 5 additions & 6 deletions gplugins/vlsir/export_netlist.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Uses VLSIRTools for converting between Klayout's DB Netlist format and other electrical schematic file formats:
"""Uses VLSIRTools for converting between Klayout's DB Netlist format and other electrical schematic file formats.

- SPICE
- Spectre
- Xyce
- Verilog (Not supported yet).

Todo:
- Add support for Verilog
- Thoroughly test the parser with more complex netlists
- Add support for Verilog.
- Thoroughly test the parser with more complex netlists.
"""

from io import StringIO
Expand Down Expand Up @@ -45,9 +46,7 @@ def _connections(**kwargs) -> list[Connection]:


def _params(**kwargs) -> list[Param]:
"""Create a list of `Param`s from keyword args of the form
`r=ParamValue(double_value=1e3)`.
"""
"""Create a list of `Param`s from keyword args of the form r=ParamValue(double_value=1e3)."""
return [Param(name=key, value=value) for key, value in kwargs.items()]


Expand Down
99 changes: 43 additions & 56 deletions notebooks/elmer_01_electrostatic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"from math import inf\n",
"\n",
"import gdsfactory as gf\n",
"import pyvista as pv\n",
"from gdsfactory.components.interdigital_capacitor_enclosed import (\n",
" interdigital_capacitor_enclosed,\n",
")\n",
Expand Down Expand Up @@ -146,61 +145,48 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"id": "8",
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"# results = run_capacitive_simulation_elmer(\n",
"# c,\n",
"# layer_stack=layer_stack,\n",
"# material_spec=material_spec,\n",
"# n_processes=1,\n",
"# element_order=1,\n",
"# simulation_folder=Path(os.getcwd()) / \"temporary\",\n",
"# mesh_parameters=dict(\n",
"# background_tag=\"vacuum\",\n",
"# background_padding=(0,) * 5 + (700,),\n",
"# port_names=c.ports.keys(),\n",
"# default_characteristic_length=200,\n",
"# resolutions={\n",
"# \"bw\": {\n",
"# \"resolution\": 15,\n",
"# },\n",
"# \"substrate\": {\n",
"# \"resolution\": 40,\n",
"# },\n",
"# \"vacuum\": {\n",
"# \"resolution\": 40,\n",
"# },\n",
"# **{\n",
"# f\"bw__{port}\": { # `__` is used as the layer–port delimiter for Elmer\n",
"# \"resolution\": 20,\n",
"# \"DistMax\": 30,\n",
"# \"DistMin\": 10,\n",
"# \"SizeMax\": 14,\n",
"# \"SizeMin\": 3,\n",
"# }\n",
"# for port in c.ports\n",
"# },\n",
"# },\n",
"# ),\n",
"# )\n",
"# display(results)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"metadata": {},
"source": [
"```python\n",
"results = run_capacitive_simulation_elmer(\n",
" c,\n",
" layer_stack=layer_stack,\n",
" material_spec=material_spec,\n",
" n_processes=1,\n",
" element_order=1,\n",
" simulation_folder=Path(os.getcwd()) / \"temporary\",\n",
" mesh_parameters=dict(\n",
" background_tag=\"vacuum\",\n",
" background_padding=(0,) * 5 + (700,),\n",
" port_names=c.ports.keys(),\n",
" default_characteristic_length=200,\n",
" resolutions={\n",
" \"bw\": {\n",
" \"resolution\": 15,\n",
" },\n",
" \"substrate\": {\n",
" \"resolution\": 40,\n",
" },\n",
" \"vacuum\": {\n",
" \"resolution\": 40,\n",
" },\n",
" **{\n",
" f\"bw__{port}\": { # `__` is used as the layer to port delimiter for Elmer\n",
" \"resolution\": 20,\n",
" \"DistMax\": 30,\n",
" \"DistMin\": 10,\n",
" \"SizeMax\": 14,\n",
" \"SizeMin\": 3,\n",
" }\n",
" for port in c.ports\n",
" },\n",
" },\n",
" ),\n",
")\n",
"display(results)\n",
"\n",
"if results.field_file_location:\n",
" pv.start_xvfb()\n",
" pv.set_jupyter_backend(\"trame\")\n",
Expand All @@ -212,12 +198,13 @@
" p.show_grid()\n",
" p.camera_position = \"xy\"\n",
" p.enable_parallel_projection()\n",
" p.show()"
" p.show()\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "10",
"id": "9",
"metadata": {},
"source": [
"## Bibliography\n",
Expand Down
82 changes: 28 additions & 54 deletions notebooks/meep_01_sparameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
"source": [
"import gdsfactory as gf\n",
"import matplotlib.pyplot as plt\n",
"import meep as mp\n",
"import numpy as np\n",
"from autograd import tensor_jacobian_product\n",
"from gdsfactory.generic_tech import get_generic_pdk\n",
"from meep import MaterialGrid, Medium, Vector3, Volume\n",
"from meep.adjoint import (\n",
Expand All @@ -108,6 +108,7 @@
"\n",
"import gplugins\n",
"import gplugins.gmeep as gm\n",
"from gplugins.gmeep.get_simulation import get_simulation\n",
"\n",
"gf.config.rich_output()\n",
"PDK = get_generic_pdk()\n",
Expand Down Expand Up @@ -812,16 +813,11 @@
"id": "52",
"metadata": {},
"source": [
"We'll define a simple objective function that returns the gradient, and records the figure of merit. We'll plot the new geometry after each iteration."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53",
"metadata": {},
"outputs": [],
"source": [
"We'll define a simple objective function that returns the gradient, and records the figure of merit. We'll plot the new geometry after each iteration.\n",
"\n",
"```python\n",
"\n",
"\n",
"evaluation_history = []\n",
"cur_iter = [0]\n",
"\n",
Expand Down Expand Up @@ -851,24 +847,19 @@
"\n",
" cur_iter[0] = cur_iter[0] + 1\n",
"\n",
" return np.real(f0)"
" return np.real(f0)\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "54",
"metadata": {},
"source": [
"We can define bitmasks to describe the boundary conditions."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "55",
"id": "53",
"metadata": {},
"outputs": [],
"source": [
"We can define bitmasks to describe the boundary conditions.\n",
"\n",
"```python\n",
"\n",
"# Define spatial arrays used to generate bit masks\n",
"x_g = np.linspace(-design_region_width / 2, design_region_width / 2, Nx)\n",
"y_g = np.linspace(-design_region_height / 2, design_region_height / 2, Ny)\n",
Expand All @@ -892,20 +883,21 @@
" | (Y_g == design_region_height / 2)\n",
")\n",
"SiO2_mask = border_mask.copy()\n",
"SiO2_mask[Si_mask] = False"
"SiO2_mask[Si_mask] = False\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "56",
"id": "54",
"metadata": {},
"source": [
"We can then finally run the optimizer, and visualize the optimized component."
]
},
{
"cell_type": "markdown",
"id": "57",
"id": "55",
"metadata": {},
"source": [
"\n",
Expand Down Expand Up @@ -965,7 +957,7 @@
},
{
"cell_type": "markdown",
"id": "58",
"id": "56",
"metadata": {},
"source": [
"The final optimized structure should look like this:\n",
Expand All @@ -977,7 +969,7 @@
},
{
"cell_type": "markdown",
"id": "59",
"id": "57",
"metadata": {},
"source": [
"## Meep fields\n",
Expand All @@ -992,22 +984,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "60",
"metadata": {},
"outputs": [],
"source": [
"from __future__ import annotations\n",
"\n",
"import gdsfactory as gf\n",
"import meep as mp\n",
"\n",
"from gplugins.gmeep.get_simulation import get_simulation"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "61",
"id": "58",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1026,7 +1003,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "62",
"id": "59",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1053,7 +1030,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "63",
"id": "60",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1064,7 +1041,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "64",
"id": "61",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1078,12 +1055,10 @@
{
"cell_type": "code",
"execution_count": null,
"id": "65",
"id": "62",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"eps_data = sim.get_array(vol=nonpml_vol, component=mp.Dielectric)\n",
"ez_data = np.real(ez_dat)\n",
"\n",
Expand All @@ -1096,7 +1071,7 @@
},
{
"cell_type": "markdown",
"id": "66",
"id": "63",
"metadata": {},
"source": [
"We can also just run the time-domain simulation with the continuous source until the field is stabilized:"
Expand All @@ -1105,7 +1080,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "67",
"id": "64",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1115,14 +1090,13 @@
{
"cell_type": "code",
"execution_count": null,
"id": "68",
"id": "65",
"metadata": {},
"outputs": [],
"source": [
"eps_data = sim.get_epsilon()\n",
"ez_data = np.real(sim.get_efield_z())\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.figure()\n",
"sim.plot2D(\n",
Expand Down
Loading
Loading