Skip to content

Commit a340912

Browse files
authored
Merge pull request invrs-io#101 from invrs-io/designs
Include additional metalens designs in docs
2 parents 6e608a7 + 9a292a6 commit a340912

File tree

4 files changed

+2485
-3
lines changed

4 files changed

+2485
-3
lines changed

docs/notebooks/metalens_challenge.ipynb

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,97 @@
184184
"cell_type": "markdown",
185185
"metadata": {},
186186
"source": [
187-
"## Metalens optimization\n",
187+
"## Performance versus length scale\n",
188188
"\n",
189-
"To optimize a metalens, you may follow the recipe in the `ceviche_challenge` and `metagrating_challenge` notebooks."
189+
"Next, we will compute the performance of the reference devices and measure their length scale using the [imageruler](https://github.com/nanocomp/imageruler) package."
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": null,
195+
"metadata": {},
196+
"outputs": [],
197+
"source": [
198+
"import glob\n",
199+
"import imageruler\n",
200+
"\n",
201+
"results = {\"invrsio\": [], \"rasmus\": [], \"mo\": []}\n",
202+
"\n",
203+
"for fname in glob.glob(\"../../reference_designs/metalens/Ex/*.csv\"):\n",
204+
" design = onp.genfromtxt(fname, delimiter=\",\")\n",
205+
" design = design[:, ::-1]\n",
206+
"\n",
207+
" grid_spacing = 0.01 if \"Rasmus\" in fname else 0.02\n",
208+
" spec = dataclasses.replace(\n",
209+
" metalens_challenge.METALENS_SPEC,\n",
210+
" width_lens=design.shape[0] * grid_spacing,\n",
211+
" width_pml=0.5,\n",
212+
" thickness_lens=design.shape[1] * grid_spacing,\n",
213+
" grid_spacing=grid_spacing,\n",
214+
" )\n",
215+
" challenge = challenges.metalens(spec=spec)\n",
216+
" dummy_params = challenge.component.init(jax.random.PRNGKey(0))\n",
217+
"\n",
218+
" padding = int(onp.around(spec.width / spec.grid_spacing)) - design.shape[0]\n",
219+
" padded_design = onp.pad(design, ((padding // 2, padding // 2), (0, 0)), mode=\"edge\")\n",
220+
" params = dataclasses.replace(dummy_params, array=padded_design)\n",
221+
"\n",
222+
" response, aux = challenge.component.response(params)\n",
223+
"\n",
224+
" # Compute the length scale in nanometers for the binary design.\n",
225+
" length_scale = (\n",
226+
" onp.amin(imageruler.minimum_length_scale(design > 0.5)) * grid_spacing * 1000\n",
227+
" )\n",
228+
"\n",
229+
" if \"Mo\" in fname:\n",
230+
" key = \"mo\"\n",
231+
" elif \"Rasmus\" in fname:\n",
232+
" key = \"rasmus\"\n",
233+
" elif \"invrsio\" in fname:\n",
234+
" key = \"invrsio\"\n",
235+
"\n",
236+
" results[key].append(\n",
237+
" {\"response\": response, \"length_scale\": length_scale, \"aux\": aux}\n",
238+
" )"
239+
]
240+
},
241+
{
242+
"cell_type": "markdown",
243+
"metadata": {},
244+
"source": [
245+
"Plotting, we see results very similar to those of figure 3 of \"[Validation and characterization of algorithms and software for photonics inverse design](https://opg.optica.org/josab/abstract.cfm?URI=josab-41-2-A161)\" by Chen et al.\n",
246+
"\n",
247+
"Differences are explained by updates to the imageruler algorithm, and the fact that we are using a different simulation algorithm to model the metalenses."
248+
]
249+
},
250+
{
251+
"cell_type": "code",
252+
"execution_count": null,
253+
"metadata": {},
254+
"outputs": [],
255+
"source": [
256+
"ax = plt.subplot(111)\n",
257+
"\n",
258+
"for key, result in results.items():\n",
259+
" enhancement = onp.asarray([onp.mean(r[\"response\"].enhancement_ex) for r in result])\n",
260+
" length_scale = onp.asarray([onp.amin(r[\"length_scale\"]) for r in result])\n",
261+
" order = onp.argsort(length_scale)\n",
262+
" ax.plot(length_scale[order], enhancement[order], \"o-\", lw=3, ms=10, label=key)\n",
263+
"\n",
264+
"ax.set_xlabel(\"Length scale (nm)\")\n",
265+
"ax.set_ylabel(\"Wavelength average intensity at focus (a.u.)\")\n",
266+
"ax.set_ylim((5, 25))\n",
267+
"_ = plt.legend()"
190268
]
191269
},
192270
{
193271
"cell_type": "markdown",
194272
"metadata": {},
195-
"source": []
273+
"source": [
274+
"## Metalens optimization\n",
275+
"\n",
276+
"To optimize a metalens, you may follow the recipe in the `ceviche_challenge` and `metagrating_challenge` notebooks."
277+
]
196278
}
197279
],
198280
"metadata": {

0 commit comments

Comments
 (0)