ams.opt.Constraint#

class ams.opt.Constraint(name: str | None = None, e_str: str | None = None, e_fn: Callable | None = None, info: str | None = None)[source]#

Base class for constraints.

Routines are authored with e_str strings; the codegen at ams.prep.generate_for_routine() compiles each e_str into a callable e_fn(r) taking a RoutineNS proxy and returning a CVXPY constraint. The mutex descriptor on e_str / e_fn keeps the two forms exclusive. Authors who need to bypass the DSL may pass e_fn= directly; codegen leaves a manually-set e_fn alone.

Parameters:
namestr, optional

A user-defined name for the constraint.

e_strstr, optional

Mathematical expression in canonical CVXPY syntax with the relational operator embedded — '<LHS> <= 0', '<LHS> == 0', or '<LHS> >= 0'. Authoring style is LHS-zero: keep all terms on the left so .v reports slack-from-zero (negative = respected, positive = violated) uniformly across every constraint. CVXPY canonicalizes every inequality to lhs - rhs <= 0 internally regardless of operator direction. Strict < / > are forbidden by CVXPY (raises NotImplementedError).

e_fncallable, optional

Callable e_fn(r) -> cp.Constraint taking a RoutineNS. Must return a fully-formed cp.constraints.Constraint (the codegen convention of returning a bare LHS expression is no longer supported — the routine source is now the single source of truth for the relational shape).

infostr, optional

Additional informational text about the constraint.

Attributes:
is_disabledbool

Flag indicating if the constraint is disabled, False by default.

rtnams.routines.Routine

The owner routine instance.

codestr, optional

The code string for the constraint

__init__(name: str | None = None, e_str: str | None = None, e_fn: Callable | None = None, info: str | None = None)[source]#

Methods

evaluate(*args, **kwargs)

get_all_idxes()

Return all the indexes of this item.

get_idx()

parse(*args, **kwargs)

Attributes

class_name

Return the class name

e

Return the calculated numerical value of the underlying expression.

e_fn

Mutex descriptor for e_str / e_fn on opt elements.

e_str

Mutex descriptor for e_str / e_fn on opt elements.

formulation_source

Where the live CVXPY object for this item came from.

n

Return the number of elements.

shape

Return the shape.

size

Return the size.

v

Return the CVXPY constraint LHS value.