LumOpt

repository·release·Indexed 42 days ago

https://github.com/chriskeraly/lumopt

A Python library for adjoint optimization of Lumerical simulations. It provides tools to automate the optimization of photonic structures using custom geometries, figures of merit like ModeMatch, and various optimizers including ScipyOptimizers, FixedStepGradientDescent, and AdaptiveGradientDescent.

Tokens
1.5K
Snippets
5
Records
12
Agent score
53%

What's inside LumOpt

  1. Understand the LumOpt optimization workflow

    release

    The LumOpt optimization process follows a specific three-step philosophy:

    1. Lumerical Setup Script: Provide a .lsf script that builds the base simulation. This script must contain everything required for the simulation except for the optimizable geometry.
    2. Python Definition: In a Python script, use LumOpt classes to define:
      • An optimizable geometry (the shape to be changed).
      • A Figure of Merit (the objective function to optimize).
      • An Optimization algorithm.
    3. Execution: The optimization engine will then inject the geometry into the Lumerical simulation and run the adjoint iterations.
  2. Install LumOpt

    release

    LumOpt requires Python 3 and the latest version of Lumerical. To install, clone the repository and run the setup script in development mode.

    Note: You must manually add the Lumerical API lumapi to your Python path for the library to function correctly.

    git clone https://github.com/chriskeraly/LumOpt.git
    python setup.py -develop
  3. Configure Lumerical base simulation requirements

    release

    To ensure the adjoint optimization runs correctly, your Lumerical setup script (.lsf) must adhere to these three requirements:

    • Sources: All simulation sources MUST have the string 'source' in their name. LumOpt identifies and deletes classic forward simulation sources to run the adjoint simulation; if a source lacks this keyword, the optimization will likely fail.
    • Optimization Field Monitor: You must include a field monitor named 'opt_fields'. This monitor must cover the entire spatial region where the optimizable geometry might move or expand. If the geometry exceeds this monitor's bounds during optimization, the process will crash. (Note: Be cautious with splines, as they can extend beyond their knots).
    • Mesh: A mesh refinement region must be placed over the same region covered by the 'opt_fields' monitor. This ensures the mesh remains static during optimization; changing the mesh during the process will cause a crash.
  4. Perform co-optimization using the + operator

    release

    LumOpt supports co-optimization by using the + operator between two optimization objects that share the same parameters. This is useful for multi-objective or robust optimization (e.g., optimizing for multiple wavelengths or ensuring performance is stable despite geometric biases).

    For example, to optimize a coupler for robustness, you can sum the Figure of Merit (FoM) of the nominal geometry with the FoM of a geometry containing a 25nm bias.

    # Example concept: Co-optimizing for robustness
    # (Referencing the pattern in examples/Ysplitter/robust_coupler.py)
    
    # Optimization for nominal geometry + Optimization for biased geometry
    robust_optimization = nominal_opt + biased_opt
  5. Run a prebuilt 2D Silicon Photonics Waveguide Y-branch optimization

    release

    You can run existing optimization examples to verify your installation. There are two primary ways to do this:

    1. Jupyter Notebook (Recommended): Copy the contents of examples/splitter/splitter_opt.py into a notebook cell. This allows for detailed inspection and debugging of results.
    2. Terminal/IDE: Navigate to the example directory and run the script directly.

    If the installation is successful, Lumerical windows will open automatically during the process.

    cd examples/splitter
    python splitter_opt_2D.py
  6. Use the ModeMatch figure of merit

    release

    The ModeMatch class is a figure of merit (FoM) used to quantify how well two optical modes match each other. It is located in the lumopt.figures_of_merit.modematch module. This is typically used in optimization tasks where the goal is to maximize or minimize the overlap between a source mode and a target mode.

    from lumopt.figures_of_merit.modematch import ModeMatch
    
    # Example initialization (exact parameters depend on implementation)
    fom = ModeMatch(...)
  7. Use AdaptiveGradientDescent for optimization

    release
    The lumopt.optimizers.adaptive_gradient_descent.AdaptiveGradientDescent class implements a gradient descent algorithm that automatically adjusts the step size during the optimization process, typically to improve convergence speed and stability.
  8. Use ScipyOptimizers for generic optimization

    release
    The lumopt.optimizers.generic_optimizers.ScipyOptimizers class provides a wrapper around various optimization algorithms available in the SciPy library. This allows you to leverage standard SciPy solvers within the LumOpt framework.
  9. Use the Material class for optimization

    release

    The lumopt.utilities.materials.Material class is used to define material properties for optimization tasks within LumOpt. It serves as a container for material-related parameters that can be passed to Lumerical simulations.

    from lumopt.utilities.materials import Material
    
    # Example instantiation (exact parameters depend on the Material implementation)
    material = Material()
  10. Create a Function-Defined Polygon geometry

    release
    Use the lumopt.geometries.polygon.FunctionDefinedPolygon class to define a polygon whose shape is determined by a mathematical function. This is useful for geometries where the boundary follows a specific functional form rather than a set of discrete vertices.