Optimization session in lumopt2#
The optimization session is the main interface for setting up and running a lumopt2 optimization.
Its key input is the optimization Project, which defines the base simulation, parameterization, and figure of merit. You can also use the session inputs to choose the optimizer and specify what data is reported during and after the optimization.
This article describes the overall optimization workflow in lumopt2 through the optimization session, and includes links to detailed guides for each of the component.
Note
For installation and getting started information, see the introduction article.
Overview#
The overall workflow for running an inverse design problem is shown in the diagram below, with subsequent subsections describing in further detail each of the components.
.fsp, .lsf, .py
lumopt2.Parametrization lumopt2.ClosedCurve
lumopt2.Fom
lumopt2.FdtdSession
lumopt2.LocalRunner
lumopt2.Project
lumopt2.ScipyOptimizer
lumopt2.GraphicalVisualizer lumopt2.FileLogger
Optimization.store_all_simulations Optimization.log_profiling_summary
lumopt2.Optimization
Optimization.run()
Project#
The project object, Project, defines the optimization problem by combining the following elements:
Base simulation (
Project.setup): configures the simulation objects, such as sources and monitors, required to run the FDTD simulations.Parametrization (
Project.parametrization): defines the optimization parameters in terms of how they modify the simulated structure.Figure of merit (
Project.fom): defines the objective function to evaluate for the optimization.FDTD session (
Project.fdtd_session): manages the session running FDTD simulations.Runner (
Project.runner): sets up the computational resources for running the optimization.
Base simulation#
The base simulation file defines the FDTD project to optimize, including the necessary geometry, sources, and monitors.
You can set up the base simulation file using an existing .fsp project file, a .lsf Lumerical script file, or a Python function.
Further information, such as the requirements on simulation object, is in the base simulation article.
Parametrization#
The parametrization defines how geometric parameters in the simulation maps to optimization parameters in lumopt2.
The lumopt2 module currently supports two different types of parametrization strategies:
Parametric optimization (
Parametrization): maps arbitrary Lumerical object properties as parameters.Closed curve optimization (
ClosedCurve): defines a closed curve formed by linear and cubic segments, typically used for photonic integrated circuit applications..
Further information for each parametrization strategy is in the parametrization article.
Figure of merit#
The figure of merit defines the objective function that the optimization evaluates at each iteration.
You can define a figure of merit based on simulation results from specific simulation objects, using the Fom() function.
lumopt2 supports field intensity results from field region objects, and results from port objects.
For further information on setting up the figure of merit from simulation results, see the figure of merit article.
FDTD session#
The FDTD session is a handler class that defines a connection to the Ansys Lumerical FDTD™ software.
The session created using FdtdSession is automatically handled by the lumopt2 module.
The GUI window is disabled by default, you can define a session with the GUI enabled using the following code.
1fdtd_session = lmpt.FdtdSession(show_fdtd_cad = True)
Runner#
The runner is responsible for managing the computational resources for running the optimization.
lumopt2 currently supports local runners for CPU and GPU optimization, defined through LocalRunner.
The runner uses the first GPU or CPU resource enabled in the FDTD resource manager list, depending on the specified type.
To set up a local runner, use the following code.
1runner_gpu = lmpt.LocalRunner(resource = 'GPU') # GPU Runner
2runner_cpu = lmpt.LocalRunner(resource = 'CPU') # CPU Runner
For further information on resource configuration and GPU simulation, please visit the following Knowledge Base pages.
Optimizer#
The optimizer defines the optimization algorithm for solving the inverse design problem.
In lumopt2, you can define an optimizer using the built-in scipy_optimizer class.
You can use the following code to set up a basic optimizer with default settings.
1optimizer = lmpt.ScipyOptimizer()
By default, the optimizer uses the gradient-based L-BFGS-B method. This method is well-suited for inverse design because of its excellent memory efficiency for high-dimensional problems, ability to naturally handle bounds, efficient usage of gradient information, and quick convergence for smooth objective functions.
In addition to the default option, you can choose any optimization algorithm supported by the scipy.optimize.minimize function. For any gradient-free methods, lumopt2 automatically skips the adjoint simulation step.
Tip
Some optimizer parameters, such as ftol, gtol, and max_fval, are exposed directly in the scipy_optimizer class and passed to the underlying optimizer when supported.
The options dictionary enables you to pass any other parameters to the selected optimizer.
Callbacks#
Callbacks are functions that are executed at specific points during the optimization process. You can use callbacks for logging and visualization during the optimization.
lumopt2 includes a built-in graphical visualizer class, GraphicalVisualizer, which you can further customize with panels to plot results from specific monitors.
You can also set up logging using classes including FileLogger.
For further information on configuring callbacks and on when they are triggered, see the callbacks article.
Additional configurations#
There are two additional useful flags in the Optimization class configuration:
Optimization.store_all_simulations: stores all simulations on diskOptimization.log_profiling_summary: controls whether wall-clock profiling is a part of the standard log
Running the optimization#
After configuring the optimization session, run the optimization using
1Optimization.run()
Optimization results#
The Optimization.run() method returns a tuple, where the first element is the best optimization parameter set, and the second element is the best figure of merit value.
You can export the optimization results in your preferred method, or recreate an FDTD project file using the optimal parameters with the Project.save_project() method for further processing and export for fabrication.
1best_params, best_fom = result
2project.save_project("L_bend_optimization_final.fsp",params=best_params)
Tip
See the Lumerical Knowledge Base article Importing and exporting GDSII files for more information on exporting a GDS file from the final project.
Diagnostics#
The lumopt2 module also includes a set of functions for gradients that are useful for diagnostics:
finite_difference_gradient(): Computes the finite difference gradient for a figure of merit.validate_gradient(): Validates the adjoint gradient by comparing it to a finite difference gradient for given parameter indices.fd_sweep_perturbation(): Conducts a finite difference convergence test for a range of perturbation values and plots the results.