Skip to content

Commit fd16306

Browse files
committed
refactor: port tidy3d to pydantic v2
fix: rebase changes for v2 chore(tidy3d): FXC-4559-add-type-checking-import-moving-and-checking-to-pre-commit-and-ci fix: minor fixes for v2 fix: stabilize model hashing in tests fix: restore copy(True) compatibility and accept doping lists fix(tidy3d): FXC-4824-fix-corrupted-data-in-vtk-arrays fix: more rebase fixes for v2 fix(tidy3d): FXC-5094-fix-deprecation-warnings-in-tests fix: even more rebase changes final rebase changes fix: repair pydantic v2 validators chore: regenerate schemas Co-authored-by: mahlau-flex <yannik.mahlau@flexcompute.com> chore(ci): fix move-type-imports and pin actions chore(ci): fix misleading python step name perf(pydantic): defer model build Fix missing Field reference in TCAD grid chore: remove stale pd references test: restore default pytest coverage docs: remove stale adjoint plugin warning
1 parent 8b7b1d7 commit fd16306

341 files changed

Lines changed: 43748 additions & 47127 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/tidy3d-python-client-tests.yml

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ on:
101101
permissions:
102102
contents: read
103103

104+
env:
105+
VERIFICATIONS_PY_VERSION: '3.11'
106+
104107
jobs:
105108
determine-test-scope:
106109
runs-on: ubuntu-latest
@@ -223,6 +226,39 @@ jobs:
223226
echo "version_match_tests=$version_match_tests"
224227
echo "extras_integration_tests=$extras_integration_tests"
225228
echo "test_type=$test_type"
229+
230+
231+
move-type-imports:
232+
name: move-type-imports
233+
needs: determine-test-scope
234+
if: needs.determine-test-scope.outputs.code_quality_tests == 'true'
235+
runs-on: ubuntu-latest
236+
steps:
237+
- name: checkout-branch
238+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
239+
with:
240+
ref: ${{ github.event.pull_request.head.ref }}
241+
repository: ${{ github.event.pull_request.head.repo.full_name }}
242+
fetch-depth: 0
243+
persist-credentials: false
244+
245+
- name: setup-python
246+
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1
247+
with:
248+
python-version: ${{ env.VERIFICATIONS_PY_VERSION }}
249+
250+
- name: install-dependencies
251+
run: |
252+
set -euo pipefail
253+
python -m venv .venv
254+
source .venv/bin/activate
255+
pip install libcst
256+
257+
- name: verify-type-import-guards
258+
run: |
259+
set -euo pipefail
260+
source .venv/bin/activate
261+
python scripts/move_type_imports.py --mode check_on_change
226262
227263
lint:
228264
needs: determine-test-scope
@@ -256,10 +292,10 @@ jobs:
256292
submodules: false
257293
persist-credentials: false
258294

259-
- name: set-python-3.10
295+
- name: setup-python-${{ env.VERIFICATIONS_PY_VERSION }}
260296
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1
261297
with:
262-
python-version: '3.10'
298+
python-version: ${{ env.VERIFICATIONS_PY_VERSION }}
263299

264300
- name: Install mypy
265301
run: |
@@ -442,7 +478,7 @@ jobs:
442478
443479
- name: install-depedencies
444480
run: |
445-
uv venv $GITHUB_WORKSPACE/.venv -p 3.11
481+
uv venv $GITHUB_WORKSPACE/.venv -p "$VERIFICATIONS_PY_VERSION"
446482
source $GITHUB_WORKSPACE/.venv/bin/activate
447483
uv pip install -e "$GITHUB_WORKSPACE"
448484
@@ -1025,6 +1061,7 @@ jobs:
10251061
- determine-test-scope
10261062
- local-tests
10271063
- remote-tests
1064+
- move-type-imports
10281065
- lint
10291066
- mypy
10301067
- verify-schema-change
@@ -1037,6 +1074,12 @@ jobs:
10371074
- extras-integration-tests
10381075
runs-on: ubuntu-latest
10391076
steps:
1077+
- name: move-type-imports
1078+
if: ${{ needs.determine-test-scope.outputs.code_quality_tests == 'true' && needs.move-type-imports.result != 'success' && needs.move-type-imports.result != 'skipped' }}
1079+
run: |
1080+
echo "❌ Found imports used only for typing that are not guarded by if TYPE_CHECKING."
1081+
exit 1
1082+
10401083
- name: check-linting-result
10411084
if: ${{ needs.determine-test-scope.outputs.code_quality_tests == 'true' && needs.lint.result != 'success' && needs.lint.result != 'skipped' }}
10421085
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Batch JSON files
22
batch*.json
33
*.vtu
4+
simulation.json
45

56
# Byte-compiled / optimized / DLL files
67
*$py.class

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ default_install_hook_types:
33
- pre-commit
44
- commit-msg
55
repos:
6+
- repo: local
7+
hooks:
8+
- id: move-type-imports
9+
name: move type-only imports under TYPE_CHECKING
10+
entry: poetry run python scripts/move_type_imports.py --mode fix --only-changed
11+
language: system
12+
pass_filenames: false
13+
stages: [pre-commit]
614
- repo: https://github.com/astral-sh/ruff-pre-commit
715
rev: "v0.11.11"
816
hooks:

pyproject.toml

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ numpy = ">=2.2.6,<2.5.0"
3333
matplotlib = "^3.10.0"
3434
shapely = "^2.0"
3535
pandas = "^2.2"
36-
pydantic = "^2.0"
36+
pydantic = ">=2.9,<3"
37+
pydantic-settings = "^2.10.0"
3738
PyYAML = "^6.0.3"
3839
dask = "^2025.12.0"
3940
toml = "^0.10.2"
@@ -175,6 +176,7 @@ dev = [
175176
'diff-cover',
176177
'openpyxl',
177178
'zizmor',
179+
'libcst',
178180
]
179181
tests = [
180182
'psutil',
@@ -309,7 +311,9 @@ banned-module-level-imports = ["scipy", "matplotlib"]
309311

310312
[tool.pytest.ini_options]
311313
# TODO: remove --assert=plain when https://github.com/scipy/scipy/issues/22236 is resolved
312-
addopts = "--cov=tidy3d --doctest-modules -n auto --dist worksteal --assert=plain -m 'not numerical and not perf and not generate_profile and not performance_profile'"
314+
addopts = """
315+
--cov=tidy3d --doctest-modules -n auto --dist worksteal --assert=plain -m 'not numerical and not perf and not generate_profile and not performance_profile'
316+
"""
313317
markers = [
314318
"numerical: marks numerical tests for adjoint gradients that require running simulations (deselect with '-m \"not numerical\"')",
315319
"generate_profile: regenerate fixture data required by the performance tests (select with '-m \"generate_profile\"')",
@@ -336,82 +340,24 @@ python_files = "*.py"
336340
[tool.mypy]
337341
python_version = "3.10"
338342
files = [
339-
"tidy3d/web",
340-
"tidy3d/config",
341-
"tidy3d/material_library",
342-
"tidy3d/components/geometry"
343+
"tidy3d",
343344
]
344345
ignore_missing_imports = true
345346
follow_imports = "skip"
346347
disallow_untyped_defs = true
347348
disable_error_code = [
348-
"abstract",
349-
"annotation-unchecked",
350349
"arg-type",
351-
"assert-type",
352350
"assignment",
353351
"attr-defined",
354-
"await-not-async",
355352
"call-arg",
356353
"call-overload",
357-
"comparison-overlap",
358-
"dict-item",
359-
"empty-body",
360-
"exit-return",
361-
"explicit-override",
362-
"func-returns-value",
363-
"has-type",
364-
"ignore-without-code",
365-
"import",
366-
"import-not-found",
367354
"import-untyped",
368355
"index",
369-
"list-item",
370-
"literal-required",
371-
"method-assign",
372356
"misc",
373-
"mutable-override",
374-
"name-defined",
375-
"name-match",
376-
"narrowed-type-not-subtype",
377-
"no-any-return",
378-
"no-any-unimported",
379-
"no-overload-impl",
380-
"no-redef",
381-
"no-untyped-call",
382357
"operator",
383-
"overload-cannot-match",
384-
"overload-overlap",
385358
"override",
386-
"possibly-undefined",
387-
"prop-decorator",
388-
"redundant-cast",
389-
"redundant-expr",
390-
"redundant-self",
391-
"return",
392359
"return-value",
393-
"safe-super",
394-
"str-bytes-safe",
395-
"str-format",
396-
"syntax",
397-
"top-level-await",
398-
"truthy-bool",
399-
"truthy-function",
400-
"truthy-iterable",
401-
"type-abstract",
402-
"type-arg",
403-
"type-var",
404-
"typeddict-item",
405-
"typeddict-readonly-mutated",
406-
"typeddict-unknown-key",
407-
"unimported-reveal",
408360
"union-attr",
409-
"unreachable",
410-
"unused-awaitable",
411-
"unused-coroutine",
412-
"unused-ignore",
413-
"used-before-def",
414-
"valid-newtype",
415361
"valid-type",
416362
"var-annotated",
417363
]

0 commit comments

Comments
 (0)