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.
BaseFomprovides 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_results
FieldResultsorPortResultsorlistofthose One or more monitor result objects whose extracted values are passed (in order) as positional arguments to
fct. All objects must beFieldResultsorPortResults.- fct
callable() Scalar-valued function of the monitor results. Its positional arguments must correspond one-to-one with the elements of
sim_resultsas supplied. The function body must useautograd.numpyoperations so thatautograd.jacobiancan differentiate it. Subclasses supply a type-appropriate default when the user does not specify one.
- sim_results
- Attributes:
- fct
callable() Wrapped version of the user-supplied function (accepts a single tuple/list argument for compatibility with
autograd.jacobian).- config_map
ConfigMap Organises the simulation results into per-config groups and stores forward/adjoint filenames.
- scaling_factor
floatorNone Physical pre-factor applied to the adjoint gradient fields. Computed and cached on the first call to
get_scaling_factor().
- fct
- Raises:
ValueErrorIf any element of
sim_resultsis not aFieldResultsorPortResultsinstance.ValueErrorIf
fctis not callable.
Methods
BaseFom.calculate_fom(fdtd_session)Compute the figure of merit using the user-defined function and monitor results.
Compute the gradient of the FOM with respect to permittivity using adjoint fields.
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
Whether forward and adjoint simulations can be run concurrently.