bag3_testbenches.design.optimize.fun
This module defines special interpolation function classes that are used for the optimization based design flow.
Module Contents
Classes
A mixin class that creates constraints in a dictionary format compatible with |
|
A DiffFunction that supports optimization constraints and argument mapping. |
|
An ArgMapFunction that supports input (de-)normalization. |
|
An interpolating function that takes in multiple sub-functions and computes a vector. |
|
A CustomVectorArgMapFunction that performs vector reduction. |
Functions
|
A helper function for de-normalizing an input element. |
|
A helper function for normalizing an input element. |
|
A helper function for de-normalizing an input vector. |
|
A helper function for normalizing an input vector. |
- class bag3_testbenches.design.optimize.fun.ConstraintMixin[source]
A mixin class that creates constraints in a dictionary format compatible with scipy.optimize.minimize’s constraints parameter.
It is meant to be used in multiple inheritance with DiffFunction.
- __eq__(other: Union[float, int, bag.math.dfun.DiffFunction]) Dict[str, Any] [source]
Return self==value.
- __ge__(other: Union[float, int, bag.math.dfun.DiffFunction]) Dict[str, Any] [source]
Return self>=value.
- __le__(other: Union[float, int, bag.math.dfun.DiffFunction]) Dict[str, Any] [source]
Return self<=value.
- class bag3_testbenches.design.optimize.fun.ArgMapFunction(fn: bag.math.dfun.DiffFunction, idx_map: Optional[Dict[int, int]] = None, fixed_vals: Optional[Dict[int, Union[int, float]]] = None, input_bounds: Optional[Dict[int, Tuple[Optional[Union[int, float]], Optional[Union[int, float]]]]] = None)[source]
Bases:
ConstraintMixin
,bag.math.dfun.DiffFunction
A DiffFunction that supports optimization constraints and argument mapping.
- Parameters:
fn (DiffFunction) – the inner/parent function.
idx_map (Optional[Dict[int, int]]) – the dictionary mapping the inner function’s argument indices to outer argument indices. Defaults to None.
fixed_vals (Optional[Dict[int, Union[int, float]]]) – the dictionary mapping the inner function’s argument indices to their fixed values. Defaults to None.
input_bounds (Optional[Dict[int, Tuple[Optional[Union[int, float]], Optional[Union[int, float]]]]]) – the dictionary mapping the inner function’s argument indices to their new bounds/ranges. These bounds are intersected with the inner function’s input ranges to get the new input ranges. Defaults to None.
- _get_args(xi: numpy.ndarray) numpy.ndarray [source]
Applies argument mapping.
- Parameters:
xi (np.ndarray) – The input coordinates, with shape (…, ndim)
- Returns:
new_xi – The output coordinates, with shape (…, inner_ndim).
- Return type:
np.ndarray
- __call__(xi: numpy.ndarray) numpy.ndarray [source]
Interpolate at the given coordinates.
Numpy broadcasting rules apply.
- Parameters:
xi (array_like) – The coordinates to evaluate, with shape (…, ndim)
- Returns:
val – The interpolated values at the given coordinates.
- Return type:
np.multiarray.ndarray
- deriv(xi: numpy.ndarray, j: int) numpy.ndarray [source]
Calculate the derivative at the given coordinates with respect to input j.
Numpy broadcasting rules apply.
- Parameters:
xi (array_like) – The coordinates to evaluate, with shape (…, ndim)
j (int) – input index.
- Returns:
val – The derivatives at the given coordinates.
- Return type:
np.multiarray.ndarray
- jacobian(xi: numpy.ndarray) numpy.ndarray [source]
Calculate the Jacobian at the given coordinates.
Numpy broadcasting rules apply.
If finite difference step sizes are not specified, will call deriv() in a for loop to compute the Jacobian.
- Parameters:
xi (array_like) – The coordinates to evaluate, with shape (…, ndim)
- Returns:
val – The Jacobian matrices at the given coordinates.
- Return type:
np.multiarray.ndarray
- class bag3_testbenches.design.optimize.fun.ArgMapNormFunction(fn: bag.math.dfun.DiffFunction, idx_map: Optional[Dict[int, int]] = None, fixed_vals: Optional[Dict[int, Union[int, float]]] = None, input_bounds: Optional[Dict[int, Tuple[Optional[Union[int, float]], Optional[Union[int, float]]]]] = None)[source]
Bases:
ArgMapFunction
An ArgMapFunction that supports input (de-)normalization. Optimizers are sensitive to the input range.
- Parameters:
fn (DiffFunction) – the inner function.
idx_map (Optional[Dict[int, int]]) – the dictionary mapping the inner function’s argument indices to outer argument indices. Defaults to None.
fixed_vals (Optional[Dict[int, Union[int, float]]]) – the dictionary mapping the inner function’s argument indices to their fixed values. Defaults to None.
input_bounds (Optional[Dict[int, Tuple[Optional[Union[int, float]], Optional[Union[int, float]]]]]) – the dictionary mapping the inner function’s argument indices to their new bounds/ranges. These bounds are intersected with the inner function’s input ranges to get the new input ranges. Defaults to None.
- property input_ranges_norm: List[Tuple[Optional[float], Optional[float]]][source]
Return the normalized input ranges.
- denorm_inner_input_elem(val: Union[float, numpy.ndarray], idx: int) numpy.ndarray [source]
De-normalizes the inner function’s input element.
- norm_inner_input_elem(val: Union[float, numpy.ndarray], idx: int) numpy.ndarray [source]
Normalizes the inner function’s input element.
- denorm_inner_input(val: numpy.ndarray) numpy.ndarray [source]
De-normalizes the inner function’s input vector.
- Parameters:
val (np.ndarray) – the inner function’s input vector to de-normalize
- Returns:
ans – The de-normalized inner function’s input vector.
- Return type:
np.ndarray
- norm_inner_input(val: numpy.ndarray) numpy.ndarray [source]
Normalizes the inner function’s input vector.
- Parameters:
val (np.ndarray) – the inner function’s input vector to normalize
- Returns:
ans – The normalized inner function’s input vector.
- Return type:
np.ndarray
- denorm_input_elem(val: Union[float, numpy.ndarray], idx: int) numpy.ndarray [source]
De-normalizes the input element.
- norm_input_elem(val: Union[float, numpy.ndarray], idx: int) numpy.ndarray [source]
Normalizes the input element.
- denorm_input(val: numpy.ndarray) numpy.ndarray [source]
De-normalizes the input vector.
- Parameters:
val (np.ndarray) – the input vector to de-normalize
- Returns:
ans – The de-normalized input vector.
- Return type:
np.ndarray
- norm_input(val: numpy.ndarray) numpy.ndarray [source]
Normalizes the input vector.
- Parameters:
val (np.ndarray) – the input vector to normalize
- Returns:
ans – The normalized input vector.
- Return type:
np.ndarray
- _get_args(xi: numpy.ndarray, is_norm_input: bool = True)[source]
Applies argument mapping and applies de-normalization (if applicable).
- Parameters:
xi (np.ndarray) – The input coordinates, with shape (…, ndim)
is_norm_input (bool) – True if the input is normalized. Default is True.
- Returns:
new_xi – The output coordinates, with shape (…, inner_ndim).
- Return type:
np.ndarray
- __call__(xi: numpy.ndarray, is_norm_input: bool = True) numpy.ndarray [source]
Interpolate at the given coordinates.
Numpy broadcasting rules apply.
- Parameters:
xi (array_like) – The coordinates to evaluate, with shape (…, ndim)
- Returns:
val – The interpolated values at the given coordinates.
- Return type:
np.multiarray.ndarray
- abstract deriv(xi: numpy.ndarray, j: int) numpy.ndarray [source]
Calculate the derivative at the given coordinates with respect to input j.
Numpy broadcasting rules apply.
- Parameters:
xi (array_like) – The coordinates to evaluate, with shape (…, ndim)
j (int) – input index.
- Returns:
val – The derivatives at the given coordinates.
- Return type:
np.multiarray.ndarray
- abstract jacobian(xi: numpy.ndarray) numpy.ndarray [source]
Calculate the Jacobian at the given coordinates.
Numpy broadcasting rules apply.
If finite difference step sizes are not specified, will call deriv() in a for loop to compute the Jacobian.
- Parameters:
xi (array_like) – The coordinates to evaluate, with shape (…, ndim)
- Returns:
val – The Jacobian matrices at the given coordinates.
- Return type:
np.multiarray.ndarray
- class bag3_testbenches.design.optimize.fun.CustomVectorArgMapFunction(fn_list: List[bag.math.dfun.DiffFunction], indep_idx_list: Optional[List[int]] = None, fixed_vals: Optional[Dict[int, Union[int, float, List[Union[int, float]], numpy.ndarray]]] = None, input_bounds: Optional[Dict[int, Tuple[Optional[Union[int, float]], Optional[Union[int, float]]]]] = None)[source]
Bases:
object
An interpolating function that takes in multiple sub-functions and computes a vector.
- Parameters:
fn_list (List[DiffFunction]) – the list of sub-functions. All sub-functions must have the same dimensions and input ranges.
indep_idx_list (Optional[List[int]]) – the list of sub-function’s argument indices for which the input value can be independently set per sub-function. Defaults to None.
fixed_vals (Optional[Dict[int, Union[int, float, List[Union[int, float]], np.ndarray]]]) – the dictionary mapping the sub-function’s argument indices to their fixed values. Defaults to None.
input_bounds (Optional[Dict[int, Tuple[Optional[Union[int, float]], Optional[Union[int, float]]]]]) – the dictionary mapping the sub-function’s argument indices to their new bounds/ranges. These bounds are intersected with the sub-function’s input ranges to get the new input ranges. Defaults to None.
- property input_ranges: List[Tuple[Optional[float], Optional[float]]][source]
Returns the list of input ranges.
- property input_ranges_norm: List[Tuple[Optional[float], Optional[float]]][source]
Returns the list of normalized input ranges.
- unmap_input(xi: numpy.ndarray) List[Union[float, numpy.ndarray]] [source]
Unmaps the input.
- Parameters:
xi (np.ndarray) – The input coordinates.
- Returns:
rv – The unmapped coordinates.
- Return type:
List[Union[float, np.ndarray]]
- map_input(xi: List[Union[float, numpy.ndarray]]) numpy.ndarray [source]
Maps the input.
- Parameters:
xi (List[Union[float, np.ndarray]]) – The input coordinates.
- Returns:
rv – The mapped coordinates.
- Return type:
np.ndarray
- denorm_input_elem(val: Union[float, numpy.ndarray], idx: int) numpy.ndarray [source]
De-normalizes the input element.
- norm_input_elem(val: Union[float, numpy.ndarray], idx: int) numpy.ndarray [source]
Normalizes the input element.
- denorm_input(val: numpy.ndarray) numpy.ndarray [source]
De-normalizes the input vector.
- Parameters:
val (np.ndarray) – the input vector to de-normalize
- Returns:
ans – The de-normalized input vector.
- Return type:
np.ndarray
- norm_input(val: numpy.ndarray) numpy.ndarray [source]
Normalizes the input vector.
- Parameters:
val (np.ndarray) – the input vector to normalize
- Returns:
ans – The normalized input vector.
- Return type:
np.ndarray
- class bag3_testbenches.design.optimize.fun.CustomVectorReduceArgMapFunction(*args, reduce_fn: Callable)[source]
Bases:
CustomVectorArgMapFunction
A CustomVectorArgMapFunction that performs vector reduction.
- Parameters:
parameters. (Refer to CustomVectorArgMapFunction for the shared) –
reduce_fn (Callable) – the reduction function.
- bag3_testbenches.design.optimize.fun._denorm_input_elem_helper(val: Union[float, numpy.ndarray], idx: int, offset_list: numpy.ndarray, spacing_list: numpy.ndarray) Union[float, numpy.ndarray] [source]
A helper function for de-normalizing an input element.
- bag3_testbenches.design.optimize.fun._norm_input_elem_helper(val: Union[float, numpy.ndarray], idx: int, offset_list: numpy.ndarray, spacing_list: numpy.ndarray) Union[float, numpy.ndarray] [source]
A helper function for normalizing an input element.
- bag3_testbenches.design.optimize.fun._denorm_input_helper(val: numpy.ndarray, offset_list: numpy.ndarray, spacing_list: numpy.ndarray) numpy.ndarray [source]
A helper function for de-normalizing an input vector.
- Parameters:
val (np.ndarray) – the input vector to de-normalize
offset_list (np.ndarray) – the offset list
spacing_list (np.ndarray) – the spacing list
- Returns:
ans – The de-normalized input vector.
- Return type:
np.ndarray
- bag3_testbenches.design.optimize.fun._norm_input_helper(val: numpy.ndarray, offset_list: numpy.ndarray, spacing_list: numpy.ndarray) numpy.ndarray [source]
A helper function for normalizing an input vector.
- Parameters:
val (np.ndarray) – the input vector to normalize
offset_list (np.ndarray) – the offset list
spacing_list (np.ndarray) – the spacing list
- Returns:
ans – The normalized input vector.
- Return type:
np.ndarray