clamp

clamp(
poly: Poly,
bounds: tuple[float | None, float | None],
label: str = '',
*,
penalty_formulation: Literal['Default', 'IntegerVariable', 'RealVariable', 'Relaxation', 'LinearRelaxation', 'QuadraticRelaxation'] | PenaltyFormulation = PenaltyFormulation.Default,
) → Constraint
clamp(
array: PolyArray[_Dim],
bounds: tuple[float | None, float | None],
label: str = '',
*,
penalty_formulation: Literal['Default', 'IntegerVariable', 'RealVariable', 'Relaxation', 'LinearRelaxation', 'QuadraticRelaxation'] | PenaltyFormulation = PenaltyFormulation.Default,
axis: None = None,
) → Constraint
clamp(
array: PolyArray[Dim],
bounds: tuple[float | None, float | None],
label: str = '',
*,
penalty_formulation: Literal['Default', 'IntegerVariable', 'RealVariable', 'Relaxation', 'LinearRelaxation', 'QuadraticRelaxation'] | PenaltyFormulation = PenaltyFormulation.Default,
axis: int | tuple[int, ...],
) → Constraint | ConstraintList

Create a range constraint.

Constrain the expression to lie within bounds. (None, upper) is equivalent to less_equal(), (lower, None) to greater_equal(). For a single polynomial poly, constrain lower <= poly <= upper. For an array with axis=None (default), constrain the sum of all elements of array to lie within bounds, returning a single Constraint. For an array with axis specified, reduce along the given axis or axes. Return a Constraint if all axes are reduced, or a ConstraintList with one constraint per remaining slice otherwise.

Overload 1.

Args:
  • poly (amplify.Poly): Left-hand side polynomial.

  • bounds (tuple[float | None, float | None]): Bounds as (lower, upper).

  • label (str): Constraint label. Defaults to ''.

  • penalty_formulation (typing.Literal['Default', 'IntegerVariable', 'RealVariable', 'Relaxation', 'LinearRelaxation', 'QuadraticRelaxation'] | amplify.PenaltyFormulation): Penalty formulation method. Defaults to PenaltyFormulation.Default.

Returns:

amplify.Constraint: Constraint object.

Raises:

ValueError: Both bounds are None.

Overload 2.

Args:
  • array (amplify.PolyArray[_Dim]): Array of polynomials to reduce.

  • bounds (tuple[float | None, float | None]): Bounds as (lower, upper).

  • label (str): Constraint label. Defaults to ''.

  • penalty_formulation (typing.Literal['Default', 'IntegerVariable', 'RealVariable', 'Relaxation', 'LinearRelaxation', 'QuadraticRelaxation'] | amplify.PenaltyFormulation): Penalty formulation method. Defaults to PenaltyFormulation.Default.

  • axis (None): Axis or axes to reduce. Defaults to None.

Returns:

amplify.Constraint: Single constraint when all axes are reduced; otherwise one constraint per remaining slice.

Overload 3.

Args:
  • array (amplify.PolyArray[Dim]): Array of polynomials to reduce.

  • bounds (tuple[float | None, float | None]): Bounds as (lower, upper).

  • label (str): Constraint label. Defaults to ''.

  • penalty_formulation (typing.Literal['Default', 'IntegerVariable', 'RealVariable', 'Relaxation', 'LinearRelaxation', 'QuadraticRelaxation'] | amplify.PenaltyFormulation): Penalty formulation method. Defaults to PenaltyFormulation.Default.

  • axis (int | tuple[int, ...]): Axis or axes to reduce.

Returns:

amplify.Constraint | amplify.ConstraintList: Single constraint when all axes are reduced; otherwise one constraint per remaining slice.