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

expose symmetry and other tidy3d simulation args #269

Merged
merged 2 commits into from
Dec 5, 2023
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
23 changes: 23 additions & 0 deletions gplugins/tidy3d/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from gdsfactory.pdk import get_layer_stack
from gdsfactory.technology import LayerStack
from pydantic import NonNegativeFloat
from tidy3d.components.types import Symmetry
from tidy3d.plugins.smatrix import ComponentModeler, Port

from gplugins.common.base_models.component import LayeredComponentBase
Expand Down Expand Up @@ -180,6 +181,8 @@ def get_simulation(
monitors: tuple[Any, ...] | None = None,
run_time: float = 10e-12,
shutoff: float = 1e-5,
symmetry: tuple[Symmetry, Symmetry, Symmetry] = (0, 0, 0),
**kwargs,
) -> td.Simulation:
"""
Returns a Simulation instance for the component.
Expand All @@ -192,6 +195,10 @@ def get_simulation(
monitors (tuple[Any, ...] | None, optional): The monitors for the simulation. If None, no monitors are used. Defaults to None.
run_time (float, optional): The run time for the simulation. Defaults to 1e-12.
shutoff (float, optional): The shutoff value for the simulation. Defaults to 1e-5.
symmetry (tuple[Symmetry, Symmetry, Symmetry], optional): The symmetry for the simulation. Defaults to (0,0,0).

Keyword Args:
**kwargs: Additional keyword arguments for the Simulation constructor.

Returns:
td.Simulation: A Simulation instance.
Expand All @@ -207,6 +214,8 @@ def get_simulation(
boundary_spec=boundary_spec,
run_time=run_time,
shutoff=shutoff,
symmetry=symmetry,
**kwargs,
)
return sim

Expand All @@ -229,6 +238,8 @@ def get_component_modeler(
folder_name: str = "default",
path_dir: str = ".",
verbose: bool = True,
symmetry: tuple[Symmetry, Symmetry, Symmetry] = (0, 0, 0),
**kwargs,
) -> ComponentModeler:
"""
Returns a ComponentModeler instance for the component.
Expand All @@ -251,6 +262,8 @@ def get_component_modeler(
folder_name: The folder name for the ComponentModeler. Defaults to "default".
path_dir: The directory path for the ComponentModeler. Defaults to ".".
verbose: Whether to print verbose output for the ComponentModeler. Defaults to True.
symmetry (tuple[Symmetry, Symmetry, Symmetry], optional): The symmetry for the simulation. Defaults to (0,0,0).
kwargs: Additional keyword arguments for the Simulation constructor.

Returns:
ComponentModeler: A ComponentModeler instance.
Expand Down Expand Up @@ -285,6 +298,8 @@ def get_component_modeler(
monitors=extra_monitors,
run_time=run_time,
shutoff=shutoff,
symmetry=symmetry,
**kwargs,
)

ports = self.get_ports(mode_spec, port_size_mult)
Expand Down Expand Up @@ -421,6 +436,7 @@ def write_sparameters(
extra_monitors: tuple[Any, ...] | None = None,
mode_spec: td.ModeSpec = td.ModeSpec(num_modes=1, filter_pol="te"),
boundary_spec: td.BoundarySpec = td.BoundarySpec.all_sides(boundary=td.PML()),
symmetry: tuple[Symmetry, Symmetry, Symmetry] = (0, 0, 0),
run_time: float = 1e-12,
shutoff: float = 1e-5,
folder_name: str = "default",
Expand All @@ -435,6 +451,7 @@ def write_sparameters(
plot_epsilon: bool = False,
filepath: PathType | None = None,
overwrite: bool = False,
**kwargs,
) -> Sparameters:
"""Writes the S-parameters for a component.

Expand Down Expand Up @@ -463,6 +480,7 @@ def write_sparameters(
mode_spec: The mode specification for the ComponentModeler. Defaults to td.ModeSpec(num_modes=1, filter_pol="te").
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).
run_time: The run time for the ComponentModeler.
shutoff: The shutoff value for the ComponentModeler. Defaults to 1e-5.
folder_name: The folder name for the ComponentModeler in flexcompute website. Defaults to "default".
Expand All @@ -476,6 +494,7 @@ def write_sparameters(
plot_mode_port_name: which port name to plot. Defaults to None.
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.

"""
layer_stack = layer_stack or get_layer_stack()
Expand Down Expand Up @@ -510,6 +529,8 @@ def write_sparameters(
shutoff=shutoff,
folder_name=folder_name,
verbose=verbose,
symmetry=symmetry,
**kwargs,
)

path_dir = pathlib.Path(dirpath) / modeler._hash_self()
Expand Down Expand Up @@ -630,6 +651,7 @@ def write_sparameters_batch(
mode_spec: The mode specification for the ComponentModeler. Defaults to td.ModeSpec(num_modes=1, filter_pol="te").
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).
run_time: The run time for the ComponentModeler. Defaults to 1e-12.
shutoff: The shutoff value for the ComponentModeler. Defaults to 1e-5.
folder_name: The folder name for the ComponentModeler in flexcompute website. Defaults to "default".
Expand All @@ -643,6 +665,7 @@ def write_sparameters_batch(
plot_mode_port_name: which port name to plot. Defaults to None.
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.
"""
kwargs.update(verbose=False)
return [_executor.submit(write_sparameters, **job, **kwargs) for job in jobs]
Expand Down
Loading