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.

Returns LaTeX representation of Irene’s 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.


find the existing sdp solvers.


Check the availability of the program system-wide. Returns the path of the program if exists and returns ‘None’ otherwise.

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.

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.


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 \(f-f_*=\sum_{i=0}^m\sigma_ig_i\). Here, \(f_*\) is the output of the SDPRelaxation.Minimize().


Returns all the exponents that appear in the reduced basis of all monomials of the auxiliary symbols of degree at most deg.


Initializes the SDP based on the value of self.Parallel. If it is True, it runs in parallel mode, otherwise in serial.


Computes the reduced symbolic moment generating matrix localized at p.


Computes the reduced symbolic moment generating matrix localized at p.


Finds the minimum of the truncated moment problem which provides a lower bound for the actual minimum.


Takes constraints on the moments. The input must be an instance of Mom class.


Returns the numerical moment matrix resulted from solving the SDP.


Sets the order of moments to be considered.


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.


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.


Returns a reduce monomial basis up to degree d.


Finds the minimum required order of moments according to user’s request, objective function and constraints.


Resumes the process of a previously saved program.


Saves the current state of the relaxation object to the file self.Name+’.rlx’.


Changes the default monomial order to ord which mustbe among lex, grlex, grevlex, ilex, igrlex, igrevlex.


Sets the maximum number of workers which cannot be bigger than number of available cores.


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.

Sets the default SDP solver. The followings are currently supported:
  • 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.


Returns the latest state of the object at last break and save.


Returns the constraint number idx of the problem after reduction modulo the relations, if given.


Returns the moment constraint number idx of the problem after reduction modulo the relations, if given.


Returns the objective function of the problem after reduction modulo the relations, if given.


Initializes the semidefinite program (SDP), in parallel, whose solution is a lower bound for the minimum of the program.


Initializes the semidefinite program (SDP), in serial mode, whose solution is a lower bound for the minimum of the program.

class relaxations.SDRelaxSol(X, symdict={}, err_tol=1e-05)[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 moments
  • SDRelaxSol.MomentMatrix the resulted moment matrix
  • SDRelaxSol.Primal the value of the SDP in primal form
  • SDRelaxSol.Dual the value of the SDP in dual form
  • SDRelaxSol.RunTime the run time of the sdp solver
  • SDRelaxSol.InitTime the total time consumed for initialization of the sdp
  • SDRelaxSol.Solver the name of sdp solver
  • SDRelaxSol.Status final status of the sdp solver
  • SDRelaxSol.RelaxationOrd order of relaxation
  • SDRelaxSol.Message the message that maybe returned by the sdp solver
  • SDRelaxSol.ScipySolver the scipy solver to extract solutions
  • SDRelaxSol.err_tol the minimum value which is considered to be nonzero
  • SDRelaxSol.Support the support of discrete measure resulted from SDPRelaxation.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 ‘Lasserre-Henrion’ and ‘Scipy’ employs a Scipy solver to find points matching the moments,

-card restricts the number of points of the support.


Extract solutions based on Lasserre–Henrion’s method.


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 by scipy:

  • hybr,
  • lm (default),
  • broyden1,
  • broyden2,
  • anderson,
  • linearmixing,
  • diagbroyden,
  • excitingmixing,
  • krylov,
  • df-sane.

Finds the rank of the moment matrix based on the size of its eigenvalues. It considers those with absolute value less than self.err_tol to be zero.


Get the leading term of each column.


Sets the scipy.optimize.root solver to solver.


Compute the stabilized row reduced echelon form.

Term2Mmnt(trm, rnk, X)[source]

Converts a moment object into an algebraic equation.

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):
  • CSDP,
  • SDPA,
  • DSDP.

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


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


This calls CVXOPT and DSDP to solve the initiated semidefinite program.

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:


    • show_progress: True or False, turns the output to the screen on or off (default: True);
    • maxiters: maximum number of iterations (default: 100);
    • abstol: absolute accuracy (default: 1e-7);
    • reltol: relative accuracy (default: 1e-6);
    • feastol: tolerance for feasibility conditions (default: 1e-7);
    • refinement: number of iterative refinement steps when solving KKT equations (default: 0 if the problem has no second-order cone or matrix inequality constraints; 1 otherwise).
  • SDPA:

    • maxIteration: Maximum number of iterations. The SDPA stops when the iteration exceeds maxIteration;
    • 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.

Takes the coefficients of the objective function.


Converts the matrix M into a column vector acceptable by CVXOPT.


Calls SDPA to solve the initiated semidefinite program.


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.


Extracts information from SDPA‘s output file filename. This was taken from ncpol2sdpa and customized for Irene.


Calls SDPA to solve the initiated semidefinite program.


Produces sdpa.param file from SolverOptions.


Solves the initiated semidefinite program according to the requested solver.


Writes the semidefinite program in the file filename with dense SDPA format.


Writes the semidefinite program in the file filename with sparse SDPA format.