Implements affine expression types.


class picos.expressions.exp_affine.AffineExpression(string, shape=(1, 1), coefficients={})[source]

Bases: picos.expressions.exp_affine.ComplexAffineExpression

A multidimensional real affine expression.


Return an equality constraint concerning the expression.


Return a constraint that the expression is lower-bounded.


Return a constraint that the expression is upper-bounded.

property H

The regular transpose of the AffineExpression.

property conj

The AffineExpression as is.

property exp[source]

The exponential function applied to the expression.

property imag[source]

A zero of same shape as the AffineExpression.

property isreal

Always true for AffineExpression instances.

property log[source]

The Logarithm of the expression.

property real

The AffineExpression as is.

class picos.expressions.exp_affine.ComplexAffineExpression(string, shape=(1, 1), coefficients={})[source]

Bases: picos.expressions.exp_biaffine.BiaffineExpression

A multidimensional (complex) affine expression.

Base class for the real AffineExpression.


Denote the default norm of the expression.

The norm used depends on the expression’s domain. It is

  1. the absolute value of a real scalar,

  2. the modulus of a complex scalar,

  3. the Euclidean norm of a vector, and

  4. the Frobenius norm of a matrix.


Return an equality constraint concerning the expression.


Denote multiplication with another expression on the right.


Denote the scalar product with another expression on the right.

For (complex) vectors a and b this is the dot product

(a \mid b)
&= \langle a, b \rangle \\
&= a \cdot b \\
&= b^H a.

For (complex) matrices A and B this is the Frobenius inner product

(A \mid B)
&= \langle A, B \rangle_F \\
&= A : B \\
&= \operatorname{tr}(B^H A) \\
&= \operatorname{vec}(B)^H \operatorname{vec}(\overline{A})


Write (A|B) instead of A|B for the scalar product of A and B to obtain correct operator binding within a larger expression context.


Denote the entrywise product with another expression on the right.

sparse_rows(varOffsetMap, lowerTriangle=False, upperTriangle=False, indexFunction=None)[source]

Return a sparse list representation of the expression.

The method is intended for internal use: It simplifies passing affine constraints to solvers that support only scalar constraints. The idea is to pose the constraint as a single (multidimensional) affine expression bounded by zero, and use the coefficients and the constant term of this expression to fill the solver’s constraint matrix (with columns representing scalar variables and rows representing scalar constraints).

  • varOffsetMap (dict) – Maps variables to column offsets.

  • lowerTriangle (bool) – Whether to return only the lower triangular part of the expression.

  • upperTriangle (bool) – Whether to return only the upper triangular part of the expression.

  • indexFunction – Instead of adding the local variable index to the value returned by varOffsetMap, use the return value of this function, that takes as argument the variable and its local index, as the “column index”, which need not be an integer. When this parameter is passed, the parameter varOffsetMap is ignored.


A list of triples (J, V, c) where J contains column indices (representing scalar variables), V contains coefficients for each column index and c is a constant term.

property imag[source]

Override imag.

The result is returned as an AffineExpression.

property real[source]

Override real.

The result is returned as an AffineExpression.


picos.expressions.exp_affine.Constant(name_or_value, value=None, shape=None)[source]

Create a constant PICOS expression.

Loads the given numeric value as a constant ComplexAffineExpression or AffineExpression, depending on the value. Optionally, the value is broadcasted or reshaped according to the shape argument.

  • name_or_value (str) – Symbolic string description of the constant. If None or the empty string, a string will be generated. If this is the only positional parameter (i.e.``value`` is not given), then this position is used as the value argument instead!

  • value – The numeric constant to load.

See load_data for supported data formats and broadcasting and reshaping rules.


>>> from picos import Constant
>>> Constant(1)
<1×1 Real Constant: 1>
>>> Constant(1, shape=(2, 2))
<2×2 Real Constant: [1]>
>>> Constant("one", 1)
<1×1 Real Constant: one>
>>> Constant("J", 1, (2, 2))
<2×2 Real Constant: J>