...
 
Commits (133)
# General
*.log
# Working files
patch
fix*.py
fix*/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
# setuptools
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# pip
pip-log.txt
pip-delete-this-directory.txt
# PyBuilder
target/
# PyInstaller
# Usually these files are written by a python script from a template
......@@ -29,29 +29,3 @@ var/
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
image: base/archlinux
stages:
- test
- deploy
old test:
stage: test
before_script:
- pacman -Sy --noconfirm python-six python-numpy python-cvxopt
script:
- python ./test_picos.py
old test (py2):
stage: test
before_script:
- pacman -Sy --noconfirm python2-six python2-numpy python2-cvxopt
script:
- python2 ./test_picos.py
doctest:
stage: test
before_script:
- pacman -Sy --noconfirm python-six python-numpy python-cvxopt
- pacman -S --noconfirm m2r python-sphinx python-matplotlib python-networkx
script:
- sphinx-build -b doctest doc doctest
pypi:
stage: deploy
before_script:
- pacman -Sy --noconfirm git twine
script:
- ./setup.py sdist
- twine upload --skip-existing dist/*
only:
- master
- pypi
anaconda:
stage: deploy
before_script:
# Install Miniconda from the AUR.
- pacman -Sy --noconfirm wget fakeroot
- wget https://aur.archlinux.org/cgit/aur.git/snapshot/miniconda3.tar.gz
- tar xf miniconda3.tar.gz
- cd miniconda3
- useradd makepkg # makepkg refuses to run as root.
- chown makepkg . # makepkg needs to write here.
- PKGEXT=".pkg.tar" su makepkg -c makepkg # Don't compress the package.
- pacman -U --noconfirm miniconda3-*.pkg.*
- cd ..
- ln -s /opt/miniconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh
script:
- ./conda/release.sh
only:
- master
- conda
pages:
stage: deploy
before_script:
# Install PICOS dependencies.
- pacman -Sy --noconfirm python-six python-numpy python-cvxopt
# Install documentation built dependencies.
- pacman -S --noconfirm m2r python-sphinx python-matplotlib python-networkx
- pacman -S --noconfirm texlive-most python-sphinx_rtd_theme python-scipy
- pacman -S --noconfirm git python-pip glpk
- pip install swiglpk
script:
- sphinx-build -b html doc html
- mkdir public
- mv html/* public
artifacts:
paths:
- public
only:
- master
- doc
# vi:ts=2:et:ai
# Changelog
This file documents major changes to PICOS.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
[1.1.3]: https://gitlab.com/picos-api/picos/compare/v1.1.2...v1.1.3
[1.1.2]: https://gitlab.com/picos-api/picos/compare/v1.1.1...v1.1.2
[1.1.1]: https://gitlab.com/picos-api/picos/compare/v1.1.0...v1.1.1
[1.1.0]: https://gitlab.com/picos-api/picos/compare/v1.0.2...v1.1.0
[1.0.2]: https://gitlab.com/picos-api/picos/compare/v1.0.1...v1.0.2
[1.0.1]: https://gitlab.com/picos-api/picos/compare/v1.0.0...v1.0.1
[1.0.0]: https://gitlab.com/picos-api/picos/compare/b65a05be...v1.0.0
[0.1.3]: about:blank
[0.1.2]: about:blank
[0.1.1]: about:blank
[0.1.0]: about:blank
## [1.1.3] - 2018-10-05
### Added
- Support for the solvers GLPK and SCIP.
- PICOS packages [on Anaconda Cloud](https://anaconda.org/picos/picos).
- PICOS packages
[in the Arch Linux User Repository](https://aur.archlinux.org/packages/?SeB=b&K=python-picos).
### Changed
- The main repository has moved to [GitLab](https://gitlab.com/picos-api/picos).
- Releases of packages and documentation changes are
[automated](https://about.gitlab.com/features/gitlab-ci-cd/) and thus more
frequent. In particular, post release versions are available.
- Test bench execution is automated for greater code stability.
- Improved test bench output.
- Improved support for the SDPA solver.
- :func:`partial_trace <picos.tools.partial_trace>` can handle rectangular
subsystems.
- The documentation was restructured; examples were converted to Python 3.
### Fixed
- Upper bounding the norm of a complex scalar.
- Multiplication with a complex scalar.
- A couple of Python 3 specific errors, in particular when deleting constraints.
- All documentation examples are reproducible with the current state of PICOS.
## [1.1.2] - 2016-07-04
### Added
- Ability to dynamically add and remove constraints, see
:ref:`the documentation on constraint deletion <delcons>`.
- Option ``pass_simple_cons_as_bound``, see below.
### Changed
- Improved efficiency when processing large expressions.
- Improved support for the SDPA solver.
- :func:`add_constraint <picos.Problem.add_constraint>` returns a handle to the
constraint when the option `return_constraints` is set.
- New signature for the function
:func:`partial_transpose <picos.tools.partial_transpose>`, which can now
transpose arbitrary subsystems from a kronecker product.
- PICOS no longer turns constraints into variable bounds, unless the new option
``pass_simple_cons_as_bound`` is enabled.
### Fixed
- Minor bugs with complex expressions.
## [1.1.1] - 2015-08-29
### Added
- Support for the SDPA solver.
- Partial trace of an affine expression, see
:func:`partial_trace <picos.tools.partial_trace>`.
### Changed
- Improved PEP 8 compliance.
### Fixed
- Compatibility with Python 3.
## [1.1.0] - 2015-04-15
### Added
- Compatibility with Python 3.
### Changed
- The main repository has moved to [GitHub](https://github.com/gsagnol/picos).
## [1.0.2] - 2015-01-30
### Added
- Ability to read and write problems in
[conic benchmark format](http://cblib.zib.de/).
- Support for inequalities involving the sum of the :math:`k` largest or
smallest elements of an affine expression, see
:func:`sum_k_largest <picos.tools.sum_k_largest>` and
:func:`sum_k_smallest <picos.tools.sum_k_smallest>`.
- Support for inequalities involving the sum of the :math:`k` largest or
smallest eigenvalues of a symmetric matrix, see
:func:`sum_k_largest_lambda <picos.tools.sum_k_largest_lambda>`,
:func:`sum_k_smallest_lambda <picos.tools.sum_k_smallest_lambda>`,
:func:`lambda_max <picos.tools.lambda_max>` and
:func:`lambda_min <picos.tools.lambda_min>`.
- Support for inequalities involving the :math:`L_{p,q}`-norm of an affine
expression, see :func:`norm <picos.tools.norm>`.
- Support for equalities involving complex coefficients.
- New :attr:`variable type <picos.Variable.vtype>` for antisymmetric matrix
variables: ``antisym``.
- Set expressions that affine expressions can be constrained to be an element
of, see :func:`ball <picos.tools.ball>`, :func:`simplex <picos.tools.simplex>`
and :func:`truncated_simplex <picos.tools.truncated_simplex>`.
- Shorthand functions :func:`maximize <picos.Problem.maximize>` and
:func:`minimize <picos.Problem.minimize>` to specify the objective function of
a problem and solve it.
- Hadamard (elementwise) product of affine expression, as an overload of the
``^`` operator, read :ref:`the tutorial on overloads <overloads>`.
- Partial transposition of an aAffine Expression, see
:func:`partial_transpose <picos.tools.partial_transpose>` and
:attr:`AffinExp.Tx <picos.AffinExp.Tx>`.
### Changed
- Improved efficiency of the sparse SDPA file format writer.
- Improved efficiency of :func:`to_real <picos.Problem.to_real>`.
### Fixed
- Scalar product of hermitian matrices.
- Conjugate of a complex expression.
## [1.0.1] - 2014-08-27
### Added
- Support for semidefinite programming over the complex domain, see
:ref:`the documentation on complex problems <complex>`.
- Helper function to input (multicommodity) graph flow problems, see
:ref:`the tutorial on flow constraints <flowcons>`.
- Additional ``coef`` argument to :func:`picos.tracepow <picos.tools.tracepow>`,
to represent constraints of the form
:math:`\operatorname{trace}(M X^p) \geq t`.
### Changed
- Significantly improved performance of
:func:`AffinExp.__getitem__ <picos.AffinExp.__getitem__>`.
- Improved performance of
:func:`_retrieve_matrix <picos.tools._retrieve_matrix>`.
- Improved performance when retrieving primal solution from CPLEX.
- The documentation received an overhaul.
## [1.0.0] - 2013-07-19
### Added
- Ability to express rational powers of affine expressions with the ``**``
operator, traces of matrix powers with
:func:`picos.tracepow <picos.tools.tracepow>`, (generalized) p-norms with
:func:`picos.norm <picos.tools.norm>` and :math:`n`-th roots of a determinant
with :func:`picos.detrootn <picos.tools.detrootn>`.
- Ability to specify variable bounds directly rather than by adding constraints,
see :func:`add_variable <picos.Problem.add_variable>`,
:func:`set_lower() <picos.Variable.set_lower>`,
:func:`set_upper() <picos.Variable.set_upper>`,
:func:`set_sparse_lower() <picos.Variable.set_sparse_lower>` and
:func:`set_sparse_upper() <picos.Variable.set_sparse_upper>`.
- Problem dualization, see :func:`dualize <picos.Problem.dualize>`.
- Option ``solve_via_dual`` which controls passing the dual problem to the
solver instead of the primal problem. This can result in a significant
speedup for certain problems.
- Semidefinite programming interface for MOSEK 7.0.
- Options ``handleBarVars`` and ``handleConeVars`` to customize how SOCPs and
SDPs are passed to MOSEK. When these are set to ``True``, PICOS tries to
minimize the number of variables of the MOSEK instance.
### Changed
- If the chosen solver supports this, updated problems will be partially
re-solved instead of solved from scratch.
### Removed
- Option ``onlyChangeObjective``.
## [0.1.3] - 2013-04-17
### Added
- A :func:`geomean <picos.tools.geomean>` function to construct geometric mean
inequalities that will be cast as SOCP constraints.
- Options ``uboundlimit`` and ``lboundlimit`` to tell CPLEX to stop the search
as soon as the given threshold is reached for the upper and lower bound,
respectively.
- Option ``boundMonitor`` to inspect the evolution of CPLEX lower and upper
bounds.
- Ability to use the weak inequality operators as an alias for the strong ones.
### Changed
- The solver search time is returned in the dictionary returned by
:func:`solve <picos.Problem.solve>`.
### Fixed
- Access to dual values of fixed variables with CPLEX.
- Evaluation of constant affine expressions with a zero coefficient.
- Number of constraints not being updated in
:func:`remove_constraint <picos.Problem.remove_constraint>`.
## [0.1.2] - 2013-01-10
### Fixed
- Writing SDPA files. The lower triangular part of the constraint matrix was
written instead of the upper triangular part.
- A wrongly raised :class:`IndexError` from
:func:`remove_constraint <picos.Problem.remove_constraint>`.
## [0.1.1] - 2012-12-08
### Added
- Interface to Gurobi.
- Ability to give an initial solution to warm-start mixed integer optimizers.
- Ability to get a reference to a constraint that was added.
### Fixed
- Minor bugs with quadratic expressions.
## [0.1.0] - 2012-06-22
### Added
- Initial release of PICOS.
v0.1.0, 22.06.2012 -- Initial release.
v0.1.1, 08.12.2012
* Picos now interfaces GUROBI !
* You can specify an initial solution to *warm-start* mixed integer optimizers.
* Minor bugs with quadratic expressions corrected
* It's possible to return a reference to a constraint added
with add_constraint()
v0.1.2, 10.01.13
bug-fix release, correcting:
* The write_to_file() function for sparse SDPA files.
The function was writing the
coefficients of the lower triangular part
of the constraint matrices
instead of the upper triangle.
* An IndexError occuring with the function
remove_constraint()
v0.1.3, 17.04.13
* geomean() function implemented, to handle inequalities involving
geometric mean and reformulate them as a set of SOCP constraints.
* Some options ['uboundlimit','lboundlimit'] were added to tell
CPLEX to stop the computation as soon as a given value for the
upper bound (or lower bound) is reached.
* The time used by the solver is now stored in the dictionary
returned bz solve().
* It is possible to get the evolution of the lower and upper bounds
over time, by using the option 'boundMonitor'.
* The weak inequalities operator can now be used.
* Minor bugs corrected (access to the duals of fixed variables with CPLEX,
evaluation of constant affine expressions with a zero coefficient appearing
in the dict of linear terms, number of constraints is now updated in remove_constraint() )
v1.0.0, 19.07.13
* Semidefinite Programming Interface for MOSEK 7.0 !!!
* New options ``handleBarVars`` and ``handleConeVars`` to customize how SOCP and SDPs are passed to MOSEK
(When these options are set to ``True`` , PICOS tries to minimize the number of variables of the
MOSEK instance).
* The function dualize() returns the Lagrangian dual of a Problem.
* The option ``solve_via_dual`` allows the user to pass the dual
of a problem to a solver, instead of the primal problem itself. This can yield important speed-up for
certain problems.
* In addition to the geometric mean function picos.geomean(), it is now possible
to pass rational powers of affine expressions (through an overload of the ``**`` operator), trace of
matrix powers with picos.tracepow(), (generalized) p-norms
with picos.norm(), and nth root of a determinant with
picos.detrootn(). These functions automatically reformulate the entered inequalities
as a set of equivalent SOCP or SDP constraints.
* It is now possible to specify variable bounds directly (rather than adding constraints of the type ``x >= 0`` ).
This can be done with the Keywords ``lower`` and ``upper`` of the function add_variable() ,
or by the methods set_lower(), set_upper(), set_sparse_lower(), and set_sparse_upper() of the class Variable.
* It is now more efficient to update a Problem and resolve it. This is done thanks to the attribute ``passed``
of the classes Constraint and Variable ,
that stores which solvers are already aware of a constraint / variable. There is also an
attribute ``obj_passed`` of the class Problem that lists the solver instances
where the objective function has already been passed. The option ``onlyChangeObjective`` has been
deprecated.
v1.0.1.dev, 18.05.14
* Complex Semidefinite Programming.
* Flow constraints in graphs
* Improved implementation of *expression slicing* (__getitem__)
v 1.0.1, 27.08.14:
Release fixing the missing functionnalities of the previous *.dev* version:
* Improved support for complex SDP (access to dual information and correction of a few
bugs, in particular sum of complex affine expression now work correctly)
* Flow constraints in graphs, including multicommodity flows.
* Additional ``coef`` argument in the function tracepow(), in order to represent
constraints of the form trace(M X^p) >= t.
* Improved implementation of retrieve_matrix(), which was taking a very long time to
process large parameters.
* Improved implementation of the retrieval of optimal primal variables with CPLEX.
With the previous versions there was an important overhead at the end of the
solving process to get the optimal values, this is now working much faster.
* Nicer documentation.
v 1.0.2, 30.01.15:
Major release with following new functionalities:
* Support (read and write) for ``.cbf`` problem files (`conic benchmark format <http://cblib.zib.de/>`_ ), which should be the standard for (mixed integer) conic optimization problems, cf. :func:`write_to_file <picos.Problem.write_to_file>` and :func:`import_cbf <picos.tools.import_cbf>` .
* Improved support for complex SDP (more efficient implementation of :func:`to_real() <picos.Problem.to_real>` , corrected bug in the implementation of the scalar product for Hermitian matrices and the conjugate of a complex expression, support for equality constraints involving complex coefficients)
* Support for inequalities involving the sum of k largest elements of an affine expression, or the k largest eigenvalues of a symmetric matrix expression, cf. the functions :func:`sum_k_largest() <picos.tools.sum_k_largest>` , :func:`sum_k_smallest() <picos.tools.sum_k_smallest>` , :func:`sum_k_largest_lambda() <picos.tools.sum_k_largest_lambda>`, :func:`sum_k_smallest_lambda() <picos.tools.sum_k_smallest_lambda>`, :func:`lambda_max() <picos.tools.lambda_max>` and :func:`lambda_min() <picos.tools.lambda_min>` .
* Support for inequalities involving the :math:`L_{p,q}-` norm of an affine expresison, cf. :func:`norm() <picos.tools.norm>` .
* New ``vtype`` for antisymmetric matrix variables ( :attr:`vtype <picos.Variable.vtype>` ``= antisym``).
* Constraints can be specified as membership in a :class:`Set <picos.Set>` . Sets can be created by the functions :func:`ball() <picos.tools.ball>` , :func:`simplex() <picos.tools.simplex>`, and :func:`truncated_simplex() <picos.tools.truncated_simplex>` .
* New functions :func:`maximize <picos.Problem.maximize>` and :func:`maximize <picos.Problem.minimize>` to specify the objective function of a problem and solve it.
And many thanks to `Petter Wittek <http://peterwittek.com/>`_ for the following improvements, who were motivated by the use of PICOS in the package `ncpol2sdpa <http://peterwittek.github.io/ncpol2sdpa/>`_ for optimization over noncommutative polynomials:
* More efficient implementation of the writer to the sparse - SDPA file format (:func:`write_to_file <picos.Problem.write_to_file>`)
* Hadamard (elementwise) product of affine expression is implemented, as an overload of the ``^`` operator, cf. an example :ref:`here <overloads>` .
* Partial transposition of an Affine Expression, cf. :func:`partial_transpose() <picos.tools.partial_transpose>` or the :attr:`Tx <picos.AffinExp.Tx>` attribute.
v 1.1.0, 15.04.15:
* PICOS is now compatible with **python 3+** (and remains compatible with python 2.6+). Many thanks to `Sergio Callegari <http://www.unibo.it/faculty/sergio.callegari>`_ for this compatibility layer ! If you plan to work with PICOS and python3, think to install the most recent version of your solver (Mosek, Cplex, Gurobi, or Cvxopt). SCIP is not supported in python3+ at this point (but remains supported with python 2.x).
* PICOS is now available on `github <http://github.com/gsagnol/picos>`_.
v 1.1.1, 29.08.15:
Minor release with following changes:
* Partial trace of an Affine Expression, cf. :func:`partial_trace() <picos.tools.partial_trace>`
* Bugfix for compatibility with python3 (thanks to `Sergio Callegari <http://www.unibo.it/faculty/sergio.callegari>`_)
* Initial support for the SDPA solver (with the option ``solver='sdpa'``, picos works as a wrapper around the SDPA executable based on the :func:`write_to_file() <picos.Problem.write_to_file()>` function; thanks to `Petter Wittek <http://peterwittek.com/>`_ )
* Better PEP8-compliance
v 1.1.2, 04.07.16:
Major release with following changes:
* Improved efficiency for the processing of large expressions.
* It is now possible to dynamically add and remove constraints, e.g. for column generation approaches, cf. :ref:`this paragraph <delcons>` for an example.
For an easier use, the function :func:`add_constraint() <picos.Problem.add_constraint()>` now returns a handle to the constraint when the option :func:`return_constraints=True <picos.Problem.set_all_options_to_default()>`
has been passed to the problem. Then, constraints can be deleted by using :func:`constraint.delete() <picos.Constraint.delete()>`.
* In previous versions, PICOS detected constraints that could be interpreted as a bound on a variable. This was creating a mess to delete constraints,
so the default behaviour is now to pass all constraints as such. To stick to the old behaviour, use the option :func:`pass_simple_cons_as_bound=True <picos.Problem.set_all_options_to_default()>`.
* New signature for the function :func:`partial_transpose() <picos.tools.partial_transpose()>`, which can now transpose arbitrary subsystems from a kronecker product.
* Corrections of minor bugs with complex expressions.
* Better support for the SDPA solver.
\ No newline at end of file
Contribution Guide
==================
Filing a bug report or feature request
--------------------------------------
### Via GitLab
If you have a GitLab account, just head to PICOS' official
[issue tracker](https://gitlab.com/picos-api/picos/issues).
### Via mail
If you don't have a GitLab account you can still create an issue by writing a
mail to `incoming+picos-api/picos@incoming.gitlab.com`. Unlike issues created
directly on GitLab, issues created by mail are *not* publicly visible.
Submitting a code change
------------------------
The canoncial way to submit a code change is to
1. [fork the PICOS repository on GitLab](https://gitlab.com/picos-api/picos/forks/new),
2. clone your fork and make your application use it instead of your system's
PICOS installation,
3. optionally create a local topic branch to work with,
4. modify the source and commit your changes, and lastly
5. make a pull request on GitLab so that we can test and merge your changes.
If you don't want to create a GitLab account, we are also happy to receive your
changes via mail as a patch created by `git patch`.
Implementing your solver
------------------------
If you want to implement support for a new solver, all you have to do is update
[solvers.py](picos/solvers.py) where applicable, and add a file called
`solver_<name>.py` in the same directory with your implementation. We recommend
that you read two or three of the existing solver implementations to get an
idea how things are done. If you want to know exactly how PICOS communicates
with your implementation, refer to the solver base class in
[solver.py](picos/solver.py).
Implementing a test case
------------------------
Production and unit test sets are implemented in the files in the
[tests](picos/tests) folder that start with `ptest_` and `utest_`, respectively.
If you want to add to our test pool, feel free to either extend these files or
create a new set, whatever is appropriate. Make sure that the tests you add are
not too computationally expensive since they are also run as part of our
continuous integration pipeline whenever a commit is pushed to GitLab.
Coding guidelines
-----------------
### Cleanup in progress
We are aiming to tidy up PICOS' codebase in the future to make it more robust
and easier to maintain and extend. That means that the cost of adding a new
feature often is to also refactor around the neighboring features. That being
said, you are encouraged to just rewrite a function that you feel does not look
so good, even if you initially just planned to add some text to it! :wink:
### Test coverage
Refactoring means stability in the long run, but can break features in the
short term. To prevent this from happening, we're happy to grow our set of
production and unit test cases. Hence, if you are running a local test to see
if your changes work, consider adding it as a permanent test case so that your
feature is protected from our clumsiness in the future.
GNU GENERAL PUBLIC LICENSE
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
......@@ -620,37 +620,3 @@ copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Picos 0.1 : A pyton Interface To Conic Optimization Solvers
Copyright (C) 2012 Guillaume Sagnol
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
For any information, please contact:
Guillaume Sagnol
sagnol@zib.de
Konrad Zuse Zentrum für Informationstechnik Berlin (ZIB)
Takustrasse 7
D-14195 Berlin-Dahlem
Germany
# file GENERATED by distutils, do NOT edit
CHANGES.txt
LICENSE.txt
README.rst
setup.py
doc/api.rst
doc/changes.rst
doc/complex.rst
doc/constraint.rst
doc/download.rst
doc/examples.rst
doc/expression.rst
doc/graphs.rst
doc/index.rst
doc/intro.rst
doc/optdes.rst
doc/problem.rst
doc/summary.rst
doc/tools.rst
doc/tuto.rst
doc/tuto_summary.rst
doc/_static/picos_big_trans.gif
doc/_static/css/theme.css
doc/_templates/download.html
doc/_templates/localtoc2.html
picos/__init__.py
picos/constraint.py
picos/cplex_callbacks.py
picos/expression.py
picos/problem.py
picos/test_picos.py
picos/tools.py
include *.txt
include *.rst
recursive-include doc *.rst
recursive-include doc/_templates *.html
recursive-include doc/_static *
A Python Interface to Conic Optimization Solvers
================================================
PICOS is a user friendly Python API to several conic and integer programming
solvers, very much like [YALMIP](http://users.isy.liu.se/johanl/yalmip/) or
[CVX](http://cvxr.com/cvx/) under [MATLAB](http://www.mathworks.com/).
PICOS allows you to enter a mathematical optimization problem as a **high level
model**, with painless support for **(complex) vector and matrix variables** and
**multidemensional algebra**. Your model will be transformed to the standard form
understood by an appropriate solver that is available at runtime. This makes
your application **portable** as users have the choice between several commercial
and open source solvers.
Features
--------
PICOS runs under both **Python 2** and **Python 3** and supports the following
solvers and problem types. To use a solver, you need to seperately install it
along with the Python interface listed here.
| Solver | Interface | [LP](https://en.wikipedia.org/wiki/Linear_programming) | [SOCP](https://en.wikipedia.org/wiki/Second-order_cone_programming) | [SDP](https://en.wikipedia.org/wiki/Semidefinite_programming) | [QCQP](https://en.wikipedia.org/wiki/Quadratically_constrained_quadratic_program) | [EXP](https://docs.mosek.com/modeling-cookbook/expo.html) | [MIP](https://en.wikipedia.org/wiki/Integer_programming) | License |
| --------------------------------------------------------- | ---------------------------------------------------------- | --- | --- | --- | --- | --- | --- | -------- |
| [CPLEX](https://www.ibm.com/analytics/cplex-optimizer) | included | Yes | Yes | | Yes | | Yes | non-free |
| [CVXOPT](https://cvxopt.org/) | native | Yes | Yes | Yes | Yes | Yes¹| | [GPL-3](https://www.gnu.org/licenses/gpl-3.0.html) |
| [ECOS](https://www.embotech.com/ECOS)² | [ecos-python](https://github.com/embotech/ecos-python) | Yes | Yes | | Yes | Yes | Yes | [GPL-3](https://www.gnu.org/licenses/gpl-3.0.html) |
| [GLPK](https://www.gnu.org/software/glpk/)² | [swiglpk](https://github.com/biosustain/swiglpk) | Yes | | | | | Yes | [GPL-3](https://www.gnu.org/licenses/gpl-3.0.html) |
| [Gurobi](http://www.gurobi.com/products/gurobi-optimizer) | included | Yes | Yes | | Yes | | Yes | non-free |
| [MOSEK](https://www.mosek.com/) | included | Yes | Yes | Yes | Yes | | Yes | non-free |
| [SMCP](http://smcp.readthedocs.io/en/latest/) | native | Yes³| Yes³| Yes | Yes³| | | [GPL-3](https://www.gnu.org/licenses/gpl-3.0.html) |
| [SCIP](http://scip.zib.de/)² | [PySCIPOpt](https://github.com/SCIP-Interfaces/PySCIPOpt/) | Yes | Yes | | Yes | | Yes | [ZIB](https://scip.zib.de/academic.txt)/[MIT](https://github.com/SCIP-Interfaces/PySCIPOpt/blob/master/LICENSE) |
¹ only [geometric programming](https://en.wikipedia.org/wiki/Geometric_programming),
² [work in progress](https://gitlab.com/picos-api/picos/tree/future),
³ experimental
### Example
This is what it looks like to solve a multidimensional mixed integer program
with PICOS:
```python
>>> import picos
>>> P = picos.Problem()
>>> x = P.add_variable("x", 2, vtype="integer")
>>> C = P.add_constraint(x <= 5.5)
>>> P.set_objective("max", 1|x) # 1|x is the sum over x
>>> solution = P.solve(verbose = 0)
>>> print(solution["status"])
'integer optimal solution'
>>> print(P.obj_value())
10.0
>>> print(x)
[ 5.00e+00]
[ 5.00e+00]
>>> print(C.slack)
[ 5.00e-01]
[ 5.00e-01]
```
### Documentation & Source
The full documentation can be found [here](https://picos-api.gitlab.io/picos/).
The source code lives on [GitLab](https://gitlab.com/picos-api/picos).
The page you are reading is featured in both places.
Installation
------------
### Via pip
If you are using [pip](https://pypi.org/project/pip/) you can run
``pip install picos`` to get the latest version.
### Via Anaconda
If you are using [Anaconda](https://anaconda.org/) you can run
``conda install -c picos picos`` to get the latest version.
### Via your system's package manager
On **Arch Linux**, there are seperate packages in the AUR for the
[latest version](https://aur.archlinux.org/packages/python-picos-git/) and the
[latest release](https://aur.archlinux.org/packages/python-picos/). Both are
split packages that ship both Python 2 and Python 3 versions of PICOS.
If you are packaging PICOS for additional systems, please tell us so we can list
your package here!
### From source
If you are installing PICOS manually, you can choose between a number of
[development versions](https://gitlab.com/picos-api/picos/branches) and
[source releases](https://gitlab.com/picos-api/picos/tags).
You will need to have at least the following Python packages installed:
- [Six](https://pypi.org/project/six/)
- [NumPy](http://www.numpy.org/)
- [CVXOPT](https://cvxopt.org/)
Credits
-------
### Developers
- [Guillaume Sagnol](http://page.math.tu-berlin.de/~sagnol/) is PICOS' initial
author and primary developer since 2012.
- [Maximilian Stahlberg](about:blank) is extending and maintaining PICOS since
2017.
### Contributors
For an up-to-date list of all code contributors, please refer to the
[contributors page](https://gitlab.com/picos-api/picos/graphs/master).
Should a reference from before 2019 be unclear, you can refer to the
[old contributors page](https://github.com/gsagnol/picos/graphs/contributors)
on GitHub as well.
License
-------
PICOS is free and open source software and available to you under the terms of
the [GNU GPL v3](https://gitlab.com/picos-api/picos/raw/master/LICENSE.txt).
`PICOS <http://picos.zib.de/>`_ is a user friendly interface
to several conic and integer programming solvers,
very much like `YALMIP <http://users.isy.liu.se/johanl/yalmip/>`_
or `CVX <http://cvxr.com/cvx/>`_ under `MATLAB <http://www.mathworks.com/>`_.
The main motivation for PICOS is to have the possibility to
enter an optimization problem as a *high level model*,
and to be able to solve it with several *different solvers*.
Multidimensional and matrix variables are handled in a natural fashion,
which makes it painless to formulate a SDP or a SOCP.
This is very useful for educational purposes,
and to quickly implement some models and
test their validity on simple examples.
Furthermore, with PICOS you can take advantage of the
python programming language to read and write data,
construct a list of constraints by using python list comprehensions,
take slices of multidimensional variables, etc.
Author
======
Picos initial author and current primary developer is:
`Guillaume Sagnol <http://www.zib.de/sagnol>`_, <sagnol( a t )zib.de>
Contributors
============
People who actively contributed to the code of Picos (in no particular order)
* `Sergio Callegari <http://www.unibo.it/faculty/sergio.callegari>`_
* `Petter Wittek <http://peterwittek.com/>`_
* Paul Fournel
* Arno Ulbricht
* Bertrand Omont
Thanks also to
==============
People who contributed to the improvement of Picos by sending
their comments, ideas, questions, ... (in no particular order):
* `Dan Stahlke <http://www.stahlke.org/>`_
* `Marco Dalai <http://www.ing.unibs.it/~marco.dalai/>`_
* `Matteo Seminaroti <http://www.cwi.nl/people/2683/>`_
* `Warren Schudy <http://cs.brown.edu/~ws/>`_
* `Elmar Swarat <http://www.zib.de/swarat>`_
$PYTHON setup.py install --single-version-externally-managed --record=record.txt
python:
- 2.7
- 3.6
# vi:ts=2:et:ai
about:
description: "A python interface to conic optimization solvers."
home: https://gitlab.com/picos-api/picos
license: GPL-3.0
package:
name: picos
version: {{ load_setup_py_data().version }}
source:
git_url: ..
build:
number: 0
include_recipe: False
requirements:
build:
- python {{ python }}
- setuptools
run:
- python {{ python }}
- cvxopt
- numpy
- six
test:
imports:
- picos
# vi:ts=2:et:ai
#!/bin/bash -l
#-------------------------------------------------------------------------------
# Copyright (C) 2018 Maximilian Stahlberg
#
# This file is part of PICOS Release Scripts.
#
# PICOS Release Scripts are free software: you can redistribute it and/or modify
# them under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PICOS Release Scripts are distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# This script builds Conda packages for all relevant platforms and uploads them
# to Anaconda Cloud. To use the script, you need a working Conda distribution
# and an Anaconda user account that has access to the ${grpname} account.
#-------------------------------------------------------------------------------
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
# Base name of the package that will be built.
pkgname="picos"
# Platforms to upload packages for.
platforms="linux-32 linux-64 win-32 win-64 osx-64"
# Name of the Anaconda user or group account to publish at.
grpname="picos"
# Output directory for built packages, relative to the recipe directory.
builddir="pkg"
# Name of the temporary conda environment.
buildenv="${pkgname}-build"
echo ">>> Removing an existing build environment, if present."
conda remove -y -n "${buildenv}" --all
echo ">>> Creating the temporary build environment."
conda create -y -n "${buildenv}" git conda-build anaconda-client
echo ">>> Activating the build environment."
conda activate "${buildenv}"
echo ">>> Building the packages."
condacmd="conda build . --no-anaconda-upload --output-folder ${builddir}"
${condacmd}
startpkgfiles="$(${condacmd} --output)"
echo ">>> Converting the packages for other OS."
for pkgfile in ${startpkgfiles}; do
conda convert ${pkgfile} -p all -o "${builddir}"
done
echo ">>> Uploading the packages to Anaconda Cloud."
pkgfiles=""
for pkgfile in ${startpkgfiles}; do
pkgfilename="$(basename "${pkgfile}")"
for platform in ${platforms}; do
pkgfiles+=" ${builddir}/${platform}/${pkgfilename}"
done
done
if anaconda upload --force -u "${grpname}" ${pkgfiles}; then
echo "(-) Upload successful."
exitcode=0
else
echo "(E) Upload failed."
exitcode=1
fi
echo ">>> Dectivating the build environment."
conda deactivate
echo ">>> Removing the build environment."
conda remove -y -n "${buildenv}" --all
exit ${exitcode}
build/
*.xcf
......@@ -5,9 +5,7 @@
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
RSYNC = rsync
LASTDIR = full_html/last
BUILDDIR = build
# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
......@@ -55,9 +53,6 @@ html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
@echo "Sync-ing with the /last directory"
$(RSYNC) -uzvr $(BUILDDIR)/html/* $(LASTDIR)
@echo "Done. The last build is in $(LASTDIR)"
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
......
This diff is collapsed.
{#
basic/download.html
~~~~~~~~~~~~~~~~~~~
Sphinx sidebar template: download link.
#}
<h3><a href="download.html">{{ _('Download') }}</a></h3>
<ul class="this-page-menu">
<li><a href="{{'dist/PICOS-'+release+'.tar.gz'}}">{{ _('Latest Version ('+release+')') }}</a></li>
</ul>
{#
basic/localtoc2.html
~~~~~~~~~~~~~~~~~~~
Sphinx sidebar template: local table of contents.
:copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- if display_toc %}
<h3><a href="{{ pathto(master_doc) }}">{{ _('Contents of this page') }}</a></h3>
{{ toc }}
{%- endif %}
.. _api:
*******************
The PICOS Reference
*******************
API Reference
=============
.. toctree::
:maxdepth: 2
problem.rst
tools.rst
expression.rst
constraint.rst
tools.rst
.. _changelog:
.. mdinclude:: ../CHANGELOG.md
This diff is collapsed.
:tocdepth: 2
.. _cheatsheet:
.. _summary:
Cheat Sheet
===========
************************************
**Summary of implemented functions**
************************************
===========================================
*Operators to manipulate PICOS Expressions*
===========================================
Manipulate expressions
----------------------
+--------------+--------------------------------+
| **Operator** | **Interpretation** |
......@@ -50,10 +46,8 @@
| ``.imag`` | imaginary part |
+--------------+--------------------------------+
===================================
*Operators that create constraints*
===================================
Create constraints
------------------
+-----------------+-----------------------------------+
| **Operator** | **Interpretation** |
......@@ -71,9 +65,8 @@
| | or set membership :math:`\ni` |
+-----------------+-----------------------------------+
==========================================
*functions that create affine expressions*
==========================================
Create affine expressions
-------------------------
+--------------------------------------------------------------+-------------------------------------------+
| **function** | **short doc** |
......@@ -95,10 +88,8 @@
|:func:`partial_trace() <picos.tools.partial_trace>` | partial trace |
+--------------------------------------------------------------+-------------------------------------------+
========================================
*functions to create convex constraints*
========================================
Create convex expressions
-------------------------
+-------------------------------------------------------------------+-----------------------------------------+
| **function** | **short doc** |
......@@ -107,9 +98,9 @@
+-------------------------------------------------------------------+-----------------------------------------+
|:func:`norm() <picos.tools.norm>` | (generalized) :math:`L_p-` norm |
+-------------------------------------------------------------------+-----------------------------------------+
|:func:`tracepow() <picos.tools.tracepow>` | trace of a *p*th matrix power |
|:func:`tracepow() <picos.tools.tracepow>` | trace of a *p*-th matrix power |
+-------------------------------------------------------------------+-----------------------------------------+
|:func:`detrootn() <picos.tools.detrootn>` | *n*th root of determinant |
|:func:`detrootn() <picos.tools.detrootn>` | *n*-th root of determinant |
+-------------------------------------------------------------------+-----------------------------------------+
|:func:`sum_k_largest() <picos.tools.sum_k_largest>` | sum of k largest elements |
+-------------------------------------------------------------------+-----------------------------------------+
......@@ -124,31 +115,28 @@
|:func:`lambda_min() <picos.tools.lambda_min>` | smallest eigenvalue |
+-------------------------------------------------------------------+-----------------------------------------+
============================
*functions that create sets*
============================
+-------------------------------------------------------------+------------------------------------------------------------------+
| **function** | **short doc** |
+=============================================================+==================================================================+
|:func:`ball(r,p) <picos.tools.ball>` | a :math:`L_p`- ball of radius ``r`` |
+-------------------------------------------------------------+------------------------------------------------------------------+
|:func:`simplex(a) <picos.tools.simplex>` | a standard simplex |
| | :math:`\{x\geq 0: \Vert x \Vert_1 \leq a \}` |
+-------------------------------------------------------------+------------------------------------------------------------------+
|:func:`truncated_simplex(a) <picos.tools.truncated_simplex>` | a set of the form |
| |:math:`\{ 0\leq x\leq 1: \Vert x \Vert_1 \leq a\}`, or |
| |:math:`\{x: \Vert x \Vert_\infty \leq 1; \Vert x \Vert_1 \leq a\}`|
+-------------------------------------------------------------+------------------------------------------------------------------+
========================
*Other useful functions*
========================
To transform a problem
Create sets
-----------
+-------------------------------------------------------------+--------------------------------------------------------------------+
| **function** | **short doc** |
+=============================================================+====================================================================+
|:func:`ball(r,p) <picos.tools.ball>` | a :math:`L_p`- ball of radius ``r`` |
+-------------------------------------------------------------+--------------------------------------------------------------------+
|:func:`simplex(a) <picos.tools.simplex>` | a standard simplex |
| | :math:`\{x\geq 0: \Vert x \Vert_1 \leq a \}` |
+-------------------------------------------------------------+--------------------------------------------------------------------+
|:func:`truncated_simplex(a) <picos.tools.truncated_simplex>` | a set of the form |
| | :math:`\{ 0\leq x\leq 1: \Vert x \Vert_1 \leq a\}`, or |
| | :math:`\{x: \Vert x \Vert_\infty \leq 1; \Vert x \Vert_1 \leq a\}` |
+-------------------------------------------------------------+--------------------------------------------------------------------+
Other useful functions
----------------------
Transform a problem
~~~~~~~~~~~~~~~~~~~
+-----------------------------------------------------------------+------------------------------------------------------+
| **function** | **short doc** |
+=================================================================+======================================================+
......@@ -161,7 +149,7 @@ To transform a problem
+-----------------------------------------------------------------+------------------------------------------------------+
Get information on a problem
----------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-----------------------------------------------------------------------------------------+-------------------------------------------+
| **function** | **short doc** |
......@@ -177,9 +165,8 @@ Get information on a problem
|:attr:`.type <picos.Problem.type>` | returns problem's type |
+-----------------------------------------------------------------------------------------+-------------------------------------------+
Other tools
------------
Miscellaneous
~~~~~~~~~~~~~
+-----------------------------------------------------------+-------------------------------------------+
| **function** | **short doc** |
......@@ -193,4 +180,3 @@ Other tools
+-----------------------------------------------------------+-------------------------------------------+
| :func:`write_to_file() <picos.Problem.write_to_file>` | writes problem to a file |
+-----------------------------------------------------------+-------------------------------------------+
:tocdepth: 2
.. _complex:
************************************
**Complex Semidefinite Programming**
************************************
Complex Semidefinite Programming
================================
Since the version 1.0.1, it is possible to
do complex semidefinite programming with Picos.
......@@ -12,7 +9,7 @@ This extension of semidefinite programming to
the complex domain was introduced by Goemans and Williamson :ref:`[1] <complex_refs>`
as relaxtions of combinatorial optimization problems, and
has applications
e.g. in Quantum Information Theory :ref:`[2] <complex_refs>`, or
e.g. in Quantum Information Theory :ref:`[2] <complex_refs>`, or
for the phase recovery problem in signal processing :ref:`[3] <complex_refs>`.
To handle complex SDPs in Picos, we have introduced two new variable types: ``'complex'``
......@@ -22,7 +19,7 @@ and ``'hermitian'``. A complex variable can be created as follows:
>>> import cvxopt as cvx
>>> P = pic.Problem()
>>> Z = P.add_variable('Z',(3,2),'complex')
it automatically creates two variables called ``Z_RE`` and ``Z_IM`` which contains the
real and imaginary part of ``Z``, and that be accessed by using the ``real`` and ``imag`` properties:
......@@ -45,12 +42,10 @@ anf ``H`` (Hermitian transposition, i.e. ``exp.H`` returns ``exp.conj.T`` ).
>>> X = P.add_variable('X',(3,3),'hermitian')
>>> X >> 0
# (3x3)-LMI constraint X ≽ |0| #
*Fidelity in Quantum Information Theory*
========================================
Fidelity in Quantum Information Theory
--------------------------------------
The material of this section is inspired from a lecture of John Watrous :ref:`[4] <complex_refs>`.
......@@ -66,13 +61,13 @@ This quantity can be expressed as the optimal value of the following complex-val
.. math::
:nowrap:
\begin{center}
\begin{eqnarray*}
&\underset{Z \in \mathbb{C}^{n \times n}}
{\mbox{maximize}}
& \frac{1}{2}\operatorname{trace}(Z + Z^*)\\
&\mbox{subject to} &
&\mbox{subject to} &
\left(\begin{array}{cc}
P & Z \\
Z^* & Q
......@@ -83,14 +78,14 @@ This quantity can be expressed as the optimal value of the following complex-val
This Problem can be solved as follows in PICOS
.. testcode::
#generate two (arbitrary) positive hermitian operators
P = cvx.matrix([ [1-1j , 2+2j , 1 ],
[3j , -2j , -1-1j],
[1+2j, -0.5+1j, 1.5 ]
])
P = P * P.H
Q = cvx.matrix([ [-1-2j , 2j , 1.5 ],
[1+2j ,-2j , 2.-3j ],
[1+2j ,-1+1j , 1+4j ]
......@@ -100,47 +95,47 @@ This Problem can be solved as follows in PICOS
n=P.size[0]
P = pic.new_param('P',P)
Q = pic.new_param('Q',Q)
#create the problem in picos
F = pic.Problem()
Z = F.add_variable('Z',(n,n),'complex')
F.set_objective('max','I'|0.5*(Z+Z.H)) #('I' | Z.real) works as well
F.add_constraint(((P & Z) // (Z.H & Q))>>0 )
print F
F.solve(verbose = 0)
print 'fidelity: F(P,Q) = {0:.4f}'.format(F.obj_value())
print 'optimal matrix Z:'
print Z
print(F)
F.solve(verbose = 0, solver = 'cvxopt')
print('fidelity: F(P,Q) = {0:.4f}'.format(F.obj_value()))
print('optimal matrix Z:')
print(Z)
#verify that we get the same value with numpy
import numpy as np
PP = np.matrix(P.value)
QQ = np.matrix(Q.value)
S,U = np.linalg.eig(PP)
sqP = U * np.diag([s**0.5 for s in S]) * U.H #square root of P
S,U = np.linalg.eig(QQ)
sqQ = U * np.diag([s**0.5 for s in S]) * U.H #square root of P
fidelity = sum(np.linalg.svd(sqP * sqQ)[1]) #trace-norm of P**0.5 * Q**0.5
print 'fidelity computed by trace-norm: F(P,Q) = {0:.4f}'.format(fidelity)
fidelity = sum(np.linalg.svd(sqP * sqQ)[1]) #trace-norm of P**0.5 * Q**0.5
print('fidelity computed by trace-norm: F(P,Q) = {0:.4f}'.format(fidelity))
.. testoutput::
:options: +NORMALIZE_WHITESPACE
---------------------
optimization problem (SDP):
18 variables, 0 affine constraints, 21 vars in 1 SD cones
Z_RE : (3, 3), continuous
Z_IM : (3, 3), continuous
Z_RE : (3, 3), continuous
maximize trace( 0.5*( Z + Z.H ) )
such that
......@@ -150,13 +145,13 @@ This Problem can be solved as follows in PICOS
optimal matrix Z:
[ 1.51e+01+j2.21e+00 -7.17e+00-j1.22e+00 2.52e+00+j6.87e-01]
[-4.88e+00+j4.06e+00 1.00e+01-j1.57e-01 8.33e+00+j1.13e+01]
[-4.32e-01+j2.98e-01 3.84e+00-j3.28e+00 1.24e+01-j2.05e+00]
[-4.33e-01+j2.98e-01 3.84e+00-j3.28e+00 1.24e+01-j2.05e+00]
fidelity computed by trace-norm: F(P,Q) = 37.4742
*Phase Recovery in Signal Processing*
=====================================
Phase Recovery in Signal Processing
-----------------------------------
The material from this section is inspired from :ref:`[3] <complex_refs>`.
......@@ -171,7 +166,7 @@ the *Phase-cut* Problem is:
.. math::
:nowrap:
\begin{center}
\begin{eqnarray*}
&\underset{U \in \mathbb{H}_n}
......@@ -189,44 +184,44 @@ Otherwise, the leading singular vector of :math:`U` is used as an approximation.
This problem can be implemented as follows using Picos:
.. testcode::
# We generate an arbitrary matrix M
import cvxopt as cvx
import picos as pic
n = 5
rank = 4 #we take a singular M for the sake of generality
M = cvx.normal (n,rank) +1j*cvx.normal (n,rank)
rank = 4 #we take a singular M for the sake of generality
M = cvx.normal (n,rank) +1j*cvx.normal (n,rank)
M = M * M.H
M = pic.new_param('M',M)
P = pic.Problem()
U = P.add_variable('U',(n,n),'hermitian')
P.add_list_of_constraints([U[i,i]==1 for i in range(n)],'i')
P.add_constraint(U >> 0)
P.set_objective('min', U | M)
print P
print(P)
#solve the problem
P.solve(verbose=0)
P.solve(verbose=0, solver='cvxopt')
#optimal complex variable
print
print 'optimal variable: U='
print U
print
print()
print('optimal variable: U=')
print(U)
print()
#Do we have a matrix of rank one ?
S, V = np.linalg.eig(U.value)
print 'rank of U = ', len([s for s in S if abs(s)>1e-6])
print('rank of U = ', len([s for s in S if abs(s)>1e-6]))
.. testoutput::
:options: +SKIP
---------------------
optimization problem (SDP):
36 variables, 8 affine constraints, 36 vars in 1 SD cones
......@@ -249,12 +244,11 @@ This problem can be implemented as follows using Picos:
rank of U = 2
.. _complex_refs:
*References*
============
References
----------
1. "Approximation algorithms for MAX-3-CUT and other problems via complex semidefinite programming",
M.X. Goemans and D. Williamson. In Proceedings of the thirty-third annual
......@@ -262,9 +256,9 @@ This problem can be implemented as follows using Picos:
2. "Semidefinite programs for completely bounded norms",
J. Watrous, arXiv preprint 0901.4709, 2009.
3. "Phase recovery, maxcut and complex semidefinite programming",
I. Waldspurger, A. d'Aspremont, and S. Mallat. *Mathematical Programming*, pp. 1-35, 2012.
4. "Semidefinite Programs for fidelity and optimal measurements", J. Watrous,
in the script of a `course on Theory of Quantum Information <https://cs.uwaterloo.ca/~watrous/CS766/LectureNotes/08.pdf>`_
in the script of a `course on Theory of Quantum Information <https://cs.uwaterloo.ca/~watrous/CS766/LectureNotes/08.pdf>`_
This diff is collapsed.
:tocdepth: 1
constraint.py
=============
.. _constraint:
==============
**Constraint**
==============
Constraint
----------
.. autoclass:: picos.Constraint
:members:
GeoMeanConstraint
-----------------
.. autoclass:: picos.GeoMeanConstraint
:members:
:inherited-members: slack
NormP_Constraint
----------------
.. autoclass:: picos.NormP_Constraint
:members:
:inherited-members: slack
NormPQ_Constraint
-----------------
.. autoclass:: picos.NormPQ_Constraint
:members:
:inherited-members: slack
TracePow_Constraint
-------------------
.. autoclass:: picos.TracePow_Constraint
:members:
:inherited-members: slack
Flow_Constraint
---------------
.. autoclass:: picos.Flow_Constraint
:members:
DetRootN_Constraint
-------------------
.. autoclass:: picos.DetRootN_Constraint
:members:
:inherited-members: slack
Sumklargest_Constraint
----------------------
.. autoclass:: picos.Sumklargest_Constraint
:members:
:inherited-members: slack
\ No newline at end of file
:inherited-members: slack
.. _contributing: