From c3ab45bc3a39e4ff622a130e3594854bcc3c154b Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Sun, 11 Aug 2024 16:51:30 -0700 Subject: [PATCH 1/3] add note on non negligible cost of finite differences to tutorial on shape derivatives --- doc/docs/Python_Tutorials/Adjoint_Solver.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/docs/Python_Tutorials/Adjoint_Solver.md b/doc/docs/Python_Tutorials/Adjoint_Solver.md index 1ab880051..9319909d8 100644 --- a/doc/docs/Python_Tutorials/Adjoint_Solver.md +++ b/doc/docs/Python_Tutorials/Adjoint_Solver.md @@ -856,7 +856,7 @@ Calculating the derivative of the diffraction efficiency ($F$) with respect to t ![](../images/levelset_gradient_backpropagation.png#center) -The derivative $\partial \rho / \partial h$ can be approximated by a finite difference using a one-pixel perturbation applied to the grating height; this is computationally convenient because it greatly simplifies the construction of $\rho(h)$ as explained below. (A finite difference involves two function evaluations of $\rho(h)$, but the cost for this is negligible since it involves no Meep simulations.) The construction of $\rho(h)$ involves two steps: first, constructing a simple binary image $b(h)$ at a high resolution; and second, smoothing $b(h)$ into a continuous level-set function $\rho(h)$. This smoothing of the image can be performed using a number of different methods including a [signed-distance function](https://en.wikipedia.org/wiki/Signed_distance_function) or convolution filter. In this example, the smoothing is based simply on downsampling the image from a high-resolution grid (10$\times$ the resolution of the simulation grid) to the lower-resolution simulation grid using bilinear interpolation, which leads to "gray" pixels at the boundaries between materials in a way that changes continuously with $h$. Only these boundary pixels have nonzero derivatives in the Jacobian $\partial\rho/\partial h$ in this case. This calculation is summarized in the schematic below. +The derivative $\partial \rho / \partial h$ can be approximated by a finite difference using a one-pixel perturbation applied to the grating height; this is computationally convenient because it greatly simplifies the construction of $\rho(h)$ as explained below. A finite difference involves two function evaluations of $\rho(h)$, but the cost for this is negligible since it involves no Meep simulations. However, when there are a large number of shape parameters and a dense design grid, the costs of the finite differences can be non negligible: $M$ shape parameters would require $M$ finite differences over $N$ grid points. The construction of $\rho(h)$ involves two steps: first, constructing a simple binary image $b(h)$ at a high resolution; and second, smoothing $b(h)$ into a continuous level-set function $\rho(h)$. This smoothing of the image can be performed using a number of different methods including a [signed-distance function](https://en.wikipedia.org/wiki/Signed_distance_function) or convolution filter. In this example, the smoothing is based simply on downsampling the image from a high-resolution grid (10$\times$ the resolution of the simulation grid) to the lower-resolution simulation grid using bilinear interpolation, which leads to "gray" pixels at the boundaries between materials in a way that changes continuously with $h$. Only these boundary pixels have nonzero derivatives in the Jacobian $\partial\rho/\partial h$ in this case. This calculation is summarized in the schematic below. ![](../images/levelset_jacobian_matrix.png#center) From 83e67e48a4e3f29b55a52bf4fb2ee6702502765e Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Sun, 11 Aug 2024 17:01:19 -0700 Subject: [PATCH 2/3] mention that material parameters must be smoothed over the design grid --- doc/docs/Python_Tutorials/Adjoint_Solver.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/docs/Python_Tutorials/Adjoint_Solver.md b/doc/docs/Python_Tutorials/Adjoint_Solver.md index 9319909d8..702c6ec0b 100644 --- a/doc/docs/Python_Tutorials/Adjoint_Solver.md +++ b/doc/docs/Python_Tutorials/Adjoint_Solver.md @@ -856,7 +856,7 @@ Calculating the derivative of the diffraction efficiency ($F$) with respect to t ![](../images/levelset_gradient_backpropagation.png#center) -The derivative $\partial \rho / \partial h$ can be approximated by a finite difference using a one-pixel perturbation applied to the grating height; this is computationally convenient because it greatly simplifies the construction of $\rho(h)$ as explained below. A finite difference involves two function evaluations of $\rho(h)$, but the cost for this is negligible since it involves no Meep simulations. However, when there are a large number of shape parameters and a dense design grid, the costs of the finite differences can be non negligible: $M$ shape parameters would require $M$ finite differences over $N$ grid points. The construction of $\rho(h)$ involves two steps: first, constructing a simple binary image $b(h)$ at a high resolution; and second, smoothing $b(h)$ into a continuous level-set function $\rho(h)$. This smoothing of the image can be performed using a number of different methods including a [signed-distance function](https://en.wikipedia.org/wiki/Signed_distance_function) or convolution filter. In this example, the smoothing is based simply on downsampling the image from a high-resolution grid (10$\times$ the resolution of the simulation grid) to the lower-resolution simulation grid using bilinear interpolation, which leads to "gray" pixels at the boundaries between materials in a way that changes continuously with $h$. Only these boundary pixels have nonzero derivatives in the Jacobian $\partial\rho/\partial h$ in this case. This calculation is summarized in the schematic below. +The derivative $\partial \rho / \partial h$ can be approximated by a finite difference using a one-pixel perturbation applied to the grating height; this is computationally convenient because it greatly simplifies the construction of $\rho(h)$ as explained below. A finite difference involves two function evaluations of $\rho(h)$, but the cost for this is negligible since it involves no Meep simulations. However, when there are a large number of shape parameters and a dense design grid, the costs of the finite differences can be non negligible: $M$ shape parameters would require $M$ finite differences over $N$ grid points (over which the material parameters need to be smoothed). The construction of $\rho(h)$ involves two steps: first, constructing a simple binary image $b(h)$ at a high resolution; and second, smoothing $b(h)$ into a continuous level-set function $\rho(h)$. This smoothing of the image can be performed using a number of different methods including a [signed-distance function](https://en.wikipedia.org/wiki/Signed_distance_function) or convolution filter. In this example, the smoothing is based simply on downsampling the image from a high-resolution grid (10$\times$ the resolution of the simulation grid) to the lower-resolution simulation grid using bilinear interpolation, which leads to "gray" pixels at the boundaries between materials in a way that changes continuously with $h$. Only these boundary pixels have nonzero derivatives in the Jacobian $\partial\rho/\partial h$ in this case. This calculation is summarized in the schematic below. ![](../images/levelset_jacobian_matrix.png#center) From afb83b0952ab59caa435eaa037ffa40da72c01cd Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Sun, 11 Aug 2024 21:00:51 -0700 Subject: [PATCH 3/3] fix typo --- doc/docs/Python_Tutorials/Adjoint_Solver.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/docs/Python_Tutorials/Adjoint_Solver.md b/doc/docs/Python_Tutorials/Adjoint_Solver.md index 702c6ec0b..af4b4db51 100644 --- a/doc/docs/Python_Tutorials/Adjoint_Solver.md +++ b/doc/docs/Python_Tutorials/Adjoint_Solver.md @@ -856,7 +856,7 @@ Calculating the derivative of the diffraction efficiency ($F$) with respect to t ![](../images/levelset_gradient_backpropagation.png#center) -The derivative $\partial \rho / \partial h$ can be approximated by a finite difference using a one-pixel perturbation applied to the grating height; this is computationally convenient because it greatly simplifies the construction of $\rho(h)$ as explained below. A finite difference involves two function evaluations of $\rho(h)$, but the cost for this is negligible since it involves no Meep simulations. However, when there are a large number of shape parameters and a dense design grid, the costs of the finite differences can be non negligible: $M$ shape parameters would require $M$ finite differences over $N$ grid points (over which the material parameters need to be smoothed). The construction of $\rho(h)$ involves two steps: first, constructing a simple binary image $b(h)$ at a high resolution; and second, smoothing $b(h)$ into a continuous level-set function $\rho(h)$. This smoothing of the image can be performed using a number of different methods including a [signed-distance function](https://en.wikipedia.org/wiki/Signed_distance_function) or convolution filter. In this example, the smoothing is based simply on downsampling the image from a high-resolution grid (10$\times$ the resolution of the simulation grid) to the lower-resolution simulation grid using bilinear interpolation, which leads to "gray" pixels at the boundaries between materials in a way that changes continuously with $h$. Only these boundary pixels have nonzero derivatives in the Jacobian $\partial\rho/\partial h$ in this case. This calculation is summarized in the schematic below. +The derivative $\partial \rho / \partial h$ can be approximated by a finite difference using a one-pixel perturbation applied to the grating height; this is computationally convenient because it greatly simplifies the construction of $\rho(h)$ as explained below. A finite difference involves two function evaluations of $\rho(h)$, but the cost for this is usually negligible since it involves no Meep simulations. However, in cases when there are a large number of shape parameters and a dense design grid, the cost of the finite differences can be non negligible: $M$ shape parameters require $M$ finite differences each involving $N$ grid points. The construction of $\rho(h)$ involves two steps: first, constructing a simple binary image $b(h)$ at a high resolution; and second, smoothing $b(h)$ into a continuous level-set function $\rho(h)$. This smoothing of the image can be performed using a number of different methods including a [signed-distance function](https://en.wikipedia.org/wiki/Signed_distance_function) or convolution filter. In this example, the smoothing is based simply on downsampling the image from a high-resolution grid (10$\times$ the resolution of the simulation grid) to the lower-resolution simulation grid using bilinear interpolation, which leads to "gray" pixels at the boundaries between materials in a way that changes continuously with $h$. Only these boundary pixels have nonzero derivatives in the Jacobian $\partial\rho/\partial h$ in this case. This calculation is summarized in the schematic below. ![](../images/levelset_jacobian_matrix.png#center)