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

Warn if time monitor start time is after simulation run time #1350

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
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: 21 additions & 0 deletions tests/test_components/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,27 @@ def test_error_large_monitors():
s.validate_pre_upload()


@pytest.mark.parametrize("start, log_level", [(1e-12, None), (1, "WARNING")])
def test_warn_time_monitor_outside_run_time(log_capture, start, log_level):
"""Make sure we get a warning if the mode monitor grid is too large."""

sim = td.Simulation(
size=(2.0, 2.0, 2.0),
grid_spec=td.GridSpec.uniform(dl=0.1),
run_time=1e-12,
sources=[
td.ModeSource(
size=(0.1, 0.1, 0),
direction="+",
source_time=td.GaussianPulse(freq0=1e12, fwidth=0.1e12),
)
],
monitors=[td.FieldTimeMonitor(size=(td.inf, 0, td.inf), start=start, name="test")],
)
with AssertLogLevel(log_capture, log_level_expected=log_level, contains_str="start time"):
sim.validate_pre_upload()


def test_dt():
"""make sure dt is reduced when there is a medium with eps_inf < 1."""
sim = td.Simulation(
Expand Down
19 changes: 17 additions & 2 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .source import CustomCurrentSource, CustomSourceTime, ContinuousWave
from .source import TFSF, Source, ModeSource
from .monitor import MonitorType, Monitor, FreqMonitor, SurfaceIntegrationMonitor
from .monitor import AbstractModeMonitor, FieldMonitor
from .monitor import AbstractModeMonitor, FieldMonitor, TimeMonitor
from .monitor import PermittivityMonitor, DiffractionMonitor, AbstractFieldProjectionMonitor
from .monitor import FieldProjectionAngleMonitor, FieldProjectionKSpaceMonitor
from .data.dataset import Dataset
Expand Down Expand Up @@ -1065,7 +1065,7 @@ def validate_pre_upload(self, source_required: bool = True) -> None:
self._validate_modes_size()
self._validate_datasets_not_none()
self._validate_tfsf_structure_intersections()
# self._validate_run_time()
self._warn_time_monitors_outside_run_time()
_ = self.volumetric_structures
log.end_capture(self)
if source_required and len(self.sources) == 0:
Expand Down Expand Up @@ -1282,6 +1282,21 @@ def _validate_tfsf_structure_intersections(self) -> None:
f" '{'xyz'[source.injection_axis]}'."
)

def _warn_time_monitors_outside_run_time(self) -> None:
"""Warn if time monitors start after the simulation run_time.
TODO: (remove this comment later) this is done as a pre-upload validator in view of a
planned change to allow ``run_time`` to accept a ``RunTimeSpec`` which would automatically
determine a run time based on simulation details. Then, we would have to access the
dynamically computed run_time e.g. through a ``_run_time`` cached property.
"""
with log as consolidated_logger:
for monitor in self.monitors:
if isinstance(monitor, TimeMonitor) and monitor.start > self.run_time:
consolidated_logger.warning(
f"Monitor {monitor.name} has a start time {monitor.start:1.2e}s exceeding"
f"the simulation run time {self.run_time:1.2e}s. No data will be recorded."
)

""" Accounting """

# candidate for removal in 3.0
Expand Down
Loading