witwin-maxwell 0.3.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- witwin/maxwell/__init__.py +164 -0
- witwin/maxwell/adapters/__init__.py +1 -0
- witwin/maxwell/adapters/gds.py +203 -0
- witwin/maxwell/adapters/tidy3d.py +1669 -0
- witwin/maxwell/adjoint_inputs.py +70 -0
- witwin/maxwell/compiler/__init__.py +11 -0
- witwin/maxwell/compiler/materials.py +1355 -0
- witwin/maxwell/compiler/monitors.py +164 -0
- witwin/maxwell/compiler/sources.py +222 -0
- witwin/maxwell/fdfd/__init__.py +3 -0
- witwin/maxwell/fdfd/adjoint/__init__.py +3 -0
- witwin/maxwell/fdfd/adjoint/bridge.py +180 -0
- witwin/maxwell/fdfd/ams.py +300 -0
- witwin/maxwell/fdfd/krylov.py +280 -0
- witwin/maxwell/fdfd/plotting.py +110 -0
- witwin/maxwell/fdfd/postprocess.py +33 -0
- witwin/maxwell/fdfd/solver.py +1057 -0
- witwin/maxwell/fdtd/__init__.py +4 -0
- witwin/maxwell/fdtd/adjoint/__init__.py +21 -0
- witwin/maxwell/fdtd/adjoint/bridge.py +746 -0
- witwin/maxwell/fdtd/adjoint/capabilities.py +29 -0
- witwin/maxwell/fdtd/adjoint/core.py +3614 -0
- witwin/maxwell/fdtd/adjoint/dispatch.py +684 -0
- witwin/maxwell/fdtd/adjoint/native.py +2561 -0
- witwin/maxwell/fdtd/adjoint/profiler.py +195 -0
- witwin/maxwell/fdtd/adjoint/reverse_common.py +207 -0
- witwin/maxwell/fdtd/adjoint/seeds.py +524 -0
- witwin/maxwell/fdtd/boundary/__init__.py +37 -0
- witwin/maxwell/fdtd/boundary/bloch.py +90 -0
- witwin/maxwell/fdtd/boundary/common.py +41 -0
- witwin/maxwell/fdtd/boundary/cpml.py +527 -0
- witwin/maxwell/fdtd/boundary/runtime.py +209 -0
- witwin/maxwell/fdtd/checkpoint.py +227 -0
- witwin/maxwell/fdtd/coords.py +32 -0
- witwin/maxwell/fdtd/cuda/__init__.py +11 -0
- witwin/maxwell/fdtd/cuda/backend.py +3532 -0
- witwin/maxwell/fdtd/cuda/build.py +292 -0
- witwin/maxwell/fdtd/cuda/extension.cpp +2053 -0
- witwin/maxwell/fdtd/cuda/kernels/adjoint.cu +5290 -0
- witwin/maxwell/fdtd/cuda/kernels/aniso.cu +1704 -0
- witwin/maxwell/fdtd/cuda/kernels/boundary.cu +424 -0
- witwin/maxwell/fdtd/cuda/kernels/common.cu +74 -0
- witwin/maxwell/fdtd/cuda/kernels/common.cuh +82 -0
- witwin/maxwell/fdtd/cuda/kernels/dispersive.cu +782 -0
- witwin/maxwell/fdtd/cuda/kernels/electric.cu +3613 -0
- witwin/maxwell/fdtd/cuda/kernels/magnetic.cu +781 -0
- witwin/maxwell/fdtd/cuda/kernels/observers.cu +347 -0
- witwin/maxwell/fdtd/cuda/kernels/projection.cu +211 -0
- witwin/maxwell/fdtd/cuda/kernels/sources.cu +1482 -0
- witwin/maxwell/fdtd/cuda/kernels/spectral.cu +297 -0
- witwin/maxwell/fdtd/cuda/launch.h +23 -0
- witwin/maxwell/fdtd/cuda/prebuilt/witwin_maxwell_fdtd_cuda.pyd +0 -0
- witwin/maxwell/fdtd/cuda/runtime/__init__.py +6 -0
- witwin/maxwell/fdtd/cuda/runtime/dispatcher.py +6 -0
- witwin/maxwell/fdtd/cuda/runtime/graph.py +33 -0
- witwin/maxwell/fdtd/cuda/tensors.h +35 -0
- witwin/maxwell/fdtd/dispersion.py +48 -0
- witwin/maxwell/fdtd/evaluation.py +290 -0
- witwin/maxwell/fdtd/excitation/__init__.py +27 -0
- witwin/maxwell/fdtd/excitation/injection.py +1102 -0
- witwin/maxwell/fdtd/excitation/modes.py +1675 -0
- witwin/maxwell/fdtd/excitation/spatial.py +469 -0
- witwin/maxwell/fdtd/excitation/temporal.py +510 -0
- witwin/maxwell/fdtd/excitation/tfsf_apply.py +264 -0
- witwin/maxwell/fdtd/excitation/tfsf_common.py +421 -0
- witwin/maxwell/fdtd/excitation/tfsf_specs.py +490 -0
- witwin/maxwell/fdtd/excitation/tfsf_state.py +778 -0
- witwin/maxwell/fdtd/io.py +31 -0
- witwin/maxwell/fdtd/material_pullback.py +371 -0
- witwin/maxwell/fdtd/meshing/__init__.py +3 -0
- witwin/maxwell/fdtd/meshing/autogrid.py +335 -0
- witwin/maxwell/fdtd/observers.py +1453 -0
- witwin/maxwell/fdtd/plotting.py +121 -0
- witwin/maxwell/fdtd/postprocess.py +205 -0
- witwin/maxwell/fdtd/runtime/__init__.py +119 -0
- witwin/maxwell/fdtd/runtime/initialization.py +236 -0
- witwin/maxwell/fdtd/runtime/materials.py +1563 -0
- witwin/maxwell/fdtd/runtime/module_cache.py +31 -0
- witwin/maxwell/fdtd/runtime/spectral.py +581 -0
- witwin/maxwell/fdtd/runtime/stepping.py +1987 -0
- witwin/maxwell/fdtd/solver.py +502 -0
- witwin/maxwell/geometry/__init__.py +5 -0
- witwin/maxwell/geometry/polyslab.py +299 -0
- witwin/maxwell/materials.py +3 -0
- witwin/maxwell/media.py +1467 -0
- witwin/maxwell/monitors.py +743 -0
- witwin/maxwell/ports.py +113 -0
- witwin/maxwell/postprocess/RCS.py +139 -0
- witwin/maxwell/postprocess/__init__.py +42 -0
- witwin/maxwell/postprocess/diffraction.py +219 -0
- witwin/maxwell/postprocess/directivity.py +152 -0
- witwin/maxwell/postprocess/emission.py +67 -0
- witwin/maxwell/postprocess/modal.py +324 -0
- witwin/maxwell/postprocess/nfft.py +266 -0
- witwin/maxwell/postprocess/scattering_parameters.py +358 -0
- witwin/maxwell/postprocess/stratton_chu.py +1193 -0
- witwin/maxwell/result.py +967 -0
- witwin/maxwell/scene.py +1338 -0
- witwin/maxwell/simulation.py +659 -0
- witwin/maxwell/sources.py +917 -0
- witwin/maxwell/visualization/__init__.py +28 -0
- witwin/maxwell/visualization/interactive.py +484 -0
- witwin/maxwell/visualization/plots.py +568 -0
- witwin_maxwell-0.3.0.dist-info/METADATA +184 -0
- witwin_maxwell-0.3.0.dist-info/RECORD +107 -0
- witwin_maxwell-0.3.0.dist-info/WHEEL +4 -0
- witwin_maxwell-0.3.0.dist-info/licenses/LICENSE +13 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Shared helpers for resolving trainable material inputs of a scene.
|
|
2
|
+
|
|
3
|
+
Used by both the FDTD and FDFD gradient bridges to find the leaf tensors
|
|
4
|
+
(SceneModule parameters, structure geometry tensors, material-region
|
|
5
|
+
densities) that actually contribute to the compiled material tensors.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import torch
|
|
11
|
+
|
|
12
|
+
from .scene import prepare_scene
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def unique_trainable_tensors(candidates) -> tuple[torch.Tensor, ...]:
|
|
16
|
+
unique = []
|
|
17
|
+
seen = set()
|
|
18
|
+
for tensor in candidates:
|
|
19
|
+
if not isinstance(tensor, torch.Tensor) or not tensor.requires_grad:
|
|
20
|
+
continue
|
|
21
|
+
key = tensor.data_ptr() if tensor.data_ptr() != 0 else id(tensor)
|
|
22
|
+
if key in seen:
|
|
23
|
+
continue
|
|
24
|
+
seen.add(key)
|
|
25
|
+
unique.append(tensor)
|
|
26
|
+
return tuple(unique)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def scene_trainable_material_tensors(scene) -> tuple[torch.Tensor, ...]:
|
|
30
|
+
candidates = []
|
|
31
|
+
for structure in scene.structures:
|
|
32
|
+
geometry = getattr(structure, "geometry", None)
|
|
33
|
+
if geometry is not None:
|
|
34
|
+
candidates.extend(
|
|
35
|
+
value for value in vars(geometry).values() if isinstance(value, torch.Tensor) and value.requires_grad
|
|
36
|
+
)
|
|
37
|
+
material = getattr(structure, "material", None)
|
|
38
|
+
perturbation = getattr(material, "perturbation", None)
|
|
39
|
+
if isinstance(perturbation, torch.Tensor) and perturbation.requires_grad:
|
|
40
|
+
candidates.append(perturbation)
|
|
41
|
+
for region in getattr(scene, "material_regions", ()):
|
|
42
|
+
density = getattr(region, "density", None)
|
|
43
|
+
if isinstance(density, torch.Tensor) and density.requires_grad:
|
|
44
|
+
candidates.append(density)
|
|
45
|
+
return unique_trainable_tensors(candidates)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def material_dependent_inputs(scene, candidates) -> tuple[torch.Tensor, ...]:
|
|
49
|
+
inputs = unique_trainable_tensors(candidates)
|
|
50
|
+
if not inputs:
|
|
51
|
+
return ()
|
|
52
|
+
dependencies = ()
|
|
53
|
+
prepared_scene = prepare_scene(scene)
|
|
54
|
+
try:
|
|
55
|
+
with torch.enable_grad():
|
|
56
|
+
eps_r, _mu_r = prepared_scene.compile_material_tensors()
|
|
57
|
+
if eps_r.requires_grad:
|
|
58
|
+
dependencies = torch.autograd.grad(
|
|
59
|
+
eps_r.sum(),
|
|
60
|
+
inputs,
|
|
61
|
+
allow_unused=True,
|
|
62
|
+
retain_graph=False,
|
|
63
|
+
)
|
|
64
|
+
finally:
|
|
65
|
+
prepared_scene.release_meshgrid()
|
|
66
|
+
return tuple(
|
|
67
|
+
tensor
|
|
68
|
+
for tensor, dependency in zip(inputs, dependencies)
|
|
69
|
+
if dependency is not None
|
|
70
|
+
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .materials import compile_material_tensors
|
|
2
|
+
from .monitors import compile_fdtd_observers, compile_fdtd_time_observers
|
|
3
|
+
from .sources import compile_fdfd_sources, compile_fdtd_sources
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"compile_fdfd_sources",
|
|
7
|
+
"compile_fdtd_observers",
|
|
8
|
+
"compile_fdtd_time_observers",
|
|
9
|
+
"compile_fdtd_sources",
|
|
10
|
+
"compile_material_tensors",
|
|
11
|
+
]
|