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_strstrings; the codegen atams.prep.generate_for_routine()compiles eache_strinto a callablee_fn(r)taking aRoutineNSproxy and returning a CVXPY constraint. The mutex descriptor one_str/e_fnkeeps the two forms exclusive. Authors who need to bypass the DSL may passe_fn=directly; codegen leaves a manually-sete_fnalone.- 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.vreports slack-from-zero (negative = respected, positive = violated) uniformly across every constraint. CVXPY canonicalizes every inequality tolhs - rhs <= 0internally regardless of operator direction. Strict</>are forbidden by CVXPY (raisesNotImplementedError).- e_fncallable, optional
Callable
e_fn(r) -> cp.Constrainttaking aRoutineNS. Must return a fully-formedcp.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
Attributes
Return the class name
Return the calculated numerical value of the underlying expression.
Mutex descriptor for
e_str/e_fnon opt elements.Mutex descriptor for
e_str/e_fnon opt elements.Where the live CVXPY object for this item came from.
Return the number of elements.
Return the shape.
Return the size.
Return the CVXPY constraint LHS value.