kaira.constraints.utils.verify_constraint

kaira.constraints.utils.verify_constraint(constraint: BaseConstraint, input_tensor: Tensor, expected_property: str, expected_value: float, tolerance: float = 1e-05) Dict[str, Any][source]

Verify that a constraint produces the expected property in the output.

Tests whether applying a constraint to a tensor results in the expected property (such as power or PAPR) within a specified tolerance.

Parameters:
  • constraint (BaseConstraint) – Constraint to test

  • input_tensor (torch.Tensor) – Input tensor to pass through the constraint

  • expected_property (str) – Name of the property to check. Valid values: ‘power’, ‘papr’, ‘amplitude’

  • expected_value (float) – Expected value for the property in linear units

  • tolerance (float, optional) – Tolerance for numerical comparison. Defaults to 1e-5.

Returns:

Results dictionary containing:
  • input_shape: Shape of the input tensor

  • output_shape: Shape of the constrained output

  • success: Whether the constraint achieved the expected property

  • measured_<property>: Actual measured value of the property

  • expected_<property>: Expected value of the property

Return type:

Dict[str, Any]

Raises:

ValueError – If expected_property is not one of the supported values

Example

>>> power_constraint = TotalPowerConstraint(1.0)
>>> input_signal = torch.randn(8, 64)
>>> result = verify_constraint(power_constraint, input_signal, 'power', 1.0)
>>> print(f"Constraint satisfied: {result['success']}")