optimization.variable.variable#
Variable Module
This module contains the Variable class for defining variables in an optical system for optimization. The Variable class serves as a wrapper around specific variable behaviors defined in separate modules.
Kramer Harrison, 2024
Classes
|
Represents a general variable in an optical system for optimization. |
- class Variable(optic, type_name, min_val=None, max_val=None, scaler: Scaler = None, **kwargs)[source]#
Represents a general variable in an optical system for optimization.
This class serves as a backend-agnostic abstraction for variables used in optical system optimization. It acts as a wrapper around specific variable behaviors defined in separate modules, and can be used with multiple optimization backends.
- Parameters:
optic (OpticalSystem) – The optical system to which the variable belongs.
type (str) – The type of the variable.
min_val (float or None) – The minimum value allowed for the variable. Defaults to None.
max_val (float or None) – The maximum value allowed for the variable. Defaults to None.
scaler (Scaler) – The scaler to use for the variable. Defaults to None, which will use the default scaler for the variable type.
**kwargs – Additional keyword arguments to be stored as attributes of the variable.
- Properties:
value: The current value of the variable. bounds: The bounds of the variable.
- Methods:
update (new_value) – Updates the variable to a new value.
- Raises:
ValueError – If an invalid variable type is provided.
- static allowed_attributes()[source]#
This method returns a set of strings that are the names of allowed attributes.
- property bounds#
Returns the bounds of the variable as a tuple.
- Returns:
the bounds of the variable
- Return type:
- update(new_value)[source]#
Update variable to a new value.
- Parameters:
new_value (float) – The new value with which to update the variable.
- Raises:
ValueError – If the variable type is invalid.
- property value#
Return the value of the variable.
- Returns:
The value of the variable.
- Return type:
- Raises:
ValueError – If the variable type is invalid.