Skip to content
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
4 changes: 2 additions & 2 deletions tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def test_VolumeSource_directional():
s = PlaneWave(size=(0, 1, 1), source_time=g, polarization="Ez", direction="+")

# test we can make planewave
s = GaussianBeam(size=(0,1,1), source_time=g, polarization='Ez', direction='+')
s = GaussianBeam(size=(0, 1, 1), source_time=g, polarization="Ez", direction="+")

# test that non-planar geometry crashes plane wave
with pytest.raises(ValidationError) as e_info:
Expand All @@ -429,7 +429,7 @@ def test_VolumeSource_directional():
with pytest.raises(ValidationError) as e_info:
s = PlaneWave(size=(1, 1, 0), source_time=g, polarization="Ez", direction="+")
with pytest.raises(ValidationError) as e_info:
s = GaussianBeam(size=(1,1,1), source_time=g, polarization='Ez', direction='+')
s = GaussianBeam(size=(1, 1, 1), source_time=g, polarization="Ez", direction="+")


def test_VolumeSource_modal():
Expand Down
4 changes: 2 additions & 2 deletions tidy3d/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Tidy3d package imports"""
__version__ = "0.0.0"

from concurrent.futures import ProcessPoolExecutor
from concurrent.futures import ProcessPoolExecutor, process

from rich import pretty, traceback

Expand Down Expand Up @@ -63,4 +63,4 @@

# make all stdout and errors pretty
pretty.install()
# traceback.install(suppress=[ProcessPoolExecutor])
# traceback.install()
6 changes: 3 additions & 3 deletions tidy3d/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# medium
from .medium import Medium, PoleResidue, Sellmeier, Debye, Drude, Lorentz, AnisotropicMedium, PEC
from .medium import AbstractMedium
from .medium import AbstractMedium, DispersiveMedium

# structure
from .structure import Structure
Expand All @@ -27,8 +27,8 @@
from .source import VolumeSource, PlaneWave, ModeSource, GaussianBeam

# monitor
from .monitor import FieldMonitor, FieldTimeMonitor, FluxMonitor, FluxTimeMonitor
from .monitor import ModeMonitor
from .monitor import AbstractFieldMonitor, FreqMonitor, TimeMonitor, FieldMonitor, FieldTimeMonitor
from .monitor import AbstractFluxMonitor, FluxMonitor, FluxTimeMonitor, ModeMonitor

# simulation
from .simulation import Simulation
Expand Down
17 changes: 16 additions & 1 deletion tidy3d/components/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from abc import ABC, abstractmethod
from typing import Dict, List, Union
import logging

import xarray as xr
import numpy as np
Expand Down Expand Up @@ -627,11 +628,14 @@ class SimulationData(Tidy3dBaseModel):
Mapping of monitor name to :class:`Tidy3dData` intance.
log_string : str = None
A string containing the log information from the simulation run.
diverged : bool = False
A boolean flag denoting if the simulation run diverged.
"""

simulation: Simulation
monitor_data: Dict[str, Tidy3dData]
log_string: str = None
diverged: bool = False

@property
def log(self):
Expand Down Expand Up @@ -825,12 +829,16 @@ def to_file(self, fname: str) -> None:

with h5py.File(fname, "a") as f_handle:

# save json string as an attribute
# save json string as a dataset
Tidy3dData.save_string(f_handle, "sim_json", self.simulation.json())

# save log string as a dataset
if self.log_string:
Tidy3dData.save_string(f_handle, "log_string", self.log_string)

# save diverged flag as an attribute
f_handle.attrs["diverged"] = self.diverged

# make a group for monitor_data
mon_data_grp = f_handle.create_group("monitor_data")
for mon_name, mon_data in self.monitor_data.items():
Expand Down Expand Up @@ -864,6 +872,12 @@ def from_file(cls, fname: str):
# get the log if exists
log_string = Tidy3dData.load_string(f_handle, "log_string")

# set the diverged flag
# TODO: add link to documentation discussing divergence
diverged = f_handle.attrs["diverged"]
if diverged:
logging.warning("Simulation run has diverged!")

# loop through monitor dataset and create all MonitorData instances
monitor_data_dict = {}
for monitor_name, monitor_data in f_handle["monitor_data"].items():
Expand All @@ -877,6 +891,7 @@ def from_file(cls, fname: str):
simulation=simulation,
monitor_data=monitor_data_dict,
log_string=log_string,
diverged=diverged,
)

def __eq__(self, other):
Expand Down
5 changes: 4 additions & 1 deletion tidy3d/components/pml.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class PML(AbsorberSpec):
>>> pml = PML(num_layers=10)
"""

type: Literal["PML"] = "PML"
num_layers: pydantic.NonNegativeInt = 12
parameters: PMLParams = DefaultPMLParameters

Expand All @@ -172,8 +173,9 @@ class StablePML(AbsorberSpec):
>>> pml = StablePML(num_layers=40)
"""

type: Literal["StablePML"] = "StablePML"
num_layers: pydantic.NonNegativeInt = 40
parameters: Literal[DefaultStablePMLParameters] = DefaultStablePMLParameters
parameters: PMLParams = DefaultStablePMLParameters


class Absorber(AbsorberSpec):
Expand All @@ -193,6 +195,7 @@ class Absorber(AbsorberSpec):
>>> pml = Absorber(num_layers=40)
"""

type: Literal["Absorber"] = "Absorber"
num_layers: pydantic.NonNegativeInt = 40
parameters: AbsorberParams = DefaultAbsorberParameters

Expand Down
6 changes: 3 additions & 3 deletions tidy3d/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def old_json_structures(sim: Simulation) -> Tuple[List[Dict], List[Dict]]:
elif isinstance(medium, DispersiveMedium):
poles = []
for (a, c) in medium.pole_residue.poles:
poles.append([a[0], a[1], c[0], c[1]])
poles.append([a.real, a.imag, c.real, c.imag])
med.update(
{
"type": "PoleResidue",
Expand Down Expand Up @@ -295,8 +295,8 @@ def old_json_sources(sim: Simulation) -> List[Dict]:
"waist_radius": float(source.waist_radius),
"waist_distance": float(source.waist_distance),
"pol_angle": float(source.pol_angle),
"amplitude": source.source_time.amplitude
}
"amplitude": source.source_time.amplitude,
}

if src:
src_list.append(src)
Expand Down
18 changes: 9 additions & 9 deletions tidy3d/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
""" Tidy3d custom exceptions """


class Tidy3DError(Exception):
class Tidy3dError(Exception):
"""Any error in tidy3d"""

def __init__(self, message: str = None):
Expand All @@ -34,35 +34,35 @@ def __init__(self, message: str = None):
super().__init__(self, message)


class ConfigError(Tidy3DError):
class ConfigError(Tidy3dError):
"""Error when configuring Tidy3d."""


class Tidy3dKeyError(Tidy3DError):
class Tidy3dKeyError(Tidy3dError):
"""Could not find a key in a Tidy3d dictionary."""


class ValidationError(Tidy3DError):
class ValidationError(Tidy3dError):
"""eError when constructing Tidy3d components."""


class SetupError(Tidy3DError):
class SetupError(Tidy3dError):
"""Error regarding the setup of the components (outside of domains, etc)."""


class FileError(Tidy3DError):
class FileError(Tidy3dError):
"""Error reading or writing to file."""


class WebError(Tidy3DError):
class WebError(Tidy3dError):
"""Error with the webAPI."""


class AuthenticationError(Tidy3DError):
class AuthenticationError(Tidy3dError):
"""Error authenticating a user through webapi webAPI."""


class DataError(Tidy3DError):
class DataError(Tidy3dError):
"""Error accessing data."""


Expand Down