optimization.optimizer.scipy.glass_expert

Optiland Glass Expert Optimization Module

This module provides a class for defining and solving optimization problems that include categorical variables in the form of lens materials. For each glass variable, the goal is to choose the glass that yields the lowest merit function value. The glasses to choose from are specified in the form of a list of strings: glasses = [‘N-BK7’, ‘S-BSM22’, ‘LF5G19’, …]

The optimizer performs categorical optimization on glass variables encoded into their (n_d, V_d) properties. It systematically searches for better-performing glasses by exploring nearest neighbors in the material space, followed by continuous local refinement of lens parameters.

drpaprika, 2025

Classes

GlassExpert(problem)

Greedy nearest-neighbour glass substitution strategy inspired by CODE V's Glass Expert.

class GlassExpert(problem: OptimizationProblem)[source]

Greedy nearest-neighbour glass substitution strategy inspired by CODE V’s Glass Expert.

This optimizer performs categorical optimization on glass variables defined by their (n_d, V_d) properties. It systematically searches for better-performing glasses by exploring nearest neighbors in the material space, followed by continuous local refinement of lens parameters.

Overview of the algorithm:

  • Treat each glass choice as a discrete (categorical) variable and perform a fixed number of greedy passes.

  • First pass, for each variable:
    • Perform a broad search over the entire glass catalogue.

  • Second pass, for each variable:
    • Retrieve the num_neighbours nearest materials in (n_d, V_d) space

    • Perform a focused search around the current glass choices.

  • For every candidate glass:
    • Substitute it into the design.

    • Run a continuous local optimization to evaluate performance.

    • If the objective improves, keep the substitution; otherwise, roll back.

  • Finally, perform one more local-only optimization over all continuous variables to polish the solution.

explore_glasses(glass_variables: list[Variable], current_glass_variable: Variable, glasses: list) None[source]

Test a list of candidate glasses by performing local optimizations.

Saves the initial state, then for each candidate:
  • Updates the glass variable

  • Runs a continuous optimization to measure objective

  • Restores the previous state before the next trial

After all trials, restores the best-performing configuration.

global_exploration(glass_variables: list[Variable], pool_size: int) None[source]

Perform a broad search over the entire glass catalogue.

For each glass variable, downsample the material map to pool_size using K-Means clustering in the (n_d, V_d) space, and evaluate all glasses. This step ensures diverse initial sampling before focusing on nearest neighbours.

Parameters:
  • glass_variables (list[Variable]) – Glass variables to optimize.

  • pool_size (int) – Number of materials to keep after downsampling.

local_exploration(glass_variables: list[Variable], num_neighbours: int) None[source]

Perform a focused search around the current glass choices.

For each glass variable, identify its nearest num_neighbours in (n_d, V_d) space, then run explore_glass_list on those candidates. This refines selections made during global exploration.

Parameters:
  • glass_variables (list[Variable]) – Glass variables to refine.

  • num_neighbours (int) – Number of nearest neighbours to consider.

optimize(method: str | None = None, maxiter: int = 1000, disp: bool = True, tol: float = 0.001, callback: Callable | None = None, plot: bool = False) optimize.OptimizeResult

Optimize the problem using the specified parameters.

Parameters:
  • method (str, optional) – The optimization method to use. Default is chosen to be one of BFGS, L-BFGS-B, SLSQP, depending on whether contraints or bounds given. Follows scipy.optimize.minimize method.

  • maxiter (int, optional) – Maximum number of iterations. Default is 1000.

  • disp (bool, optional) – Whether to display optimization information. Default is True.

  • tol (float, optional) – Tolerance for convergence. Default is 1e-3.

  • callback (callable) – A callable called after each iteration.

  • plot – If True, update live plots during optimization.

Returns:

The optimization result.

Return type:

result (OptimizeResult)

run(num_neighbours: int = 7, maxiter: int = 1000, tol: float = 0.001, disp: bool = True, plot: bool = False, callback: Any = None, verbose: bool = True, plot_glass_map=False)[source]

Execute the full glass optimization workflow.

This includes:
  1. Global exploration of diverse materials.

  2. Local refinement around current selections.

  3. Final continuous optimization on remaining variables.

This method performs a greedy, cyclic optimization over all glass variables by iteratively substituting each one with its neighbors in refractive index (n_d) and Abbe number (V_d) space. For each neighbor, a local optimization is performed over the continuous variables only to evaluate merit. If a substitution improves the objective function, it is retained. After completing the greedy passes, a final local optimization is performed over all continuous variables only.

Args: num_neighbours (int, optional): Number of nearest neighbors to try

for each categorical variable during each pass. Default is 7.

maxiter (int, optional): Maximum number of iterations for each

local optimization run. Default is 1000.

tol (float, optional): Tolerance for convergence in local optimization.

Default is 1e-3.

disp (bool, optional): Whether to display internal messages from the optimizer.

Default is True.

plot: If True, update live plots during optimization. callback (callable, optional): Optional function called at each

iteration of the optimizer.

verbose (bool, optional): Whether to print informative messages

from this method. Default is True.

plot_glass_map (bool, optional): Wheter to plot the glass selection

on a (nd, vd) glass map. Default is False.

Returns:

Result of the final local optimization

containing fields such as: - x: optimized continuous variable values - fun: final objective function value - nfev: number of function evaluations, etc.

Return type:

result (OptimizeResult)

undo()

Undo the last optimization step.

vprint(*args, **kwargs)[source]