Package: ncpol2sdpa
Ncpol2sdpaNcpol2sdpa solves global polynomial optimization problems of either commutative variables or noncommutative operators through a semidefinite programming (SDP) relaxation. The optimization problem can be unconstrained or constrained by equalities and inequalities, and also by constraints on the moments. The objective is to be able to solve large scale optimization problems. Example applications include:When the polynomial optimization problem is defined over commutative variables, the generated SDP hierarchy is identical toLasserre’s. In this case, the functionality resembles the MATLAB toolboxesGloptipoly, and, with the chordal extension,SparsePOP.Relaxationsofparametricandbilevelpolynomial optimization problems.When the polynomials are over noncommutative operators, the generated SDP is a step in the Navascués-Pironio-Acín (NPA) hierarchy. The most notable example is calculating themaximum quantum violationofBell inequalities, also inmultipartite scenarios.Nieto-Sillerashierarchy forquantifying randomnessand forcalculating maximum guessing probability.Moroderhierarchy to enable PPT-style and other additional constraints.Sums-of-square (SOS) decomposition based on the dual solution.Ground-state energy problems: bosonic andfermionic systems, Pauli spin operators. This methodology closely resembles the reduced density matrix (RDM) method.Hierarchy for quantum steering.The implementation has an intuitive syntax for entering problems and it scales for a larger number of noncommutative variables using a sparse representation of the SDP problem.  Further details are found in the following paper:Peter Wittek. Algorithm 950: Ncpol2sdpa—Sparse Semidefinite Programming Relaxations for Polynomial Optimization Problems of Noncommuting Variables.ACM Transactions on Mathematical Software, 41(3), 21, 2015. DOI:10.1145/2699464. arXiv:1308.6029.DependenciesThe implementation requiresSymPyandNumpy. The code is compatible with both Python 2 and 3. While the default CPython interpreter is sufficient for small to medium-scale problems, execution time becomes excessive for larger problems. The code is compatible with Pypy. Using it yields a 10-20x speedup. If you use Pypy, you will need thePypy fork of Numpy.By default, Ncpol2sdpa does not require a solver, but then it will not be able to solve a generated relaxation either. Install any supported solver and it will be detected automatically.Optional dependencies include:SDPAis a possible target solver.SciPyyields faster execution with the default CPython interpreter.PICOSis necessary for using the Cvxopt solver and for converting the problem to a PICOS instance.MOSEKPython module is necessary to work with the MOSEK solver.CVXPYis required for converting the problem to or by solving it by CVXPY or by SCS.Cvxoptis required by both Chompack and PICOS.Chompackimproves the sparsity of the chordal graph extension.UsageDocumentation is available onRead the Docs. The following code replicates the toy example from Pironio, S.; Navascués, M. & Acín, A. Convergent relaxations of polynomial optimization problems with noncommuting variables SIAM Journal on Optimization, SIAM, 2010, 20, 2157-2180.fromncpol2sdpaimportgenerate_operators,SdpRelaxation# Number of operatorsn_vars=2# Level of relaxationlevel=2# Get Hermitian operatorsX=generate_operators('X',n_vars,hermitian=True)# Define the objective functionobj=X[0]*X[1]+X[1]*X[0]# Inequality constraintsinequalities=[-X[1]**2+X[1]+0.5>=0]# Simple monomial substitutionssubstitutions={X[0]**2:X[0]}# Obtain SDP relaxationsdpRelaxation=SdpRelaxation(X)sdpRelaxation.get_relaxation(level,objective=obj,inequalities=inequalities,substitutions=substitutions)sdpRelaxation.solve()print(sdpRelaxation.primal,sdpRelaxation.dual,sdpRelaxation.status)Further examples are found in the documentation.InstallationThe code is available on PyPI, hence it can be installed by$ sudo pip install ncpol2sdpaIf you want the latest git version, follow the standard procedure for installing Python modules after cloning the repository:$ sudo python setup.py installAcknowledgmentThis work is supported by the European Commission Seventh Framework Programme under Grant Agreement Number FP7-601138PERICLES, by theRed Espanola de Supercomputaciongrants number FI-2013-1-0008 and  FI-2013-3-0004, and by theSwedish National Infrastructure for Computingprojects SNIC 2014/2-7 and SNIC 2015/1-162.