tidy3d.plugins.autograd.utilities.scalar_objective

Contents

tidy3d.plugins.autograd.utilities.scalar_objective#

class scalar_objective[source]#

Bases:

Decorator to ensure the objective function returns a real scalar value.

This decorator wraps an objective function to ensure that its return value is a real scalar. If the function returns auxiliary data, it expects the return value to be a tuple of the form (result, aux_data).

Parameters:
  • func (Callable, optional) – The objective function to be decorated. If not provided, the decorator should be used with arguments.

  • has_aux (bool = False) – If True, expects the function to return a tuple (result, aux_data).

Returns:

The wrapped function that ensures a real scalar return value. If has_aux is True, the wrapped function returns a tuple (result, aux_data).

Return type:

Callable

Raises:

Tidy3dError – If the return value is not a real scalar, or if has_aux is True and the function does not return a tuple of length 2.

Inherited Common Usage