Skip to content
Open
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 .github/workflows/tidy3d-python-client-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ jobs:
persist-credentials: false
- uses: astral-sh/ruff-action@57714a7c8a2e59f32539362ba31877a1957dded1 # v3.5.1
with:
version: 0.11.11
version: 0.14.1
- 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
Expand Up @@ -4,7 +4,7 @@ default_install_hook_types:
- commit-msg
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.11.11"
rev: "v0.14.1"
hooks:
- id: ruff-check
args: [ --fix ]
Expand Down
52 changes: 26 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typing-extensions = "*"

### Optional dependencies ###
# development core
ruff = { version = "0.11.11", optional = true }
ruff = { version = "0.14.1", optional = true }
coverage = { version = "*", optional = true }
dill = { version = "*", optional = true }
ipython = { version = "*", optional = true }
Expand Down Expand Up @@ -236,38 +236,38 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
target-version = "py39"
target-version = "py310"
line-length = 100
extend-exclude = ["docs/faq/", "docs/notebooks/"]

[tool.ruff.lint]
extend-select = [
"E", # pycodestyle errors
"F", # pyflakes
"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
"E", # pycodestyle errors
"F", # pyflakes
"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
"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
"NPY002", # TODO: Revisit RNG handling
"PLC0415", # allow imports not at top level
]

[tool.ruff.lint.isort]
Expand Down
3 changes: 1 addition & 2 deletions tests/_test_local/_test_fit_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from math import isclose

import numpy as np

from tidy3d.plugins.fitter import AdvancedFitterParam, StableDispersionFitter

np.random.seed(4)
Expand Down Expand Up @@ -37,7 +36,7 @@ def test_dispersion_lossless():
num_poles = 3
num_tries = 10
tolerance_rms = 1e-3
best_medium, best_rms = fitter.fit(
best_medium, _best_rms = fitter.fit(
num_tries=num_tries, num_poles=num_poles, tolerance_rms=tolerance_rms
)

Expand Down
1 change: 0 additions & 1 deletion tests/_test_local/_test_plugins_web.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import numpy as np

from tidy3d.plugins.fitter import DispersionFitter, StableDispersionFitter


Expand Down
3 changes: 2 additions & 1 deletion tests/_test_local/_test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import os
from unittest import TestCase, mock

import tidy3d.web as web
from tidy3d.web.auth import encode_password, get_credentials

import tidy3d.web as web

from ..utils import SIM_FULL as sim_original

CALLBACK_URL = "https://callbackurl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ def test_box_and_polyslab_gradients_match(is_3d, infinite_dim_2d, shift_box_cent
local_gradient=False,
)

box_value, box_grad = value_and_grad(box_objective)([initial_params])
polyslab_value, polyslab_grad = value_and_grad(polyslab_objective)([initial_params])
_box_value, box_grad = value_and_grad(box_objective)([initial_params])
_polyslab_value, polyslab_grad = value_and_grad(polyslab_objective)([initial_params])

box_grad_np = box_grad
polyslab_grad_np = polyslab_grad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def make_base_sim(
]
)

src_size = sim_size_um[0:2] + (0,)
src_size = (*sim_size_um[0:2], 0)

wl_min_src_um = 0.9 * adj_wvl_um
wl_max_src_um = 1.1 * adj_wvl_um
Expand Down Expand Up @@ -409,10 +409,10 @@ def test_finite_difference_conductivity_data(
sim_geometry = get_sim_geometry(mesh_wvl_um)

box_for_override = td.Box(
center=(0, 0, 0), size=sim_geometry.size[0:2] + (thickness_um + mesh_wvl_um,)
center=(0, 0, 0), size=(*sim_geometry.size[0:2], thickness_um + mesh_wvl_um)
)

eval_fns, eval_fn_names = make_eval_fns(monitor_size_wvl)
eval_fns, _eval_fn_names = make_eval_fns(monitor_size_wvl)

sim_path_dir = tmp_path / f"test{test_number}"
sim_path_dir.mkdir()
Expand Down Expand Up @@ -443,7 +443,7 @@ def test_finite_difference_conductivity_data(
)
conductivity_init = overall_conductivity_scaling * np.ones((dim, dim, Nz))

obj, adj_grad = obj_val_and_grad([conductivity_init])
_obj, adj_grad = obj_val_and_grad([conductivity_init])

# empirical step size for finite difference set as 1/10 the size of the conductivity seed value
fd_step = 0.1 * overall_conductivity_scaling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def make_base_sim(
]
)

src_size = sim_size_um[0:2] + (0,)
src_size = (*sim_size_um[0:2], 0)

wl_min_src_um = 0.9 * adj_wvl_um
wl_max_src_um = 1.1 * adj_wvl_um
Expand Down Expand Up @@ -425,7 +425,7 @@ def eval_fn(sim_data):
vertex_centers_x = 1.1 * mesh_wvl_um * np.cos(angles)
vertex_centers_y = 0.8 * mesh_wvl_um * np.sin(angles)

obj, adj_grad = obj_val_and_grad([list(vertex_centers_x) + list(vertex_centers_y)])
_obj, adj_grad = obj_val_and_grad([list(vertex_centers_x) + list(vertex_centers_y)])

for fd_idx in range(NUM_FINITE_DIFFERENCE):
# Create random perturbation of vertices to check against the computed adjoint gradient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def make_base_sim(
]
)

src_size = sim_size_um[0:2] + (0,)
src_size = (*sim_size_um[0:2], 0)

wl_min_src_um = 0.9 * adj_wvl_um
wl_max_src_um = 1.1 * adj_wvl_um
Expand Down Expand Up @@ -269,10 +269,10 @@ def test_finite_difference_field_data(field_data_test_parameters, rng, tmp_path,
sim_geometry = get_sim_geometry(mesh_wvl_um)

box_for_override = td.Box(
center=(0, 0, 0), size=sim_geometry.size[0:2] + (thickness_um + mesh_wvl_um,)
center=(0, 0, 0), size=(*sim_geometry.size[0:2], thickness_um + mesh_wvl_um)
)

eval_fns, eval_fn_names = make_eval_fns(monitor_size_wvl)
eval_fns, _eval_fn_names = make_eval_fns(monitor_size_wvl)

sim_path_dir = tmp_path / f"test{test_number}"
sim_path_dir.mkdir()
Expand All @@ -298,7 +298,7 @@ def test_finite_difference_field_data(field_data_test_parameters, rng, tmp_path,

perm_init = FINITE_DIFF_PERM_SEED * np.ones((dim, dim, Nz))

obj, adj_grad = obj_val_and_grad([perm_init])
_obj, adj_grad = obj_val_and_grad([perm_init])

# empirical step size from running other finite difference tests for field
# cases with permittivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def make_base_sim(
]
)

src_size = sim_size_um[0:2] + (0,)
src_size = (*sim_size_um[0:2], 0)

wl_min_src_um = 0.9 * adj_wvl_um
wl_max_src_um = 1.1 * adj_wvl_um
Expand Down Expand Up @@ -324,10 +324,10 @@ def test_finite_difference_diffraction_data(

box_for_override = td.Box(
center=(sim_geometry.center[0], sim_geometry.center[1], 0),
size=sim_geometry.size[0:2] + (thickness_um + mesh_wvl_um,),
size=(*sim_geometry.size[0:2], thickness_um + mesh_wvl_um),
)

eval_fns, eval_fn_names = make_eval_fns(
_eval_fns, _eval_fn_names = make_eval_fns(
orders_x=order_x, orders_y=order_y, polarization=polarization
)

Expand Down Expand Up @@ -357,7 +357,7 @@ def test_finite_difference_diffraction_data(

perm_init = FINITE_DIFF_PERM_SEED * np.ones((dim, dim, Nz))

obj, adj_grad = obj_val_and_grad([perm_init])
_obj, adj_grad = obj_val_and_grad([perm_init])

# empirical step size from running other finite difference tests for field
# cases with permittivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_autograd_polyslab_sidewall_vs_fd(axis, reference_plane, theta0_deg, tmp

# objective and adjoint grad
obj_fun = lambda tdeg: _objective(tdeg, axis, reference_plane, tmp_path, verbose)
obj, grad_adj = value_and_grad(obj_fun)(anp.array(theta0_deg))
_obj, grad_adj = value_and_grad(obj_fun)(anp.array(theta0_deg))

# centered finite difference
uid = f"axis{axis}_ref{reference_plane}_t{float(theta0_deg):+0.3f}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def make_base_sim(
]
)

src_size = sim_size_um[0:2] + (0,)
src_size = (*sim_size_um[0:2], 0)

wl_min_src_um = 0.9 * adj_wvl_um
wl_max_src_um = 1.1 * adj_wvl_um
Expand Down Expand Up @@ -168,7 +168,7 @@ def make_eval_fns(monitor_size_wvl):

def intensity(sim_data):
field_data = sim_data["monitor_fields"]
shape_x, shape_y, shape_z, *_ = field_data.Ex.values.shape
_shape_x, _shape_y, _shape_z, *_ = field_data.Ex.values.shape

return np.sum(np.abs(field_data.Ex.values) ** 2 + np.abs(field_data.Ey.values) ** 2)

Expand Down Expand Up @@ -273,10 +273,10 @@ def test_adjoint_difference_symmetry(
sim_geometry = get_sim_geometry(mesh_wvl_um)

box_for_override = td.Box(
center=(0, 0, 0), size=sim_geometry.size[0:2] + (thickness_um + mesh_wvl_um,)
center=(0, 0, 0), size=(*sim_geometry.size[0:2], thickness_um + mesh_wvl_um)
)

eval_fns, eval_fn_names = make_eval_fns(monitor_size_wvl)
eval_fns, _eval_fn_names = make_eval_fns(monitor_size_wvl)

sim_path_dir = tmp_path / f"test{test_number}"
sim_path_dir.mkdir()
Expand Down
19 changes: 10 additions & 9 deletions tests/test_components/autograd/test_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def plot_sim(sim: td.Simulation, plot_eps: bool = True) -> None:

plot_fn = sim.plot_eps if plot_eps else sim.plot

f, (ax1, ax2, ax3) = plt.subplots(1, 3, tight_layout=True)
_f, (ax1, ax2, ax3) = plt.subplots(1, 3, tight_layout=True)
plot_fn(x=0, ax=ax1)
plot_fn(y=0, ax=ax2)
plot_fn(z=0, ax=ax3)
Expand Down Expand Up @@ -949,7 +949,7 @@ def obj(center: tuple, size: tuple) -> float:
return objval

d_power = ag.value_and_grad(obj, argnum=(0, 1))
val, (dp_dcenter, dp_dsize) = d_power(self.center0, self.size0)
_val, (dp_dcenter, dp_dsize) = d_power(self.center0, self.size0)

assert len(dp_dcenter) == 3
assert len(dp_dsize) == 3
Expand Down Expand Up @@ -980,7 +980,7 @@ def objective(*args):
values.append(postprocess(sim_data))
return min(values)

val, grad = ag.value_and_grad(objective)(params0)
_val, grad = ag.value_and_grad(objective)(params0)

assert anp.all(grad != 0.0), "some gradients are 0"

Expand Down Expand Up @@ -1034,7 +1034,7 @@ def objective(*args):
# if speed test, get the profile
with cProfile.Profile() as pr:
t = time.time()
val, grad = ag.value_and_grad(objective)(params0)
_val, _grad = ag.value_and_grad(objective)(params0)
t2 = time.time() - t
pr.print_stats(sort="cumtime")
pr.dump_stats("results.prof")
Expand All @@ -1050,7 +1050,7 @@ def test_autograd_polyslab_cylinder(use_emulated_run, monitor_key):

num_pts = 819

monitor, postprocess = make_monitors()[monitor_key]
monitor, _postprocess = make_monitors()[monitor_key]

def make_cylinder(radius, x0, y0, t):
return td.Cylinder(
Expand Down Expand Up @@ -1122,7 +1122,7 @@ def objective(*args):
value = postprocess(data)
return value

val, grad = ag.value_and_grad(objective)(params0)
_val, grad = ag.value_and_grad(objective)(params0)
assert np.all(np.abs(grad) > 0), "some gradients are 0"


Expand All @@ -1144,7 +1144,7 @@ def objective(*args):
value = value + postprocess(sim_data)
return value

val, grad = ag.value_and_grad(objective)(params0)
_val, grad = ag.value_and_grad(objective)(params0)
assert np.all(np.abs(grad) > 0), "some gradients are 0"


Expand Down Expand Up @@ -2838,7 +2838,8 @@ def rotated_grad(angle: float, axis: int) -> np.ndarray:

if expect_exception:
with pytest.raises(
AttributeError, match=".*'Transformed' object has no attribute 'vertices'.*"
AttributeError,
match=r".*'Transformed' object has no attribute 'vertices'.*",
):
rotated_grad(theta, axis)
else:
Expand Down Expand Up @@ -2984,7 +2985,7 @@ def objective(params):
)
return postprocess(data, data[monitor.name])

val, grad = ag.value_and_grad(objective)(params0)
_val, grad = ag.value_and_grad(objective)(params0)

assert anp.all(grad != 0.0), "some gradients are 0 for conductivity-only test"

Expand Down
6 changes: 2 additions & 4 deletions tests/test_components/autograd/test_autograd_polyslab.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

from __future__ import annotations

from typing import Optional

import numpy as np
import numpy.testing as npt
import pytest
Expand Down Expand Up @@ -95,8 +93,8 @@ def __init__(
paths,
axis: int,
coeffs: dict[str, float],
bounds_intersect: Optional[tuple[tuple[float, ...], tuple[float, ...]]] = None,
simulation_bounds: Optional[tuple[tuple[float, ...], tuple[float, ...]]] = None,
bounds_intersect: tuple[tuple[float, ...], tuple[float, ...]] | None = None,
simulation_bounds: tuple[tuple[float, ...], tuple[float, ...]] | None = None,
) -> None:
self.paths = paths
self.axis = axis
Expand Down
Loading