optimization.operand.operand

Operand Module

This module defines various operands to be used during lens optimization. These include paraxial, real ray, aberrations, wavefront, spot size, and many other operand types.

In general, to use one of these operands in optimization, you can simply do the following:

  1. Identify the key in the METRIC_DICT variable, or add your new operand.

  2. Identify the input data dictionary that is required for the calculation of this operand.

  3. Add the operand to your optimization.OptimizationProblem instance using the add_operand method. Include the operand type, target, weight, and the input data (in dict format). See examples.

Kramer Harrison, 2024

Classes

Operand([operand_type, target, min_val, ...])

Represents an operand used in optimization calculations.

OperandRegistry()

A registry to manage operand functions.

class Operand(operand_type: str = None, target: float = None, min_val: float = None, max_val: float = None, weight: float = None, input_data: dict = None)[source]

Represents an operand used in optimization calculations. If no target is specified, a default is created at the current value.

operand_type

The type of the operand.

Type:

str

target

The target value of the operand (equality operand).

Type:

float

min_val

The operand should stay above this value (inequality operand).

Type:

float

max_val

The operand should stay below this value (inequality operand).

Type:

float

weight

The weight of the operand.

Type:

float

input_data

Additional input data for the operand.

Type:

dict

value()

Get the current value of the operand.

delta_target()[source]

Calculate the difference between the value and target.

delta_ineq()[source]

Calculate the difference between the value and targets.

fun()[source]

Calculate the objective function value.

delta()[source]

Calculate the difference to target

delta_ineq()[source]

Calculate the difference between the value and bounds.

If the value is within the bound(s), then this operand simply is zero. Otherwise, it is the distance to the closest bound.

delta_target()[source]

Calculate the difference between the value and target

effective_weight(optic=None) float[source]

Return the total scaling factor this operand contributes.

This is operand.weight × field_weight × wavelength_weight, where field and wavelength weights come from the optic’s current field/wavelength definitions. If the operand references a field or wavelength index, the corresponding weight is looked up from the optic. User-specified raw coordinates default to weight=1.0.

The optic is resolved in the following order:

  1. The optic argument (if provided).

  2. self.input_data["optic"] (the standard operand convention).

  3. Falls back to field_w = wl_w = 1.0 when no optic is available.

Parameters:

optic – The optic this operand will be evaluated against. If None, the optic is read from self.input_data.

Returns:

The effective scalar multiplier for this operand’s contribution.

fun()[source]

Calculate the objective function value

input_data: dict = None
max_val: float = None
min_val: float = None
operand_type: str = None
target: float = None
property value

Get current value of the operand

weight: float = None
class OperandRegistry[source]

A registry to manage operand functions. This class allows you to register functions with specific operand names, retrieve them, and check if an operand name is registered.

_registry

A dictionary to store operand names and their associated functions.

Type:

dict

register(name, func)[source]

Register a function with a specified operand name.

get(name)[source]

Retrieve the function associated with an operand name.

__contains__(name)[source]

Check if an operand name is registered.

__repr__()[source]

Return a string representation of the OperandRegistry.

get(name)[source]

Retrieve the function associated with an operand name.

Parameters:

name (str) – The name of the operand.

register(name, func, overwrite=False)[source]

Register a function with a specified operand name.

Parameters:
  • name (str) – The name of the operand.

  • func (function) – The function to be registered.

  • overwrite (bool) – Whether to overwrite an existing registration.

Example

>>> def my_operand(optic, surface_number):
...     return optic.surfaces[surface_number].geometry.radius
>>> operand_registry.register("my_radius", my_operand)
>>> # Now usable in OptimizationProblem:
>>> # problem.add_operand("my_radius", target=10.0, input_data={...})