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.

Parameters:
  • monitor (str) – Name of the monitor.

  • axis (int) – Direction of power flow (0=x, 1=y, 2=z).

  • freq_idx (int) – Which frequency index to use.

Return type:

PowerFlow

hyperwave_community.objectives.intensity(component, monitor, freq_idx=0)#

Field intensity |E_component|^2 summed over monitor.

Parameters:
  • component (str) – “Ex”, “Ey”, or “Ez”.

  • monitor (str) – Name of the monitor.

  • freq_idx (int) – Which frequency index to use.

Return type:

Intensity

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.

Parameters:
  • component (str) – “Ex”, “Ey”, “Ez”, “Hx”, “Hy”, or “Hz”.

  • monitor (str) – Name of the monitor.

  • freq_idx (int) – Which frequency index to use.

Return type:

FieldComponent

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.

Return type:

Tuple[dict, List[ndarray]]

Returns:

(spec, arrays) where spec is a nested dict with array references as integer indices, and arrays is the list of referenced arrays.

__neg__()#
Return type:

Objective

__add__(other)#
Return type:

Objective

__sub__(other)#
Return type:

Objective

__mul__(other)#
Return type:

Objective

__truediv__(other)#
Return type:

Objective

__pow__(other)#
Return type:

Objective