In this notebook, we will use inverse design to optimize coupling from a silicon waveguide to a photonic crystal slab.
We’ll first set up a very simple photonic crystal in a silicon slab.
Then, we’ll maximize the transmitted flux through the crystal at a frequency just above the bandgap.
Our degrees of freedom will be the center of the holes cut in the photonic crystal, but modifying this example, one can easily adjust the radius of each hole as well as an extra design parameter.
import autograd# we'll use autograd for automatic differentiation, so derivative-traced numpy operations will use autograd.numpyimport autograd.numpy as anpimport matplotlib.pyplot as pltimport numpy as npimport tidy3d as tdimport tidy3d.web as web
Setup
First, we will set up some of our global parameters for the study.
The structure will consist of a rectangular lattice of air holes in a silicon slab.
# silicon material (for slab)n_si =3.48si = td.Medium(permittivity=n_si**2)air = td.Medium()
# radius of holesr0 =90* nm# when we optimize, the radius will vary between these two values# for now we just constrain all radius to r0, but change these values to add more degrees of freedomr_range = rmin, rmax = (r0, r0)rmid = r0# how much centers can move from the centerdrmax = a /4
# number of holes in x and yN_rows =15N_cols =19N_cols_static =5# total length of the PhC regionLx_phc = N_cols * a + a /2Ly_phc = N_rows * sqrt3_div2 * a + a /2# buffer on each side of the design regionbuffer=1.0* wvl0# thickness of slabt_slab =220* nm# waveguide widthw_wg =1.3* a
# define grid resolutionsteps_per_unit_cell =14dx = a / steps_per_unit_celldy = a * sqrt3_div2 / steps_per_unit_cellgrid_spec = td.GridSpec( grid_x=td.UniformGrid(dl=dx), grid_y=td.UniformGrid(dl=dy), grid_z=td.AutoGrid(min_steps_per_wvl=steps_per_unit_cell),)
def make_holes(params) -> td.Structure:"""Convenience function to make the phc holes given the design parameters.""" hole_spacing_x = a hole_spacing_y = a * sqrt3_div2 x_slab_length, y_slab_length = ( hole_spacing_x * (N_cols +0.5), hole_spacing_y * N_rows, ) start_x, start_y = (-x_slab_length /2+ hole_spacing_x /2,-y_slab_length /2+ hole_spacing_y /2, ) cylinders = []for i inrange(0, N_cols):for j inrange(0, N_rows):# depending on distance from central column, hole is either static i_dist =abs(i - N_cols //2)if i_dist < ((N_cols_static) /2): radius = rmid dx = dy =0# or optimizableelse: radius = params[0, i, j] dx = params[1, i, j] dy = params[2, i, j] x0 = dx + start_x + (i + (j %2) *0.5) * hole_spacing_x y0 = dy + start_y + j * hole_spacing_yif j != N_rows //2: c = td.Cylinder( axis=2, radius=radius, center=(x0, y0, 0), length=td.inf, ) cylinders.append(c)# use GeometryGroup since all same medium, for performance structure = td.Structure( geometry=td.GeometryGroup(geometries=cylinders), medium=air, background_medium=si, # note: we need this for correct gradients when embedded in slab )return structure
01:47:02 UTC Estimated FlexCredit cost: 0.252. This assumes the FDTD solver runs
for the full simulation time; if early shutoff is reached, the
billed cost can be lower. Use 'web.real_cost(task_id)' to get the
billed FlexCredit cost after a simulation run.
01:47:03 UTC status = success
01:47:05 UTC Loading results from simulation_data.hdf5
Created task 'initial PhC norm' with resource_id
'fdve-b7559525-ac31-4078-8820-303dc1d822e5' and task_type 'FDTD'.
01:47:06 UTC Estimated FlexCredit cost: 0.252. This assumes the FDTD solver runs
for the full simulation time; if early shutoff is reached, the
billed cost can be lower. Use 'web.real_cost(task_id)' to get the
billed FlexCredit cost after a simulation run.
01:47:07 UTC status = success
01:47:09 UTC Loading results from simulation_data.hdf5
Let’s visualize the transmission. We can clearly see the bandgap, but above the bandgap, the transmission is not great. We will optimize transmitted flux at the orange line.
Note: one can also do this with ModeMonitor and include a broadband objective.
The normalization flux is about 1, which is as expected as our ModeSource takes this into account.
Optimization
Next, we will define our inverse design problem. We’ll adjust the centers and radii (if desired) to maximize flux at freq0, normalized by our straight waveguide transmission.
As always, we can use one line of autograd code to get a function that gives the value and gradient of our objective when passed some parameters.
val_grad = autograd.value_and_grad(objective)
And then we can use this function in our gradient-ascent optimizer using Tidy3D’s built-in Adam helper.
We first set up the optimizer parameters.
from autograd.tracer import getvalfrom tidy3d.plugins.autograd import adam, optimize# hyperparametersnum_steps =10learning_rate = a /40# note: the step size needs to be quite low because of the direct modification of geometric parameter# initialize adam optimizer with starting parametersparams = np.array(params0).copy()optimizer = adam(learning_rate=learning_rate)# store historyobjective_history = []param_history = []data_history = []# define lower and upper bounds for the optimizationlower_bounds = np.zeros_like(params0)upper_bounds = np.zeros_like(params0)lower_bounds[0] = rminupper_bounds[0] = rmaxlower_bounds[1:] =-drmaxupper_bounds[1:] = drmax
And then run the optimization in a for loop (note: to continue optimization, you can always re-run this cell assuming params is set to the last parameters from your previous run.
01:55:30 UTC Estimated FlexCredit cost: 0.252. This assumes the FDTD solver runs
for the full simulation time; if early shutoff is reached, the
billed cost can be lower. Use 'web.real_cost(task_id)' to get the
billed FlexCredit cost after a simulation run.
01:55:31 UTC status = queued
To cancel the simulation, use 'web.abort(task_id)' or
'web.delete(task_id)' or abort/delete the task in the web UI.
Terminating the Python script will not stop the job running on the
cloud.
01:55:40 UTC status = preprocess
01:55:45 UTC starting up solver
running solver
01:56:17 UTC early shutoff detected at 17%, exiting.
And the new transmission (orange) is far higher above the bandgap, meaning that this new device is coupling light much better from the input waveguide!
We use necessary cookies to run this website. With your permission, we
also use analytics cookies to understand site usage and marketing
cookies for advertising, retargeting, and HubSpot tracking.
Learn more about our cookie policy.
Privacy choices
Choose which optional cookies Flexcompute may use. Necessary cookies
are always on because they support core website behavior, security, and
saving your consent record.
Your browser is sending a Global Privacy Control signal, so marketing
cookies are disabled.
Subscribe
Thanks for subscribing
Publish Your Notebook
Thank you for publishingA confirmation email has been sent to your inbox. Your notebook will be available within the next 48 hours.
Community Library
TERMS & CONDITIONS
EFFECTIVE DATE: January 1, 2025
Terms and Conditions for User-Submitted Content
By submitting content to Flexcompute, you agree to the following terms:
1. Ownership and Copyright
All content, including but not limited to text, data, images, and other materials submitted by users,
remains the sole property of the original creator. Flexcompute does not claim ownership of the submitted
content or any intellectual property rights associated with it.
Users affirm that they own the copyright or have obtained all necessary permissions for the submitted
content and are fully responsible for ensuring that their submissions do not infringe on any third-party
rights.
2. Responsibility for Content
Users are solely responsible for the content they submit. Flexcompute does not endorse, guarantee,
or verify the accuracy, legality, or appropriateness of any submitted content. Users are responsible
for ensuring that their content complies with all applicable laws and regulations.
Users declare that they have obtained authorization from all co-authors and collaborators associated
with the submitted content, granting them the right to submit and sign on behalf of all contributors.
Users agree not to submit content that is illegal, defamatory, obscene, or violates the rights
of others, including privacy and intellectual property rights.
3. Modification and Presentation
Flexcompute reserves the right to review, edit, or modify submitted content to improve clarity,
formatting, and presentation while maintaining the original intent and message.
These modifications are made to enhance the overall quality and readability of the published material.
Users acknowledge that Flexcompute may format or present the content in a way
that aligns with our editorial and visual standards.
4. Liability Disclaimer
Flexcompute shall not be held liable for any disputes arising from user-submitted content, including
but not limited to copyright claims, inaccuracies, or damages resulting from the publication of user content.
Users agree to indemnify Flexcompute against any claims or legal actions resulting from their submitted content.
5. Content Use Rights
By submitting content, users grant Flexcompute a non-exclusive, royalty-free, worldwide license to publish, distribute,
and promote the content for the purposes of showcasing user contributions and marketing our services.
This license does not transfer ownership of the content or any copyright to Flexcompute.
Users retain the right to withdraw their submissions at any time.
Upon request, Flexcompute will remove the content from its platform.
6. Privacy and Confidentiality
Users acknowledge that submitted content may be publicly accessible and therefore waive any
rights to confidentiality or privacy regarding the published material.
Flexcompute will not share personal information of users without
their consent, in accordance with our privacy policy.
Community Library
How the process works:
You submit your notebook.
You will get a permanent URL to promote your work.
Cite the URL as a reference for others in your upcoming papers to enhance the impact.
When someone clicks your URL, your notebook will be displayed.
Enter your email address below to receive the presentation slides. In the future, we’ll share you very few emails when we have new tutorial release, development updates, valuable toolkits and technical guidance . You can unsubscribe at any time by clicking the link at the bottom of every email. We’ll never share your information.