diff --git a/docs/_config.yml b/docs/_config.yml index 31592134..f40958a5 100755 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -60,7 +60,6 @@ sphinx: - "sphinx.ext.napoleon" - "sphinx.ext.viewcode" - "matplotlib.sphinxext.plot_directive" - - "sphinxcontrib.autodoc_pydantic" - "sphinxcontrib.bibtex" config: #autodoc_typehints: description diff --git a/docs/notebooks/tidy3d_01_tidy3d_modes.py b/docs/notebooks/tidy3d_01_tidy3d_modes.py index b1fb8e3d..9149dca2 100644 --- a/docs/notebooks/tidy3d_01_tidy3d_modes.py +++ b/docs/notebooks/tidy3d_01_tidy3d_modes.py @@ -47,14 +47,12 @@ ) # get the index of a material with a given refractive index float # %% -gt.materials.get_index( - "SiO2" -) # get the index of a material with a name string, for the case that the refractive index has only one variant +# get the index of a material with a name string, for the case that the refractive index has only one variant +gt.materials.get_index("AlxOy") # %% -gt.materials.get_index( - ("cSi", "Li1993_293K") -) # get the index of a material with a name string, for the case that the refractive index has more than one variant +# get the index of a material with a name string, for the case that the refractive index has more than one variant +gt.materials.get_index(("cSi", "Li1993_293K")) # %% [markdown] # ## Waveguides diff --git a/gplugins/devsim/doping.py b/gplugins/devsim/doping.py index fa134af8..96382c05 100644 --- a/gplugins/devsim/doping.py +++ b/gplugins/devsim/doping.py @@ -3,7 +3,7 @@ import numpy as np from gdsfactory.generic_tech import LAYER from gdsfactory.typings import Layer -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict class DopingLayerLevel(BaseModel): @@ -20,13 +20,7 @@ class DopingLayerLevel(BaseModel): layer: Layer type: str z_profile: Callable - # xy_profile: Optional[Callable] = None # not implemented yet - - class Config: - """pydantic config.""" - - frozen = True - extra = "forbid" + model_config = ConfigDict(frozen=True, extra="forbid") cm3_to_um3 = 1e-12 diff --git a/gplugins/devsim/get_simulation_xsection.py b/gplugins/devsim/get_simulation_xsection.py index 57ea374c..9f2c2782 100644 --- a/gplugins/devsim/get_simulation_xsection.py +++ b/gplugins/devsim/get_simulation_xsection.py @@ -20,7 +20,7 @@ import pyvista as pv import tidy3d as td from devsim.python_packages import model_create, simple_physics -from pydantic import BaseModel, Extra +from pydantic import BaseModel, ConfigDict from scipy.interpolate import griddata from gplugins.tidy3d.materials import get_nk @@ -171,11 +171,7 @@ class PINWaveguide(BaseModel): atol: float = 1e8 rtol: float = 1e-8 max_iter: int = 60 - - class Config: - """Enable adding new.""" - - extra = Extra.allow + model_config = ConfigDict(extra="allow") # @property # def t_sim(self): diff --git a/gplugins/tidy3d/materials.py b/gplugins/tidy3d/materials.py index c8f53344..0af4ceac 100644 --- a/gplugins/tidy3d/materials.py +++ b/gplugins/tidy3d/materials.py @@ -115,5 +115,6 @@ def get_medium(spec: MaterialSpecTidy3d) -> td.Medium: # print(get_index(spec="si")) # print(get_index(spec=3.4)) # m = get_medium("SiO2") - m = get_medium(("cSi", "Li1993_293K")) + # m = get_medium(("cSi", "Li1993_293K")) # m = td.Medium(permittivity=1.45 ** 2) + m = get_medium(td.material_library["cSi"]["Li1993_293K"]) diff --git a/gplugins/tidy3d/modes.py b/gplugins/tidy3d/modes.py index 72e7e972..b84a0ef7 100644 --- a/gplugins/tidy3d/modes.py +++ b/gplugins/tidy3d/modes.py @@ -18,12 +18,12 @@ from typing import Any, Literal import numpy as np -import pydantic +import pydantic.v1 as pydantic import tidy3d as td import xarray from gdsfactory.config import PATH, logger from gdsfactory.typings import PathType -from pydantic import BaseModel +from pydantic.v1 import BaseModel, ConfigDict from tidy3d.plugins import waveguide from tqdm.auto import tqdm @@ -58,7 +58,7 @@ def custom_serializer(data: str | float | BaseModel) -> str: raise ValueError(f"Unsupported data type: {type(data)}") -class Waveguide(pydantic.BaseModel): +class Waveguide(BaseModel): """Waveguide Model. All dimensions must be specified in μm (1e-6 m). @@ -155,15 +155,11 @@ class Waveguide(pydantic.BaseModel): _cached_data = pydantic.PrivateAttr() _waveguide = pydantic.PrivateAttr() - - class Config: - """pydantic config.""" - - extra = "forbid" + model_config = ConfigDict(extra="forbid") @pydantic.validator("wavelength") - def _fix_wavelength_type(cls, value): - return np.array(value, dtype=float) + def _fix_wavelength_type(cls, v): + return np.array(v, dtype=float) @property def filepath(self) -> pathlib.Path | None: @@ -272,7 +268,7 @@ def _data(self): wg = self.waveguide - fields = wg.mode_solver.data._centered_fields + fields = wg.mode_solver.data.field_components self._cached_data = { f + c: fields[f + c].squeeze(drop=True).values for f in "EH" @@ -377,13 +373,14 @@ def plot_grid(self) -> None: """Plot the waveguide grid.""" self.waveguide.plot_grid(z=0) - def plot_index(self, **kwargs) -> None: + def plot_index(self, **kwargs): """Plot the waveguide index distribution. Keyword arguments are passed to xarray.DataArray.plot. """ artist = self.index.real.plot(**kwargs) artist.axes.set_aspect("equal") + return artist def plot_field( self, @@ -392,7 +389,7 @@ def plot_field( mode_index: int = 0, wavelength: float | None = None, **kwargs, - ) -> None: + ): """Plot the selected field distribution from a waveguide mode. Parameters: @@ -445,6 +442,7 @@ def plot_field( data_array.name = field_name artist = data_array.plot(**kwargs) artist.axes.set_aspect("equal") + return artist def _ipython_display_(self) -> None: """Show index in matplotlib for Jupyter Notebooks.""" @@ -1006,14 +1004,13 @@ def sweep_coupling_length( # overwrite=True # ) - import matplotlib.pyplot as plt - strip = Waveguide( wavelength=1.55, core_width=1.0, slab_thickness=0.0, # core_material="si", - core_material=td.material_library["cSi"]["Li1993_293K"], + # core_material=td.material_library["cSi"]["Li1993_293K"], + core_material=3.47, clad_material="sio2", core_thickness=220 * nm, num_modes=4, @@ -1021,8 +1018,8 @@ def sweep_coupling_length( # strip._data # strip.filepath # strip.plot_index() - strip.plot_field("Ex", mode_index=0, wavelength=1.55, value="dB") - plt.show() + # strip.plot_field("Ex", mode_index=0, wavelength=1.55, value="dB") + # plt.show() # w = np.linspace(400 * nm, 1000 * nm, 7) # n_eff = sweep_n_eff(strip, core_width=w) # fraction_te = sweep_fraction_te(strip, core_width=w) diff --git a/gplugins/tidy3d/tests/test_materials.py b/gplugins/tidy3d/tests/test_materials.py index b3534bd3..b0ec8af3 100644 --- a/gplugins/tidy3d/tests/test_materials.py +++ b/gplugins/tidy3d/tests/test_materials.py @@ -2,7 +2,7 @@ import pytest import tidy3d as td -from pydantic import ValidationError +from pydantic.v1 import ValidationError import gplugins.tidy3d as gt @@ -66,8 +66,8 @@ def test_material_library_many_variants() -> None: def test_material_library_single_variant() -> None: strip = gt.modes.Waveguide( - core_material="SiO2", - clad_material="sio2", + core_material="AlxOy", + clad_material="AlxOy", **settings, ) strip._data @@ -84,6 +84,7 @@ def test_material_library() -> None: if __name__ == "__main__": pytest.main([__file__]) + # test_material_validation_error() # test_material_medium() # test_material_float() # test_material_library() diff --git a/pyproject.toml b/pyproject.toml index a63806f8..f552f810 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ classifiers = [ "Operating System :: OS Independent" ] dependencies = [ - "gdsfactory[cad]>=7.3.2", + "gdsfactory[cad]>=7.4.0", "pint" ] description = "gdsfactory plugins" @@ -26,12 +26,11 @@ requires-python = ">=3.10" version = "0.3.1" [project.optional-dependencies] +dagster = ["dagster", "dagit"] database = [ "sqlalchemy", "sqlalchemy-utils", - "dagster", - "dagit", - "sqlmodel", + # "sqlmodel>=0.0.8,<0.1", "boto3", "pymysql" ] @@ -44,17 +43,16 @@ dev = [ "mypy", "pyswarms", "autograd", - "ray[tune,air]", - "hyperopt" + "hyperopt", + "ray" ] devsim = [ "devsim", "pyvista", - "tidy3d" + "tidy3d>=2.4.0rc2,<2.5.0" ] docs = [ "jupytext", - "autodoc_pydantic", "matplotlib", "jupyter-book==0.15.1", "pyvista[jupyter]" @@ -74,14 +72,14 @@ gmsh = [ "meshwell>=0.0.9,<0.3.1" ] klayout = [ - "kfactory[git,ipy]==0.7.5" + "kfactory[git,ipy]>=0.8.4,<0.9" ] meow = [ - "meow-sim>=0.7.1,<0.8.0", - "tidy3d>=2.3.3,<2.4.0" + "meow-sim>=0.7.3,<0.8.0", + "tidy3d>=2.4.0rc2,<2.5.0" ] sax = [ - "sax>=0.8.8,<0.9.0", + "sax>=0.9.2,<0.10.0", "jaxlib", "jax", "scikit-learn" @@ -91,12 +89,12 @@ schematic = [ "natsort" ] tidy3d = [ - "tidy3d>=2.3.3,<2.4.0" + "tidy3d>=2.4.0rc2,<2.5.0" ] web = [ "jinja2", "python-multipart", - "fastapi", + "fastapi>=0.102.0,<1", "uvicorn[standard]" ] @@ -136,6 +134,8 @@ strict = true addopts = '--tb=short' norecursedirs = [ "extra/*.py", + 'gplugins/dagster', + 'gplugins/database', 'gplugins/devsim', 'gplugins/sax/integrations', 'gplugins/tidy3d/tests/tests_sparameters'