# \[pre-ANN\] Differentiable FDTD for inverse design in photonics, acoustics and RF

**URL:** <https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405>\
**Category:** Package Announcements\
**Tags:** package, announcement, diffeq, flux, machine-learning\
**Created:** [October 26, 2023, 12:22am UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405 "2023-10-26T00:22:55Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [January 26, 2024, 2:05am UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/21 "2024-01-26T02:05:06Z")

</div>

3d works now 🙂 We even did (attempted) 3d inverse design of a silicon photonics signal splitter - it’s converging though the low resolution (for saving time) produced artifacts. Below are 3d scattering and antenna simulations. Previous 1d/2d code broke but will be fixed later

We also reduced malloc without messing up autodiff by using Zygote.Buffer and renamed to FDTDEngine until we find a better name 😃

If you’re running 3d simulations feel free to try. Follow the quickstart in [docs](https://paulxshen.github.io/FDTDEngine.jl/)  
If you’re doing inverse design then it’s more complicated since geometry generation and FOM are problem specific. Message me for starter scripts.

We’ll clean up repo and tighten up the inverse design scripts for silicon photonics and RF metamaterials in the coming weeks

---

<div class="post-metadata">

**Author:** ![Allan\_Baker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/allan_baker/32/42645_2.png) [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Post date:** [February 21, 2024, 2:13am UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/22 "2024-02-21T02:13:46Z")

</div>

Could this simulate arbitrary strip-line antenna geometry and calculate far-field complex polarization responses for arbitrary frequencies and angle of arrivals?

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [February 21, 2024, 11:12pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/23 "2024-02-21T23:12:19Z")

</div>

Yes I can add such a postprocessing feature - just need to fft the monitor surfaces and do a far field integration. Or just far field integrate the approximate current distribution on the strip without FDTD. I can make either adjoint differentiable. Feel free to PM me.

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [February 29, 2024, 3:36pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/24 "2024-02-29T15:36:40Z")

</div>

Added GPU support, forward and adjoint. Improved API for monitors, modal sources… Did inverse design of a simple 3d signal splitter in silicon photonics

---

<div class="post-metadata">

**Author:** ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Post date:** [February 29, 2024, 3:53pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/25 "2024-02-29T15:53:01Z")

</div>

Would it make sense to move this package to [JuliaPhysics](https://github.com/JuliaPhysics/)?

There is also a couple of other wave/optics packages

---

<div class="post-metadata">

**Author:** ![kylebeggs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kylebeggs/32/43348_2.png) [@kylebeggs](https://discourse.julialang.org/u/kylebeggs)\
**Post date:** [February 29, 2024, 4:15pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/26 "2024-02-29T16:15:20Z")

</div>

Sweet! Can you link to the file which produced this? Edit - found it

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [February 29, 2024, 7:50pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/27 "2024-02-29T19:50:13Z")

</div>

Cool - fOr other folks that file is at [FDTDEngine.jl/examples/inverse\_design\_signal\_splitter/inverse\_design\_signal\_splitter.jl at master · paulxshen/FDTDEngine.jl · GitHub](https://github.com/paulxshen/FDTDEngine.jl/blob/master/examples/inverse_design_signal_splitter/inverse_design_signal_splitter.jl)  
sorry missed couple installation issues - fixed now - that example should run

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [March 31, 2024, 12:19am UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/28 "2024-03-31T00:19:27Z")

</div>

Still prerelease but pushed updates:

- spherical monitor for nearfield radiation pattern (see antenna example)
- documentation for tutorials
- inverse design example now does a 2D TE adjoint optimization first as a fast approximation (3D adjoint optimization has stability issues requiring a low Courant #)
- bug fixes

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [June 14, 2024, 7:39pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/29 "2024-06-14T19:39:44Z")

</div>

Update: we’re working with [gdsfactory](https://gdsfactory.github.io/) on a python api for photonics IC sim and inverse design. will be ready in a month.

---

<div class="post-metadata">

**Author:** ![kylebeggs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kylebeggs/32/43348_2.png) [@kylebeggs](https://discourse.julialang.org/u/kylebeggs)\
**Post date:** [June 14, 2024, 8:01pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/30 "2024-06-14T20:01:57Z")

</div>

@pxshen So you are you wrapping this package in Python?

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [June 15, 2024, 12:04am UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/31 "2024-06-15T00:04:20Z")

</div>

Only a specialized wrapper, in same style as gdsfactory [gplugin](https://gdsfactory.github.io/gplugins/) for meep. Workflow is to create IC layout in gdsfactory and call plugin for sparams or inverse design.

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [June 30, 2024, 3:05pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/32 "2024-06-30T15:05:18Z")

</div>

Here’s a [working draft](https://paulxshen.github.io/Luminescent.jl/luminescent.html) of the python api gdsfactory plugin for photonics. Can get sparams or do inverse design in just few lines of code. LMK of your thoughts 🙂

---

<div class="post-metadata">

**Author:** ![kdotom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdotom/32/210388_2.png) [@kdotom](https://discourse.julialang.org/u/kdotom)\
**Post date:** [July 1, 2024, 10:54pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/33 "2024-07-01T22:54:34Z")

</div>

Great work! I’m trying to install the packages based on the tutorial and running into compatibility issues. Do you have the version info for the julia installation and packages you currently have working? Or any tips on addressing the compatibility issues?

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [July 1, 2024, 11:11pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/34 "2024-07-01T23:11:35Z")

</div>

Thanks! Sorry don’t have everything in a Project.toml but everything is latest . I used Julia 10.4 . Is GLMakie failing? What’s error msg?

---

<div class="post-metadata">

**Author:** ![kdotom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdotom/32/210388_2.png) [@kdotom](https://discourse.julialang.org/u/kdotom)\
**Post date:** [July 1, 2024, 11:54pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/35 "2024-07-01T23:54:58Z")

</div>

With the goal of following the [tutorial](https://paulxshen.github.io/Luminescent.jl/luminescent.html), I’m attempting to install the packages in the " ]add " line.

GLMakie imports fine (has some warnings, but appears to be importing)

I just installed julia today (version 1.4.1).

These are the package versions I have (from checking “status” in the julia console):

BSON v0.3.9  
CoordinateTransformations v0.6.3  
DataStructures v0.17.20  
FileIO v1.16.3  
Flux v0.10.4  
Functors v0.2.8  
GLMakie v0.4.2  
ImageTransformations v0.8.13  
Images v0.24.1  
JSON v0.21.4  
Lazy v0.15.1  
StatsBase v0.33.21  
UnPack v1.0.2  
Zygote v0.4.22  
Dates

* * *

These are the packages that fail:

Meshes  
GPUArraysCore  
Jello (add [https://github.com/paulxshen/Jello.jl](https://github.com/paulxshen/Jello.jl))  
ArrayPadding  
AbbreviatedStackTraces

* * *

The all appear to have a similar error:

> restricted by julia compatibility requirements to versions: uninstalled — no versions left.

All that said, this may be an error in how I’m setting things up or an issue outside of the scope of this project, but in case it’s an issue other users might encounter, I wanted to put it on your radar.

---

<div class="post-metadata">

**Author:** ![kdotom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdotom/32/210388_2.png) [@kdotom](https://discourse.julialang.org/u/kdotom)\
**Post date:** [July 2, 2024, 12:28am UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/36 "2024-07-02T00:28:06Z")

</div>

Ok. Mostly resolved. Installed julia by “curl” directly from [julialang.org](http://julialang.org). Version matches now. The rest of the installation works well. …until GLMakie

> ERROR: LoadError: GLFWError (API\_UNAVAILABLE): EGL: Failed to get EGL display: Success

Is there a way around this?  
(For context, this is on WSL w/ Ubuntu)

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [July 2, 2024, 12:59am UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/37 "2024-07-02T00:59:54Z")

</div>

Yeah GLMakie (3D plot) is known to fail in many cases eg headless servers. I’ll make a fallback to a 2D plot in tonight’s update to catch GLMakie failures.

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [July 2, 2024, 1:44am UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/38 "2024-07-02T01:44:51Z")

</div>

pushed - just update the py frontend - also install CairoMakie on Julia. lmk if it works now 🙂

---

<div class="post-metadata">

**Author:** ![kdotom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdotom/32/210388_2.png) [@kdotom](https://discourse.julialang.org/u/kdotom)\
**Post date:** [July 2, 2024, 2:35am UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/39 "2024-07-02T02:35:34Z")

</div>

Thanks!

I updated the front end, installed CairoMakie (and Uninstalled GLMakie), and also installed Porcupine (not listed in the packages, but it seems like the first example script in the tutorial needs it). The first script runs with this error:

> ERROR: LoadError: UndefVarError: `heatmap` not defined

for

> File “/home/blah/blah/python3.11/site-packages/luminescent/gplugins/luminescent/sol.py”, line 73, in write\_sparams

Let me know if you need more context.

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [July 2, 2024, 4:17pm UTC](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405/40 "2024-07-02T16:17:57Z")

</div>

That’s a plotting error - I pushed again - try pip update now

[Previous page](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405.md?page=1)

[Next page](https://discourse.julialang.org/t/pre-ann-differentiable-fdtd-for-inverse-design-in-photonics-acoustics-and-rf/105405.md?page=3)
