Skip to content

Commit c7f1967

Browse files
committed
Setting default mode precision to 'double', except in EME solver
1 parent d13703c commit c7f1967

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4141
- Upon initialization, an FDTD `Simulation` will now try to create all `ModeSolver` objects associated to `ModeSource`-s and `ModeMonitor`-s so they can be validated.
4242
- `tidy3d.plugins.autograd.interpolate_spline()` and `tidy3d.plugins.autograd.add_at()` can now be called with keyword arguments during tracing.
4343
- Zero-size dimensions automatically receive periodic boundary conditions instead of raising an error.
44+
- Set `ModeSpec` precision to `double` by deafult for more accurate mode solver results. Does not apply to `EMEModeSpec`, where the `auto` precision is still default for speed and cost.
4445

4546
## [2.8.4] - 2025-05-15
4647

tests/test_plugins/test_mode_solver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def test_mode_solver_group_index_warning(group_index_step, log_level):
312312
mode_spec = td.ModeSpec(
313313
num_modes=1,
314314
group_index_step=group_index_step,
315+
precision="auto",
315316
)
316317

317318
_ = ModeSolver(

tidy3d/components/eme/grid.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ class EMEModeSpec(ModeSpec):
5454
units=RADIAN,
5555
)
5656

57+
precision: Literal["auto", "single", "double"] = pd.Field(
58+
"auto",
59+
title="single, double, or automatic precision in mode solver",
60+
description="The solver will be faster and using less memory under "
61+
"single precision, but more accurate under double precision. "
62+
"Choose ``'auto'`` to apply double precision if the simulation contains a good "
63+
"conductor, single precision otherwise.",
64+
)
65+
5766
# this method is not supported because not all ModeSpec features are supported
5867
# @classmethod
5968
# def _from_mode_spec(cls, mode_spec: ModeSpec) -> EMEModeSpec:
@@ -74,19 +83,9 @@ class EMEModeSpec(ModeSpec):
7483

7584
def _to_mode_spec(self) -> ModeSpec:
7685
"""Convert to ordinary :class:`.ModeSpec`."""
77-
return ModeSpec(
78-
num_modes=self.num_modes,
79-
target_neff=self.target_neff,
80-
num_pml=self.num_pml,
81-
filter_pol=self.filter_pol,
82-
angle_theta=self.angle_theta,
83-
angle_phi=self.angle_phi,
84-
precision=self.precision,
85-
bend_radius=self.bend_radius,
86-
bend_axis=self.bend_axis,
87-
track_freq=self.track_freq,
88-
group_index_step=self.group_index_step,
89-
)
86+
ms_dict = self.dict()
87+
ms_dict.pop("type")
88+
return ModeSpec.parse_obj(ms_dict)
9089

9190

9291
class EMEGridSpec(Tidy3dBaseModel, ABC):

tidy3d/components/mode_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ class ModeSpec(Tidy3dBaseModel):
106106
)
107107

108108
precision: Literal["auto", "single", "double"] = pd.Field(
109-
"auto",
109+
"double",
110110
title="single, double, or automatic precision in mode solver",
111111
description="The solver will be faster and using less memory under "
112112
"single precision, but more accurate under double precision. "
113-
"With the default ``'auto'``, apply double precision if the simulation contains a good "
113+
"Choose ``'auto'`` to apply double precision if the simulation contains a good "
114114
"conductor, single precision otherwise.",
115115
)
116116

0 commit comments

Comments
 (0)