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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
fetch-depth: 1
- uses: astral-sh/ruff-action@v3
with:
version: 0.5.5
version: 0.11.11
- name: Run ruff format
run: ruff format --check --diff
- name: Run ruff check
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.5"
rev: "v0.11.11"
hooks:
- id: ruff
args: [ --fix ]
Expand Down
2 changes: 2 additions & 0 deletions docs/_ext/custom-meta.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os


Expand Down
2 changes: 2 additions & 0 deletions docs/_ext/custom-robots.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os


Expand Down
2 changes: 2 additions & 0 deletions docs/_ext/custom-sitemap.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import re
import xml.etree.ElementTree as ET

Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
#
from __future__ import annotations

import datetime
import logging
import os
Expand Down
7 changes: 3 additions & 4 deletions docs/generate_doc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generate documentation for Material Library (Python)
from __future__ import annotations

import numpy as np

Expand All @@ -24,8 +25,7 @@ def generate_material_library_doc():
def num2str(num):
if np.isinf(num):
return " "
else:
return str(round(num, 2))
return str(round(num, 2))

with open(fname, "w") as f:
# Write file header
Expand Down Expand Up @@ -238,8 +238,7 @@ def generate_rf_material_library_doc():
def num2str(num):
if np.isinf(num):
return " "
else:
return str(round(num, 2))
return str(round(num, 2))

with open(fname, "w") as f:
# Write file header
Expand Down
129 changes: 66 additions & 63 deletions poetry.lock

Large diffs are not rendered by default.

63 changes: 40 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ joblib = "*"
### Optional dependencies ###
# development core
bump-my-version = { version = "*", optional = true }
ruff = { version = "0.5.5", optional = true }
ruff = { version = "0.11.11", optional = true }
coverage = { version = "*", optional = true }
dill = { version = "*", optional = true }
ipython = { version = "*", optional = true }
Expand Down Expand Up @@ -245,31 +245,48 @@ line-length = 100
extend-exclude = ["docs/faq/", "docs/notebooks/"]

[tool.ruff.lint]
typing-modules = [
"tidy3d.components.types",
] # without this Literal["something fails"]
select = [
"I", # isort
extend-select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"C", # flake8-comprehensions
"B", # flake8-bugbear
"UP",
"NPY201", # numpy 2.* compatibility check
"B", # bugbear
"I", # isort
"UP", # pyupgrade
"W", # pycodestyle
"C4", # flake8-comprehensions
"NPY", # numpy-specific rules
"RUF", # ruff builtins
"ISC", # implicit string concatenation
"PIE", # flake8-pie
"RSE", # unnecessary parantheses on raised exceptions
"TID", # no relative imports from parent modules
"PLE", # pylint errors
"PLC", # pylint conventions
]
extend-ignore = [
"RUF001", # ambiguous unicode characters
"RUF002", # ambiguous unicode characters
"RUF003", # ambiguous unicode characters
"RUF012", # type hints for mutable defaults
"RUF015", # next(iter(...)) instead of list(...)[0]
"E501", # line too long
"B905", # `zip()` without an explicit `strict=` parameter
"UP007", # TODO: Remove once Python >= 3.10
"NPY002", # TODO: Revisit RNG handling
]
ignore = [
"E501",
"B008", # do not perform function calls in argument defaults
"C901", # too complex
"UP007", # use x | y instead of union[x,y] (does not work)
"B905", # `zip()` without an explicit `strict=` parameter
"C408", # C408 Unnecessary `dict` call (rewrite as a literal)
"B904",
"B028", # stacklevel
"UP006", # typy annotation with Tuple[float] messes up pydantic
"UP038", # TODO decide what to do here
"UP035", # TODO decide what to do here

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.per-file-ignores]
"tests/**/*" = [
"B015", # useless comparison
"B018", # useless expression
"E402", # module-level import not at top of file
"E731", # lambda assignment
"F841", # unused local variable
"S101", # asserts allowed in tests
"NPY201", # numpy 2.* compatibility check
"TID252", # allow relative imports in tests
]

[tool.pytest.ini_options]
Expand Down
3 changes: 3 additions & 0 deletions scripts/benchmark_import.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


def test_import():
import subprocess
import time
Expand Down
6 changes: 4 additions & 2 deletions scripts/make_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

"""

from __future__ import annotations

import argparse
import os
import re
Expand Down Expand Up @@ -83,11 +85,11 @@ def main(args):
# read the formatted content back
with open(temp_file_path, encoding="utf-8") as temp_file:
sim_string = temp_file.read()
except subprocess.CalledProcessError:
except subprocess.CalledProcessError as exc:
raise RuntimeError(
"Ruff formatting failed. Your script might not be compatible with make_script.py. "
"This could be due to unsupported features like CustomMedium."
)
) from exc
finally:
# remove the temporary file
os.remove(temp_file_path)
Expand Down
2 changes: 2 additions & 0 deletions scripts/sample.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Generates sample simulation json and h5 files in the tests/sims folder"""

from __future__ import annotations

import sys
from os.path import join

Expand Down
2 changes: 2 additions & 0 deletions scripts/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Generates schema for Simulation, saves it to file."""

from __future__ import annotations

import json

import tidy3d
Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import sys

sys.path.append("./")
4 changes: 3 additions & 1 deletion tests/_test_data/_test_datasets_no_vtk.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests tidy3d/components/data/dataset.py"""

from __future__ import annotations

import builtins

import pytest
Expand All @@ -14,7 +16,7 @@ def hide_vtk(monkeypatch, request):

def mocked_import(name, *args, **kwargs):
if name in ["vtk", "vtkmodules.vtkCommonCore"]:
raise ImportError()
raise ImportError
return import_orig(name, *args, **kwargs)

monkeypatch.setattr(builtins, "__import__", mocked_import)
Expand Down
17 changes: 10 additions & 7 deletions tests/_test_local/_test_adjoint_performance.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from __future__ import annotations

import sys
import time

import matplotlib.pyplot as plt
import numpy as np
import pytest
import tidy3d as td
from jax import grad
from memory_profiler import profile

import tidy3d as td
from tidy3d.plugins.adjoint.components.data.data_array import JaxDataArray
from tidy3d.plugins.adjoint.components.data.dataset import JaxPermittivityDataset
from tidy3d.plugins.adjoint.components.geometry import JaxBox
Expand Down Expand Up @@ -52,12 +55,12 @@ def make_sim(eps_values: np.ndarray) -> JaxSimulation:

# custom medium
(xmin, ymin, zmin), (xmax, ymax, zmax) = jax_box.bounds
coords = dict(
x=np.linspace(xmin, xmax, Nx).tolist(),
y=np.linspace(ymin, ymax, Ny).tolist(),
z=np.linspace(zmin, zmax, Nz).tolist(),
f=[FREQ0],
)
coords = {
"x": np.linspace(xmin, xmax, Nx).tolist(),
"y": np.linspace(ymin, ymax, Ny).tolist(),
"z": np.linspace(zmin, zmax, Nz).tolist(),
"f": [FREQ0],
}

eps_ii = JaxDataArray(values=eps_values, coords=coords)
field_components = {f"eps_{dim}{dim}": eps_ii for dim in "xyz"}
Expand Down
5 changes: 4 additions & 1 deletion tests/_test_local/_test_adjoint_performance_multi.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import annotations

import cProfile

import jax
import jax.numpy as jnp
import pytest
from memory_profiler import profile

import tidy3d as td
import tidy3d.plugins.adjoint as tda
from memory_profiler import profile
from tidy3d.plugins.adjoint.web import run_local as run

from ..utils import run_emulated
Expand Down
15 changes: 9 additions & 6 deletions tests/_test_local/_test_data_performance.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from __future__ import annotations

import os
import sys

import numpy as np
import tidy3d as td
from memory_profiler import profile

import tidy3d as td
from tidy3d.components.data.data_array import ScalarFieldDataArray
from tidy3d.components.data.monitor_data import FieldData
from tidy3d.components.data.sim_data import SimulationData
Expand Down Expand Up @@ -48,7 +51,7 @@ def make_sim_data_1(file_size_gb=FILE_SIZE_GB):
src = PointDipole(
center=(0, 0, 0), source_time=GaussianPulse(freq0=3e14, fwidth=1e14), polarization="Ex"
)
coords = dict(x=x, y=y, z=z, f=f)
coords = {"x": x, "y": y, "z": z, "f": f}
Ex = ScalarFieldDataArray(data, coords=coords)
monitor = FieldMonitor(size=(2, 2, 2), freqs=f, name="test", fields=["Ex"])
field_data = FieldData(monitor=monitor, Ex=Ex)
Expand All @@ -70,7 +73,7 @@ def make_sim_data_1(file_size_gb=FILE_SIZE_GB):

@profile
def test_memory_1_save():
print(f'sim_data_size = {SIM_DATA_1.monitor_data["test"].Ex.nbytes:.2e} Bytes')
print(f"sim_data_size = {SIM_DATA_1.monitor_data['test'].Ex.nbytes:.2e} Bytes")
SIM_DATA_1.to_file(PATH)
print(f"file_size = {os.path.getsize(PATH):.2e} Bytes")

Expand All @@ -88,7 +91,7 @@ def test_core_profile_small_1_save():
y = np.arange(Ny)
z = np.arange(Nz)
t = np.arange(Nt)
coords = dict(x=x, y=y, z=z, t=t)
coords = {"x": x, "y": y, "z": z, "t": t}
scalar_field = td.ScalarFieldTimeDataArray(np.random.random((Nx, Ny, Nz, Nt)), coords=coords)
monitor = td.FieldTimeMonitor(size=(2, 4, 6), interval=100, name="field", fields=["Ex", "Hz"])
data = td.FieldTimeData(monitor=monitor, Ex=scalar_field, Hz=scalar_field)
Expand Down Expand Up @@ -123,7 +126,7 @@ def test_speed_many_datasets():
y = np.arange(Ny)
z = np.arange(Nz)
f = np.arange(Nf)
coords = dict(x=x, y=y, z=z, f=f)
coords = {"x": x, "y": y, "z": z, "f": f}
scalar_field = td.ScalarFieldDataArray(np.random.random((Nx, Ny, Nz, Nf)), coords=coords)

def make_field_data(num_index: int):
Expand All @@ -133,7 +136,7 @@ def make_field_data(num_index: int):
freqs=np.linspace(1e14, 2e14, Nf).tolist(),
name=str(num_index),
)
scalar_fields = {fld: scalar_field for fld in monitor.fields}
scalar_fields = dict.fromkeys(monitor.fields, scalar_field)

return td.FieldData(monitor=monitor, **scalar_fields)

Expand Down
3 changes: 3 additions & 0 deletions tests/_test_local/_test_fit_web.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from math import isclose

import numpy as np

from tidy3d.plugins.fitter import AdvancedFitterParam, StableDispersionFitter

np.random.seed(4)
Expand Down
3 changes: 3 additions & 0 deletions tests/_test_local/_test_plugins_web.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

import numpy as np

from tidy3d.plugins.fitter import DispersionFitter, StableDispersionFitter


Expand Down
2 changes: 2 additions & 0 deletions tests/_test_local/_test_web.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""tests converted webapi"""

from __future__ import annotations

import os
from unittest import TestCase, mock

Expand Down
4 changes: 3 additions & 1 deletion tests/_test_notebooks/full_test_notebooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import sys

Expand Down Expand Up @@ -66,7 +68,7 @@
]

# if any run only supplied, only add those
if len(run_only):
if run_only:
notebook_filenames_all = [NOTEBOOK_DIR + base + ".ipynb" for base in run_only]

# filter out the skip notebooks
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
from pathlib import Path

Expand All @@ -7,9 +9,10 @@
import numpy as np
import psutil
import pytest
import tidy3d as td
from autograd.test_util import check_grads
from autograd.wrap_util import unary_to_nary

import tidy3d as td
from tidy3d.log import DEFAULT_LEVEL, set_logging_console, set_logging_level


Expand Down
Loading
Loading