From f44bdf3a3887b0357ab75acff4af35408ad19160 Mon Sep 17 00:00:00 2001 From: heydaridlm <137212650+heydaridlm@users.noreply.github.com> Date: Mon, 8 Dec 2025 12:57:18 -0800 Subject: [PATCH 1/4] in the write_sparameters method we only allow upload and not run, allows used to run from GUI for safe measure --- gplugins/tidy3d/component.py | 55 +++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/gplugins/tidy3d/component.py b/gplugins/tidy3d/component.py index fe535a8c..4f7eaf05 100644 --- a/gplugins/tidy3d/component.py +++ b/gplugins/tidy3d/component.py @@ -20,6 +20,9 @@ from functools import cached_property from typing import Any, Literal +import tidy3d.web.api.webapi as web +from tidy3d.components.monitor import FieldMonitor + import matplotlib.pyplot as plt import numpy as np import tidy3d as td @@ -591,25 +594,39 @@ def write_sparameters( return dict(np.load(filepath)) else: time.sleep(0.2) - s = modeler.run() - for port_in in s.port_in.values: - 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 - ) - - frequency = s.f.values - sp["wavelengths"] = td.constants.C_0 / frequency - np.savez_compressed(filepath, **sp) - print(f"Simulation saved to {filepath!r}") - return sp + # s = modeler.run() + plot_sources = [modeler.to_source(port=p, mode_index=0) for p in modeler.ports] + plot_monitors = [modeler.to_monitor(port=p) for p in modeler.ports] + + cz = c.get_layer_center("core")[2] + birdseye = FieldMonitor(name="birdseye", interval_space=(4, 4, 1),freqs=td.C_0 / wavelength, center=(c.center[0], c.center[1], cz), size=(c.size[0], c.size[1], 0)) + + sim_with_sources = modeler.simulation.copy( + update={"sources": plot_sources, "monitors": list(modeler.simulation.monitors) + plot_monitors + [birdseye]} + ) + + s = web.upload(sim_with_sources, task_name=folder_name) + return s + + # if s.status != "completed": + # for port_in in s.port_in.values: + # 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 + # ) + + # frequency = s.f.values + # sp["wavelengths"] = td.constants.C_0 / frequency + # np.savez_compressed(filepath, **sp) + # print(f"Simulation saved to {filepath!r}") + # return sp def write_sparameters_batch( From c2134d29a2342bd4e529c50b0b64dee8399f4e94 Mon Sep 17 00:00:00 2001 From: heydaridlm <137212650+heydaridlm@users.noreply.github.com> Date: Thu, 11 Dec 2025 11:28:35 -0800 Subject: [PATCH 2/4] flag for upload only prevents breaking the function for other users --- gplugins/tidy3d/component.py | 66 +++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/gplugins/tidy3d/component.py b/gplugins/tidy3d/component.py index 4f7eaf05..053ebd1c 100644 --- a/gplugins/tidy3d/component.py +++ b/gplugins/tidy3d/component.py @@ -448,6 +448,7 @@ def write_sparameters( plot_epsilon: bool = False, filepath: PathType | None = None, overwrite: bool = False, + upload_only: bool = False, **kwargs: Any, ) -> Sparameters: """Writes the S-parameters for a component. @@ -594,39 +595,40 @@ def write_sparameters( return dict(np.load(filepath)) else: time.sleep(0.2) - # s = modeler.run() - plot_sources = [modeler.to_source(port=p, mode_index=0) for p in modeler.ports] - plot_monitors = [modeler.to_monitor(port=p) for p in modeler.ports] - - cz = c.get_layer_center("core")[2] - birdseye = FieldMonitor(name="birdseye", interval_space=(4, 4, 1),freqs=td.C_0 / wavelength, center=(c.center[0], c.center[1], cz), size=(c.size[0], c.size[1], 0)) - - sim_with_sources = modeler.simulation.copy( - update={"sources": plot_sources, "monitors": list(modeler.simulation.monitors) + plot_monitors + [birdseye]} - ) + if upload_only: + plot_sources = [modeler.to_source(port=p, mode_index=0) for p in modeler.ports] + plot_monitors = [modeler.to_monitor(port=p) for p in modeler.ports] + + cz = c.get_layer_center("core")[2] + birdseye = FieldMonitor(name="birdseye", interval_space=(4, 4, 1),freqs=td.constants.C_0 / wavelength, center=(c.center[0], c.center[1], cz), size=(c.size[0], c.size[1], 0)) + + sim_with_sources = modeler.simulation.copy( + update={"sources": plot_sources, "monitors": list(modeler.simulation.monitors) + plot_monitors + [birdseye]} + ) - s = web.upload(sim_with_sources, task_name=folder_name) - return s - - # if s.status != "completed": - # for port_in in s.port_in.values: - # 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 - # ) - - # frequency = s.f.values - # sp["wavelengths"] = td.constants.C_0 / frequency - # np.savez_compressed(filepath, **sp) - # print(f"Simulation saved to {filepath!r}") - # return sp + s = web.upload(sim_with_sources, task_name=folder_name) + return s + if not upload_only: + s = modeler.run() + if s.status != "completed": + for port_in in s.port_in.values: + 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 + ) + + frequency = s.f.values + sp["wavelengths"] = td.constants.C_0 / frequency + np.savez_compressed(filepath, **sp) + print(f"Simulation saved to {filepath!r}") + return sp def write_sparameters_batch( From f206f13f846222f9e733cf4e793de29579392a3d Mon Sep 17 00:00:00 2001 From: heydaridlm <137212650+heydaridlm@users.noreply.github.com> Date: Thu, 11 Dec 2025 11:44:11 -0800 Subject: [PATCH 3/4] tidy.constants.C_0 for speed of light --- gplugins/tidy3d/component.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gplugins/tidy3d/component.py b/gplugins/tidy3d/component.py index 053ebd1c..5fa6598c 100644 --- a/gplugins/tidy3d/component.py +++ b/gplugins/tidy3d/component.py @@ -280,7 +280,7 @@ def get_component_modeler( cz = np.round(cz, abs(int(np.log10(grid_eps)))).item() - freqs = td.C_0 / np.linspace( + freqs = td.constants.C_0 / np.linspace( wavelength - bandwidth / 2, wavelength + bandwidth / 2, num_freqs ) From 8e7fff3efbd392be35319ee1b5f62438512f4c0e Mon Sep 17 00:00:00 2001 From: heydaridlm <137212650+heydaridlm@users.noreply.github.com> Date: Tue, 16 Dec 2025 09:12:59 -0800 Subject: [PATCH 4/4] fixed precom errors --- gplugins/tidy3d/component.py | 44 +++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/gplugins/tidy3d/component.py b/gplugins/tidy3d/component.py index 5fa6598c..9a95db12 100644 --- a/gplugins/tidy3d/component.py +++ b/gplugins/tidy3d/component.py @@ -20,17 +20,16 @@ from functools import cached_property from typing import Any, Literal -import tidy3d.web.api.webapi as web -from tidy3d.components.monitor import FieldMonitor - import matplotlib.pyplot as plt import numpy as np import tidy3d as td +import tidy3d.web.api.webapi as web from gdsfactory.component import Component from gdsfactory.pdk import get_layer_stack from gdsfactory.technology import LayerStack from pydantic import NonNegativeFloat from tidy3d.components.geometry.base import from_shapely +from tidy3d.components.monitor import FieldMonitor from tidy3d.components.types import Symmetry from tidy3d.plugins.smatrix import ComponentModeler, Port @@ -494,7 +493,7 @@ def write_sparameters( filepath: Optional file path for the S-parameters. If None, uses hash of simulation. overwrite: Whether to overwrite existing S-parameters. Defaults to False. kwargs: Additional keyword arguments for the tidy3d Simulation constructor. - + upload_only: Whether to upload the simulation to the cloud only. Defaults to False. """ layer_stack = layer_stack or get_layer_stack() @@ -596,14 +595,27 @@ def write_sparameters( else: time.sleep(0.2) if upload_only: - plot_sources = [modeler.to_source(port=p, mode_index=0) for p in modeler.ports] + plot_sources = [ + modeler.to_source(port=p, mode_index=0) for p in modeler.ports + ] plot_monitors = [modeler.to_monitor(port=p) for p in modeler.ports] - + cz = c.get_layer_center("core")[2] - birdseye = FieldMonitor(name="birdseye", interval_space=(4, 4, 1),freqs=td.constants.C_0 / wavelength, center=(c.center[0], c.center[1], cz), size=(c.size[0], c.size[1], 0)) + birdseye = FieldMonitor( + name="birdseye", + interval_space=(4, 4, 1), + freqs=td.constants.C_0 / wavelength, + center=(c.center[0], c.center[1], cz), + size=(c.size[0], c.size[1], 0), + ) sim_with_sources = modeler.simulation.copy( - update={"sources": plot_sources, "monitors": list(modeler.simulation.monitors) + plot_monitors + [birdseye]} + update={ + "sources": plot_sources, + "monitors": list(modeler.simulation.monitors) + + plot_monitors + + [birdseye], + } ) s = web.upload(sim_with_sources, task_name=folder_name) @@ -615,14 +627,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