BaseFom#

class lumopt2.fom.base_fom.BaseFom(sim_results: str | list, fct: callable)#

Base class for figure of merit (FOM) calculation driven by user-defined functions and simulation monitors.

BaseFom provides shared FOM infrastructure including constructor validation, result loading, Jacobian computation, and gradient field assembly. Subclasses (FieldFom, PortFom) specialize the adjoint setup and adjoint field extraction for different monitor types.

Parameters:
sim_resultsFieldResults or PortResults or list of those

One or more monitor result objects whose extracted values are passed (in order) as positional arguments to fct. All objects must be FieldResults or PortResults.

fctcallable()

Scalar-valued function of the monitor results. Its positional arguments must correspond one-to-one with the elements of sim_results as supplied. The function body must use autograd.numpy operations so that autograd.jacobian can differentiate it. Subclasses supply a type-appropriate default when the user does not specify one.

Attributes:
fctcallable()

Wrapped version of the user-supplied function (accepts a single tuple/list argument for compatibility with autograd.jacobian).

config_mapConfigMap

Organises the simulation results into per-config groups and stores forward/adjoint filenames.

scaling_factorfloat or None

Physical pre-factor applied to the adjoint gradient fields. Computed and cached on the first call to get_scaling_factor().

Raises:
ValueError

If any element of sim_results is not a FieldResults or PortResults instance.

ValueError

If fct is not callable.

Methods

BaseFom.calculate_fom(fdtd_session)

Compute the figure of merit using the user-defined function and monitor results.

BaseFom.calculate_gradient_fields(...)

Compute the gradient of the FOM with respect to permittivity using adjoint fields.

BaseFom.create_project_folder()

Create the project folder based on the project name in the config map.

BaseFom.get_adjoint_fields(fdtd_session, entry)

Apply necessary scaling to the adjoint simulation fields.

BaseFom.get_jacobian(fdtd_session)

Compute the Jacobian of the FOM with respect to monitor result values.

BaseFom.get_scaling_factor(fdtd_session, ...)

Compute and cache a scaling factor for the adjoint gradient.

BaseFom.set_project_name(project_name)

Set the project name used to determine the simulation output folder.

Attributes

BaseFom.supports_concurrent_adjoint

Whether forward and adjoint simulations can be run concurrently.