Skip to content
Merged
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
21 changes: 9 additions & 12 deletions gplugins/tidy3d/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import matplotlib.pyplot as plt
import numpy as np
import tidy3d as td
import tidy3d.web as web
from gdsfactory.component import Component
from gdsfactory.pdk import get_layer_stack
from gdsfactory.technology import LayerStack
Expand Down Expand Up @@ -227,7 +228,7 @@ def get_component_modeler(
run_only: tuple[tuple[str, int], ...] | None = None,
element_mappings: Tidy3DElementMapping = (),
extra_monitors: tuple[Any, ...] | None = None,
mode_spec: td.ModeSpec = td.ModeSpec(num_modes=1, filter_pol="te"),
mode_spec: td.ModeSpec = td.ModeSpec(num_modes=1),
boundary_spec: td.BoundarySpec = td.BoundarySpec.all_sides(boundary=td.PML()),
run_time: float = 10e-12,
shutoff: float = 1e-5,
Expand All @@ -251,7 +252,7 @@ def get_component_modeler(
run_only: The run only specification for the ComponentModeler. Defaults to None.
element_mappings: The element mappings for the ComponentModeler. Defaults to ().
extra_monitors: The extra monitors for the ComponentModeler. Defaults to None.
mode_spec: The mode specification for the ComponentModeler. Defaults to td.ModeSpec(num_modes=1, filter_pol="te").
mode_spec: The mode specification for the ComponentModeler. Defaults to td.ModeSpec(num_modes=1).
boundary_spec: The boundary specification for the ComponentModeler. Defaults to td.BoundarySpec.all_sides(boundary=td.PML()).
run_time: The run time for the ComponentModeler.
shutoff: The shutoff value for the ComponentModeler. Defaults to 1e-5.
Expand Down Expand Up @@ -308,9 +309,6 @@ def get_component_modeler(
freqs=tuple(freqs),
element_mappings=element_mappings,
run_only=run_only,
folder_name=folder_name,
path_dir=path_dir,
verbose=verbose,
)

@td.components.viz.add_ax_if_none
Expand Down Expand Up @@ -428,7 +426,7 @@ def write_sparameters(
run_only: tuple[tuple[str, int], ...] | None = None,
element_mappings: Tidy3DElementMapping = (),
extra_monitors: tuple[Any, ...] | None = None,
mode_spec: td.ModeSpec = td.ModeSpec(num_modes=1, filter_pol="te"),
mode_spec: td.ModeSpec = td.ModeSpec(num_modes=1),
boundary_spec: td.BoundarySpec = td.BoundarySpec.all_sides(boundary=td.PML()),
symmetry: tuple[Symmetry, Symmetry, Symmetry] = (0, 0, 0),
run_time: float = 1e-12,
Expand Down Expand Up @@ -471,7 +469,7 @@ def write_sparameters(
run_only: The run only specification for the ComponentModeler. Defaults to None.
element_mappings: The element mappings for the ComponentModeler. Defaults to ().
extra_monitors: The extra monitors for the ComponentModeler. Defaults to None.
mode_spec: The mode specification for the ComponentModeler. Defaults to td.ModeSpec(num_modes=1, filter_pol="te").
mode_spec: The mode specification for the ComponentModeler. Defaults to td.ModeSpec(num_modes=1).
boundary_spec: The boundary specification for the ComponentModeler.
Defaults to td.BoundarySpec.all_sides(boundary=td.PML()).
symmetry (tuple[Symmetry, Symmetry, Symmetry], optional): The symmetry for the simulation. Defaults to (0,0,0).
Expand Down Expand Up @@ -522,14 +520,12 @@ def write_sparameters(
boundary_spec=boundary_spec,
run_time=run_time,
shutoff=shutoff,
folder_name=folder_name,
verbose=verbose,
symmetry=symmetry,
**kwargs,
)

path_dir = pathlib.Path(dirpath) / modeler._hash_self()
modeler = modeler.updated_copy(path_dir=str(path_dir))
modeler = modeler.updated_copy()
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: path_dir is computed but no longer used, which suggests either dead code or an incomplete refactor.

After switching to modeler.updated_copy() with no arguments, path_dir is no longer referenced. If the hashed directory behavior is being removed, path_dir should likely be deleted. If that behavior is still needed (for organization/caching), updated_copy should probably still receive path_dir (or the new target directory) as an argument.


sp = {}

Expand Down Expand Up @@ -591,7 +587,8 @@ def write_sparameters(
return dict(np.load(filepath))
else:
time.sleep(0.2)
s = modeler.run()
modeler_data = web.run(modeler, verbose=verbose, path=dirpath / "simulation.hdf5")
s = modeler_data.smatrix()
Comment on lines +590 to +591
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Using dirpath / "simulation.hdf5" assumes dirpath is a Path, which may be a regression if callers pass a string.

Previously we only wrapped dirpath in Path when building path_dir, so callers could still pass a plain string. With web.run(..., path=dirpath / "simulation.hdf5"), a string dirpath will now raise a TypeError. Please either normalize dirpath once at the top (e.g. dirpath = pathlib.Path(dirpath)) or change this call to path=pathlib.Path(dirpath) / "simulation.hdf5" to handle both strings and Path objects safely.

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:
Expand Down Expand Up @@ -645,7 +642,7 @@ def write_sparameters_batch(
run_only: The run only specification for the ComponentModeler. Defaults to None.
element_mappings: The element mappings for the ComponentModeler. Defaults to ().
extra_monitors: The extra monitors for the ComponentModeler. Defaults to None.
mode_spec: The mode specification for the ComponentModeler. Defaults to td.ModeSpec(num_modes=1, filter_pol="te").
mode_spec: The mode specification for the ComponentModeler. Defaults to td.ModeSpec(num_modes=1).
boundary_spec: The boundary specification for the ComponentModeler.
Defaults to td.BoundarySpec.all_sides(boundary=td.PML()).
symmetry (tuple[Symmetry, Symmetry, Symmetry], optional): The symmetry for the simulation. Defaults to (0,0,0).
Expand Down
Loading