Code Documentation¶
This is the base module for all other objects of the package.
 LaTeX returns a LaTeX string out of an Irene object.
 base is the parent of all Irene objects.

class
base.
base
[source]¶ All the modules in Irene extend this class which perform some common tasks such as checking existence of certain softwares.
This module is responsible for conversion of a given symbolic optimization problem into semidefinite optimization problems. The main classes included in this module are:
 SDPRelaxations
 SDRelaxSol
 Mom

relaxations.
Calpha_
(expn, Mmnt)[source]¶ Given an exponent expn, this function finds the corresponding \(C_{expn}\) matrix which can be used for parallel processing.

relaxations.
Calpha__
(expn, Mmnt, ii, q)[source]¶ Given an exponent expn, this function finds the corresponding \(C_{expn}\) matrix which can be used for parallel processing.

class
relaxations.
Mom
(expr)[source]¶ This is a simple interface to define moment constraints to be used via SDPRelaxations.MomentConstraint. It takes a sympy expression as input and initiates an object which can be used to force particular constraints on the moment sequence.
Example: Force the moment of \(x^2f(x) + f(x)^2\) to be at least .5:
Mom(x**2 * f + f**2) >= .5 # OR Mom(x**2 * f) + Mom(f**2) >= .5

class
relaxations.
SDPRelaxations
(gens, relations=(), name='SDPRlx')[source]¶ This class defines a function space by taking a family of sympy symbolic functions and relations among them. Simply, it initiates a commutative free real algebra on the symbolic functions and defines the function space as the quotient of the free algebra by the ideal generated by the given relations. It takes two arguments:
 gens which is a list of
sympy
symbols and function symbols,  relations which is a set of
sympy
expressions in terms of gens that defines an ideal.  name is a given name which is used to save the state of the instant at break.

AddConstraint
(cnst)[source]¶ Takes an (in)equality as an algebraic combination of the generating functions that defines the feasibility region. It reduces the defining (in)equalities according to the given relations.

Calpha
(expn, Mmnt)[source]¶ Given an exponent expn, this method finds the corresponding \(C_{expn}\) matrix.

Commit
(blk, c, idx)[source]¶ Sets the latest computed values for the final SDP and saves the current state.

Decompose
()[source]¶ Returns a dictionary that associates a list to every constraint, \(g_i\ge0\) for \(i=0,\dots,m\), where \(g_0=1\). Each list consists of elements of algebra whose sums of squares is equal to \(\sigma_i\) and \(ff_*=\sum_{i=0}^m\sigma_ig_i\). Here, \(f_*\) is the output of the
SDPRelaxation.Minimize()
.

ExponentsVec
(deg)[source]¶ Returns all the exponents that appear in the reduced basis of all monomials of the auxiliary symbols of degree at most deg.

InitSDP
()[source]¶ Initializes the SDP based on the value of
self.Parallel
. If it isTrue
, it runs in parallel mode, otherwise in serial.

Minimize
()[source]¶ Finds the minimum of the truncated moment problem which provides a lower bound for the actual minimum.

MomentConstraint
(cnst)[source]¶ Takes constraints on the moments. The input must be an instance of Mom class.

PolyCoefFullVec
()[source]¶ return the vector of coefficient of the reduced objective function as an element of the vector space of elements of degree up to the order of moments.

ReduceExp
(expr)[source]¶ Takes an expression expr, either in terms of internal free symbolic variables or generating functions and returns the reduced expression in terms of internal symbolic variables, if a relation among generators is present, otherwise it just substitutes generating functions with their corresponding internal symbols.

RelaxationDeg
()[source]¶ Finds the minimum required order of moments according to user’s request, objective function and constraints.

SetMonoOrd
(ord)[source]¶ Changes the default monomial order to ord which mustbe among lex, grlex, grevlex, ilex, igrlex, igrevlex.

SetNumCores
(num)[source]¶ Sets the maximum number of workers which cannot be bigger than number of available cores.

SetObjective
(obj)[source]¶ Takes the objective function obj as an algebraic combination of the generating symbolic functions, replace the symbolic functions with corresponding auxiliary symbols and reduce them according to the given relations.

SetSDPSolver
(solver)[source]¶  Sets the default SDP solver. The followings are currently supported:
 CVXOPT
 DSDP
 SDPA
 CSDP
The selected solver must be installed otherwise it cannot be called. The default solver is CVXOPT which has an interface for Python. DSDP is called through the CVXOPT’s interface. SDPA and CSDP are called independently.

getConstraint
(idx)[source]¶ Returns the constraint number idx of the problem after reduction modulo the relations, if given.

getMomentConstraint
(idx)[source]¶ Returns the moment constraint number idx of the problem after reduction modulo the relations, if given.

getObjective
()[source]¶ Returns the objective function of the problem after reduction modulo the relations, if given.
 gens which is a list of

class
relaxations.
SDRelaxSol
(X, symdict={}, err_tol=1e05)[source]¶ Instances of this class carry information on the solution of the semidefinite relaxation associated to a optimization problem. It include various pieces of information:
SDRelaxSol.TruncatedMmntSeq
a dictionary of resulted momentsSDRelaxSol.MomentMatrix
the resulted moment matrixSDRelaxSol.Primal
the value of the SDP in primal formSDRelaxSol.Dual
the value of the SDP in dual formSDRelaxSol.RunTime
the run time of the sdp solverSDRelaxSol.InitTime
the total time consumed for initialization of the sdpSDRelaxSol.Solver
the name of sdp solverSDRelaxSol.Status
final status of the sdp solverSDRelaxSol.RelaxationOrd
order of relaxationSDRelaxSol.Message
the message that maybe returned by the sdp solverSDRelaxSol.ScipySolver
the scipy solver to extract solutionsSDRelaxSol.err_tol
the minimum value which is considered to be nonzeroSDRelaxSol.Support
the support of discrete measure resulted fromSDPRelaxation.Minimize()
SDRelaxSol.Weights
corresponding weights for the Dirac measures

ExtractSolution
(mthd='LH', card=0)[source]¶ Extract support of the solution measure from
SDPRelaxations
:
mthd
should be either ‘LH’ or ‘Scipy’, where ‘LH’ stands for ‘LasserreHenrion’ and ‘Scipy’ employs a Scipy solver to find points matching the moments,
card
restricts the number of points of the support.

ExtractSolutionScipy
(card=0)[source]¶ This method tries to extract the corresponding values for generators of the
SDPRelaxation
class. Number of points is the rank of the moment matrix which is computed numerically according to the size of its eigenvalues. Then the points are extracted as solutions of a system of polynomial equations using a scipy solver. The followin solvers are currently acceptable byscipy
:hybr
,lm
(default),broyden1
,broyden2
,anderson
,linearmixing
,diagbroyden
,excitingmixing
,krylov
,dfsane
.

class
sdp.
sdp
(solver='cvxopt', solver_path={})[source]¶ This is the class which intends to solve semidefinite programs in primal format:
\[\begin{split}\left\lbrace \begin{array}{lll} \min & \sum_{i=1}^m b_i x_i & \\ \textrm{subject to} & & \\ & \sum_{i=1}^m A_{ij}x_i  C_j \succeq 0 & j=1,\dots,k. \end{array}\right.\end{split}\] For the argument solver following sdp solvers are supported (if they are installed):
 CVXOPT,
 CSDP,
 SDPA,
 DSDP.

AddConstantBlock
(C)[source]¶ C must be a list of
numpy
matrices that represent \(C_j\) for each j. This method sets the value for \(C=[C_1,\dots,C_k]\).

AddConstraintBlock
(A)[source]¶ This takes a list of square matrices which corresponds to coefficient of \(x_i\). Simply, \(A_i=[A_{i1},\dots,A_{ik}]\). Note that the \(i^{th}\) call of
AddConstraintBlock
fills the blocks associated with \(i^{th}\) variable \(x_i\).

Option
(param, val)[source]¶ Sets the param option of the solver to val if the solver accepts such an option. The following options are supported by solvers:
CVXOPT
:show_progress
:True
orFalse
, turns the output to the screen on or off (default:True
);maxiters
: maximum number of iterations (default: 100);abstol
: absolute accuracy (default: 1e7);reltol
: relative accuracy (default: 1e6);feastol
: tolerance for feasibility conditions (default: 1e7);refinement
: number of iterative refinement steps when solving KKT equations (default: 0 if the problem has no secondorder cone or matrix inequality constraints; 1 otherwise).
SDPA
:maxIteration
: Maximum number of iterations. The SDPA stops when the iteration exceedsmaxIteration
;epsilonStar
,epsilonDash
: The accuracy of an approximate optimal solution of the SDP;lambdaStar
: This parameter determines an initial point;omegaStar
: This parameter determines the region in which the SDPA searches an optimal solution;lowerBound
: Lower bound of the minimum objective value of the primal problem;upperBound
: Upper bound of the maximum objective value of the dual problem;betaStar
: Parameter controlling the search direction when current state is feasible;betaBar
: Parameter controlling the search direction when current state is infeasible;gammaStar
: Reduction factor for the primal and dual step lengths; 0.0 <gammaStar
< 1.0.

parse_solution_matrix
(iterator)[source]¶ Parses and returns the matrices and vectors found by SDPA solver. This was taken from ncpol2sdpa and customized for Irene.

read_csdp_out
(filename, txt)[source]¶ Takes a file name and a string that are the outputs of CSDP as a file and command line outputs of the solver and extracts the required information.

read_sdpa_out
(filename)[source]¶ Extracts information from SDPA‘s output file filename. This was taken from ncpol2sdpa and customized for Irene.