Optimization of Photonic Devices: Implementation of Auto-Differentiable Numerical Methods in Open-Source Software
Séminaire GDR Ondes
\[ \usepackage{amsmath,amssymb} \newcommand{\e}{\varepsilon} \newcommand{\exx}{\e_{xx}} \newcommand{\eyy}{\e_{yy}} \newcommand{\ea}{\e_{a}} \newcommand{\ezz}{\e_{zz}} \newcommand{\exy}{\e_{xy}} \newcommand{\eyx}{\e_{yx}} \newcommand{\muxx}{\mu_{xx}} \newcommand{\muyy}{\mu_{yy}} \newcommand{\mua}{\mu_{a}} \newcommand{\muzz}{\mu_{zz}} \newcommand{\ef}{\e_{\rm f}} \newcommand{\ed}{\e_{\rm d}} \newcommand{\tdf}{\tan \delta_{\rm f}} \newcommand{\td}{\tan \delta} \newcommand{\Eb}{E_{\rm B}} \newcommand{\Em}{\B{\mathcal{E}}} \newcommand{\Hm}{{\mathcal{H}}} \usepackage{bm} \newcommand{\B}[1]{\boldsymbol{#1}} \newcommand{\tens}[1]{\B{#1}} \newcommand{\re}{\mathrm{Re}\,} \newcommand{\im}{\mathrm{Im}\,} \newcommand{\grad}{\B{\nabla}} \newcommand{\ddiv}{\B{\nabla}\cdotp} \newcommand{\curl}{\B{\nabla}\times} \newcommand{\dt}{\mathrm{d}} \newcommand{\etens}{\tens{\e}} \newcommand{\h}[1]{\tilde{#1}} \newcommand{\T}[1]{#1^{\rm T}} \newcommand{\lp}{\left(} \newcommand{\rp}{\right)} \newcommand{\bra}{\left\langle} \newcommand{\ket}{\right\rangle} \newcommand{\mn}[1]{\bra #1 \ket} \newcommand{\D}{\partial} \newcommand{\dd}{\rm d} \newcommand{\der}[2]{\frac{\D #1}{\D #2}} \newcommand{\rhof}{\tilde{\rho}} \newcommand{\rhop}{\hat{\rho}} \newcommand{\matthree}[9]{ \begin{pmatrix} #1 & #2 & #3\\ #4 & #5 & #6\\ #7 & #8 & #9 \end{pmatrix} } \newcommand{\ehom}{\tilde{\etens}} \newcommand{\ezaniso}{\matthree{\exx}{\ea^\star}{0}{\ea}{\eyy}{0}{0}{0}{\ezz}} \newcommand{\muzaniso}{\matthree{\muxx}{\mua^\star}{0}{\mua}{\muyy}{0}{0}{0}{\muzz}} \newcommand{\LSO}{L^2({{\rm\textbf{curl}}}, \Omega)} \newcommand{\rpara}{\B{r_\parallel}} \newcommand{\densf}{\tilde{p}} \newcommand{\densp}{\hat{p}} \newcommand{\exxh}{\h{\e}_{xx}} \newcommand{\eyyh}{\h{\e}_{yy}} \newcommand{\exyh}{\h{\e}_{xy}} \newcommand{\eyxh}{\h{\e}_{yx}} \newcommand{\ezzh}{\h{\e}_{zz}} \newcommand{\tdhxx}{\tan \h{\delta}_{xx}} \newcommand{\tunh}{\h{\eta}} \]
What is topology optimization?
A mathematical method that optimizes material layout within a given design space, for a given set of sources, boundary conditions and constraints with the goal of maximizing the performance of the system
Topology optimization Hello World!
: Maximizing a beam stiffness with fixed volume fraction (Bleyer 2018)
\[\densp(\densf) = \frac{\tanh\left[\beta\nu\right] + \tanh\left[\beta(\densf-\nu)\right] }{\tanh\left[\beta\nu\right]
+ \tanh\left[\beta(1-\nu)\right]}\] with \(\nu=1/2\) and \(\beta>0\) increased during the course of the optimization. (Wang et al. 2010)
\(\varepsilon(\densp)=(\varepsilon_{\rm max}-\varepsilon_{\rm min})\,\densp^m + \varepsilon_{\rm min}\) (Bendsøe et al. 1999)
nlopt
package (Johnson 2007)Solution vector \(\B u\) depends on a vector of parameters \(\B p\) of size \(M\) and defined implicitly through an operator \(\B F\) as: \[ \B F(\B u, \B p) = \B 0 \qquad(1)\]
\(\B G\) is a functional of interest of dimension \(N\), representing the quantity to be optimized
\[ \frac{\mathrm{d}\B G}{\mathrm{d}p_i} \approx \frac{\B G(\B p + h \B e_i) - \B G(\B p)}{h} \] where \(\B e_i\) is the vector with \(0\) in all entries except for \(1\) in the \(i^{th}\) entry.
Explicitly, the gradient can be computed applying the chain rule: \[ \frac{\mathrm{d}\B G}{\mathrm{d}\B p} = \frac{\partial \B G}{\partial \B p} + \frac{\partial \B G}{\partial \B u} \frac{\mathrm{d}\B u}{\mathrm{d}\B p}. \qquad(2)\] Taking the total derivative of Equation 1 we obtain the tangent linear equation: \[ {\frac{\partial \B F(\B u, \B p)}{\partial \B u}} {\frac{\mathrm{d}\B u}{\mathrm{d}\B p}} = {-\frac{\partial \B F(\B u, \B p)}{\partial \B p}}. \]
Assuming the tangent linear system is invertible, we can rewrite the Jacobian as: \[ \frac{\mathrm{d}\B u}{\mathrm{d}\B p} = - \left(\frac{\partial \B F(\B u, \B p)}{\partial \B u}\right)^{-1} \frac{\partial \B F(\B u, \B p)}{\partial \B p}. \] After substituting this value in Equation 2 and taking the adjoint (Hermitian transpose, denoted by \(\dagger\)) we get: \[ \frac{\mathrm{d}\B G}{\mathrm{d}\B p}^{\dagger} = \frac{\partial \B G}{\partial \B p}^{\dagger} - \frac{\partial \B F(\B u, \B p)}{\partial \B p}^{\dagger} \left(\frac{\partial \B F(\B u, \B p)}{\partial \B u}\right)^{-\dagger} \frac{\partial \B G}{\partial \B u}^{\dagger} . \]
Defining the adjoint variable \(\B \lambda\) as: \[ \B \lambda = \left(\frac{\partial \B F(\B u, \B p)}{\partial \B u}\right)^{-\dagger} \frac{\partial \B G}{\partial \B u}^{\dagger} \] we obtain the adjoint equation \[ \left(\frac{\partial \B F(\B u, \B p)}{\partial \B u}\right)^{\dagger} \B \lambda = \frac{\partial \B G}{\partial \B u}^{\dagger}. \]
\(f: \mathbb{R}^M \rightarrow \mathbb{R}^N\)
Example: \(f(x_1,x_2) = x_1x_2 + \sin(x_1)\)
Forward mode
Reverse mode
Open-source code
Open source libraries with bindings for the python
programming language using a custom code gyptis
(Vial 2022).
gmsh
(Geuzaine et al. 2009)fenics
using second order Lagrange basis functions (Alnæs et al. 2015)dolfin-adjoint
library with automatic differentiation (Mitusch et al. 2019)Objective: focal point at two different locations depending on the excitation frequency (Vial, Whittaker, et al. 2022) \[ \max_{p(\B r)} \quad \Phi = \left|E_1(\omega_1,\B r_1)\right| + \left|E_2(\omega_2,\B r_2)\right| \]
Objective: maximize the normalized scattering width (Vial and Hao 2022) \[ \max_{p(\B r)} \quad \Phi = \sigma_s/2R \]
Open-source code
FMM and PWEM in python
with various numerical backends for core linear algebra operations and array manipulation
numpy
(Harris et al. 2020)scipy
(Virtanen et al. 2020)autograd
(AD) (Maclaurin et al. 2015)pytorch
(AD + GPU) (Paszke et al. 2019, 2017)jax
(AD + GPU) (Bradbury et al. 2018)Objective: maximize the average of the transmission coefficient in the \((1,0)\) diffracted order for both polarizations: \[ \max_{p(\B r)} \quad \Phi = \frac{1}{2} \left( T^{\rm TE}_{(1,0)} + T^{\rm TM}_{(1,0)}\right) \]
Open-source code
Objective: open and maximize a bandgap between the \(5^{th}\) and \(6^{th}\) eigenvalues:\[\begin{equation*}\max_{p(\B r)} \quad \Phi = \min_{\B k} \omega_{6}(\B k) - \max_{\B k} \omega_{5}(\B k)\end{equation*}\]
Objective: obtain a prescribed dispersion curve for the \(6^{th}\) band \[\begin{equation*}\min_{p(\B r)} \quad \Phi = \left\langle\left|\omega_{6}(k_x) - \langle \omega_{6}\rangle - \omega_{\rm tar}(k_x) \right|^2\right\rangle \end{equation*}\] with \[\begin{align*}\omega_{\rm tar}(k_x) =& -0.02 \cos(k_x a) + 0.01 \cos(2 k_x a) \\ &+ 0.007 \cos(3 k_x a)\end{align*}\] \(\langle f\rangle =\frac{1}{M}\sum_{m=0}^M f_m\)
FEM
FMM
PWEM