Objectives#
Composable, safe loss functions for inverse design. Objectives are expression trees built with operator overloading, serialized to JSON, and evaluated on the GPU with full JAX autodiff support. No user code runs on the GPU.
Constructors#
- hyperwave_community.objectives.mode_coupling(mode_field, input_power, mode_cross_power, monitor, axis=0, freq_idx=0)#
Mode coupling efficiency measurement.
- Parameters:
mode_field (
ndarray) – Reference mode field, shape (1, 6, …) or (n_freq, 6, …).input_power (
float) – Source input power for normalization.mode_cross_power (
float) – Mode self-overlap power.monitor (
str) – Name of the output monitor.axis (
int) – Propagation axis (0=x, 1=y, 2=z).freq_idx (
int) – Which frequency index to use.
- Return type:
ModeCoupling
- hyperwave_community.objectives.power(monitor, axis=0, freq_idx=0)#
Poynting vector power flow through a monitor plane.
- hyperwave_community.objectives.intensity(component, monitor, freq_idx=0)#
Field intensity |E_component|^2 summed over monitor.
- hyperwave_community.objectives.field(component, monitor, freq_idx=0)#
Raw field component at a monitor.
Returns the full spatial array, not a scalar. Combine with sum_spatial(), real(), conj(), etc. to build custom measurements.
- hyperwave_community.objectives.const(value)#
Scalar constant.
- Return type:
Const
Combinators#
- hyperwave_community.objectives.min_of(*terms)#
Minimum across multiple objectives (worst-case optimization).
- Return type:
MinOf
- hyperwave_community.objectives.max_of(*terms)#
Maximum across multiple objectives.
- Return type:
MaxOf
Math Operations#
- hyperwave_community.objectives.abs_val(x)#
Absolute value.
- Return type:
AbsVal
- hyperwave_community.objectives.log(x)#
Natural logarithm.
- Return type:
Log
- hyperwave_community.objectives.log10(x)#
Base-10 logarithm.
- Return type:
Log10
- hyperwave_community.objectives.sqrt(x)#
Square root.
- Return type:
Sqrt
- hyperwave_community.objectives.relu(x)#
max(0, x). Useful for penalty terms: relu(threshold - measurement).
- Return type:
Relu
- hyperwave_community.objectives.real(x)#
Real part of complex value.
- Return type:
Real
- hyperwave_community.objectives.imag(x)#
Imaginary part of complex value.
- Return type:
Imag
- hyperwave_community.objectives.conj(x)#
Complex conjugate.
- Return type:
Conj
Spatial Reductions#
- hyperwave_community.objectives.sum_spatial(x)#
Sum over all spatial dimensions, reducing to a scalar.
- Return type:
SumSpatial
- hyperwave_community.objectives.mean_spatial(x)#
Mean over all spatial dimensions, reducing to a scalar.
- Return type:
MeanSpatial
Base Class#
- class hyperwave_community.objectives.Objective#
Base class for objective expression tree nodes.
Nodes are either measurements (leaf nodes that read from simulation fields) or math operations (internal nodes that combine child nodes). The tree is pure data. Operator overloading builds the tree, nothing is computed until evaluate() is called on the server with JAX.
- serialize()#
Serialize to a JSON-safe spec dict and a list of numpy arrays.