Backend for constraint type implementations.


class picos.constraints.constraint.ConicConstraint(typeTerm, customString=None, printSize=False)[source]

Bases: picos.constraints.constraint.Constraint

Base class for constraints with an immediate conic representation.

abstract property conic_membership_form

The constraint in conic membership form.

For a conic constraint Ax \succeq_C b \Leftrightarrow Ax - b \in C this is the pair (Ax - b, C) where Ax - b is an affine expression and C a basic cone supported by PICOS.

property conic_standard_form[source]

The constraint in conic standard form.

For a conic constraint Ax \succeq_C b this is the triple (Ax, b, C) where Ax is a linear expression, b is a constant, and C a basic cone supported by PICOS.

property inverse_conic_standard_form[source]

The constraint in inverse conic standard form.

For a conic constraint Ax \succeq_C b \Leftrightarrow -Ax \preceq_C -b this is the triple (-Ax, -b, C) where Ax is a linear expression, b is a constant, and C a basic cone supported by PICOS.

class picos.constraints.constraint.Constraint(typeTerm, customString=None, printSize=False)[source]

Bases: abc.ABC

Abstract base class for optimization constraints.


  • need to implement at least the abstract methods _str, _expression_names, and _get_slack,

  • need to implement _get_size, unless duals are not supported, and

  • are supposed to call Constraint.__init__ from within their own implementation of __init__.

__init__(typeTerm, customString=None, printSize=False)[source]

Perform basic initialization for Constraint instances.

  • typeTerm (str) – Short string denoting the constraint type.

  • customString (str) – Optional string description.

  • printSize (bool) – Whether to include the constraint’s shape in its representation string.


Return an algebraic string representation of the constraint.


Raise a NotImplementedError.

Formerly this would remove the constraint from the single problem it is assigned to, if any.

Deprecated since version 2.0: Both variables and constraints have been decoupled from problems: Both may safely appear in multiple problems but at the same time they do not know which problems they were added to. To remove a constraint from a problem, you have to call its remove_constraint method.


Whether the left side is posed greater or equal than the right.


Whether the constraints states an equality.


Whether the left side is posed smaller or equal than the right.


Whether the constraints states an inequality.


Return the regular string representation.

classmethod make_type(*args, **kwargs)[source]

Create a detailed constraint type from subtype parameters.


Make the constraint concern a different set of mutables.

See replace_mutables for more.

EQ = '='
GE = '>'
LE = '<'
property dual

Value of the constraint’s Lagrange dual variable.

property expressions

Yield expressions stored with the constraint.

property id

The unique ID of the constraint, assigned at creation.

The ID is kept when the constraint is copied via replace_mutables, so that the copy can be identified with the original despite pointing to different expressions and mutable objects.

property mutables[source]

All mutables referenced by the constraint.

property parameters[source]

All parameters referenced by the constraint.

property size

Langrange dual variable shape.

The dimensionality of the constraint, more precisely the dimensionality of its Lagrange dual variable, as a pair.

property slack

Value of a slack variable or of the negative constraint violation.

A negative value whose absolute value corresponds to the amount of violation, if the constraint is violated, or a non-negative value that corresponds to the value of a slack variable, otherwise.

property subtype
property type

Detailed type of the constraint.

The detailed type of the constraint, which is suffcient to predict the outcome (detailed types and quantities of auxilary variables and constraints) of any constraint conversion.

property variables[source]

All decision variables referenced by the constraint.

class picos.constraints.constraint.ConstraintConversion[source]

Bases: abc.ABC

Recipe for conversion from one constraint to a set of other constraints.

Implementations of this class are defined within the class body of a Constraint implementation to tell PICOS’ reformulation framework how that constraint can be reformulated into a number of other constraints and auxiliary variables.

Implementation class names must end in Conversion, and in particular may be called just Conversion. If for instance AbsoluteValueConstraint defines AffineConversion, then the reformulation will be coined AbsoluteValueToAffineReformulation. If the conversions was just named Conversion, the result would be a class named AbsoluteValueReformulation.


Raise a TypeError on instanciation.

abstract classmethod convert(constraint, options)[source]

Convert a given constraint.

Returns a temporary problem instance that contains auxilary constraints and variables replacing the given constraint.

classmethod dual(auxVarPrimals, auxConDuals, options)[source]

Convert back the dual value of a constraint that was converted.

Given a mapping of auxilary variable names (as named in convert) to primals and a list of auxilary constraint duals (in the order as the constraints were added in convert), returns a dual value for the converted constraint.


NotImplementedError – When dual format not decided upon or not known. This will be caught by the reformulation’s backward method.

abstract classmethod predict(subtype, options)[source]

Predict the outcome of a constraint conversion.

  • subtype (object) – A hashable object as could be returned by the _subtype method of the parent constraint implementation.

  • options (Options) – Solution options to assume used.


Records to be added to a problem footprint when an instance of the parent constraint with the given subtype is converted according to this conversion.

class picos.constraints.constraint.ConstraintType(theClass, subtype)[source]

Bases: picos.containers.DetailedType

Container for a pair of constraint class type and constraint subtype.