adjoint-helper 0.0.1__py3-none-any.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.
Files changed (32) hide show
  1. adjoint_helper/__init__.py +35 -0
  2. adjoint_helper/backends/legume/__init__.py +0 -0
  3. adjoint_helper/backends/meep/__init__.py +0 -0
  4. adjoint_helper/backends/meep/utils.py +83 -0
  5. adjoint_helper/backends/tidy3d/__init__.py +0 -0
  6. adjoint_helper/core/__init__.py +0 -0
  7. adjoint_helper/core/base_settings.py +1084 -0
  8. adjoint_helper/core/defs.py +312 -0
  9. adjoint_helper/core/differentiation_defs.py +257 -0
  10. adjoint_helper/core/optimization_history.py +268 -0
  11. adjoint_helper/core/pydantic_defs.py +156 -0
  12. adjoint_helper/optimizers/__init__.py +0 -0
  13. adjoint_helper/optimizers/diffusion_optimization.py +121 -0
  14. adjoint_helper/optimizers/nlopt_epigraph_optimization.py +423 -0
  15. adjoint_helper/optimizers/nlopt_optimization.py +212 -0
  16. adjoint_helper/optimizers/optax_optimization.py +177 -0
  17. adjoint_helper/optimizers/structural_attention.py +521 -0
  18. adjoint_helper/utils/__init__.py +0 -0
  19. adjoint_helper/utils/design_analysis.py +52 -0
  20. adjoint_helper/utils/digital_design_helpers.py +102 -0
  21. adjoint_helper/utils/logging_utils.py +123 -0
  22. adjoint_helper/utils/normalization_functions.py +170 -0
  23. adjoint_helper/utils/util.py +112 -0
  24. adjoint_helper/utils/visualization.py +100 -0
  25. adjoint_helper/vendors/meep/LICENSE +339 -0
  26. adjoint_helper/vendors/meep/README.md +8 -0
  27. adjoint_helper/vendors/meep/connectivity.py +297 -0
  28. adjoint_helper/vendors/meep/filters.py +1236 -0
  29. adjoint_helper-0.0.1.dist-info/METADATA +184 -0
  30. adjoint_helper-0.0.1.dist-info/RECORD +32 -0
  31. adjoint_helper-0.0.1.dist-info/WHEEL +4 -0
  32. adjoint_helper-0.0.1.dist-info/licenses/LICENSE +661 -0
@@ -0,0 +1,35 @@
1
+ """
2
+ Main entry point for Adjoint Helper
3
+ """
4
+
5
+ """
6
+ Adjoint Helper
7
+ Copyright (C) 2026 Ben Cerjan
8
+
9
+ This program is free software: you can redistribute it and/or modify
10
+ it under the terms of the GNU Affero General Public License as
11
+ published by the Free Software Foundation, either version 3 of the
12
+ License, or (at your option) any later version.
13
+
14
+ This program is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ GNU Affero General Public License for more details.
18
+
19
+ You should have received a copy of the GNU Affero General Public License
20
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
21
+ """
22
+
23
+ from .core.base_settings import OptimizationSettings, SimulationSettings, DesignRegion
24
+ from .core.defs import (
25
+ Edge,
26
+ MaskRegion,
27
+ ObjectiveReturn,
28
+ ObjectiveFunction,
29
+ OptimizationFunction,
30
+ SimulationReturn,
31
+ )
32
+ from .core.differentiation_defs import anp
33
+ from .core.optimization_history import OptimizationHistory
34
+ from .utils.util import save_fom_history, save_output
35
+ from .utils.normalization_functions import normalize_meep_output
File without changes
File without changes
@@ -0,0 +1,83 @@
1
+ import meep as mp # type: ignore
2
+ import meep.adjoint as mpa # type: ignore
3
+ import matplotlib.pyplot as plt
4
+
5
+ from adjoint_helper.core.defs import (
6
+ RawWeightsType,
7
+ )
8
+
9
+
10
+ def add_flux_box(
11
+ size: mp.Vector3,
12
+ center: mp.Vector3 = mp.Vector3(),
13
+ ) -> list[mp.FluxRegion]:
14
+ """
15
+ Adds 6 flux regions to create a box around the center point with the given
16
+ size. Specifies the weight parameter on each assuming we care about flux
17
+ leaving the box (and not entering)
18
+ """
19
+
20
+ out: list[mp.FluxRegion] = []
21
+
22
+ top = mp.FluxRegion(
23
+ center=center + mp.Vector3(0, 0, size.z / 2),
24
+ size=mp.Vector3(size.x, size.y, 0),
25
+ )
26
+
27
+ bot = mp.FluxRegion(
28
+ center=center - mp.Vector3(0, 0, size.z / 2),
29
+ size=mp.Vector3(size.x, size.y, 0),
30
+ weight=-1,
31
+ )
32
+
33
+ x_r = mp.FluxRegion(
34
+ center=center + mp.Vector3(size.x / 2, 0, 0),
35
+ size=mp.Vector3(0, size.y, size.z),
36
+ )
37
+
38
+ x_l = mp.FluxRegion(
39
+ center=center + mp.Vector3(-size.x / 2, 0, 0),
40
+ size=mp.Vector3(0, size.y, size.z),
41
+ weight=-1,
42
+ )
43
+
44
+ y_b = mp.FluxRegion(
45
+ center=center + mp.Vector3(0, size.y / 2, 0),
46
+ size=mp.Vector3(size.x, 0, size.z),
47
+ )
48
+
49
+ y_f = mp.FluxRegion(
50
+ center=center + mp.Vector3(0, -size.y / 2, 0),
51
+ size=mp.Vector3(size.x, 0, size.z),
52
+ weight=-1,
53
+ )
54
+
55
+ out.extend([top, bot, x_r, x_l, y_b, y_f])
56
+
57
+ return out
58
+
59
+
60
+ def get_total_box_flux(fluxes: list[mp.DftFlux]) -> float:
61
+ flux: float = 0
62
+
63
+ for f in fluxes:
64
+ temp = mp.get_fluxes(f) # type: ignore
65
+ flux += temp[0] # TODO: check!
66
+
67
+ return flux
68
+
69
+
70
+ def plot_structure(
71
+ opt: mpa.OptimizationProblem,
72
+ weights: RawWeightsType | list[RawWeightsType],
73
+ volume: mp.Volume = mp.Volume(
74
+ size=mp.Vector3(mp.inf, mp.inf, 0), center=mp.Vector3()
75
+ ),
76
+ ) -> None:
77
+
78
+ if not isinstance(weights, list):
79
+ weights = [weights]
80
+ opt.update_design(weights) # type: ignore
81
+
82
+ opt.plot2D(True, output_plane=volume) # type: ignore
83
+ plt.show() # type: ignore
File without changes
File without changes