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
2 changes: 1 addition & 1 deletion lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def main():

results = Run([path], do_exit=False)

final_score = results.linter.stats["global_note"]
final_score = results.linter.stats.global_note

if final_score < threshold:

Expand Down
18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
from distutils.util import convert_path


PACKAGE_NAME = 'tidy3d'
PIP_NAME = 'tidy3d-beta'
REPO_NAME = 'tidy3d'
PACKAGE_NAME = "tidy3d"
PIP_NAME = "tidy3d-beta"
REPO_NAME = "tidy3d"

version = {}
version_path = convert_path(f'{PACKAGE_NAME}/version.py')
version_path = convert_path(f"{PACKAGE_NAME}/version.py")
with open(version_path) as version_file:
exec(version_file.read(), version)

print(version['__version__'])
print(version["__version__"])

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()

with open('requirements.txt') as f:
with open("requirements.txt") as f:
required = f.read().splitlines()

setuptools.setup(
name=PIP_NAME,
version=version['__version__'],
version=version["__version__"],
author="Tyler Hughes",
author_email="tyler@flexcompute.com",
description="A fast FDTD solver",
Expand All @@ -39,5 +39,5 @@
# package_dir={"": ""},
packages=[PACKAGE_NAME],
python_requires=">=3.6",
install_requires=required
)
install_requires=required,
)
4 changes: 3 additions & 1 deletion tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ def test_sim_grid_size(caplog, grid_size, log_level):
size=(0, 0, 0),
polarization="Ex",
)
_ = Simulation(size=(1, 1, 1), grid_size=(0.01, 0.01, grid_size), structures=[box], sources=[src])
_ = Simulation(
size=(1, 1, 1), grid_size=(0.01, 0.01, grid_size), structures=[box], sources=[src]
)

assert_log_level(caplog, log_level)

Expand Down
2 changes: 1 addition & 1 deletion tidy3d/components/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def plot_field( # pylint:disable=too-many-arguments, too-many-locals
freq: float = None,
time: float = None,
eps_alpha: float = 0.2,
robust : bool = True,
robust: bool = True,
ax: Ax = None,
**kwargs,
) -> Ax:
Expand Down
2 changes: 1 addition & 1 deletion tidy3d/components/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from descartes import PolygonPatch

from .base import Tidy3dBaseModel
from .types import Literal, Bound, Size, Coordinate, Axis, Coordinate2D, ArrayLike
from .types import Bound, Size, Coordinate, Axis, Coordinate2D, ArrayLike
from .types import Vertices, Ax, Shapely
from .viz import add_ax_if_none
from ..log import Tidy3dKeyError, SetupError, ValidationError
Expand Down
2 changes: 1 addition & 1 deletion tidy3d/components/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from .base import Tidy3dBaseModel
from .types import PoleAndResidue, Literal, Ax, FreqBound, ComplexNumber
from .types import PoleAndResidue, Ax, FreqBound
from .viz import add_ax_if_none
from .validators import validate_name_str

Expand Down
31 changes: 15 additions & 16 deletions tidy3d/components/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from typing import List, Union

import pydantic
import numpy as np

from .types import Literal, Ax, Direction, EMField, ArrayLike, FieldType
from .types import Literal, Ax, Direction, EMField, ArrayLike
from .geometry import Box
from .validators import assert_plane, validate_name_str
from .validators import assert_plane
from .mode import ModeSpec
from .viz import add_ax_if_none, MonitorParams
from ..log import SetupError, ValidationError
from ..log import SetupError
from ..constants import HERTZ, SECOND


Expand Down Expand Up @@ -99,20 +98,20 @@ def stop_greater_than_start(cls, val, values):
class AbstractFieldMonitor(Monitor, ABC):
""":class:`Monitor` that records electromagnetic field data as a function of x,y,z."""

fields: List = pydantic.Field(
fields: List[EMField] = pydantic.Field(
["Ex", "Ey", "Ez", "Hx", "Hy", "Hz"],
title="Field Components",
description="Collection of field components to store in the monitor.",
)

def surfaces(self) -> List["AbstractFieldMonitor"]:
def surfaces(self) -> List["AbstractFieldMonitor"]: #pylint: disable=too-many-locals
"""Returns a list of 6 monitors corresponding to each surface of the field monitor.
The output monitors are stored in the order [x-, x+, y-, y+, z-, z+], where x, y, and z denote
which axis is perpendicular to that surface, while "-" and "+" denote the direction of the
normal vector of that surface. Each output monitor will have the same frequency/time data as the calling
object. Its name will be that of the calling object appended with the above symbols.
E.g., if the calling object's name is "field", the x+ monitor's name will be "field_x+".
Does not work when the calling monitor has zero volume.
The output monitors are stored in the order [x-, x+, y-, y+, z-, z+], where x, y, and z
denote which axis is perpendicular to that surface, while "-" and "+" denote the direction
of the normal vector of that surface. Each output monitor will have the same frequency/time
data as the calling object. Its name will be that of the calling object appended with the
above symbols. E.g., if the calling object's name is "field", the x+ monitor's name will be
"field_x+". Does not work when the calling monitor has zero volume.

Returns
-------
Expand Down Expand Up @@ -142,17 +141,17 @@ def surfaces(self) -> List["AbstractFieldMonitor"]:
(center_x, self_bmin[1], center_z), # y-
(center_x, self_bmax[1], center_z), # y+
(center_x, center_y, self_bmin[2]), # z-
(center_x, center_y, self_bmax[2]),
) # z+
(center_x, center_y, self_bmax[2]), # z+
)

surface_sizes = (
(0.0, size_y, size_z), # x-
(0.0, size_y, size_z), # x+
(size_x, 0.0, size_z), # y-
(size_x, 0.0, size_z), # y+
(size_x, size_y, 0.0), # z-
(size_x, size_y, 0.0),
) # z+
(size_x, size_y, 0.0), # z+
)

surface_names = (
self.name + "_x-",
Expand Down
2 changes: 1 addition & 1 deletion tidy3d/components/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Structure(Tidy3dBaseModel):
_name_validator = validate_name_str()

@add_ax_if_none
def plot(
def plot( # pylint:disable=missing-function-docstring
self, x: float = None, y: float = None, z: float = None, ax: Ax = None, **patch_kwargs
) -> Ax:

Expand Down
60 changes: 38 additions & 22 deletions tidy3d/components/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,48 @@ def __truediv__(self, other):


# built in instance of Inf ()
inf = LARGE_NUMBER # comment out to use Inf().
inf = LARGE_NUMBER # pylint:disable=invalid-name
# TODO: use inf as a reserved quantity for plotting, etc.
# inf = Inf()


""" Complex Values """


class ComplexNumber(pydantic.BaseModel):
"""Complex number with a well defined schema."""

real: float
imag: float

@property
def z(self):
def as_complex(self):
"""return complex representation of ComplexNumber."""
return self.real + 1j * self.imag


class tidycomplex(complex):
class tidycomplex(complex): # pylint: disable=invalid-name
"""complex type that we can use in our models."""

@classmethod
def __get_validators__(cls):
"""Defines which validator function to use for NumpyArray."""
yield cls.validate

@classmethod
def validate(cls, value, field):
def validate(cls, value):
"""What gets called when you construct a tidycomplex."""

if isinstance(value, ComplexNumber):
return value.z
elif isinstance(value, dict):
return value.as_complex
if isinstance(value, dict):
c = ComplexNumber(**value)
return c.z
else:
return cls(value)
return c.as_complex
return cls(value)

@classmethod
def __modify_schema__(cls, field_schema):
"""Sets the schema of NumpyArray."""
field_schema.update(ComplexNumber.schema())


Expand Down Expand Up @@ -154,41 +162,49 @@ class Array(np.ndarray, metaclass=ArrayMeta):
"""type of numpy array with annotated type (Array[float], Array[complex])"""


""" note:
^ this is the best way to declare numpy types if you know dtype.
for example: ``field_amps: Array[float] = np.random.random(5)``.
"""


class NumpyArray(pydantic.BaseModel):
"""Wrapper around numpy arrays that has a well defined json schema."""

data_list: List

@property
def arr(self):
"""Contructs a numpy array representation of the NumpyArray."""
return np.array(self.data_list)


class tidynumpy(np.ndarray):
class tidynumpy(np.ndarray): # pylint: disable=invalid-name
"""Numpy array type that we can use in place of np.ndarray."""

@classmethod
def __get_validators__(cls):
"""Defines which validator function to use for NumpyArray."""
yield cls.validate

@classmethod
def validate(cls, value, field):
def validate(cls, value):
"""What gets called when you construct a tidynumpy."""
if isinstance(value, NumpyArray):
return value.arr
elif isinstance(value, dict):
n = NumpyArray(**value)
return n.arr
elif isinstance(value, list):
if isinstance(value, dict):
numpy_array = NumpyArray(**value)
return numpy_array.arr
if isinstance(value, list):
return value
else:
return np.array(value)
return np.array(value)

@classmethod
def __modify_schema__(cls, field_schema):
"""Sets the schema of NumpyArray."""
field_schema.update(NumpyArray.schema())


""" note:
^ this is the best way to declare numpy types if you know dtype.
for example: ``field_amps: Array[float] = np.random.random(5)``.
"""

ArrayLike = Union[tidynumpy, NumpyArray, List]


Expand Down
2 changes: 1 addition & 1 deletion tidy3d/web/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_credentials() -> None:
set_authentication_config(email, password)
break

except Exception as e: # pylint:disable=broad-except
except Exception: # pylint:disable=broad-except
raise AuthenticationError(
"Error: Failed to log in with new username and password."
) from None
Expand Down
1 change: 0 additions & 1 deletion tidy3d/web/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from datetime import datetime
import logging

import h5py
import requests
from rich.console import Console
from rich.progress import Progress
Expand Down