Commits (344)
......@@ -3,8 +3,10 @@
# Working files
patch
fix*.py
fix*/
fix_*.py
fix_*/
test_*.py
test_*/
# Byte-compiled / optimized / DLL files
__pycache__/
......
......@@ -4,25 +4,34 @@ stages:
- test
- deploy
old test:
testbench (py3):
stage: test
before_script:
- pacman -Sy --noconfirm python-six python-numpy python-cvxopt
# Install PICOS dependencies.
- pacman -Sy --noconfirm python-numpy python-cvxopt
# Install additional solvers.
- pacman -S --noconfirm python-pip glpk gcc
- pip install swiglpk smcp
script:
- python ./test_picos.py
- python ./test.py -vv -s cvxopt glpk smcp
old test (py2):
testbench (py2):
stage: test
before_script:
- pacman -Sy --noconfirm python2-six python2-numpy python2-cvxopt
# Install PICOS dependencies.
- pacman -Sy --noconfirm python2-numpy python2-cvxopt
# Install additional solvers.
- pacman -S --noconfirm python2-pip glpk gcc
- pip2 install swiglpk smcp
script:
- python2 ./test_picos.py
- python2 ./test.py -vv -s cvxopt glpk smcp
doctest:
stage: test
before_script:
- pacman -Sy --noconfirm python-six python-numpy python-cvxopt
- pacman -Sy --noconfirm python-pip python-numpy python-cvxopt
- pacman -S --noconfirm m2r python-sphinx python-matplotlib python-networkx
- pip install sphinx-automodapi
script:
- sphinx-build -b doctest doc doctest
......@@ -41,7 +50,7 @@ anaconda:
stage: deploy
before_script:
# Install Miniconda from the AUR.
- pacman -Sy --noconfirm wget fakeroot
- pacman -Sy --noconfirm wget fakeroot audit
- wget https://aur.archlinux.org/cgit/aur.git/snapshot/miniconda3.tar.gz
- tar xf miniconda3.tar.gz
- cd miniconda3
......@@ -61,12 +70,12 @@ pages:
stage: deploy
before_script:
# Install PICOS dependencies.
- pacman -Sy --noconfirm python-six python-numpy python-cvxopt
- pacman -Sy --noconfirm 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
- pacman -S --noconfirm git python-pip glpk graphviz
- pip install sphinx-automodapi swiglpk
script:
- sphinx-build -b html doc html
- mkdir public
......
......@@ -3,6 +3,7 @@
This file documents major changes to PICOS.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
[1.2.0]: https://gitlab.com/picos-api/picos/compare/v1.1.3...v1.2.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
......@@ -16,6 +17,64 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
[0.1.0]: about:blank
## [1.2.0] - 2019-01-11
### Important
- :attr:`A scalar expression's value <picos.expressions.Expression.value>` and
:attr:`a scalar constraint's dual <picos.constraints.Constraint.dual>` are
returned as scalar types as opposed to 1×1 matrices.
- The dual value returned for rotated second order cone constraints is now a
proper member of the dual cone (which equals the primal cone up to a factor of
:math:`4`). Previously, the dual of an equivalent second order cone constraint
was returned.
- The Python 2/3 compatibility library ``six`` is no longer a dependency.
### Added
- Support for the ECOS solver.
- Experimental support for MOSEK's new Fusion API.
- Full support for exponential cone programming.
- A production testing framework featuring around 40 novel optimization test
cases that allows quick selection of tests, solvers, and solver options.
- A "glyph" system that allows the user to adjust the string representations of
future expressions and constraints. For instance,
:func:`picos.latin1() <picos.glyphs.latin1>` disables use of unicode symbols.
- Support for symmetric variables with all solvers, even if they do not support
semidefinite programming.
### Changed
- Solver implementations each have a source file of their own, and a common
interface that makes implementing new solvers easier.
- Likewise, constraint implementations each have a source file of their own.
- The implementations of CPLEX, Gurobi, MOSEK and SCIP have been rewritten.
- Solver selection takes into account how well a problem is supported,
distinguishing between native, secondary, experimental and limited support.
- Unsupported operations on expressions now produce meaningful exceptions.
- :func:`add_constraint <picos.Problem.add_constraint>` and
:func:`add_list_of_constraints <picos.Problem.add_list_of_constraints>`
always return the constraints
passed to them.
- :func:`add_list_of_constraints <picos.Problem.add_list_of_constraints>`
and :func:`picos.sum <picos.tools.sum>` find a short string representation
automatically.
### Removed
- The old production testing script.
- Support for the SDPA solver.
- Support for sequential quadratic programming.
- The options ``convert_quad_to_socp_if_needed``, ``pass_simple_cons_as_bound``,
``return_constraints``, ``handleBarVars``, ``handleConeVars`` and
``smcp_feas``.
- Support for GLPK and MOSEK through CVXOPT.
### Fixed
- Performance issues when exporting variable bounds to CVXOPT.
- Hadamard product involving complex matrices.
- Adding constant terms to quadratic expression.
- Incorrect or redundant expression string representations.
- GLPK handling of the default ``maxit`` option.
- Miscellaneous solver-specific bugs in the solvers that were re-implemented.
## [1.1.3] - 2018-10-05
### Added
......@@ -106,8 +165,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- 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``.
- New :attr:`variable type <picos.expressions.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>`.
......@@ -118,11 +177,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
``^`` 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>`.
:attr:`AffinExp.Tx <picos.expressions.AffinExp.Tx>`.
### Changed
- Improved efficiency of the sparse SDPA file format writer.
- Improved efficiency of :func:`to_real <picos.Problem.to_real>`.
- Improved efficiency of :func:`to_real <picos.Problem.as_real>`.
### Fixed
- Scalar product of hermitian matrices.
......@@ -136,15 +195,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
: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
- Additional ``coef`` argument to :func:`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__>`.
- Significantly improved slicing performance for
:class:`affine expressions <picos.expressions.AffinExp>`.
- Improved performance of
:func:`_retrieve_matrix <picos.tools._retrieve_matrix>`.
:func:`retrieve_matrix <picos.tools.retrieve_matrix>`.
- Improved performance when retrieving primal solution from CPLEX.
- The documentation received an overhaul.
......@@ -159,11 +218,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
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>`.
:func:`set_lower() <picos.expressions.Variable.set_lower>`,
:func:`set_upper() <picos.expressions.Variable.set_upper>`,
:func:`set_sparse_lower() <picos.expressions.Variable.set_sparse_lower>` and
:func:`set_sparse_upper() <picos.expressions.Variable.set_sparse_upper>`.
- Problem dualization, see :func:`dualize <picos.Problem.as_dual>`.
- 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.
......
......@@ -7,10 +7,10 @@ solvers, very much like [YALMIP](http://users.isy.liu.se/johanl/yalmip/) or
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.
**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
--------
......@@ -23,16 +23,15 @@ along with the Python interface listed here.
| --------------------------------------------------------- | ---------------------------------------------------------- | --- | --- | --- | --- | --- | --- | -------- |
| [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) |
| [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) |
| [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
² experimental
### Example
......@@ -94,7 +93,6 @@ If you are installing PICOS manually, you can choose between a number of
[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/)
......
......@@ -23,7 +23,6 @@ requirements:
- python {{ python }}
- cvxopt
- numpy
- six
test:
imports:
......
build/
automodapi/
*.xcf
......@@ -3,10 +3,45 @@
API Reference
=============
.. rubric:: Basic interface
To use PICOS to its full extend you just need to know about the two components
below.
.. toctree::
:maxdepth: 3
api/problem.rst
api/tools.rst
.. rubric:: Generated expressions and constraints
When you use the basic interface above, PICOS creates mathematical expressions
and constraints involving your variables and data. The following sections
describe these objects.
.. toctree::
:maxdepth: 3
api/expressions.rst
api/constraints.rst
.. rubric:: Customizing PICOS
The following components allow you to fine-tune the behavior of PICOS.
.. toctree::
:maxdepth: 3
api/glyphs.rst
.. rubric:: Internal Gears
You don't usually come in direct contact with the classes and functions below,
but if you like to poke around or :ref:`contribute to PICOS <contributing>` we
got you covered!
.. toctree::
:maxdepth: 2
:maxdepth: 3
problem.rst
expression.rst
constraint.rst
tools.rst
api/solvers.rst
.. _constraints:
The Constraints package
=======================
.. automodapi:: picos.constraints
:no-heading:
:headings: =-
.. _expression:
The Expressions module
======================
.. automodule:: picos.expressions
.. _glyphs:
The Glyphs module
=================
.. automodule:: picos.glyphs
.. _problem:
The Problem class
=================
The :class:`Problem <picos.Problem>` class represents your optimization problem
and is your main way of interfacing PICOS. After you create a problem instance,
you can add variables to it via :meth:`add_variable
<picos.Problem.add_variable>` and use standard Python algebraic operators
(:ref:`cheatsheet`) and algebraic functions (:ref:`tools`) to create expressions
and constraints involving these variables.
.. autoclass:: picos.Problem
.. _solvers:
The Solvers package
===================
.. automodapi:: picos.solvers
:no-heading:
:headings: =-
.. _tools:
The Tools module
================
Many of the tools, in particular the algebraic functions, are also available
in the ``picos`` namespace. For example, you can write :func:`picos.sum
<picos.tools.sum>` instead of :func:`picos.tools.sum <picos.tools.sum>`.
In the future, we are looking to split the toolbox into mutltiple modules, so
that it is clear which of the functions are imported into the ``picos``
namespace.
.. automodule:: picos.tools
......@@ -137,16 +137,16 @@ Other useful functions
Transform a problem
~~~~~~~~~~~~~~~~~~~
+-----------------------------------------------------------------+------------------------------------------------------+
| **function** | **short doc** |
+=================================================================+======================================================+
|:func:`convert_quad_to_socp() <picos.tools.convert_quad_to_socp>`| replaces quadratic constraints by |
| | equivalent second order cone constraints |
+-----------------------------------------------------------------+------------------------------------------------------+
|:func:`to_real() <picos.tools.to_real>` | transform complex SDP to equivalent real-valued SDP |
+-----------------------------------------------------------------+------------------------------------------------------+
|:func:`dualize() <picos.tools.dualize>` | returns Lagrangian dual of a problem |
+-----------------------------------------------------------------+------------------------------------------------------+
+-------------------------------------------------------------------+------------------------------------------------------+
| **function** | **short doc** |
+===================================================================+======================================================+
|:func:`convert_quad_to_socp() <picos.Problem.convert_quad_to_socp>`| replaces quadratic constraints by |
| | equivalent second order cone constraints |
+-------------------------------------------------------------------+------------------------------------------------------+
|:func:`as_real() <picos.Problem.as_real>` | transform complex SDP to equivalent real-valued SDP |
+-------------------------------------------------------------------+------------------------------------------------------+
|:func:`as_dual() <picos.Problem.as_dual>` | returns Lagrangian dual of a problem |
+-------------------------------------------------------------------+------------------------------------------------------+
Get information on a problem
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -168,15 +168,15 @@ Get information on a problem
Miscellaneous
~~~~~~~~~~~~~
+-----------------------------------------------------------+-------------------------------------------+
| **function** | **short doc** |
+===========================================================+===========================================+
|:func:`available_solvers() <picos.tools.available_solvers>`| lists installed solvers |
+-----------------------------------------------------------+-------------------------------------------+
|:func:`import_cbf() <picos.tools.import_cbf>` | imports data from a .cbf file |
+-----------------------------------------------------------+-------------------------------------------+
|:func:`eval_dict() <picos.tools.eval_dict>` | evaluates a dictionary of picos variables |
| | (after a problem has been solved) |
+-----------------------------------------------------------+-------------------------------------------+
| :func:`write_to_file() <picos.Problem.write_to_file>` | writes problem to a file |
+-----------------------------------------------------------+-------------------------------------------+
+-------------------------------------------------------------+-------------------------------------------+
| **function** | **short doc** |
+=============================================================+===========================================+
|:func:`available_solvers() <picos.solvers.available_solvers>`| lists installed solvers |
+-------------------------------------------------------------+-------------------------------------------+
|:func:`import_cbf() <picos.tools.import_cbf>` | imports data from a .cbf file |
+-------------------------------------------------------------+-------------------------------------------+
|:func:`eval_dict() <picos.tools.eval_dict>` | evaluates a dictionary of picos variables |
| | (after a problem has been solved) |
+-------------------------------------------------------------+-------------------------------------------+
| :func:`write_to_file() <picos.Problem.write_to_file>` | writes problem to a file |
+-------------------------------------------------------------+-------------------------------------------+
......@@ -24,9 +24,9 @@ it automatically creates two variables called ``Z_RE`` and ``Z_IM`` which contai
real and imaginary part of ``Z``, and that be accessed by using the ``real`` and ``imag`` properties:
>>> Z.real
# variable Z_RE:(3 x 2),continuous #
<3×2 Continuous Variable: Z_RE>
>>> Z.imag
# variable Z_IM:(3 x 2),continuous #
<3×2 Continuous Variable: Z_IM>
>>> Z.vtype
'complex'
......@@ -41,7 +41,7 @@ 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| #
<3×3 LMI Constraint: X ≽ 0>
Fidelity in Quantum Information Theory
......@@ -131,15 +131,15 @@ This Problem can be solved as follows in PICOS
:options: +NORMALIZE_WHITESPACE
---------------------
optimization problem (SDP):
optimization problem (Complex SDP):
18 variables, 0 affine constraints, 21 vars in 1 SD cones
Z_IM : (3, 3), continuous
Z_RE : (3, 3), continuous
maximize trace( 0.5*( Z + Z.H ) )
maximize trace(0.5·(Z + Zᴴ))
such that
[P,Z;Z.H,Q] ≽ |0|
[P, Z; Zᴴ, Q] ≽ 0
---------------------
fidelity: F(P,Q) = 37.4742
optimal matrix Z:
......@@ -228,10 +228,10 @@ This problem can be implemented as follows using Picos:
U : (8, 8), hermitian
minimize 〈 U | M 〉
minimize ⟨U, M⟩
such that
U[i,i] = 1.0 for all i
U ≽ |0|
U[i,i] = 1 ∀ i ∈ [0…4]
U ≽ 0
---------------------
optimal variable: U=
......
......@@ -15,24 +15,41 @@ sys.path.insert(0, os.path.abspath(".."))
# Add Sphinx extensions.
extensions = [
'sphinx.ext.autodoc',
# Use for a final build.
#'sphinx.ext.intersphinx'
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.doctest',
'sphinx.ext.imgmath',
'matplotlib.sphinxext.only_directives',
'sphinx_automodapi.automodapi',
'sphinx_automodapi.smart_resolver',
'matplotlib.sphinxext.plot_directive',
'm2r' # Markdown support.
]
# Configure autodoc.
autoclass_content = 'both'
autodoc_member_order = 'groupwise'
autodoc_default_options = {
'members': None,
'undoc-members': None,
# TODO: Uncomment once autodoc_inherit_docstrings works.
#'inherited-members': None,
'show-inheritance': True
}
# HACK: The following does not seem to work as expected, but at least it makes
# an unrelated warning go away…
autodoc_inherit_docstrings = False
# Configure automodapi.
automodapi_toctreedirnm = 'automodapi'
automodsumm_inherited_members = True
# Configure intersphinx.
intersphinx_cache_limit = 10
intersphinx_mapping = {
'sphinx': ('http://sphinx.pocoo.org', None),
'python': ('http://docs.python.org/2.7', None),
'matplotlib':('http://matplotlib.sourceforge.net', None),
'python': ('http://docs.python.org/3', None),
'numpy': ('http://docs.scipy.org/doc/numpy', None),
'cvxopt': ('http://abel.ee.ucla.edu/cvxopt/userguide', None),
'cvxopt': ('http://cvxopt.org/userguide', None)
}
# Configure matplotlib.
......@@ -40,25 +57,31 @@ plot_html_show_source_link = False
plot_formats = ['png']
plot_html_show_formats = False
# ???
# Configure todo.
todo_include_todos = True
# Add template directories.
templates_path = []
# Warn about all invalid references.
nitpicky = True
# HACK: Work around namedtuple instances throwing bad nitpicky warnings.
nitpick_ignore = [
("py:class", "SOCC"),
("py:class", "RSOCC")
]
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
projectname = u'PICOS'
project = u'PICOS'
copyright = u'2012–2018 G. Sagnol, 2017–2018 M. Stahlberg'
copyright = u'2012–2018 G. Sagnol, 2017–2019 M. Stahlberg'
# Name the version and release strings to use throughout the docuemnt.
from version import get_version, SHORT
......@@ -92,6 +115,9 @@ show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# Disable function parentheses.
add_function_parentheses = False
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
......
constraint.py
=============
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
expression.py
=============
Expression
----------
.. autoclass:: picos.Expression
:members:
AffinExp
--------
.. autoclass:: picos.AffinExp
:members:
Variable
--------
.. _variable:
.. autoclass:: picos.Variable
:members:
Norm
----
.. autoclass:: picos.Norm
:members:
QuadExp
-------
.. autoclass:: picos.QuadExp
:members:
LogSumExp
---------
.. autoclass:: picos.LogSumExp
:members:
GeoMeanExp
----------
.. autoclass:: picos.GeoMeanExp
:members:
NormP_Exp
---------
.. autoclass:: picos.NormP_Exp
:members:
TracePow_Exp
------------
.. autoclass:: picos.TracePow_Exp
:members:
DetRootN_Exp
------------
.. autoclass:: picos.DetRootN_Exp
:members:
Set
---
.. autoclass:: picos.Set
:members:
Ball
----
.. autoclass:: picos.Ball
:members:
Truncated_Simplex
-----------------
.. autoclass:: picos.Truncated_Simplex
:members:
......@@ -180,7 +180,7 @@ function :func:`flow_Constraint <picos.tools.flow_Constraint>`:
F=maxflow2.add_variable('F',1)
# Enforce all flow constraints at once.
maxflow2.addConstraint(pic.flow_Constraint(
maxflow2.add_constraint(pic.flow_Constraint(
G, f, source=16, sink=10, capacity='capacity', flow_value=F, graphName='G'))
# Set the objective.
......@@ -199,7 +199,7 @@ Let us now draw the maximum flow computed with the second approach:
new_figure()
# Determine which edges carry flow.
flow_edges=[e for e in G.edges() if f[e].value[0] > 1e-4]
flow_edges=[e for e in G.edges() if f[e].value > 1e-4]
# Draw the nodes and the edges that don't carry flow.
nx.draw_networkx(G, pos, edge_color='lightgrey', node_color=node_colors,
......@@ -306,9 +306,9 @@ We solve the min-cut problem below, again for ``s=16`` and ``t=10``:
# Determine the cut edges and node sets.
# Rounding is done because solvers might return near-optimal solutions due to
# numerical precision issues.
cut=[e for e in G.edges() if abs(d[e].value[0]-1) < 1e-6]
S =[n for n in G.nodes() if abs(p[n].value[0]-1) < 1e-6]
T =[n for n in G.nodes() if abs(p[n].value[0] ) < 1e-6]
cut=[e for e in G.edges() if abs(d[e].value-1) < 1e-6]
S =[n for n in G.nodes() if abs(p[n].value-1) < 1e-6]
T =[n for n in G.nodes() if abs(p[n].value ) < 1e-6]
Note that the minimum-cut can also be derived from the dual variables of the
max-flow LP:
......@@ -461,7 +461,7 @@ We solve the multicut problem below, for the terminal pairs
multicut.solve(verbose=0,solver='glpk')
# Extract the cut.
cut=[e for e in G.edges() if y[e].value[0]==1]
cut=[e for e in G.edges() if y[e].value==1]
Let us now draw the multicut:
......@@ -614,7 +614,7 @@ Then, we perform the random projection:
while (count < 100 or obj < 0.878*obj_sdp):
r=cvx.normal(20,1)
x=cvx.matrix(np.sign(V*r))
o=(x.T*L*x).value[0]
o=(x.T*L*x).value
if o > obj:
x_cut=x
obj=o
......
......@@ -132,16 +132,16 @@ Generated output:
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (SOCP):
optimization problem (SOCP):
32 variables, 5 affine constraints, 32 vars in 8 SO cones
mu : (8, 1), continuous
z : list of 8 variables, (3, 1), continuous
minimize 〈 |1| | mu
minimize ⟨[1], mu
such that
||z[i]|| < mu[i] for all i in [s]
Σ_{i in [s]} A[i]*z[i] = c
z[i]‖ ≤ mu[i] ∀ i ∈ [0…7]
∑(A[i]·z[i] : i ∈ [0…7]) = c
---------------------
The optimal design is:
......@@ -210,14 +210,14 @@ Generated output:
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (SOCP):
optimization problem (SOCP):
5 variables, 0 affine constraints, 32 vars in 8 SO cones
u : (5, 1), continuous
maximize 〈 c | u 〉
maximize ⟨c, u⟩
such that
||A[i].T*u|| < 1 for all i in [s]
A[i]ᵀ·u‖ ≤ 1 ∀ i ∈ [0…7]
---------------------
The optimal design is:
......@@ -292,16 +292,16 @@ inequalities when :math:`z_i` is scalar, so the problem is a LP indeed:
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (LP):
optimization problem (LP):
22 variables, 27 affine constraints
mu : (11, 1), continuous
z : list of 11 variables, (1, 1), continuous
minimize 〈 |1| | mu
minimize ⟨[1], mu
such that
||z[i]|| < mu[i] for all i in [s]
Σ_{i in [s]} A[i]*z[i] = c
|z[i]| mu[i] ∀ i ∈ [0…10]
∑(A[i]·z[i] : i ∈ [0…10]) = c
---------------------
The optimal design is:
......@@ -376,15 +376,15 @@ The SDP formulation of the c-optimal design problem is:
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (SDP):
optimization problem (SDP):
8 variables, 8 affine constraints, 15 vars in 1 SD cones
mu : (8, 1), continuous
minimize 〈 |1| | mu
minimize ⟨[1], mu
such that
Σ_{i in [s]} mu[i]*A[i]*A[i].T ≽ c*c.T
mu > |0|
∑(mu[i]·A[i]·A[i]ᵀ : i ∈ [0…7]) ≽ c·cᵀ
mu ≥ 0
---------------------
The optimal design is:
......@@ -439,7 +439,7 @@ and to provide one additional example in this doc:
#solve the problem and retrieve the weights of the optimal design
print(prob_SDP_c_dual)
prob_SDP_c_dual.solve(verbose=0,solver='cvxopt')
mu = [cons.dual[0] for cons in prob_SDP_c_dual.get_constraint((0,))] #Lagrangian duals of the SOC constraints
mu = [cons.dual for cons in prob_SDP_c_dual.get_constraint((0,))] #Lagrangian duals of the SOC constraints
mu = cvx.matrix(mu)
w=mu/sum(mu) #normalize mu to get the optimal weights
print()
......@@ -457,10 +457,10 @@ and to provide one additional example in this doc:
X : (5, 5), symmetric
maximize c.T*X*c
maximize cᵀ·X·c
such that
A[i]*A[i].T | X 〉 < 1.0 for all i in [s]
X ≽ |0|
A[i]·A[i]ᵀ, X⟩ ≤ 1 ∀ i ∈ [0…7]
X ≽ 0
---------------------
The optimal design is:
......@@ -550,16 +550,16 @@ The SOCP for the A-optimal design problem is:
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (SOCP):
optimization problem (SOCP):
128 variables, 25 affine constraints, 128 vars in 8 SO cones
Z : list of 8 variables, (3, 5), continuous
mu : (8, 1), continuous
minimize 〈 |1| | mu
minimize ⟨[1], mu
such that
||Z[i]|| < mu[i] for all i in [s]
Σ_{i in [s]} A[i]*Z[i] = I
Z[i]‖ ≤ mu[i] ∀ i ∈ [0…7]
∑(A[i]·Z[i] : i ∈ [0…7]) = I
---------------------
The optimal design is:
......@@ -622,14 +622,14 @@ and to provide one additional example in this doc:
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (SOCP):
optimization problem (SOCP):
25 variables, 0 affine constraints, 128 vars in 8 SO cones
U : (5, 5), continuous
maximize trace( U )
maximize trace(U)
such that
||A[i].T*U|| < 1 for all i in [s]
A[i]ᵀ·U‖ ≤ 1 ∀ i ∈ [0…7]
---------------------
The optimal design is:
......@@ -713,19 +713,19 @@ and respectively 6.54%, 11.9%, 9.02% and 22.5% to the design points #5 to #8:
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (SOCP):
optimization problem (SOCP):
136 variables, 27 affine constraints, 136 vars in 8 SO cones
Z : list of 8 variables, (3, 5), continuous
mu : (8, 1), continuous
w : (8, 1), continuous
minimize 〈 |1| | mu
minimize ⟨[1], mu
such that
Σ_{i in [s]} A[i]*Z[i] = I
〈 |1| | w[:4] 〉 < 0.5
〈 |1| | w[4:] 〉 < 0.5
||Z[i]||^2 < ( mu[i])( w[i]) for all i in [s]
∑(A[i]·Z[i] : i ∈ [0…7]) = I
⟨[1], w[:4]⟩ ≤ 0.5
⟨[1], w[4:]⟩ ≤ 0.5
Z[i]‖² ≤ mu[i]·w[i] ∀ i ∈ [0…7]
---------------------
The optimal design is:
......@@ -809,21 +809,21 @@ The exact optimal design is :math:`\mathbf{n}=[0,0,5,3,2,2,3,5]`:
can currently solve it.
.. testoutput::
:options: +SKIP
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS, +SKIP
---------------------
optimization problem (MISOCP):
optimization problem (MISOCP):
136 variables, 26 affine constraints, 136 vars in 8 SO cones
Z : list of 8 variables, (3, 5), continuous
n : (8, 1), integer
t : (8, 1), continuous
minimize 〈 |1| | t 〉
minimize ⟨[1], t⟩
such that
||Z[i]||^2 < ( n[i])( t[i]) for all i in [s]
Σ_{i in [s]} A[i]*Z[i] = I
〈 |1| | n 〉 < N
Z[i]‖² ≤ n[i]·t[i] ∀ i ∈ [0…7]
∑(A[i]·Z[i] : i ∈ [0…7]) = I
⟨[1], n⟩ ≤ N
---------------------
[...]
[...]
......@@ -904,85 +904,21 @@ to the design points #3 to #8.
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (SOCP):
159 variables, 36 affine constraints, 146 vars in 14 SO cones
L : (5, 5), continuous
V : list of 8 variables, (3, 5), continuous
t : (1, 1), continuous
w : (8, 1), continuous
maximize t
such that
L = Σ_{i in [s]} A[i]*V[i]
L[i,j] = 0 for all (i,j) in upper triangle
||V[i]|| < (m)**0.5*w[i] for all i in [s]
〈 |1| | w 〉 < 1.0
t<geomean( diag(L))
---------------------
[...]
[...]
[ 2.27e-01]
[ 3.38e-02]
[ 1.65e-02]
[ 5.44e-02]
[ 3.18e-01]
[ 3.51e-01]
We point out that until
the version 0.1.3 of PICOS, the SOC constraints used to
represent the geometric mean had to be added manually. For the previous example,
a possible trick consists in creating a variable :math:`t`
that must satisfies :math:`t^8 \leq \prod_{i=0}^4 L_{i,i}`:
.. testcode::
#remove the geometric mean inequality
prob_D.remove_constraint((4,))
#additional variables to handle the product of the diagonal elements of L
u={}
for k in ['01','23','4.','0123','4...']:
u[k] = prob_D.add_variable('u['+k+']',1)
#SOC constraints to define u['01234'] such that u['01234']**8 < L[0,0] * L[1,1] * ... * L[4,4]
prob_D.add_constraint(u['01']**2 <L[0,0]*L[1,1])
prob_D.add_constraint(u['23']**2 <L[2,2]*L[3,3])
prob_D.add_constraint(u['4.']**2 <L[4,4])
prob_D.add_constraint(u['0123']**2 <u['01']*u['23'])
prob_D.add_constraint(u['4...']**2 <u['4.'])
prob_D.add_constraint(t**2<u['0123']*u['4...'])
#solve the problem and display the optimal design
print(prob_D)
prob_D.solve(verbose=0,solver='cvxopt')
print(w)
.. testoutput::
:hide:
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (SOCP):
optimization problem (SOCP):
159 variables, 36 affine constraints, 146 vars in 14 SO cones
L : (5, 5), continuous
V : list of 8 variables, (3, 5), continuous
t : (1, 1), continuous
u : dict of 5 variables, (1, 1), continuous
w : (8, 1), continuous
maximize t
such that
L = Σ_{i in [s]} A[i]*V[i]
L[i,j] = 0 for all (i,j) in upper triangle
||V[i]|| < (m)**0.5*w[i] for all i in [s]
〈 |1| | w 〉 < 1.0
||u[01]||^2 < ( L[0,0])( L[1,1])
||u[23]||^2 < ( L[2,2])( L[3,3])
||u[4.]||^2 < L[4,4]
||u[0123]||^2 < ( u[01])( u[23])
||u[4...]||^2 < u[4.]
||t||^2 < ( u[0123])( u[4...])
L = ∑(A[i]·V[i] : i ∈ [0…7])
L[i,j] = 0 ∀ (i,j) ∈ zip([0,0,…,2,3],[1,2,…,4,4])
‖V[i]‖ ≤ m^0.5·w[i] ∀ i ∈ [0…7]
⟨[1], w⟩ ≤ 1
t ≤ geomean(diag(L))
---------------------
[...]
[...]
......@@ -1048,7 +984,7 @@ we obtain the following N-exact D-optimal design:
:options: +SKIP
---------------------
optimization problem (MISOCP):
optimization problem (MISOCP):
199 variables, 41 affine constraints, 218 vars in 46 SO cones
L : (5, 5), continuous
......@@ -1059,12 +995,12 @@ we obtain the following N-exact D-optimal design:
maximize t
such that
L = Σ_{i in [s]} A[i]*V[i]
L[i,j] = 0 for all (i,j) in upper triangle
||V[i][:,k]||^2 < ( n[i] / N)( T[i,k]) for all (i,k)
〈 |1| | T[:,k] 〉 < 1.0 for all k
〈 |1| | n 〉 < N
t<geomean( diag(L))
L = ∑(A[i]·V[i] : i ∈ [0…7])
L[i,j] = 0 ∀ (i,j) ∈ zip([0,0,…,2,3],[1,2,…,4,4])
V[i][:,j]‖^2 (n[i]/N)·T[i,k] ∀ (i,j) ∈ ???
⟨[1], T[:,i]⟩ ≤ 1 ∀ i ∈ ???
⟨[1], n⟩ ≤ N
t ≤ geomean(diag(L))
---------------------
[...]
[...]
......@@ -1110,7 +1046,7 @@ The following code finds the same design as the SOCP approach presented above.
:options: +NORMALIZE_WHITESPACE, +ELLIPSIS
---------------------
optimization problem (ConeP):
optimization problem (Conic Program):
29 variables, 1 affine constraints, 18 vars in 6 SO cones, 55 vars in 1 SD cones
t : (1, 1), continuous
......@@ -1118,8 +1054,8 @@ The following code finds the same design as the SOCP approach presented above.
maximize t
such that
〈 |1| | w 〉 < 1.0
det( Σ_i w[i]*A[i]*A[i].T)**1/5>t
⟨[1], w⟩ ≤ 1
det(∑(w[i]·A[i]·A[i]ᵀ : i ∈ [0…7]))^(1/5) ≥ t
---------------------
[ ...]
[ ...]
......@@ -1200,7 +1136,7 @@ allocating respectively (20.6%, 0.0%, 0.0%, 0.92%, 40.8%, 37.7%), and
*** p=0.2 ***
---------------------
optimization problem (SDP):
optimization problem (SDP):
54 variables, 2 affine constraints, 165 vars in 3 SD cones
t : (1, 1), continuous
......@@ -1208,8 +1144,8 @@ allocating respectively (20.6%, 0.0%, 0.0%, 0.92%, 40.8%, 37.7%), and
maximize t
such that
〈 |1| | w 〉 < 1.0
trace( Σ_i w[i]*A[i]*A[i].T)**1/5>t
⟨[1], w⟩ ≤ 1
trace(∑(w[i]·A[i]·A[i]ᵀ : i ∈ [0…7])^(1/5)) ≥ t
---------------------
[ ...]
[ ...]
......@@ -1222,7 +1158,7 @@ allocating respectively (20.6%, 0.0%, 0.0%, 0.92%, 40.8%, 37.7%), and
*** p= -3 ***
---------------------
optimization problem (SDP):
optimization problem (SDP):
39 variables, 2 affine constraints, 110 vars in 2 SD cones
t : (1, 1), continuous
......@@ -1230,8 +1166,8 @@ allocating respectively (20.6%, 0.0%, 0.0%, 0.92%, 40.8%, 37.7%), and
minimize t
such that
〈 |1| | w 〉 < 1.0
trace( Σ_i w[i]*A[i]*A[i].T)**-3<t
⟨[1], w⟩ ≤ 1
trace(∑(w[i]·A[i]·A[i]ᵀ : i ∈ [0…7])^-3) ≤ t
---------------------
[ ...]
[ ...]
......