Constraint Modules¶
Base Classes¶
fdtdx.constraints.module.ConstraintInterface
¶
Bases: ExtendedTreeClass
Interface specification for constraint module inputs/outputs.
Defines the type and shapes of arrays that a constraint module accepts or produces.
Attributes:
Name | Type | Description |
---|---|---|
type |
Literal['latent', 'index', 'inv_permittivity']
|
The type of constraint interface - one of: - "latent": Raw latent parameters - "index": Discrete material indices - "inv_permittivity": Inverse permittivity values |
shapes |
dict[str, tuple[int, ...]]
|
Dictionary mapping array names to their expected shapes |
Source code in src/fdtdx/constraints/module.py
fdtdx.constraints.module.ConstraintModule
¶
Bases: ExtendedTreeClass
, ABC
Abstract base class for constraint modules.
Constraint modules transform parameters between different representations while enforcing physical and fabrication constraints. They form a chain of transformations from latent parameters to final inverse permittivity values.
Attributes:
Name | Type | Description |
---|---|---|
_permittivity_config |
dict[str, float]
|
Dictionary mapping material names to permittivity values |
_config |
SimulationConfig
|
Global simulation configuration |
_output_interface |
ConstraintInterface
|
Interface specification for module outputs |
_input_interface |
ConstraintInterface
|
Interface specification for module inputs |
Source code in src/fdtdx/constraints/module.py
Value Range Transformations¶
fdtdx.constraints.module.StandardToInversePermittivityRange
¶
Bases: ConstraintModule
Maps standard [0,1] range to inverse permittivity range.
Linearly maps values from [0,1] to the range between minimum and maximum inverse permittivity values allowed by the material configuration.
Source code in src/fdtdx/constraints/module.py
fdtdx.constraints.module.StandardToCustomRange
¶
Bases: ConstraintModule
Maps standard [0,1] range to custom range [min_value, max_value].
Linearly maps values from [0,1] to a custom range specified by min_value and max_value parameters.
Attributes:
Name | Type | Description |
---|---|---|
min_value |
float
|
Minimum value of target range |
max_value |
float
|
Maximum value of target range |
Source code in src/fdtdx/constraints/module.py
fdtdx.constraints.module.StandardToPlusOneMinusOneRange
¶
Bases: StandardToCustomRange
Maps standard [0,1] range to [-1,1] range.
Special case of StandardToCustomRange that maps to [-1,1] range. Used for symmetric value ranges around zero.
Attributes:
Name | Type | Description |
---|---|---|
min_value |
float
|
Fixed to -1 |
max_value |
float
|
Fixed to 1 |
Source code in src/fdtdx/constraints/module.py
Material Index Transformations¶
fdtdx.constraints.module.ClosestIndex
¶
Bases: ConstraintModule
Maps continuous values to nearest allowed material indices.
For each input value, finds the index of the closest allowed inverse permittivity value. Uses straight-through gradient estimation to maintain differentiability.
Source code in src/fdtdx/constraints/module.py
fdtdx.constraints.module.IndicesToInversePermittivities
¶
Bases: ConstraintModule
Maps material indices to their inverse permittivity values.
Converts discrete material indices into their corresponding inverse permittivity values from the allowed materials list. Uses straight-through gradient estimation to maintain differentiability.