fdtdx 0.1.0__tar.gz

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 (131) hide show
  1. fdtdx-0.1.0/.editorconfig +6 -0
  2. fdtdx-0.1.0/.github/actions/setup-python-env/action.yml +30 -0
  3. fdtdx-0.1.0/.github/workflows/main.yml +71 -0
  4. fdtdx-0.1.0/.gitignore +107 -0
  5. fdtdx-0.1.0/.pre-commit-config.yaml +35 -0
  6. fdtdx-0.1.0/LICENSE +21 -0
  7. fdtdx-0.1.0/PKG-INFO +86 -0
  8. fdtdx-0.1.0/README.md +60 -0
  9. fdtdx-0.1.0/docs/api/constraints/binary.md +17 -0
  10. fdtdx-0.1.0/docs/api/constraints/discrete.md +17 -0
  11. fdtdx-0.1.0/docs/api/constraints/index.md +11 -0
  12. fdtdx-0.1.0/docs/api/constraints/mapping.md +3 -0
  13. fdtdx-0.1.0/docs/api/constraints/modules.md +14 -0
  14. fdtdx-0.1.0/docs/api/constraints/utils.md +9 -0
  15. fdtdx-0.1.0/docs/api/core/arrays.md +12 -0
  16. fdtdx-0.1.0/docs/api/core/config.md +4 -0
  17. fdtdx-0.1.0/docs/api/core/distributed.md +6 -0
  18. fdtdx-0.1.0/docs/api/core/index.md +12 -0
  19. fdtdx-0.1.0/docs/api/core/jax.md +10 -0
  20. fdtdx-0.1.0/docs/api/core/pytree.md +11 -0
  21. fdtdx-0.1.0/docs/api/core/types.md +13 -0
  22. fdtdx-0.1.0/docs/api/fdtd/core.md +29 -0
  23. fdtdx-0.1.0/docs/api/fdtd/fields.md +8 -0
  24. fdtdx-0.1.0/docs/api/fdtd/index.md +10 -0
  25. fdtdx-0.1.0/docs/api/fdtd/interfaces.md +8 -0
  26. fdtdx-0.1.0/docs/api/fdtd/updates.md +9 -0
  27. fdtdx-0.1.0/docs/api/index.md +45 -0
  28. fdtdx-0.1.0/docs/api/objects/base.md +31 -0
  29. fdtdx-0.1.0/docs/api/objects/containers.md +19 -0
  30. fdtdx-0.1.0/docs/api/objects/index.md +10 -0
  31. fdtdx-0.1.0/docs/api/objects/initialization.md +18 -0
  32. fdtdx-0.1.0/docs/api/objects/materials.md +17 -0
  33. fdtdx-0.1.0/docs/api/physics/constants.md +31 -0
  34. fdtdx-0.1.0/docs/api/physics/index.md +7 -0
  35. fdtdx-0.1.0/docs/api/physics/metrics.md +9 -0
  36. fdtdx-0.1.0/docs/api/physics/modes.md +7 -0
  37. fdtdx-0.1.0/docs/api/utils/conversion.md +8 -0
  38. fdtdx-0.1.0/docs/api/utils/image.md +3 -0
  39. fdtdx-0.1.0/docs/api/utils/index.md +7 -0
  40. fdtdx-0.1.0/docs/api/utils/visualization.md +8 -0
  41. fdtdx-0.1.0/docs/index.md +47 -0
  42. fdtdx-0.1.0/docs/static/.gitkeep +0 -0
  43. fdtdx-0.1.0/docs/stylesheets/extra.css +67 -0
  44. fdtdx-0.1.0/docs/tutorials/object_placement.md +167 -0
  45. fdtdx-0.1.0/examples/evaluate_random_scatterer.py +279 -0
  46. fdtdx-0.1.0/examples/optimize_ceviche_corner.py +485 -0
  47. fdtdx-0.1.0/examples/optimize_vertical_polymer_coupler.py +480 -0
  48. fdtdx-0.1.0/examples/optimize_vertical_silicon_coupler.py +441 -0
  49. fdtdx-0.1.0/examples/optimize_waveguide_stitching.py +464 -0
  50. fdtdx-0.1.0/examples/simulate_gaussian_source.py +187 -0
  51. fdtdx-0.1.0/mkdocs.yml +104 -0
  52. fdtdx-0.1.0/pyproject.toml +62 -0
  53. fdtdx-0.1.0/src/fdtdx/__init__.py +37 -0
  54. fdtdx-0.1.0/src/fdtdx/constraints/__init__.py +14 -0
  55. fdtdx-0.1.0/src/fdtdx/constraints/binary_transform.py +407 -0
  56. fdtdx-0.1.0/src/fdtdx/constraints/discrete.py +407 -0
  57. fdtdx-0.1.0/src/fdtdx/constraints/mapping.py +102 -0
  58. fdtdx-0.1.0/src/fdtdx/constraints/module.py +268 -0
  59. fdtdx-0.1.0/src/fdtdx/constraints/pillars.py +140 -0
  60. fdtdx-0.1.0/src/fdtdx/constraints/utils.py +186 -0
  61. fdtdx-0.1.0/src/fdtdx/core/__init__.py +15 -0
  62. fdtdx-0.1.0/src/fdtdx/core/config.py +153 -0
  63. fdtdx-0.1.0/src/fdtdx/core/conversion/__init__.py +14 -0
  64. fdtdx-0.1.0/src/fdtdx/core/conversion/export.py +169 -0
  65. fdtdx-0.1.0/src/fdtdx/core/conversion/import_utils.py +57 -0
  66. fdtdx-0.1.0/src/fdtdx/core/conversion/load_stl.py +55 -0
  67. fdtdx-0.1.0/src/fdtdx/core/gaussian_blur.py +148 -0
  68. fdtdx-0.1.0/src/fdtdx/core/jax/__init__.py +14 -0
  69. fdtdx-0.1.0/src/fdtdx/core/jax/pytrees.py +307 -0
  70. fdtdx-0.1.0/src/fdtdx/core/jax/sharding.py +134 -0
  71. fdtdx-0.1.0/src/fdtdx/core/jax/ste.py +33 -0
  72. fdtdx-0.1.0/src/fdtdx/core/jax/typing.py +58 -0
  73. fdtdx-0.1.0/src/fdtdx/core/jax/utils.py +36 -0
  74. fdtdx-0.1.0/src/fdtdx/core/misc.py +753 -0
  75. fdtdx-0.1.0/src/fdtdx/core/modes.py +135 -0
  76. fdtdx-0.1.0/src/fdtdx/core/physics/__init__.py +14 -0
  77. fdtdx-0.1.0/src/fdtdx/core/physics/constants.py +119 -0
  78. fdtdx-0.1.0/src/fdtdx/core/physics/losses.py +45 -0
  79. fdtdx-0.1.0/src/fdtdx/core/physics/metrics.py +86 -0
  80. fdtdx-0.1.0/src/fdtdx/core/physics/modes.py +119 -0
  81. fdtdx-0.1.0/src/fdtdx/core/plotting/__init__.py +14 -0
  82. fdtdx-0.1.0/src/fdtdx/core/plotting/colors.py +40 -0
  83. fdtdx-0.1.0/src/fdtdx/core/plotting/debug.py +98 -0
  84. fdtdx-0.1.0/src/fdtdx/core/plotting/device_permittivity_index_utils.py +148 -0
  85. fdtdx-0.1.0/src/fdtdx/core/plotting/utils.py +89 -0
  86. fdtdx-0.1.0/src/fdtdx/fdtd/__init__.py +17 -0
  87. fdtdx-0.1.0/src/fdtdx/fdtd/backward.py +139 -0
  88. fdtdx-0.1.0/src/fdtdx/fdtd/curl.py +120 -0
  89. fdtdx-0.1.0/src/fdtdx/fdtd/fdtd.py +420 -0
  90. fdtdx-0.1.0/src/fdtdx/fdtd/forward.py +196 -0
  91. fdtdx-0.1.0/src/fdtdx/fdtd/update.py +453 -0
  92. fdtdx-0.1.0/src/fdtdx/interfaces/__init__.py +0 -0
  93. fdtdx-0.1.0/src/fdtdx/interfaces/modules.py +227 -0
  94. fdtdx-0.1.0/src/fdtdx/interfaces/recorder.py +321 -0
  95. fdtdx-0.1.0/src/fdtdx/interfaces/state.py +82 -0
  96. fdtdx-0.1.0/src/fdtdx/interfaces/time_filter.py +576 -0
  97. fdtdx-0.1.0/src/fdtdx/objects/__init__.py +14 -0
  98. fdtdx-0.1.0/src/fdtdx/objects/boundaries/__init__.py +14 -0
  99. fdtdx-0.1.0/src/fdtdx/objects/boundaries/boundary_utils.py +306 -0
  100. fdtdx-0.1.0/src/fdtdx/objects/boundaries/initialization.py +219 -0
  101. fdtdx-0.1.0/src/fdtdx/objects/boundaries/perfectly_matched_layer.py +415 -0
  102. fdtdx-0.1.0/src/fdtdx/objects/container.py +175 -0
  103. fdtdx-0.1.0/src/fdtdx/objects/detectors/__init__.py +14 -0
  104. fdtdx-0.1.0/src/fdtdx/objects/detectors/detector.py +402 -0
  105. fdtdx-0.1.0/src/fdtdx/objects/detectors/energy.py +106 -0
  106. fdtdx-0.1.0/src/fdtdx/objects/detectors/phasor.py +142 -0
  107. fdtdx-0.1.0/src/fdtdx/objects/detectors/plotting/__init__.py +14 -0
  108. fdtdx-0.1.0/src/fdtdx/objects/detectors/plotting/line_plot.py +28 -0
  109. fdtdx-0.1.0/src/fdtdx/objects/detectors/plotting/plot2d.py +148 -0
  110. fdtdx-0.1.0/src/fdtdx/objects/detectors/plotting/video.py +166 -0
  111. fdtdx-0.1.0/src/fdtdx/objects/detectors/poynting_flux.py +103 -0
  112. fdtdx-0.1.0/src/fdtdx/objects/initialization.py +630 -0
  113. fdtdx-0.1.0/src/fdtdx/objects/material.py +130 -0
  114. fdtdx-0.1.0/src/fdtdx/objects/multi_material/__init__.py +14 -0
  115. fdtdx-0.1.0/src/fdtdx/objects/multi_material/device.py +174 -0
  116. fdtdx-0.1.0/src/fdtdx/objects/multi_material/fiber.py +164 -0
  117. fdtdx-0.1.0/src/fdtdx/objects/multi_material/multi_material.py +169 -0
  118. fdtdx-0.1.0/src/fdtdx/objects/multi_material/random_scatterer.py +202 -0
  119. fdtdx-0.1.0/src/fdtdx/objects/object.py +811 -0
  120. fdtdx-0.1.0/src/fdtdx/objects/sources/__init__.py +14 -0
  121. fdtdx-0.1.0/src/fdtdx/objects/sources/plane_source.py +926 -0
  122. fdtdx-0.1.0/src/fdtdx/objects/sources/source.py +258 -0
  123. fdtdx-0.1.0/src/fdtdx/objects/wavelength.py +112 -0
  124. fdtdx-0.1.0/src/fdtdx/py.typed +0 -0
  125. fdtdx-0.1.0/src/fdtdx/shared/__init__.py +0 -0
  126. fdtdx-0.1.0/src/fdtdx/shared/logger.py +328 -0
  127. fdtdx-0.1.0/src/fdtdx/shared/misc.py +70 -0
  128. fdtdx-0.1.0/src/fdtdx/shared/plot_setup.py +166 -0
  129. fdtdx-0.1.0/tests/test_sanity.py +2 -0
  130. fdtdx-0.1.0/tox.ini +15 -0
  131. fdtdx-0.1.0/uv.lock +3265 -0
@@ -0,0 +1,6 @@
1
+ [*]
2
+ max_line_length = 120
3
+
4
+ [*.json]
5
+ indent_style = space
6
+ indent_size = 4
@@ -0,0 +1,30 @@
1
+ name: "Setup Python Environment"
2
+ description: "Set up Python environment for the given Python version"
3
+
4
+ inputs:
5
+ python-version:
6
+ description: "Python version to use"
7
+ required: true
8
+ default: "3.12"
9
+ uv-version:
10
+ description: "uv version to use"
11
+ required: true
12
+ default: "0.5.8"
13
+
14
+ runs:
15
+ using: "composite"
16
+ steps:
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ inputs.python-version }}
20
+
21
+ - name: Install uv
22
+ uses: astral-sh/setup-uv@v2
23
+ with:
24
+ version: ${{ inputs.uv-version }}
25
+ enable-cache: "true"
26
+ cache-suffix: ${{ matrix.python-version }}
27
+
28
+ - name: Install Python dependencies
29
+ run: uv sync --frozen
30
+ shell: bash
@@ -0,0 +1,71 @@
1
+ name: Main
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, synchronize, reopened]
6
+ push:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ checks:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Check out
14
+ uses: actions/checkout@v4
15
+ with:
16
+ persist-credentials: false
17
+
18
+ - uses: actions/cache@v4
19
+ with:
20
+ path: ~/.cache/pre-commit
21
+ key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
22
+
23
+ - name: Set up the environment
24
+ uses: ./.github/actions/setup-python-env
25
+
26
+ - name: Run pre-commit
27
+ run: uv run pre-commit run -a --show-diff-on-failure
28
+
29
+ - name: Check lock file consistency
30
+ run: uv sync --locked
31
+
32
+ tests:
33
+ runs-on: ubuntu-latest
34
+ strategy:
35
+ matrix:
36
+ python-version: ["3.11", "3.12"]
37
+ fail-fast: false
38
+ defaults:
39
+ run:
40
+ shell: bash
41
+ steps:
42
+ - name: Check out
43
+ uses: actions/checkout@v4
44
+ with:
45
+ persist-credentials: false
46
+
47
+ - name: Set up the environment
48
+ uses: ./.github/actions/setup-python-env
49
+ with:
50
+ python-version: ${{ matrix.python-version }}
51
+
52
+ - name: Run tests
53
+ run: uv run python -m pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
54
+
55
+ - name: Upload coverage reports to Codecov with GitHub Action on Python 3.12 for Ubuntu
56
+ uses: codecov/codecov-action@v3
57
+ if: ${{ matrix.python-version == '3.12' }}
58
+
59
+ deploy-docs:
60
+ runs-on: ubuntu-latest
61
+ steps:
62
+ - name: Check out
63
+ uses: actions/checkout@v4
64
+ with:
65
+ persist-credentials: false
66
+
67
+ - name: Set up the environment
68
+ uses: ./.github/actions/setup-python-env
69
+
70
+ - name: Deploy documentation
71
+ run: uv run mkdocs gh-deploy --force
fdtdx-0.1.0/.gitignore ADDED
@@ -0,0 +1,107 @@
1
+ multirun
2
+ outputs
3
+ *.png
4
+ tmp
5
+ slurm-*
6
+ .jax_cache
7
+ .vscode
8
+ .pytest_cache
9
+ .ruff_cache
10
+ planos
11
+ scripts/configs/run_config.yaml
12
+ .ragatouille
13
+ *.jsonl
14
+ .aider*
15
+ .DS_Store
16
+ site
17
+
18
+ # Byte-compiled / optimized / DLL files
19
+ __pycache__/
20
+ *.py[cod]
21
+ *$py.class
22
+
23
+ # C extensions
24
+ *.so
25
+
26
+ # Distribution / packaging
27
+ .Python
28
+ env/
29
+ build/
30
+ develop-eggs/
31
+ dist/
32
+ downloads/
33
+ eggs/
34
+ .eggs/
35
+ lib/
36
+ lib64/
37
+ parts/
38
+ sdist/
39
+ var/
40
+ *.egg-info/
41
+ .installed.cfg
42
+ *.egg
43
+
44
+ # PyInstaller
45
+ # Usually these files are written by a python script from a template
46
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
47
+ *.manifest
48
+ *.spec
49
+
50
+ # Installer logs
51
+ pip-log.txt
52
+ pip-delete-this-directory.txt
53
+
54
+ # Unit test / coverage reports
55
+ htmlcov/
56
+ .tox/
57
+ .coverage
58
+ .coverage.*
59
+ .cache
60
+ nosetests.xml
61
+ coverage.xml
62
+ *,cover
63
+ .hypothesis/
64
+
65
+ # Translations
66
+ *.mo
67
+ *.pot
68
+
69
+ # Django stuff:
70
+ *.log
71
+ local_settings.py
72
+
73
+ # Flask stuff:
74
+ instance/
75
+ .webassets-cache
76
+
77
+ # Scrapy stuff:
78
+ .scrapy
79
+
80
+ # Sphinx documentation
81
+ docs/_build/
82
+
83
+ # PyBuilder
84
+ target/
85
+
86
+ # IPython Notebook
87
+ .ipynb_checkpoints
88
+
89
+ # pyenv
90
+ .python-version
91
+
92
+ # celery beat schedule file
93
+ celerybeat-schedule
94
+
95
+ # dotenv
96
+ .env
97
+
98
+ # virtualenv
99
+ .venv/
100
+ venv/
101
+ ENV/
102
+
103
+ # Spyder project settings
104
+ .spyderproject
105
+
106
+ # Rope project settings
107
+ .ropeproject
@@ -0,0 +1,35 @@
1
+ # See https://pre-commit.com for more information
2
+ # See https://pre-commit.com/hooks.html for more hooks
3
+ repos:
4
+ - repo: https://github.com/pre-commit/pre-commit-hooks
5
+ rev: v5.0.0
6
+ hooks:
7
+ - id: check-yaml
8
+ - id: check-added-large-files
9
+ - id: check-shebang-scripts-are-executable
10
+ - id: check-toml
11
+ - id: check-merge-conflict
12
+ args: [--assume-in-merge]
13
+ - repo: https://github.com/astral-sh/ruff-pre-commit
14
+ # Ruff version.
15
+ rev: v0.8.2
16
+ hooks:
17
+ # Run the linter.
18
+ - id: ruff
19
+ args:
20
+ - --fix
21
+ # Run the formatter.
22
+ - id: ruff-format
23
+ - repo: local
24
+ hooks:
25
+ - id: mkdocs-build
26
+ name: mkdocs-build
27
+ entry: mkdocs build
28
+ language: system
29
+ pass_filenames: false # Or true if you want to pass files as arguments
30
+ always_run: true # Usually you want to build every time
31
+ stages: [pre-commit]
32
+ - repo: https://github.com/woodruffw/zizmor-pre-commit
33
+ rev: v0.9.2
34
+ hooks:
35
+ - id: zizmor
fdtdx-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Florian Maas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
fdtdx-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: fdtdx
3
+ Version: 0.1.0
4
+ Summary: A JAX framework for the finite-difference time-domain (FDTD) method for solving Maxwell's equations with a focus on inverse design of photonic devices.
5
+ Project-URL: Repository, https://github.com/ymahlau/fdtdx
6
+ Project-URL: Documentation, https://ymahlau.github.io/fdtdx/
7
+ Author-email: Yannik Mahlau <mahlau@tnt.uni-hannover.de>, Frederik Schubert <schubert@tnt.uni-hannover.de>
8
+ License-File: LICENSE
9
+ Requires-Python: <3.13,>=3.11
10
+ Requires-Dist: equinox>=0.11.10
11
+ Requires-Dist: jax<0.4.36; platform_system != 'Linux'
12
+ Requires-Dist: jax[cuda12]<0.4.36; platform_system == 'Linux'
13
+ Requires-Dist: loguru>=0.7.3
14
+ Requires-Dist: matfree>=0.1.1
15
+ Requires-Dist: matplotlib>=3.9.4
16
+ Requires-Dist: moviepy>=2.1.1
17
+ Requires-Dist: optax>=0.2.4
18
+ Requires-Dist: pytreeclass>=0.9.2
19
+ Requires-Dist: rich>=13.9.4
20
+ Requires-Dist: seaborn>=0.13.2
21
+ Requires-Dist: sharedarray>=3.2.4
22
+ Requires-Dist: tidy3d>=2.7.8
23
+ Requires-Dist: trimesh>=4.5.3
24
+ Requires-Dist: zstandard>=0.23.0
25
+ Description-Content-Type: text/markdown
26
+
27
+ # FDTDX
28
+
29
+ FDTDX is an efficient open-source Python package for the inverse design of three-dimensional photonic nanostructures using the Finite-Difference Time-Domain (FDTD) method. Built on JAX, it provides native GPU support and automatic differentiation capabilities, making it ideal for large-scale 3D design in nanophotonics.
30
+
31
+ ## Key Features
32
+
33
+ - **High Performance**: GPU-accelerated FDTD simulations with multi-GPU scaling capabilities
34
+ - **Memory Efficient**: Leverages time-reversibility in Maxwell's equations for efficient gradient computation
35
+ - **Automatic Differentiation**: Built-in gradient-based optimization for complex 3D structures
36
+ - **User-Friendly API**: Intuitive positioning and sizing of objects in absolute or relative coordinates
37
+ - **Large-Scale Design**: Capable of handling simulations with billions of grid cells
38
+ - **Open Source**: Freely available for research and development
39
+
40
+ ## Documentation
41
+
42
+ Visit our [documentation](https://ymahlau.github.io/fdtdx) for:
43
+ - Detailed API reference
44
+ - Tutorial guides
45
+ - Example simulations
46
+ - Best practices
47
+
48
+
49
+ ## Installation
50
+
51
+ Install FDTDX using pip:
52
+
53
+ ```bash
54
+ pip install fdtdx
55
+ ```
56
+
57
+ For development installation, clone the repository and install in editable mode:
58
+
59
+ ```bash
60
+ git clone https://github.com/ymahlau/fdtdx
61
+ cd fdtdx
62
+ pip install -e .
63
+ ```
64
+
65
+ ## Multi-GPU
66
+
67
+ ```bash
68
+ # The following lines often lead to better memory usage in JAX
69
+ # when using multiple GPU.
70
+ export XLA_PYTHON_CLIENT_ALLOCATOR=platform
71
+ export XLA_PYTHON_CLIENT_PREALLOCATE=false
72
+ export NCCL_LL128_BUFFSIZE="-2"
73
+ export NCCL_LL_BUFFSIZE="-2"
74
+ export NCCL_PROTO="SIMPLE,LL,LL128"
75
+ ```
76
+
77
+ ## Citation
78
+ If you find this repository helpful for you work, please consider citing:
79
+ ```
80
+ @article{schubert2024quantized,
81
+ title={Quantized Inverse Design for Photonic Integrated Circuits},
82
+ author={Schubert, Frederik and Mahlau, Yannik and Bethmann, Konrad and Hartmann, Fabian and Caspary, Reinhard and Munderloh, Marco and Ostermann, J{\"o}rn and Rosenhahn, Bodo},
83
+ journal={arXiv preprint arXiv:2407.10273},
84
+ year={2024}
85
+ }
86
+ ```
fdtdx-0.1.0/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # FDTDX
2
+
3
+ FDTDX is an efficient open-source Python package for the inverse design of three-dimensional photonic nanostructures using the Finite-Difference Time-Domain (FDTD) method. Built on JAX, it provides native GPU support and automatic differentiation capabilities, making it ideal for large-scale 3D design in nanophotonics.
4
+
5
+ ## Key Features
6
+
7
+ - **High Performance**: GPU-accelerated FDTD simulations with multi-GPU scaling capabilities
8
+ - **Memory Efficient**: Leverages time-reversibility in Maxwell's equations for efficient gradient computation
9
+ - **Automatic Differentiation**: Built-in gradient-based optimization for complex 3D structures
10
+ - **User-Friendly API**: Intuitive positioning and sizing of objects in absolute or relative coordinates
11
+ - **Large-Scale Design**: Capable of handling simulations with billions of grid cells
12
+ - **Open Source**: Freely available for research and development
13
+
14
+ ## Documentation
15
+
16
+ Visit our [documentation](https://ymahlau.github.io/fdtdx) for:
17
+ - Detailed API reference
18
+ - Tutorial guides
19
+ - Example simulations
20
+ - Best practices
21
+
22
+
23
+ ## Installation
24
+
25
+ Install FDTDX using pip:
26
+
27
+ ```bash
28
+ pip install fdtdx
29
+ ```
30
+
31
+ For development installation, clone the repository and install in editable mode:
32
+
33
+ ```bash
34
+ git clone https://github.com/ymahlau/fdtdx
35
+ cd fdtdx
36
+ pip install -e .
37
+ ```
38
+
39
+ ## Multi-GPU
40
+
41
+ ```bash
42
+ # The following lines often lead to better memory usage in JAX
43
+ # when using multiple GPU.
44
+ export XLA_PYTHON_CLIENT_ALLOCATOR=platform
45
+ export XLA_PYTHON_CLIENT_PREALLOCATE=false
46
+ export NCCL_LL128_BUFFSIZE="-2"
47
+ export NCCL_LL_BUFFSIZE="-2"
48
+ export NCCL_PROTO="SIMPLE,LL,LL128"
49
+ ```
50
+
51
+ ## Citation
52
+ If you find this repository helpful for you work, please consider citing:
53
+ ```
54
+ @article{schubert2024quantized,
55
+ title={Quantized Inverse Design for Photonic Integrated Circuits},
56
+ author={Schubert, Frederik and Mahlau, Yannik and Bethmann, Konrad and Hartmann, Fabian and Caspary, Reinhard and Munderloh, Marco and Ostermann, J{\"o}rn and Rosenhahn, Bodo},
57
+ journal={arXiv preprint arXiv:2407.10273},
58
+ year={2024}
59
+ }
60
+ ```
@@ -0,0 +1,17 @@
1
+ # Binary Operations
2
+
3
+ ## Morphological Operations
4
+ ::: fdtdx.constraints.binary_transform.dilate_jax
5
+ ::: fdtdx.constraints.binary_transform.erode_jax
6
+ ::: fdtdx.constraints.binary_transform.seperated_3d_dilation
7
+ ::: fdtdx.constraints.binary_transform.binary_median_filter
8
+
9
+ ## Connectivity Analysis
10
+ ::: fdtdx.constraints.binary_transform.compute_polymer_connection
11
+ ::: fdtdx.constraints.binary_transform.compute_air_connection
12
+ ::: fdtdx.constraints.binary_transform.connect_slice
13
+
14
+ ## Structure Optimization
15
+ ::: fdtdx.constraints.binary_transform.remove_floating_polymer
16
+ ::: fdtdx.constraints.binary_transform.remove_polymer_non_connected_to_x_max_middle
17
+ ::: fdtdx.constraints.binary_transform.connect_holes_and_structures
@@ -0,0 +1,17 @@
1
+ # Discrete Constraints
2
+
3
+ ## Material Connectivity
4
+ ::: fdtdx.constraints.discrete.RemoveFloatingMaterial
5
+ ::: fdtdx.constraints.discrete.ConnectHolesAndStructures
6
+
7
+ ## Feature Size Control
8
+ ::: fdtdx.constraints.discrete.circular_brush
9
+ ::: fdtdx.constraints.discrete.BrushConstraint2D
10
+
11
+ ## Smoothing and Filtering
12
+ ::: fdtdx.constraints.discrete.BinaryMedianFilterModule
13
+ ::: fdtdx.constraints.discrete.BOTTOM_Z_PADDING_CONFIG
14
+ ::: fdtdx.constraints.discrete.BOTTOM_Z_PADDING_CONFIG_REPEAT
15
+
16
+ ## Pillar Constraints
17
+ ::: fdtdx.constraints.pillars.PillarMapping
@@ -0,0 +1,11 @@
1
+ # Constraints
2
+
3
+ The constraints package provides tools for applying physical and geometric constraints during optimization.
4
+
5
+ ## Components
6
+
7
+ - [Mapping](mapping.md) - Constraint mapping functionality
8
+ - [Modules](modules.md) - Base classes and transformation modules
9
+ - [Utilities](utils.md) - Index generation and value matching utilities
10
+ - [Binary Operations](binary.md) - Morphological operations and connectivity analysis
11
+ - [Discrete Constraints](discrete.md) - Material connectivity and feature size control
@@ -0,0 +1,3 @@
1
+ # Constraint Mapping
2
+
3
+ ::: fdtdx.constraints.mapping.ConstraintMapping
@@ -0,0 +1,14 @@
1
+ # Constraint Modules
2
+
3
+ ## Base Classes
4
+ ::: fdtdx.constraints.module.ConstraintInterface
5
+ ::: fdtdx.constraints.module.ConstraintModule
6
+
7
+ ## Value Range Transformations
8
+ ::: fdtdx.constraints.module.StandardToInversePermittivityRange
9
+ ::: fdtdx.constraints.module.StandardToCustomRange
10
+ ::: fdtdx.constraints.module.StandardToPlusOneMinusOneRange
11
+
12
+ ## Material Index Transformations
13
+ ::: fdtdx.constraints.module.ClosestIndex
14
+ ::: fdtdx.constraints.module.IndicesToInversePermittivities
@@ -0,0 +1,9 @@
1
+ # Constraint Utilities
2
+
3
+ ## Index Generation
4
+ ::: fdtdx.constraints.utils.compute_allowed_indices
5
+ ::: fdtdx.constraints.utils.compute_allowed_indices_without_holes
6
+ ::: fdtdx.constraints.utils.compute_allowed_indices_without_holes_single_polymer_columns
7
+
8
+ ## Value Matching
9
+ ::: fdtdx.constraints.utils.nearest_index
@@ -0,0 +1,12 @@
1
+ # Array Operations
2
+
3
+ ::: fdtdx.core.misc.expand_matrix
4
+ ::: fdtdx.core.misc.ensure_slice_tuple
5
+ ::: fdtdx.core.misc.index_1d_array
6
+ ::: fdtdx.core.misc.index_by_slice
7
+ ::: fdtdx.core.misc.index_by_slice_take_1d
8
+ ::: fdtdx.core.misc.index_by_slice_take
9
+ ::: fdtdx.core.misc.mask_1d_from_slice
10
+ ::: fdtdx.core.misc.assimilate_shape
11
+ ::: fdtdx.core.misc.linear_interpolated_indexing
12
+ ::: fdtdx.core.misc.advanced_padding
@@ -0,0 +1,4 @@
1
+ # Configuration
2
+
3
+ ::: fdtdx.core.config.GradientConfig
4
+ ::: fdtdx.core.config.SimulationConfig
@@ -0,0 +1,6 @@
1
+ # Distributed Computing
2
+
3
+ ::: fdtdx.core.jax.sharding.get_named_sharding_from_shape
4
+ ::: fdtdx.core.jax.sharding.get_dtype_bytes
5
+ ::: fdtdx.core.jax.sharding.pretty_print_sharding
6
+ ::: fdtdx.core.jax.sharding.create_named_sharded_matrix
@@ -0,0 +1,12 @@
1
+ # Core Package
2
+
3
+ The core package provides fundamental functionality for FDTD simulations.
4
+
5
+ ## Components
6
+
7
+ - [Types](types.md) - Shape and slice type definitions
8
+ - [Configuration](config.md) - Simulation and gradient configuration
9
+ - [PyTree Utilities](pytree.md) - Tree class utilities and fields
10
+ - [JAX Utilities](jax.md) - JAX-specific utilities
11
+ - [Array Operations](arrays.md) - Array manipulation functions
12
+ - [Distributed Computing](distributed.md) - Sharding and distributed computation
@@ -0,0 +1,10 @@
1
+ # JAX Utilities
2
+
3
+ ## Shape and Type Checking
4
+ ::: fdtdx.core.jax.utils.check_shape_dtype
5
+
6
+ ## Utility Classes
7
+ ::: fdtdx.core.misc.PaddingConfig
8
+
9
+ ## Gradient Estimators
10
+ ::: fdtdx.core.jax.ste.straight_through_estimator
@@ -0,0 +1,11 @@
1
+ # PyTree Utilities
2
+
3
+ ## Core Utilities
4
+ ::: fdtdx.core.jax.pytrees.extended_autoinit
5
+ ::: fdtdx.core.jax.pytrees.field
6
+ ::: fdtdx.core.jax.pytrees.frozen_field
7
+ ::: fdtdx.core.jax.pytrees.frozen_private_field
8
+
9
+ ## Tree Classes and Fields
10
+ ::: fdtdx.core.jax.pytrees.ExtendedTreeClassIndexer
11
+ ::: fdtdx.core.jax.pytrees.ExtendedTreeClass
@@ -0,0 +1,13 @@
1
+ # Types
2
+
3
+ ## Shape Types
4
+ ::: fdtdx.core.jax.typing.RealShape3D
5
+ ::: fdtdx.core.jax.typing.PartialRealShape3D
6
+ ::: fdtdx.core.jax.typing.GridShape3D
7
+ ::: fdtdx.core.jax.typing.PartialGridShape3D
8
+
9
+ ## Slice Types
10
+ ::: fdtdx.core.jax.typing.SliceTuple3D
11
+ ::: fdtdx.core.jax.typing.PartialSliceTuple3D
12
+ ::: fdtdx.core.jax.typing.Slice3D
13
+ ::: fdtdx.core.jax.typing.PartialSlice3D
@@ -0,0 +1,29 @@
1
+ # Core FDTD Algorithms
2
+
3
+ ## Memory-Efficient Implementations
4
+
5
+ ### Reversible FDTD
6
+ ::: fdtdx.fdtd.reversible_fdtd
7
+ Time-reversal symmetric FDTD implementation with O(1) memory usage.
8
+
9
+ ### Checkpointed FDTD
10
+ ::: fdtdx.fdtd.checkpointed_fdtd
11
+ Gradient checkpointing FDTD implementation for memory-performance tradeoff.
12
+
13
+ ## Custom Time Evolution
14
+ ::: fdtdx.fdtd.custom_fdtd_forward
15
+ Customizable FDTD implementation for partial time evolution and analysis.
16
+
17
+ ## Forward Propagation
18
+ ::: fdtdx.fdtd.forward.forward
19
+ Standard forward FDTD time stepping implementation.
20
+
21
+ ::: fdtdx.fdtd.forward.forward_single_args_wrapper
22
+ JAX-compatible wrapper for forward propagation.
23
+
24
+ ## Backward Propagation
25
+ ::: fdtdx.fdtd.backward.full_backward
26
+ Complete backward FDTD propagation from current state to start time.
27
+
28
+ ::: fdtdx.fdtd.backward.backward
29
+ Single step backward FDTD propagation.
@@ -0,0 +1,8 @@
1
+ # Field Operations
2
+
3
+ ## Field Interpolation
4
+ ::: fdtdx.fdtd.curl.interpolate_fields
5
+
6
+ ## Curl Operations
7
+ ::: fdtdx.fdtd.curl.curl_E
8
+ ::: fdtdx.fdtd.curl.curl_H
@@ -0,0 +1,10 @@
1
+ # FDTD Implementations
2
+
3
+ This section documents the FDTD (Finite-Difference Time-Domain) implementations available in the package.
4
+
5
+ ## Contents
6
+
7
+ - [Core FDTD Algorithms](core.md) - Memory-efficient and customizable FDTD implementations
8
+ - [Field Operations](fields.md) - Field interpolation and curl operations
9
+ - [Field Updates](updates.md) - Electric and magnetic field update functions
10
+ - [Interface Management](interfaces.md) - Detector and interface handling
@@ -0,0 +1,8 @@
1
+ # Detector and Interface Management
2
+
3
+ ## Detector Updates
4
+ ::: fdtdx.fdtd.update.update_detector_states
5
+
6
+ ## Interface Handling
7
+ ::: fdtdx.fdtd.update.collect_interfaces
8
+ ::: fdtdx.fdtd.update.add_interfaces
@@ -0,0 +1,9 @@
1
+ # Field Updates
2
+
3
+ ## Electric Field Updates
4
+ ::: fdtdx.fdtd.update.update_E
5
+ ::: fdtdx.fdtd.update.update_E_reverse
6
+
7
+ ## Magnetic Field Updates
8
+ ::: fdtdx.fdtd.update.update_H
9
+ ::: fdtdx.fdtd.update.update_H_reverse