Implements the UncertainExpression base class.


exception picos.expressions.uncertain.uexpression.IntractableWorstCase[source]

Bases: RuntimeError

Computing a worst-case (expected) value is hard and not supported.

Raised by worst_case and methods that depend on it.


class picos.expressions.uncertain.uexpression.UncertainExpression[source]

Bases: object

Primary base class for uncertainty affected expression types.

The secondary base class must be Expression or a subclass thereof.

Uncertain expressions have a distinct behavior when used to form a constraint or when posed as an objective function. The exact behavior depends on the type of uncertainty involved. If the perturbation parameter that describes the uncertainty is confied to a perturbation set, then the worst-case realization of the parameter is assumed when determining feasibility and optimality. If the perturbation parameter is a random variable (whose distribution may itself be ambiguous), then the constraint or objective implicitly considers the expected value of the uncertain expression (under the worst-case distribution). Uncertain expressions are thus used in the contexts of robust optimization, stochastic programming and distributionally robust optimization.


Find a worst-case realization of the uncertainty for the expression.

Expressions that are affected by uncertainty are only partially valued once an optimization solution has been applied. While their decision values are populated with a robust optimal solution, the parameter that controls the uncertainty is not valued unless the user assigned it a particular realization by hand. This method computes a worst-case (expected) value of the expression and returns it together with a realization of the perturbation parameter for which the worst case is attained (or None in the case of stochastic uncertainty).

For multidimensional expressions, this method computes the entrywise worst case and returns an attaining realization for each entry.


direction (str) – Either "min" or "max", denoting the worst-case direction.


A pair (value, realization). For a scalar expression, value is its worst-case (expected) value as a float and realization is a realization of the perturbation parameter that attains this worst case as a float or CVXOPT matrix. For a multidimensional expression, value is a CVXOPT dense matrix denoting the entrywise worst-case values and realization is a tuple of attaining realizations corresponding to the expression vectorized in in column-major order. Lastly, realization is None if the expression is certain or when its uncertainty is of stochastic nature.

  • picos.NotValued – When the decision variables that occur in the expression are not fully valued.

  • picos.uncertain.IntractableWorstCase – When computing the worst-case (expected) value is not supported, in particular when it would require solving a nonconvex problem.

  • RuntimeError – When the computation is supported but fails.


A string describing the expression within a worst-case context.


direction (str) – Either "min" or "max", denoting the worst-case direction.


A shorthand for the first value returned by worst_case.

property certain

Whether the uncertain expression is actually certain.

property perturbation[source]

The parameter controlling the uncertainty, or None.

property random

Whether the uncertainty is of stochastic nature.

See also distributional.

property uncertain

Whether the uncertain expression is in fact uncertain.

property universe[source]

Universe that the perturbation parameter lives in, or None.

If this is not None, then this is the same as perturbation.:attr:~.perturbation.Perturbation.universe.