Skip to content

Commit fe7e4e7

Browse files
committed
Avoid error in importing ModeSolver if scipy is not installed
1 parent 4c243e6 commit fe7e4e7

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Warning if nonlinear mediums are used in an `adjoint` simulation. In this case, the gradients will not be accurate, but may be approximately correct if the nonlinearity is weak.
1111

1212
### Changed
13+
- Credit cost for remote mode solver has been modified to be defined in advance based on the mode solver details. Previously, the cost was based on elapsed runtime. On average, there should be little difference in the cost.
14+
- Mode solves that are part of an FDTD simulation (i.e. for mode sources and monitors) are now charged at the same flex credit cost as a corresponding standalone mode solver call.
1315

1416
### Fixed
1517

@@ -34,8 +36,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3436
- Removed spurious ``-1`` factor in field amplitudes injected by field sources in some cases. The injected ``E``-field should now exactly match the analytic, mode, or custom fields that the source is expected to inject, both in the forward and in the backward direction.
3537
- Restriction on the maximum memory that a monitor would need internally during the solver run, even if the final monitor data is smaller.
3638
- Restriction on the maximum size of mode solver data produced by a `ModeSolver` server call.
37-
- Credit cost for remote mode solver has been modified to be defined in advance based on the mode solver details. Previously, the cost was based on elapses runtime. On average, there should be little difference in the cost.
38-
- Mode solves that are part of an FDTD simulation (i.e. for mode sources and monitors) are now charged at the same flex credit cost as a corresponding standalone mode solver call.
3939

4040
### Fixed
4141
- Fixed the duplication of log messages in Jupyter when `set_logging_file` is used.

tidy3d/plugins/mode/mode_solver.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@
2626
from ...components.data.monitor_data import ModeSolverData
2727
from ...exceptions import ValidationError, SetupError
2828
from ...constants import C_0
29-
from .solver import compute_modes, EigSolver
29+
30+
# Importing the local solver may not work if e.g. scipy is not installed
31+
IMPORT_ERROR_MSG = """Could not import local solver, 'ModeSolver' objects can still be constructed
32+
but will have to be run through the server.
33+
"""
34+
try:
35+
from .solver import compute_modes
36+
37+
LOCAL_SOLVER_IMPORTED = True
38+
except ImportError:
39+
log.warning(IMPORT_ERROR_MSG)
40+
LOCAL_SOLVER_IMPORTED = False
3041

3142
FIELD = Tuple[ArrayComplex3D, ArrayComplex3D, ArrayComplex3D]
3243
MODE_MONITOR_NAME = "<<<MODE_SOLVER_MONITOR>>>"
@@ -453,6 +464,10 @@ def _solve_single_freq(
453464
454465
The fields are rotated from propagation coordinates back to global coordinates.
455466
"""
467+
468+
if not LOCAL_SOLVER_IMPORTED:
469+
raise ImportError(IMPORT_ERROR_MSG)
470+
456471
solver_fields, n_complex, eps_spec = compute_modes(
457472
eps_cross=self._solver_eps(freq),
458473
coords=coords,
@@ -628,9 +643,10 @@ def _has_complex_eps(self) -> bool:
628643
eps and mu and uses a tolerance to determine whether to use real or complex fields, so
629644
the actual behavior may differ from what's predicted by this property."""
630645
for int_mat in self._intersecting_media:
631-
if EigSolver.isinstance_complex(int_mat.eps_model(np.array(self.freqs))):
632-
return True
633-
return False
646+
max_imag_eps = np.amax(np.abs(np.imag(int_mat.eps_model(np.array(self.freqs)))))
647+
if not np.isclose(max_imag_eps, 0):
648+
return False
649+
return True
634650

635651
def to_source(
636652
self,

0 commit comments

Comments
 (0)