finite_difference_gradient#

lumopt2.utils.fd_grad.finite_difference_gradient(project: Project, params: List[float] | ndarray, indices: List[int], perturbation: float = 0.01) ndarray#

Compute the gradient of the figure of merit using finite difference.

All perturbed simulations are independent and are queued together then run concurrently, rather than executed one at a time.

Parameters:
projectlumopt2.Project

Project instance for which the gradient is computed.

paramsUnion[List, np.ndarray]

Optimization parameters to update geometry with before computing FOM.

indicesList[int]

List of parameter indices to compute the finite difference gradient for.

perturbationfloat, optional

Small perturbation value (default: 1e-2).

Returns:
np.ndarray

Array of computed finite difference gradient values corresponding to the provided indices.

Raises:
ValueError

If input types are invalid or project is not a lumopt2.Project instance.