picos.expressions.exp_affine

Implements affine expression types.

Classes

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

Bases: picos.expressions.exp_affine.ComplexAffineExpression

A multidimensional real affine expression.

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.

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).

Parameters
  • 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.

Returns

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.

Functions

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.

Parameters
  • 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.

Example

>>> 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>