├── .bumpversion.cfg
├── .github
└── workflows
│ └── build.yml
├── .gitmodules
├── LICENSE
├── MANIFEST.in
├── Makefile
├── Pipfile
├── Pipfile.lock
├── README
├── README.md
├── pyproject.toml
├── requirements.txt
├── setup.py
└── src
├── ecos
├── __init__.py
├── ecos.py
└── version.py
├── ecosmodule.c
├── test_interface.py
└── test_interface_bb.py
/.bumpversion.cfg:
--------------------------------------------------------------------------------
1 | [bumpversion]
2 | current_version = 2.0.14
3 | files = setup.py src/ecos/version.py
4 | commit = True
5 | tag = True
6 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on:
4 | pull_request:
5 | push:
6 | branches:
7 | - master
8 | tags:
9 | - '*'
10 |
11 | # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
12 | # Only cancels-in-progress on PRs (head_ref only defined in PR, fallback run_id always unique)
13 | concurrency:
14 | group: ${{ github.head_ref || github.run_id }}
15 | cancel-in-progress: true
16 |
17 | jobs:
18 | build:
19 | runs-on: ${{ matrix.os }}
20 | defaults:
21 | run:
22 | shell: bash -l {0}
23 | strategy:
24 | fail-fast: false
25 | matrix:
26 | os: [ ubuntu-20.04, macos-12, windows-2019 ]
27 | python-version: [ 3.8, 3.9, "3.10", "3.11", "3.12" ]
28 |
29 | env:
30 | PYTHON_VERSION: ${{ matrix.python-version }}
31 |
32 | steps:
33 | - uses: actions/checkout@v4
34 | with:
35 | submodules: recursive
36 | - uses: conda-incubator/setup-miniconda@v3
37 | with:
38 | auto-update-conda: true
39 | python-version: ${{ matrix.python-version }}
40 | channels: conda-forge,anaconda
41 | - name: Install
42 | run: |
43 | if [[ "$PYTHON_VERSION" == "3.7" ]] || [[ "$PYTHON_VERSION" == "3.8" ]]; then
44 | conda install scipy=1.3 numpy=1.16 pytest
45 | elif [[ "$PYTHON_VERSION" == "3.9" ]]; then
46 | conda install scipy=1.5 numpy=1.19 pytest
47 | elif [[ "$PYTHON_VERSION" == "3.10" ]]; then
48 | conda install scipy=1.7 numpy=1.21 pytest
49 | elif [[ "$PYTHON_VERSION" == "3.11" ]]; then
50 | conda install scipy=1.9.3 numpy=1.23.4 pytest
51 | elif [[ "$PYTHON_VERSION" == "3.12" ]]; then
52 | conda install scipy=1.11.3 numpy=1.26.0 pytest
53 | fi
54 | if [[ "$RUNNER_OS" == "macOS" ]]; then
55 | sudo rm -rf /Library/Developer/CommandLineTools
56 | fi
57 |
58 | - name: Test
59 | run: |
60 | make install
61 | python -m pytest
62 | rm -rf build/
63 |
64 | build_wheels:
65 | needs: build
66 |
67 | runs-on: ${{ matrix.os }}
68 | strategy:
69 | fail-fast: false
70 | matrix:
71 | os: [ ubuntu-20.04, macos-12, windows-2019 ]
72 | python-version: [ 3.9, "3.10", "3.11", "3.12" ]
73 | include:
74 | - os: ubuntu-20.04
75 | python-version: 3.8
76 | single_action_config: "True"
77 | - os: macos-12
78 | python-version: 3.8
79 | - os: windows-2019
80 | python-version: 3.8
81 |
82 | env:
83 | RUNNER_OS: ${{ matrix.os }}
84 | PYTHON_VERSION: ${{ matrix.python-version }}
85 | SINGLE_ACTION_CONFIG: "${{ matrix.single_action_config == 'True' }}"
86 | PYPI_SERVER: ${{ secrets.PYPI_SERVER }}
87 | PYPI_USER: ${{ secrets.PYPI_USER }}
88 | PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
89 |
90 | steps:
91 |
92 | - uses: actions/checkout@v4
93 | with:
94 | submodules: recursive
95 | - uses: actions/setup-python@v5
96 | with:
97 | python-version: ${{ matrix.python-version }}
98 | - name: Set Additional Envs
99 | shell: bash
100 | run: |
101 | echo "PYTHON_SUBVERSION=$(echo $PYTHON_VERSION | cut -c 3-)" >> $GITHUB_ENV
102 | echo "DEPLOY_PYPI_SOURCE=$( [[ $PYTHON_VERSION == 3.8 && $RUNNER_OS == 'macOS' ]] && echo 'True' || echo 'False' )" >> $GITHUB_ENV
103 | echo "DEPLOY=$( [[ $GITHUB_EVENT_NAME == 'push' && $GITHUB_REF == 'refs/tags'* ]] && echo 'True' || echo 'False' )" >> $GITHUB_ENV
104 |
105 | - name: Build wheels
106 | if: ${{env.DEPLOY == 'True'}}
107 | env:
108 | CIBW_BUILD: "cp3${{env.PYTHON_SUBVERSION}}-*"
109 | CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux*"
110 | uses: pypa/cibuildwheel@v2.19.1
111 |
112 | - name: Build source
113 | if: ${{env.DEPLOY == 'True' && env.SINGLE_ACTION_CONFIG == 'True'}}
114 | run: |
115 | python setup.py sdist --dist-dir=wheelhouse
116 |
117 | - name: Release to pypi
118 | if: ${{env.DEPLOY == 'True'}}
119 | shell: bash
120 | run: |
121 | python -m pip install --upgrade twine
122 | twine check wheelhouse/*
123 | twine upload --skip-existing --repository-url $PYPI_SERVER wheelhouse/* -u $PYPI_USER -p $PYPI_PASSWORD
124 |
125 | - name: Upload artifacts to github
126 | if: ${{env.DEPLOY == 'True'}}
127 | uses: actions/upload-artifact@v4
128 | with:
129 | name: wheels-${{ matrix.os }}-${{ matrix.python-version }}
130 | path: ./wheelhouse
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "ecos"]
2 | path = ecos
3 | url = https://github.com/embotech/ecos.git
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
676 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | graft ecos/include
2 | graft ecos/external/amd/include
3 | graft ecos/external/ldl/include
4 | graft ecos/external/SuiteSparse_config
5 | include LICENSE
6 | include README.md
7 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: all install version release clean
2 |
3 | help:
4 | @echo "Make commands for packaging, releasing, and publishing ecos-python"
5 | @echo ""
6 | @echo " version: generates a version string using git tags for ecos-python"
7 | @echo " install: installs local version of ecos-python"
8 | @echo " release: uploads the wheels in the `dist` folder"
9 |
10 | TAG := $(shell git describe --tags --always --dirty=.dirty | \
11 | sed 's/v\(.*\)/\1/' | \
12 | sed 's/\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\(rc[0-9]*\)\{0,1\}-\([0-9][0-9]*\)-\(g.*\)/\1\2.dev\3+\4/')
13 |
14 | all: version
15 |
16 | version:
17 | @echo "__version__=\"$(TAG)\"" > src/ecos/version.py
18 |
19 | src/ecos/version.py: version
20 |
21 | install: version
22 | pip install .
23 |
24 | release: version
25 | -rm -rf dist
26 | mkdir -p dist
27 | python setup.py sdist
28 | curl -s https://api.github.com/repos/embotech/ecos-python/releases/tags/$(TAG) \
29 | | grep browser_download_url.*whl \
30 | | cut -d : -f 2,3 \
31 | | tr -d \" \
32 | | wget -P dist -qi -
33 | twine upload dist/*
34 |
35 | clean:
36 | @echo "nothing"
37 |
38 |
--------------------------------------------------------------------------------
/Pipfile:
--------------------------------------------------------------------------------
1 | [[source]]
2 | url = "https://pypi.python.org/simple"
3 | verify_ssl = true
4 | name = "pypi"
5 |
6 | [dev-packages]
7 | pytest = "*"
8 |
9 | [packages]
10 | numpy = "*"
11 |
12 | [requires]
13 | python_version = "3.6"
14 |
--------------------------------------------------------------------------------
/Pipfile.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_meta": {
3 | "hash": {
4 | "sha256": "01e35b99ecbe27e2ed9f2ab1d12dbee14db6e5ebafba221a324d420eefbe6f1a"
5 | },
6 | "pipfile-spec": 6,
7 | "requires": {
8 | "python_version": "3.6"
9 | },
10 | "sources": [
11 | {
12 | "name": "pypi",
13 | "url": "https://pypi.python.org/simple",
14 | "verify_ssl": true
15 | }
16 | ]
17 | },
18 | "default": {
19 | "numpy": {
20 | "hashes": [
21 | "sha256:02f98011ba4ab17f46f80f7f8f1c291ee7d855fcef0a5a98db80767a468c85cd",
22 | "sha256:0b7e807d6888da0db6e7e75838444d62495e2b588b99e90dd80c3459594e857b",
23 | "sha256:12c70ac274b32bc00c7f61b515126c9205323703abb99cd41836e8125ea0043e",
24 | "sha256:1666f634cb3c80ccbd77ec97bc17337718f56d6658acf5d3b906ca03e90ce87f",
25 | "sha256:18c3319a7d39b2c6a9e3bb75aab2304ab79a811ac0168a671a62e6346c29b03f",
26 | "sha256:211ddd1e94817ed2d175b60b6374120244a4dd2287f4ece45d49228b4d529178",
27 | "sha256:21a9484e75ad018974a2fdaa216524d64ed4212e418e0a551a2d83403b0531d3",
28 | "sha256:39763aee6dfdd4878032361b30b2b12593fb445ddb66bbac802e2113eb8a6ac4",
29 | "sha256:3c67423b3703f8fbd90f5adaa37f85b5794d3366948efe9a5190a5f3a83fc34e",
30 | "sha256:46f47ee566d98849323f01b349d58f2557f02167ee301e5e28809a8c0e27a2d0",
31 | "sha256:51c7f1b344f302067b02e0f5b5d2daa9ed4a721cf49f070280ac202738ea7f00",
32 | "sha256:5f24750ef94d56ce6e33e4019a8a4d68cfdb1ef661a52cdaee628a56d2437419",
33 | "sha256:697df43e2b6310ecc9d95f05d5ef20eacc09c7c4ecc9da3f235d39e71b7da1e4",
34 | "sha256:6d45b3ec2faed4baca41c76617fcdcfa4f684ff7a151ce6fc78ad3b6e85af0a6",
35 | "sha256:77810ef29e0fb1d289d225cabb9ee6cf4d11978a00bb99f7f8ec2132a84e0166",
36 | "sha256:7ca4f24341df071877849eb2034948459ce3a07915c2734f1abb4018d9c49d7b",
37 | "sha256:7f784e13e598e9594750b2ef6729bcd5a47f6cfe4a12cca13def35e06d8163e3",
38 | "sha256:806dd64230dbbfaca8a27faa64e2f414bf1c6622ab78cc4264f7f5f028fee3bf",
39 | "sha256:867e3644e208c8922a3be26fc6bbf112a035f50f0a86497f98f228c50c607bb2",
40 | "sha256:8c66d6fec467e8c0f975818c1796d25c53521124b7cfb760114be0abad53a0a2",
41 | "sha256:8ed07a90f5450d99dad60d3799f9c03c6566709bd53b497eb9ccad9a55867f36",
42 | "sha256:9bc6d1a7f8cedd519c4b7b1156d98e051b726bf160715b769106661d567b3f03",
43 | "sha256:9e1591f6ae98bcfac2a4bbf9221c0b92ab49762228f38287f6eeb5f3f55905ce",
44 | "sha256:9e87562b91f68dd8b1c39149d0323b42e0082db7ddb8e934ab4c292094d575d6",
45 | "sha256:a7081fd19a6d573e1a05e600c82a1c421011db7935ed0d5c483e9dd96b99cf13",
46 | "sha256:a8474703bffc65ca15853d5fd4d06b18138ae90c17c8d12169968e998e448bb5",
47 | "sha256:af36e0aa45e25c9f57bf684b1175e59ea05d9a7d3e8e87b7ae1a1da246f2767e",
48 | "sha256:b1240f767f69d7c4c8a29adde2310b871153df9b26b5cb2b54a561ac85146485",
49 | "sha256:b4d362e17bcb0011738c2d83e0a65ea8ce627057b2fdda37678f4374a382a137",
50 | "sha256:b831295e5472954104ecb46cd98c08b98b49c69fdb7040483aff799a755a7374",
51 | "sha256:b8c275f0ae90069496068c714387b4a0eba5d531aace269559ff2b43655edd58",
52 | "sha256:bdd2b45bf079d9ad90377048e2747a0c82351989a2165821f0c96831b4a2a54b",
53 | "sha256:cc0743f0302b94f397a4a65a660d4cd24267439eb16493fb3caad2e4389bccbb",
54 | "sha256:da4b0c6c699a0ad73c810736303f7fbae483bcb012e38d7eb06a5e3b432c981b",
55 | "sha256:f25e2811a9c932e43943a2615e65fc487a0b6b49218899e62e426e7f0a57eeda",
56 | "sha256:f73497e8c38295aaa4741bdfa4fda1a5aedda5473074369eca10626835445511"
57 | ],
58 | "index": "pypi",
59 | "markers": "python_version >= '3.9'",
60 | "version": "==1.26.3"
61 | }
62 | },
63 | "develop": {
64 | "iniconfig": {
65 | "hashes": [
66 | "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3",
67 | "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"
68 | ],
69 | "markers": "python_version >= '3.7'",
70 | "version": "==2.0.0"
71 | },
72 | "packaging": {
73 | "hashes": [
74 | "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5",
75 | "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"
76 | ],
77 | "markers": "python_version >= '3.7'",
78 | "version": "==23.2"
79 | },
80 | "pluggy": {
81 | "hashes": [
82 | "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981",
83 | "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be"
84 | ],
85 | "markers": "python_version >= '3.8'",
86 | "version": "==1.4.0"
87 | },
88 | "pytest": {
89 | "hashes": [
90 | "sha256:249b1b0864530ba251b7438274c4d251c58d868edaaec8762893ad4a0d71c36c",
91 | "sha256:50fb9cbe836c3f20f0dfa99c565201fb75dc54c8d76373cd1bde06b06657bdb6"
92 | ],
93 | "index": "pypi",
94 | "markers": "python_version >= '3.8'",
95 | "version": "==8.0.0"
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | See the github repository for a detailed README.
2 |
3 | http://github.com/embotech/ecos
4 |
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Python Wrapper for Embedded Conic Solver (ECOS)
2 |
3 | [](https://github.com/embotech/ecos-python/actions/workflows/build.yml)
4 |
5 |
6 | **Visit www.embotech.com/ECOS for detailed information on ECOS.**
7 |
8 | ECOS is a numerical software for solving convex second-order cone
9 | programs (SOCPs) of type
10 | ```
11 | min c'*x
12 | s.t. A*x = b
13 | G*x <=_K h
14 | ```
15 | where the last inequality is generalized, i.e. `h - G*x` belongs to the
16 | cone `K`. ECOS supports the positive orthant `R_+` and second-order
17 | cones `Q_n` defined as
18 | ```
19 | Q_n = { (t,x) | t >= || x ||_2 }
20 | ```
21 | In the definition above, t is a scalar and `x` is in `R_{n-1}`. The cone
22 | `K` is therefore a direct product of the positive orthant and
23 | second-order cones:
24 | ```
25 | K = R_+ x Q_n1 x ... x Q_nN
26 | ```
27 |
28 | ## Installation
29 | The latest version of ECOS is available via `pip`:
30 |
31 | pip install ecos
32 |
33 | This will download the relevant wheel for your machine.
34 |
35 | ### Building from source
36 | If you are attempting to build the Python extension from source, then
37 | use
38 |
39 | make install
40 |
41 | This will use the latest tag on git to version your local installation
42 | of ECOS.
43 |
44 | You will need [Numpy](http://www.numpy.org/)
45 | and [Scipy](http://www.scipy.org/). For installation instructions, see
46 | their respective pages.
47 |
48 | You may need `sudo` privileges for a global installation.
49 |
50 | ### Windows users
51 | Windows users may experience some extreme pain when installing ECOS from
52 | source for Python 2.7. We suggest switching to Linux or Mac OSX.
53 |
54 | If you must use (or insist on using) Windows, we suggest using
55 | the [Miniconda](http://repo.continuum.io/miniconda/)
56 | distribution to minimize this pain.
57 |
58 | If during the installation process, you see the error message
59 | `Unable to find vcvarsall.bat`, you will need to install
60 | [Microsoft Visual Studio Express 2008](go.microsoft.com/?linkid=7729279),
61 | since *Python 2.7* is built against the 2008 compiler.
62 |
63 | If using a newer version of Python, you can use a newer version of
64 | Visual Studio. For instance, Python 3.3 is built against [Visual Studio
65 | 2010](http://go.microsoft.com/?linkid=9709949).
66 |
67 | ## Calling ECOS from Python
68 |
69 | After installing the ECOS interface, you must import the module with
70 | ```
71 | import ecos
72 | ```
73 | This module provides a single function `ecos` with one of the following calling sequences:
74 | ```
75 | solution = ecos.solve(c,G,h,dims)
76 | solution = ecos.solve(c,G,h,dims,A,b,**kwargs)
77 | ```
78 | The arguments `c`, `h`, and `b` are Numpy arrays (i.e., matrices with a single
79 | column). The arguments `G` and `A` are Scipy *sparse* matrices in CSR format;
80 | if they are not of the proper format, ECOS will attempt to convert them. The
81 | argument `dims` is a dictionary with two fields, `dims['l']` and `dims['q']`.
82 | These are the same fields as in the Matlab case. If the fields are omitted or
83 | empty, they default to 0.
84 | The argument `kwargs` can include the keywords
85 | + `feastol`, `abstol`, `reltol`, `feastol_inacc`, `abstol_innac`, and `reltol_inacc` for tolerance values,
86 | + `max_iters` for the maximum number of iterations,
87 | + the Booleans `verbose` and `mi_verbose`,
88 | + `bool_vars_idx`, a list of `int`s which index the boolean variables,
89 | + `int_vars_idx`, a list of `int`s which index the integer variables,
90 | + `mi_max_iters` for maximum number of branch and bound iterations (mixed integer problems only),
91 | + `mi_abs_eps` for the absolute tolerance between upper and lower bounds (mixed integer problems only), and
92 | + `mi_rel_eps` for the relative tolerance, (U-L)/L, between upper and lower bounds (mixed integer problems only).
93 |
94 | The arguments `A`, `b`, and `kwargs` are optional.
95 |
96 | The returned object is a dictionary containing the fields `solution['x']`, `solution['y']`, `solution['s']`, `solution['z']`, and `solution['info']`.
97 | The first four are Numpy arrays containing the relevant solution. The last field contains a dictionary with the same fields as the `info` struct in the MATLAB interface.
98 |
99 | ## Using ECOS with CVXPY
100 |
101 | [CVXPY](http://cvxpy.org) is a powerful Python modeling framework for
102 | convex optimization, similar to the MATLAB counterpart CVX. ECOS is one
103 | of the default solvers in CVXPY, so there is nothing special you have to
104 | do in order to use ECOS with CVXPY, besides specifying it as a solver.
105 | Here is a small
106 | [example](http://www.cvxpy.org/en/latest/tutorial/advanced/index.html#solve-method-options)
107 | from the CVXPY tutorial:
108 |
109 | ```py
110 | import cvxpy as cp
111 |
112 | # Solving a problem with different solvers.
113 | x = cp.Variable(2)
114 | obj = cp.Minimize(cp.norm(x, 2) + cp.norm(x, 1))
115 | constraints = [x >= 2]
116 | prob = cp.Problem(obj, constraints)
117 |
118 | # Solve with ECOS.
119 | prob.solve(solver=cp.ECOS)
120 | print("optimal value with ECOS:", prob.value)
121 | ```
122 |
123 | ## ECOS Versioning
124 | The Python module contains two version numbers:
125 |
126 | 1. `ecos.__version__`: This is the version of the Python wrapper for
127 | ECOS
128 | 2. `ecos.__solver_version__`: This is the version of the underlying ECOS
129 | solver
130 |
131 | These two version numbers should typically agree, but they might not
132 | when a bug in the Python module has been fixed and nothing in the
133 | underlying C solver has changed. The major version numbers should agree,
134 | however.
135 |
136 | ### What happened to 2.0.7?
137 | Because version-syncing ECOS and ECOS-Python can be tricky, the 2.0.7
138 | version did not incorporate some minor changes to ECOS. In an
139 | ill-advised move, the release was deleted in hopes it could be
140 | re-uploaded, despite plenty warnings stating otherwise.
141 |
142 | Instead, a post release has been made that contains identical content to
143 | the 2.0.7 release. Generally, `pip` should pick up the post release for
144 | 2.0.7 and any dependencies such as `pip install "ecos>=2.0.5"` should still
145 | work as expected.
146 |
147 | ## Deployment
148 | When creating new versions of the Python wrapper, please use
149 | `bumpversion` to bump the version number and also remember to tag the
150 | commit so that CI is able to properly pick it up. See
151 | [Release](RELEASE.md) for more information.
152 |
153 | ## Python2 Support
154 | Starting with version 2.0.8, ecos-python will no longer support
155 | Python2.7. You may be able to download an [older
156 | version](https://github.com/embotech/ecos-python/releases/tag/2.0.7.post1)
157 | but moving forward we will no longer publish Python2 wheels for use.
158 |
159 | ## License
160 |
161 | ECOS is distributed under the [GNU General Public License
162 | v3.0](http://www.gnu.org/copyleft/gpl.html). Other licenses may be
163 | available upon request from [embotech](http://www.embotech.com).
164 |
165 |
166 |
167 |
168 | ## Credits
169 |
170 | The solver is essentially based on Lieven Vandenberghe's [CVXOPT](http://cvxopt.org) [ConeLP](http://www.ee.ucla.edu/~vandenbe/publications/coneprog.pdf) solver, although it differs in the particular way the linear systems are treated.
171 |
172 | The following people have been, and are, involved in the development and maintenance of ECOS:
173 |
174 | + Alexander Domahidi (principal developer)
175 | + Eric Chu (Python interface, unit tests)
176 | + Stephen Boyd (methods and maths)
177 | + Michael Grant (CVX interface)
178 | + Johan Löfberg (YALMIP interface)
179 | + João Felipe Santos, Iain Dunning (Julia interface)
180 | + Han Wang (ECOS branch and bound)
181 |
182 | The main technical idea behind ECOS is described in a short [paper](http://www.stanford.edu/~boyd/papers/ecos.html). More details are given in Alexander Domahidi's [PhD Thesis](http://e-collection.library.ethz.ch/view/eth:7611?q=domahidi) in Chapter 9.
183 |
184 | If you find ECOS useful, you can cite it using the following BibTex entry:
185 |
186 | ```
187 | @INPROCEEDINGS{bib:Domahidi2013ecos,
188 | author={Domahidi, A. and Chu, E. and Boyd, S.},
189 | booktitle={European Control Conference (ECC)},
190 | title={{ECOS}: {A}n {SOCP} solver for embedded systems},
191 | year={2013},
192 | pages={3071-3076}
193 | }
194 | ```
195 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = [
3 | "numpy >= 2.0.0; python_version > '3.8'",
4 | "oldest-supported-numpy; python_version <= '3.8'",
5 | "wheel",
6 | "setuptools"
7 | ]
8 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | numpy
2 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | try:
3 | from setuptools import setup, Extension
4 | from setuptools.command.build_ext import build_ext as _build_ext
5 | except ImportError:
6 | print("Please use pip (https://pypi.python.org/pypi/pip) to install.")
7 | raise
8 |
9 | import os
10 | from glob import glob
11 | from platform import system
12 |
13 | lib = []
14 | if system() == 'Linux':
15 | lib += ['rt']
16 |
17 | _ecos = Extension('_ecos', libraries = lib,
18 | # define LDL and AMD to use long ints
19 | # also define that we are building a python module
20 | define_macros = [
21 | ('PYTHON',None),
22 | ('DLONG', None),
23 | ('LDL_LONG', None),
24 | ('CTRLC', 1)],
25 | include_dirs = ['ecos/include',
26 | 'ecos/external/amd/include',
27 | 'ecos/external/ldl/include',
28 | 'ecos/external/SuiteSparse_config'],
29 | sources = ['src/ecosmodule.c',
30 | 'ecos/external/ldl/src/ldl.c',
31 | 'ecos/src/cone.c',
32 | 'ecos/src/ctrlc.c',
33 | 'ecos/src/ecos.c',
34 | 'ecos/src/equil.c',
35 | 'ecos/src/expcone.c',
36 | 'ecos/src/kkt.c',
37 | 'ecos/src/preproc.c',
38 | 'ecos/src/spla.c',
39 | 'ecos/src/splamm.c',
40 | 'ecos/src/timer.c',
41 | 'ecos/src/wright_omega.c'
42 | ] + glob('ecos/external/amd/src/*.c')
43 | + glob('ecos/ecos_bb/*.c')) # glob bb source files
44 |
45 | def set_builtin(name, value):
46 | if isinstance(__builtins__, dict):
47 | __builtins__[name] = value
48 | else:
49 | setattr(__builtins__, name, value)
50 |
51 | class build_ext(_build_ext):
52 | """ This custom class for building extensions exists so we can force
53 | a numpy install before building the extension, thereby giving us
54 | access to the numpy headers.
55 | """
56 | def finalize_options(self):
57 | _build_ext.finalize_options(self)
58 | # Prevent numpy from thinking it is still in its setup process:
59 | set_builtin("__NUMPY_SETUP__", False)
60 | import numpy
61 | self.include_dirs.append(numpy.get_include())
62 |
63 | setup(
64 | name = 'ecos',
65 | version = '2.0.14',
66 | author = 'Alexander Domahidi, Eric Chu, Han Wang, Santiago Akle',
67 | author_email = 'domahidi@embotech.com, echu@cs.stanford.edu, hanwang2@stanford.edu, tiagoakle@gmail.com',
68 | url = 'http://github.com/embotech/ecos',
69 | description = 'This is the Python package for ECOS: Embedded Cone Solver. See Github page for more information.',
70 | long_description=open('README.md').read(),
71 | long_description_content_type="text/markdown",
72 | license = "GPLv3",
73 | packages = ['ecos'],
74 | package_dir = {'': 'src'},
75 | cmdclass = {'build_ext': build_ext},
76 | ext_modules = [_ecos],
77 | setup_requires = [
78 | "numpy >= 1.6"
79 | ],
80 | install_requires = [
81 | "numpy >= 1.6",
82 | "scipy >= 0.9"
83 | ],
84 | tests_require=['pytest']
85 | )
86 |
--------------------------------------------------------------------------------
/src/ecos/__init__.py:
--------------------------------------------------------------------------------
1 | from .ecos import solve, __solver_version__
2 | from .version import __version__
3 |
--------------------------------------------------------------------------------
/src/ecos/ecos.py:
--------------------------------------------------------------------------------
1 | import _ecos
2 | from warnings import warn
3 | import numpy as np
4 | from scipy import sparse
5 |
6 | __solver_version__ = _ecos.version()
7 |
8 | def solve(c,G,h,dims,A=None,b=None, **kwargs):
9 | """ This Python routine "unpacks" scipy sparse matrices G and A into the
10 | data structures that we need for calling ECOS' csolve routine.
11 |
12 | If G and h are both None, then we will automatically create an "empty"
13 | CSC matrix to use with ECOS.
14 |
15 | It is *not* compatible with CVXOPT spmatrix and matrix, although
16 | it would not be very difficult to make it compatible. We put the
17 | onus on the user to convert CVXOPT matrix types into numpy, scipy
18 | array types.
19 | """
20 | if G is not None and not sparse.issparse(G):
21 | raise TypeError("G is required to be a sparse matrix")
22 | if A is not None and not sparse.issparse(A):
23 | raise TypeError("A is required to be a sparse matrix")
24 |
25 | if G is not None and not sparse.isspmatrix_csc(G):
26 | warn("Converting G to a CSC matrix; may take a while.")
27 | G = G.tocsc()
28 | if A is not None and not sparse.isspmatrix_csc(A):
29 | warn("Converting A to a CSC matrix; may take a while.")
30 | A = A.tocsc()
31 |
32 | # set the dimensions
33 | # note that we forcibly coerce the shape values to Python ints
34 | # (C longs) in case of shenanigans with the underlying storage
35 | m,n1 = (0,len(c)) if G is None else map(int, G.get_shape())
36 | p,n2 = (0,n1) if A is None else map(int, A.shape)
37 |
38 | if n1 != n2:
39 | raise TypeError("Columns of A and G don't match")
40 |
41 |
42 | # G.sort_indices() # ECHU: performance hit? do we need this?
43 | # if A is not None: A.sort_indices()
44 |
45 | if (G is None and h is not None) or (G is not None and h is None):
46 | raise TypeError("G and h must be supplied together")
47 |
48 | if (A is None and b is not None) or (A is not None and b is None):
49 | raise TypeError("A and b must be supplied together")
50 |
51 | if G is None:
52 | data = np.zeros((0,),dtype=np.double)
53 | indices = np.zeros((0,),dtype=np.int64)
54 | colptr = np.zeros((n1+1,),dtype=np.int64)
55 | h = np.zeros((0,))
56 | else:
57 | data, indices, colptr = G.data, G.indices, G.indptr
58 |
59 | if A is None:
60 | return _ecos.csolve((m,n1,p), c, data, indices, colptr, h, dims, **kwargs)
61 | else:
62 | return _ecos.csolve((m,n1,p), c, data, indices, colptr, h, dims, A.data, A.indices, A.indptr, b, **kwargs)
63 |
--------------------------------------------------------------------------------
/src/ecos/version.py:
--------------------------------------------------------------------------------
1 | __version__="2.0.14"
--------------------------------------------------------------------------------
/src/ecosmodule.c:
--------------------------------------------------------------------------------
1 | /* Check that we are clean against numpy 1.7 */
2 | #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
3 |
4 | #include
5 | #include "ecos.h"
6 | #include "ecos_bb.h"
7 | #include "numpy/arrayobject.h"
8 | /*
9 | * Define INLINE for MSVC compatibility.
10 | */
11 | #ifdef _MSC_VER
12 | #define INLINE __inline
13 | #else
14 | #define INLINE inline
15 | #endif
16 |
17 | /* IMPORTANT: This code now uses numpy array types. It is a private C module
18 | * in the sense that end users only see the front-facing Python code in
19 | * "ecos.py"; hence, we can get away with the inputs being numpy arrays of
20 | * the CSR data structures.
21 | *
22 | * WARNING: This code also does not check that the data for the sparse
23 | * matrices are *actually* in column compressed storage for a sparse matrix.
24 | * The C module is not designed to be used stand-alone. If the data provided
25 | * does not correspond to a CSR matrix, this code will just crash inelegantly.
26 | * Please use the "solve" interface in ecos.py.
27 | */
28 | /* #include "cvxopt.h" */
29 |
30 | /* ECHU: Note, Python3.x may require special handling for the int and double
31 | * types. */
32 | static INLINE int getIntType(void) {
33 | switch(sizeof(idxint)) {
34 | case 1: return NPY_INT8;
35 | case 2: return NPY_INT16;
36 | case 4: return NPY_INT32;
37 | case 8: return NPY_INT64;
38 | default: return NPY_INT32; /* defaults to 4 byte int */
39 | }
40 | }
41 |
42 | static INLINE int getDoubleType(void) {
43 | /* ECHU: known bug, if pfloat isn't "double", will cause aliasing in memory */
44 | return NPY_DOUBLE;
45 | }
46 |
47 | static INLINE PyArrayObject *getContiguous(PyArrayObject *array, int typenum) {
48 | /* gets the pointer to the block of contiguous C memory
49 | * the overhead should be small unless the numpy array has been
50 | * reordered in some way or the data type doesn't quite match
51 | *
52 | * the "tmp_arr" pointer has to have Py_DECREF called on it; new_owner
53 | * owns the "new" array object created by PyArray_Cast
54 | */
55 | PyArrayObject *tmp_arr;
56 | PyArrayObject *new_owner;
57 | tmp_arr = PyArray_GETCONTIGUOUS(array);
58 | new_owner = (PyArrayObject *) PyArray_Cast(tmp_arr, typenum);
59 | Py_DECREF(tmp_arr);
60 | return new_owner;
61 | }
62 |
63 | /* The PyInt variable is a PyLong in Python3.x.
64 | */
65 | #if PY_MAJOR_VERSION >= 3
66 | #define PyInt_AsLong PyLong_AsLong
67 | #define PyInt_Check PyLong_Check
68 | #endif
69 |
70 | static PyObject *version(PyObject* self)
71 | {
72 | return Py_BuildValue("s",ECOS_VERSION);
73 | }
74 |
75 | static int checkNonnegativeInt(const char *key, idxint val) {
76 | if (val >= 0) {
77 | return 0;
78 | }
79 | PyErr_Format(PyExc_ValueError, "'%s' must be a nonnegative integer", key);
80 | return -1;
81 | }
82 |
83 | static int checkPositiveFloat(const char *key, pfloat val) {
84 | if (val > 0) {
85 | return 0;
86 | }
87 | PyErr_Format(PyExc_ValueError, "'%s' must be a positive float", key);
88 | return -1;
89 | }
90 |
91 | static PyObject *csolve(PyObject* self, PyObject *args, PyObject *kwargs)
92 | {
93 | /* Expects a function call
94 | * sol = csolve((m,n,p),c,Gx,Gi,Gp,h,dims,Ax,Ai,Ap,b,**kwargs)
95 | * where
96 | *
97 | * the triple (m,n,p) corresponds to:
98 | * `m`: the rows of G
99 | * `n`: the cols of G and A, must agree with the length of c
100 | * `p`: the rows of A
101 | * `c` is a Numpy array of doubles
102 | * "G" is a sparse matrix in column compressed storage. "Gx" are the values,
103 | * "Gi" are the rows, and "Gp" are the column pointers.
104 | * `Gx` is a Numpy array of doubles
105 | * `Gi` is a Numpy array of ints
106 | * `Gp` is a Numpy array of ints
107 | * `h` is a Numpy array
108 | * `dims` is a dictionary with
109 | * `dims['l']` an integer specifying the dimension of positive orthant cone
110 | * `dims['q']` an *list* specifying dimensions of second-order cones
111 | * `dims['e']` an integer specifying the number of exponential cones
112 | *
113 | * "A" is an optional sparse matrix in column compressed storage. "Ax" are
114 | * the values, "Ai" are the rows, and "Ap" are the column pointers.
115 | * `Ax` is a Numpy array of doubles
116 | * `Ai` is a Numpy array of ints
117 | * `Ap` is a Numpy array of ints
118 | * `b` is an optional argument, which is a Numpy array of doubles
119 | * other optional arguments are:
120 | * `feastol`: the tolerance on the primal and dual residual
121 | * `abstol`: the absolute tolerance on the duality gap
122 | * `reltol`: the relative tolerance on the duality gap
123 | * `feastol_inacc`: the tolerance on the primal and dual residual if reduced precisions
124 | * `abstol_inacc`: the absolute tolerance on the duality gap if reduced precision
125 | * `reltolL_inacc`: the relative tolerance on the duality gap if reduced precision
126 | * `max_iters`: the maximum numer of iterations.
127 | * `nitref`: the number of iterative refinement steps.
128 | * `verbose`: signals to print on non zero value.
129 | * `mi_max_iters`: maximum number of branch and bound iterations
130 | * (mixed integer problems only),
131 | * `mi_abs_eps`: the absolute tolerance between upper and lower
132 | * bounds (mixed integer problems only),
133 | * `mi_rel_eps`: the relative tolerance, (U-L)/L, between upper
134 | * and lower bounds (mixed integer problems only).
135 | * `mi_verbose`: whether to be verbose when solving mixed integer
136 | * problems
137 | *
138 | * This call will solve the problem
139 | *
140 | * minimize c'*x
141 | * subject to A*x = b
142 | * h - G*x \in K
143 | *
144 | * The code returns a Python dictionary with five keys, 'x', 'y', 'info', 's',
145 | * and 'z'. These correspond to the following:
146 | *
147 | * `x`: primal variables
148 | * `y`: dual variables for equality constraints
149 | * `s`: slacks for Gx + s <= h, s \in K
150 | * `z`: dual variables for inequality constraints s \in K
151 | * `info`: another dictionary with the following fields:
152 | * exitflag: 0=OPTIMAL, 1=PRIMAL INFEASIBLE, 2=DUAL INFEASIBLE, -1=MAXIT REACHED
153 | * infostring: gives information about the status of solution
154 | * pcost: value of primal objective
155 | * dcost: value of dual objective
156 | * pres: primal residual on inequalities and equalities
157 | * dres: dual residual
158 | * pinf: primal infeasibility measure
159 | * dinf: dual infeasibility measure
160 | * pinfres: NaN
161 | * dinfres: 3.9666e+15
162 | * gap: duality gap
163 | * relgap: relative duality gap
164 | * r0: ???
165 | * numerr: numerical error?
166 | * iter: number of iterations
167 | * timing: dictionary with timing information
168 | */
169 |
170 | /* data structures for arguments */
171 | /* ECHU: below is for CVXOPT
172 | * matrix *c, *h, *b = NULL;
173 | * spmatrix *G, *A = NULL;
174 | */
175 |
176 | /* BEGIN VARIABLE DECLARATIONS */
177 | PyArrayObject *Gx, *Gi, *Gp, *c, *h;
178 | PyListObject *bool_idx = NULL;
179 | PyListObject *int_idx = NULL;
180 | PyArrayObject *Ax = NULL;
181 | PyArrayObject *Ai = NULL;
182 | PyArrayObject *Ap = NULL;
183 | PyArrayObject *b = NULL;
184 | PyObject *dims = NULL;
185 | PyObject *verbose = NULL;
186 | PyObject *mi_verbose = NULL;
187 | idxint n; /* number or variables */
188 | idxint m; /* number of conic variables */
189 | idxint p = 0; /* number of equality constraints */
190 | idxint ncones = 0; /* number of cones */
191 | idxint numConicVariables = 0;
192 |
193 | /* ECOS data structures */
194 | idxint l = 0;
195 | idxint *q = NULL;
196 | idxint e = 0;
197 |
198 | pfloat *Gpr = NULL;
199 | idxint *Gjc = NULL;
200 | idxint *Gir = NULL;
201 |
202 | pfloat *Apr = NULL;
203 | idxint *Ajc = NULL;
204 | idxint *Air = NULL;
205 |
206 | pfloat *cpr = NULL;
207 | pfloat *hpr = NULL;
208 | pfloat *bpr = NULL;
209 |
210 | idxint *bool_vars_idx = NULL;
211 | idxint *int_vars_idx = NULL;
212 | idxint num_bool = 0;
213 | idxint num_int = 0;
214 |
215 | long mi_iterations = -1;
216 |
217 | /* Default ECOS settings */
218 | settings opts_ecos = {0};
219 | settings_bb opts_ecos_bb = {0};
220 |
221 | pwork* mywork = NULL;
222 | ecos_bb_pwork* myecos_bb_work = NULL;
223 |
224 | idxint i;
225 | static char *kwlist[] = {"shape", "c", "Gx", "Gi", "Gp", "h", "dims",
226 | "Ax", "Ai", "Ap", "b",
227 | "verbose", "feastol", "abstol", "reltol",
228 | "feastol_inacc", "abstol_inacc", "reltol_inacc",
229 | "max_iters", "nitref", "bool_vars_idx", "int_vars_idx",
230 | "mi_verbose", "mi_max_iters", "mi_abs_eps",
231 | "mi_rel_eps", "mi_int_tol", NULL};
232 | int intType, doubleType;
233 |
234 | /* parse the arguments and ensure they are the correct type */
235 | #ifdef DLONG
236 | #ifdef _WIN64
237 | // use long long on win64
238 | static char *argparse_string = "(LLL)O!O!O!O!O!O!|O!O!O!O!O!ddddddLLO!O!O!Lddd";
239 | #else
240 | static char *argparse_string = "(lll)O!O!O!O!O!O!|O!O!O!O!O!ddddddllO!O!O!lddd";
241 | #endif
242 | #else
243 | static char *argparse_string = "(iii)O!O!O!O!O!O!|O!O!O!O!O!ddddddiiO!O!O!iddd";
244 | #endif
245 | PyArrayObject *Gx_arr, *Gi_arr, *Gp_arr;
246 | PyArrayObject *c_arr;
247 | PyArrayObject *h_arr;
248 | PyObject *linearObj;
249 | PyObject *socObj;
250 | PyObject *expObj;
251 | PyArrayObject *Ax_arr = NULL;
252 | PyArrayObject *Ai_arr = NULL;
253 | PyArrayObject *Ap_arr = NULL;
254 | PyArrayObject *b_arr = NULL;
255 |
256 | idxint exitcode, numerr = 0;
257 | npy_intp veclen[1];
258 | PyObject *x, *y, *z, *s;
259 | const char* infostring;
260 | PyObject *infoDict = NULL;
261 | PyObject *tinfos = NULL;
262 | PyObject *returnDict = NULL;
263 | /* END VARIABLE DECLARATIONS */
264 |
265 | /* Default ECOS settings */
266 | opts_ecos.feastol = FEASTOL;
267 | opts_ecos.reltol = RELTOL;
268 | opts_ecos.abstol = ABSTOL;
269 | opts_ecos.feastol_inacc = FTOL_INACC;
270 | opts_ecos.abstol_inacc = ATOL_INACC;
271 | opts_ecos.reltol_inacc = RTOL_INACC;
272 | opts_ecos.maxit = MAXIT;
273 | opts_ecos.nitref = NITREF;
274 | opts_ecos.verbose = VERBOSE;
275 |
276 | opts_ecos_bb.verbose = 1;
277 | opts_ecos_bb.maxit = MI_MAXITER;
278 | opts_ecos_bb.abs_tol_gap = MI_ABS_EPS;
279 | opts_ecos_bb.rel_tol_gap = MI_REL_EPS;
280 | opts_ecos_bb.integer_tol = MI_INT_TOL;
281 |
282 | if( !PyArg_ParseTupleAndKeywords(args, kwargs, argparse_string, kwlist,
283 | &m, &n, &p,
284 | &PyArray_Type, &c,
285 | &PyArray_Type, &Gx,
286 | &PyArray_Type, &Gi,
287 | &PyArray_Type, &Gp,
288 | &PyArray_Type, &h,
289 | &PyDict_Type, &dims,
290 | &PyArray_Type, &Ax,
291 | &PyArray_Type, &Ai,
292 | &PyArray_Type, &Ap,
293 | &PyArray_Type, &b,
294 | &PyBool_Type, &verbose,
295 | &opts_ecos.feastol,
296 | &opts_ecos.abstol,
297 | &opts_ecos.reltol,
298 | &opts_ecos.feastol_inacc,
299 | &opts_ecos.abstol_inacc,
300 | &opts_ecos.reltol_inacc,
301 | &opts_ecos.maxit,
302 | &opts_ecos.nitref,
303 | &PyList_Type, &bool_idx,
304 | &PyList_Type, &int_idx,
305 | &PyBool_Type, &mi_verbose,
306 | &opts_ecos_bb.maxit,
307 | &opts_ecos_bb.abs_tol_gap,
308 | &opts_ecos_bb.rel_tol_gap,
309 | &opts_ecos_bb.integer_tol
310 | )
311 | ) { return NULL; }
312 |
313 | if (checkNonnegativeInt("m", m) < 0) return NULL;
314 | if (checkNonnegativeInt("n", n) < 0) return NULL;
315 | if (checkNonnegativeInt("p", p) < 0) return NULL;
316 |
317 | if (bool_idx){
318 | if (!PyList_Check(bool_idx)){
319 | PyErr_SetString(PyExc_TypeError, "bool_vars_idx must be a list");
320 | return NULL;
321 | }
322 |
323 | /* Ensure the list of indices are monotonic */
324 | PyList_Sort((PyObject *) bool_idx);
325 |
326 | num_bool = (idxint)PyList_Size((PyObject *) bool_idx);
327 | for (i = 0; i= n ||
334 | PyLong_AsLong(PyList_GetItem((PyObject *) bool_idx, (Py_ssize_t)i)) < 0){
335 | PyErr_SetString(PyExc_ValueError, "bool_vars_idx must be in range [0,n-1] ");
336 | return NULL;
337 | }
338 | }
339 | }
340 |
341 | if (int_idx){
342 | if (!PyList_Check(int_idx)){
343 | PyErr_SetString(PyExc_TypeError, "int_vars_idx must be a list");
344 | return NULL;
345 | }
346 |
347 | /* Ensure the list of indices are monotonic */
348 | PyList_Sort((PyObject *) int_idx);
349 |
350 | num_int = (idxint)PyList_Size((PyObject *) int_idx);
351 | for (i = 0; i= n ||
359 | PyLong_AsLong(PyList_GetItem((PyObject *) int_idx, (Py_ssize_t)i)) < 0){
360 | PyErr_SetString(PyExc_ValueError, "int_vars_idx entries must be in range [0,n-1] ");
361 | return NULL;
362 | }
363 | }
364 | }
365 |
366 |
367 | /* check the opts*/
368 | if (verbose)
369 | opts_ecos.verbose = (idxint) PyObject_IsTrue(verbose);
370 | if (checkNonnegativeInt("maxit", opts_ecos.maxit) < 0) return NULL;
371 | if (checkNonnegativeInt("nitref", opts_ecos.nitref) < 0) return NULL;
372 | if (checkPositiveFloat("abstol", opts_ecos.abstol) < 0) return NULL;
373 | if (checkPositiveFloat("feastol", opts_ecos.feastol) < 0) return NULL;
374 | if (checkPositiveFloat("reltol", opts_ecos.reltol) < 0) return NULL;
375 | if (checkPositiveFloat("abstol_inacc", opts_ecos.abstol_inacc) < 0) return NULL;
376 | if (checkPositiveFloat("feastol_inacc", opts_ecos.feastol_inacc) < 0) return NULL;
377 | if (checkPositiveFloat("reltol_inacc", opts_ecos.reltol_inacc) < 0) return NULL;
378 |
379 | if (mi_verbose)
380 | opts_ecos_bb.verbose = (idxint) PyObject_IsTrue(mi_verbose);
381 | if (checkNonnegativeInt("mi_max_iters", opts_ecos_bb.maxit) < 0) return NULL;
382 | if (checkPositiveFloat("mi_abs_eps", opts_ecos_bb.abs_tol_gap) < 0) return NULL;
383 | if (checkPositiveFloat("mi_rel_eps", opts_ecos_bb.rel_tol_gap) < 0) return NULL;
384 | if (checkPositiveFloat("mi_int_tol", opts_ecos_bb.integer_tol) < 0) return NULL;
385 |
386 | /* get the typenum for the primitive int and double types */
387 | intType = getIntType();
388 | doubleType = getDoubleType();
389 |
390 | /* set G */
391 | if( !PyArray_ISFLOAT(Gx) || PyArray_NDIM(Gx) != 1) {
392 | PyErr_SetString(PyExc_TypeError, "Gx must be a numpy array of floats");
393 | return NULL;
394 | }
395 | if( !PyArray_ISINTEGER(Gi) || PyArray_NDIM(Gi) != 1) {
396 | PyErr_SetString(PyExc_TypeError, "Gi must be a numpy array of ints");
397 | return NULL;
398 | }
399 | if( !PyArray_ISINTEGER(Gp) || PyArray_NDIM(Gp) != 1) {
400 | PyErr_SetString(PyExc_TypeError, "Gp must be a numpy array of ints");
401 | return NULL;
402 | }
403 | Gx_arr = getContiguous(Gx, doubleType);
404 | Gi_arr = getContiguous(Gi, intType);
405 | Gp_arr = getContiguous(Gp, intType);
406 | Gpr = (pfloat *) PyArray_DATA(Gx_arr);
407 | Gir = (idxint *) PyArray_DATA(Gi_arr);
408 | Gjc = (idxint *) PyArray_DATA(Gp_arr);
409 |
410 | /* set c */
411 | if (!PyArray_ISFLOAT(c) || PyArray_NDIM(c) != 1) {
412 | PyErr_SetString(PyExc_TypeError, "c must be a dense numpy float array with one dimension");
413 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
414 | return NULL;
415 | }
416 |
417 | if (PyArray_DIM(c,0) != n){
418 | PyErr_SetString(PyExc_ValueError, "c has incompatible dimension with G");
419 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
420 | return NULL;
421 | }
422 | c_arr = getContiguous(c, doubleType);
423 | cpr = (pfloat *) PyArray_DATA(c_arr);
424 |
425 | /* set h */
426 | if (!PyArray_ISFLOAT(h) || PyArray_NDIM(h) != 1) {
427 | PyErr_SetString(PyExc_TypeError, "h must be a dense numpy float array with one dimension");
428 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
429 | Py_DECREF(c_arr);
430 | return NULL;
431 | }
432 |
433 |
434 | if (PyArray_DIM(h,0) != m){
435 | PyErr_SetString(PyExc_ValueError, "h has incompatible dimension with G");
436 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
437 | Py_DECREF(c_arr);
438 | return NULL;
439 | }
440 | h_arr = getContiguous(h, doubleType);
441 | hpr = (pfloat *) PyArray_DATA(h_arr);
442 |
443 | /* get dims['l'] */
444 | linearObj = PyDict_GetItemString(dims, "l");
445 | if(linearObj) {
446 | if ( (PyInt_Check(linearObj) && ((l = (idxint) PyInt_AsLong(linearObj)) >= 0)) ||
447 | (PyLong_Check(linearObj) && ((l = PyLong_AsLong(linearObj)) >= 0)) ){
448 | numConicVariables += l;
449 | } else {
450 | PyErr_SetString(PyExc_TypeError, "dims['l'] ought to be a nonnegative integer");
451 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
452 | Py_DECREF(c_arr); Py_DECREF(h_arr);
453 | return NULL;
454 | }
455 | }
456 |
457 | /* get dims['q'] */
458 | socObj = PyDict_GetItemString(dims, "q");
459 | if(socObj) {
460 | if (PyList_Check(socObj)) {
461 | ncones = (idxint)PyList_Size(socObj);
462 | q = calloc(ncones, sizeof(idxint));
463 | for (i = 0; i < ncones; ++i) {
464 | PyObject *qi = PyList_GetItem(socObj, i);
465 | if( (PyInt_Check(qi) && ((q[i] = (idxint) PyInt_AsLong(qi)) > 0)) ||
466 | (PyLong_Check(qi) && ((q[i] = PyLong_AsLong(qi)) > 0)) ) {
467 | numConicVariables += q[i];
468 | } else {
469 | PyErr_SetString(PyExc_TypeError, "dims['q'] ought to be a list of positive integers");
470 | if(q) free(q);
471 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
472 | Py_DECREF(c_arr); Py_DECREF(h_arr);
473 | return NULL;
474 | }
475 |
476 | }
477 | } else {
478 | PyErr_SetString(PyExc_TypeError, "dims['q'] ought to be a list");
479 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
480 | Py_DECREF(c_arr); Py_DECREF(h_arr);
481 | return NULL;
482 | }
483 | }
484 |
485 |
486 | /* get dims['e'] */
487 | expObj = PyDict_GetItemString(dims, "e");
488 | if(expObj) {
489 | if ( (PyInt_Check(expObj) && ((e = (idxint) PyInt_AsLong(expObj)) >= 0)) ||
490 | (PyLong_Check(expObj) && ((e = PyLong_AsLong(expObj)) >= 0)) ){
491 | numConicVariables += 3*e;
492 | } else {
493 | PyErr_SetString(PyExc_TypeError, "dims['e'] ought to be a nonnegative integer");
494 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
495 | Py_DECREF(c_arr); Py_DECREF(h_arr);
496 | return NULL;
497 | }
498 | }
499 |
500 |
501 | if(Ax && Ai && Ap && b) {
502 | /* set A */
503 | if( !PyArray_ISFLOAT(Ax) || PyArray_NDIM(Ax) != 1 ) {
504 | PyErr_SetString(PyExc_TypeError, "Ax must be a numpy array of floats");
505 | if(q) free(q);
506 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
507 | Py_DECREF(c_arr); Py_DECREF(h_arr);
508 | return NULL;
509 | }
510 | if( !PyArray_ISINTEGER(Ai) || PyArray_NDIM(Ai) != 1) {
511 | PyErr_SetString(PyExc_TypeError, "Ai must be a numpy array of ints");
512 | if(q) free(q);
513 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
514 | Py_DECREF(c_arr); Py_DECREF(h_arr);
515 | return NULL;
516 | }
517 | if( !PyArray_ISINTEGER(Ap) || PyArray_NDIM(Ap) != 1) {
518 | PyErr_SetString(PyExc_TypeError, "Ap must be a numpy array of ints");
519 | if(q) free(q);
520 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
521 | Py_DECREF(c_arr); Py_DECREF(h_arr);
522 | return NULL;
523 | }
524 | /* if ((SpMatrix_Check(A) && SP_ID(A) != DOUBLE)){
525 | * PyErr_SetString(PyExc_TypeError, "A must be a sparse 'd' matrix");
526 | * if(q) free(q);
527 | * Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
528 | * Py_DECREF(c_arr); Py_DECREF(h_arr);
529 | * return NULL;
530 | * }
531 | * if ((p = SP_NROWS(A)) < 0) {
532 | * PyErr_SetString(PyExc_ValueError, "p must be a nonnegative integer");
533 | * if(q) free(q);
534 | * Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
535 | * Py_DECREF(c_arr); Py_DECREF(h_arr);
536 | * return NULL;
537 | * }
538 | * if (SP_NCOLS(A) != n) {
539 | * PyErr_SetString(PyExc_ValueError, "A has incompatible dimension with c");
540 | * if(q) free(q);
541 | * Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
542 | * Py_DECREF(c_arr); Py_DECREF(h_arr);
543 | * return NULL;
544 | * }
545 | * if (p != 0) {
546 | * Apr = SP_VALD(A);
547 | * Air = SP_ROW(A);
548 | * Ajc = SP_COL(A);
549 | * }
550 | */
551 | Ax_arr = getContiguous(Ax, doubleType);
552 | Ai_arr = getContiguous(Ai, intType);
553 | Ap_arr = getContiguous(Ap, intType);
554 | Apr = (pfloat *) PyArray_DATA(Ax_arr);
555 | Air = (idxint *) PyArray_DATA(Ai_arr);
556 | Ajc = (idxint *) PyArray_DATA(Ap_arr);
557 |
558 | /* set b */
559 | /* if (!Matrix_Check(b) || MAT_NCOLS(b) != 1 || MAT_ID(b) != DOUBLE) {
560 | * PyErr_SetString(PyExc_TypeError, "b must be a dense 'd' matrix with one column");
561 | * if(q) free(q);
562 | * return NULL;
563 | * }
564 | * if (MAT_NROWS(b) != p){
565 | * PyErr_SetString(PyExc_ValueError, "b has incompatible dimension with A");
566 | * if(q) free(q);
567 | * return NULL;
568 | * }
569 | * if (p != 0) {
570 | * bpr = MAT_BUFD(b);
571 | * }
572 | */
573 | if (!PyArray_ISFLOAT(b) || PyArray_NDIM(b) != 1) {
574 | PyErr_SetString(PyExc_TypeError, "b must be a dense numpy float array with one dimension");
575 | if(q) free(q);
576 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
577 | Py_DECREF(c_arr); Py_DECREF(h_arr);
578 | Py_DECREF(Ax_arr); Py_DECREF(Ai_arr); Py_DECREF(Ap_arr);
579 | return NULL;
580 | }
581 | if (PyArray_DIM(b,0) != p){
582 | PyErr_SetString(PyExc_ValueError, "b has incompatible dimension with A");
583 | if(q) free(q);
584 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
585 | Py_DECREF(c_arr); Py_DECREF(h_arr);
586 | Py_DECREF(Ax_arr); Py_DECREF(Ai_arr); Py_DECREF(Ap_arr);
587 | return NULL;
588 | }
589 | b_arr = getContiguous(b, doubleType);
590 | bpr = (pfloat *) PyArray_DATA(b_arr);
591 | } else if (Ax || Ai || Ap || b) {
592 | /* check that A and b are both supplied */
593 | PyErr_SetString(PyExc_ValueError, "A and b arguments must be supplied together");
594 | if(q) free(q);
595 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
596 | Py_DECREF(c_arr); Py_DECREF(h_arr);
597 | return NULL;
598 | }
599 |
600 | /* check that sum(q) + l = m */
601 | if( numConicVariables != m ){
602 | PyErr_SetString(PyExc_ValueError, "Number of rows of G does not match dims.l+sum(dims.q)+dims.e");
603 | if (q) free(q);
604 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
605 | Py_DECREF(c_arr); Py_DECREF(h_arr);
606 | if (b_arr) Py_DECREF(b_arr);
607 | if (Ax_arr) Py_DECREF(Ax_arr);
608 | if (Ai_arr) Py_DECREF(Ai_arr);
609 | if (Ap_arr) Py_DECREF(Ap_arr);
610 | return NULL;
611 | }
612 |
613 | if (num_bool > 0 || num_int > 0){
614 | if (bool_idx){
615 | bool_vars_idx = malloc( num_bool*sizeof(idxint) );
616 | for (i=0; iecos_prob;
643 |
644 | /* Set settings for ECOS. */
645 | mywork->stgs->verbose = opts_ecos.verbose;
646 | mywork->stgs->abstol = opts_ecos.abstol;
647 | mywork->stgs->feastol = opts_ecos.feastol;
648 | mywork->stgs->reltol = opts_ecos.reltol;
649 | mywork->stgs->abstol_inacc = opts_ecos.abstol_inacc;
650 | mywork->stgs->feastol_inacc = opts_ecos.feastol_inacc;
651 | mywork->stgs->reltol_inacc = opts_ecos.reltol_inacc;
652 | mywork->stgs->maxit = opts_ecos.maxit;
653 | mywork->stgs->nitref = opts_ecos.nitref;
654 |
655 | /* Solve! */
656 | Py_BEGIN_ALLOW_THREADS;
657 | exitcode = ECOS_BB_solve(myecos_bb_work);
658 | Py_END_ALLOW_THREADS;
659 | mi_iterations =(long) myecos_bb_work->iter;
660 |
661 | } else{
662 |
663 | /* This calls ECOS setup function. */
664 | Py_BEGIN_ALLOW_THREADS;
665 | mywork = ECOS_setup(n, m, p, l, ncones, q, e, Gpr, Gjc, Gir, Apr, Ajc, Air, cpr, hpr, bpr);
666 | Py_END_ALLOW_THREADS;
667 | if( mywork == NULL ){
668 | PyErr_SetString(PyExc_RuntimeError, "Internal problem occurred in ECOS while setting up the problem.\nPlease send a bug report with data to Alexander Domahidi.\nEmail: domahidi@control.ee.ethz.ch");
669 | if(q) free(q);
670 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
671 | Py_DECREF(c_arr); Py_DECREF(h_arr);
672 | if (b_arr) Py_DECREF(b_arr);
673 | if (Ax_arr) Py_DECREF(Ax_arr);
674 | if (Ai_arr) Py_DECREF(Ai_arr);
675 | if (Ap_arr) Py_DECREF(Ap_arr);
676 | return NULL;
677 | }
678 |
679 | /* Set settings for ECOS. */
680 | mywork->stgs->verbose = opts_ecos.verbose;
681 | mywork->stgs->abstol = opts_ecos.abstol;
682 | mywork->stgs->feastol = opts_ecos.feastol;
683 | mywork->stgs->reltol = opts_ecos.reltol;
684 | mywork->stgs->abstol_inacc = opts_ecos.abstol_inacc;
685 | mywork->stgs->feastol_inacc = opts_ecos.feastol_inacc;
686 | mywork->stgs->reltol_inacc = opts_ecos.reltol_inacc;
687 | mywork->stgs->maxit = opts_ecos.maxit;
688 | mywork->stgs->nitref = opts_ecos.nitref;
689 |
690 | /* Solve! */
691 | Py_BEGIN_ALLOW_THREADS;
692 | exitcode = ECOS_solve(mywork);
693 | Py_END_ALLOW_THREADS;
694 | }
695 |
696 | /* create output (all data is *deep copied*) */
697 | /* TODO: request CVXOPT API for constructing from existing pointer */
698 | /* x */
699 | /* matrix *x;
700 | * if(!(x = Matrix_New(n,1,DOUBLE)))
701 | * return PyErr_NoMemory();
702 | * memcpy(MAT_BUFD(x), mywork->x, n*sizeof(double));
703 | */
704 | veclen[0] = n;
705 | x = PyArray_SimpleNewFromData(1, veclen, NPY_DOUBLE, mywork->x);
706 | /* give memory ownership to numpy array */
707 | PyArray_ENABLEFLAGS((PyArrayObject *) x, NPY_ARRAY_OWNDATA);
708 |
709 | /* y */
710 | /* matrix *y;
711 | * if(!(y = Matrix_New(p,1,DOUBLE)))
712 | * return PyErr_NoMemory();
713 | * memcpy(MAT_BUFD(y), mywork->y, p*sizeof(double));
714 | */
715 | veclen[0] = p;
716 | y = PyArray_SimpleNewFromData(1, veclen, NPY_DOUBLE, mywork->y);
717 | /* give memory ownership to numpy array */
718 | PyArray_ENABLEFLAGS((PyArrayObject *) y, NPY_ARRAY_OWNDATA);
719 |
720 | /* s */
721 | /* matrix *s;
722 | * if(!(s = Matrix_New(m,1,DOUBLE)))
723 | * return PyErr_NoMemory();
724 | * memcpy(MAT_BUFD(s), mywork->s, m*sizeof(double));
725 | */
726 | veclen[0] = m;
727 | s = PyArray_SimpleNewFromData(1, veclen, NPY_DOUBLE, mywork->s);
728 | /* give memory ownership to numpy array */
729 | PyArray_ENABLEFLAGS((PyArrayObject *) s, NPY_ARRAY_OWNDATA);
730 |
731 | /* z */
732 | /* matrix *z;
733 | * if(!(z = Matrix_New(m,1,DOUBLE)))
734 | * return PyErr_NoMemory();
735 | * memcpy(MAT_BUFD(z), mywork->z, m*sizeof(double));
736 | */
737 | veclen[0] = m;
738 | z = PyArray_SimpleNewFromData(1, veclen, NPY_DOUBLE, mywork->z);
739 | /* give memory ownership to numpy array */
740 | PyArray_ENABLEFLAGS((PyArrayObject *) z, NPY_ARRAY_OWNDATA);
741 |
742 | if (num_bool > 0 || num_int > 0){
743 | /* info dict */
744 | /* infostring */
745 | switch( exitcode ){
746 | case MI_OPTIMAL_SOLN:
747 | infostring = "Optimal branch and bound solution found";
748 | break;
749 | case MI_MAXITER_FEASIBLE_SOLN:
750 | infostring = "Maximum iterations reached with feasible solution found";
751 | break;
752 | case MI_MAXITER_NO_SOLN:
753 | infostring = "Maximum iterations reached with no feasible solution found";
754 | break;
755 | case MI_INFEASIBLE:
756 | infostring = "Problem is infeasible";
757 | break;
758 | default:
759 | infostring = "UNKNOWN PROBLEM IN BRANCH AND BOUND SOLVER";
760 | }
761 | } else {
762 | /* info dict */
763 | /* infostring */
764 | switch( exitcode ){
765 | case ECOS_OPTIMAL:
766 | infostring = "Optimal solution found";
767 | break;
768 | case ECOS_OPTIMAL + ECOS_INACC_OFFSET:
769 | infostring = "Close to optimal solution found";
770 | break;
771 | case ECOS_MAXIT:
772 | infostring = "Maximum number of iterations reached";
773 | break;
774 | case ECOS_PINF:
775 | infostring = "Primal infeasible";
776 | break;
777 | case ECOS_PINF + ECOS_INACC_OFFSET:
778 | infostring = "Close to primal infeasible";
779 | break;
780 | case ECOS_DINF:
781 | infostring = "Dual infeasible";
782 | break;
783 | case ECOS_DINF + ECOS_INACC_OFFSET:
784 | infostring = "Close to dual infeasible";
785 | break;
786 | case ECOS_NUMERICS:
787 | infostring = "Run into numerical problems";
788 | break;
789 | case ECOS_OUTCONE:
790 | infostring = "PROBLEM: Multipliers leaving the cone";
791 | break;
792 | case ECOS_FATAL:
793 | infostring = "PROBLEM: Fatal error during initialization";
794 | break;
795 | default:
796 | infostring = "UNKNOWN PROBLEM IN SOLVER";
797 | }
798 |
799 | /* numerical errors */
800 | if( (exitcode == ECOS_NUMERICS) || (exitcode == ECOS_OUTCONE) || (exitcode == ECOS_FATAL) ){
801 | numerr = 1;
802 | }
803 | }
804 |
805 | /* timings */
806 | #if PROFILING > 0
807 | tinfos = Py_BuildValue(
808 | #if PROFILING > 1
809 | "{s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d}",
810 | #else
811 | "{s:d,s:d,s:d}",
812 | #endif
813 | #if PROFILING > 1
814 | "tkktcreate",(double)mywork->info->tkktcreate,
815 | "tkktsolve",(double)mywork->info->tkktsolve,
816 | "tkktfactor",(double)mywork->info->tfactor,
817 | "torder",(double)mywork->info->torder,
818 | "ttranspose",(double)mywork->info->ttranspose,
819 | #endif
820 | "runtime",(double)mywork->info->tsolve + (double)mywork->info->tsetup,
821 | "tsetup",(double)mywork->info->tsetup,
822 | "tsolve",(double)mywork->info->tsolve);
823 | #endif
824 |
825 | infoDict = Py_BuildValue(
826 | #if PROFILING > 0
827 | "{s:l,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:l,s:l,s:s,s:O,s:l}",
828 | #else
829 | "{s:l,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:l,s:l,s:s,s:l}",
830 | #endif
831 | "exitFlag", exitcode,
832 | "pcost", (double)mywork->info->pcost,
833 | "dcost", (double)mywork->info->dcost,
834 | "pres", (double)mywork->info->pres,
835 | "dres", (double)mywork->info->dres,
836 | "pinf", (double)mywork->info->pinf,
837 | "dinf", (double)mywork->info->dinf,
838 | "pinfres",(double)mywork->info->pinfres,
839 | "dinfres",(double)mywork->info->dinfres,
840 | "gap",(double)mywork->info->gap,
841 | "relgap",(double)mywork->info->relgap,
842 | "r0",(double)mywork->stgs->feastol,
843 | "iter",mywork->info->iter,
844 | "mi_iter",mi_iterations,
845 | "infostring",infostring,
846 | #if PROFILING > 0
847 | "timing", tinfos,
848 | #endif
849 | "numerr",numerr);
850 |
851 | #if PROFILING > 0
852 | /* give reference to infoDict */
853 | Py_DECREF(tinfos);
854 | #endif
855 |
856 | returnDict = Py_BuildValue(
857 | "{s:O,s:O,s:O,s:O,s:O}",
858 | "x",x,
859 | "y",y,
860 | "z",z,
861 | "s",s,
862 | "info",infoDict);
863 | /* give up ownership to the return dictionary */
864 | Py_DECREF(x); Py_DECREF(y); Py_DECREF(z); Py_DECREF(s); Py_DECREF(infoDict);
865 |
866 | /* cleanup */
867 | if (num_bool > 0 || num_int > 0){
868 | ECOS_BB_cleanup(myecos_bb_work, 4);
869 | } else {
870 | ECOS_cleanup(mywork, 4);
871 | }
872 |
873 | /* no longer need pointers to arrays that held primitives */
874 | if(q) free(q);
875 | if(bool_vars_idx) free(bool_vars_idx);
876 | if(int_vars_idx) free(int_vars_idx);
877 | Py_DECREF(Gx_arr); Py_DECREF(Gi_arr); Py_DECREF(Gp_arr);
878 | Py_DECREF(c_arr); Py_DECREF(h_arr);
879 | if (b_arr) Py_DECREF(b_arr);
880 | if (Ax_arr) Py_DECREF(Ax_arr);
881 | if (Ai_arr) Py_DECREF(Ai_arr);
882 | if (Ap_arr) Py_DECREF(Ap_arr);
883 |
884 | return returnDict;
885 | }
886 |
887 | static PyMethodDef ECOSMethods[] =
888 | {
889 | {"csolve", (PyCFunction)csolve, METH_VARARGS | METH_KEYWORDS,
890 | "Solve an SOCP using ECOS."},
891 | {"version", (PyCFunction)version, METH_NOARGS, "Version number for ECOS."},
892 | {NULL, NULL, 0, NULL} /* sentinel */
893 | };
894 |
895 | /* Module initialization */
896 | #if PY_MAJOR_VERSION >= 3
897 | static struct PyModuleDef moduledef = {
898 | PyModuleDef_HEAD_INIT,
899 | "_ecos", /* m_name */
900 | "Solve an SOCP using ECOS.", /* m_doc */
901 | -1, /* m_size */
902 | ECOSMethods, /* m_methods */
903 | NULL, /* m_reload */
904 | NULL, /* m_traverse */
905 | NULL, /* m_clear */
906 | NULL, /* m_free */
907 | };
908 | #endif
909 |
910 | static PyObject* moduleinit(void)
911 | {
912 | PyObject* m;
913 |
914 | #if PY_MAJOR_VERSION >= 3
915 | m = PyModule_Create(&moduledef);
916 | #else
917 | m = Py_InitModule("_ecos", ECOSMethods);
918 | #endif
919 |
920 | /*if (import_array() < 0) return NULL; */ /* for numpy arrays */
921 | /*if (import_cvxopt() < 0) return NULL; */ /* for cvxopt support */
922 |
923 | if (m == NULL)
924 | return NULL;
925 |
926 | return m;
927 | };
928 |
929 | #if PY_MAJOR_VERSION >= 3
930 | PyMODINIT_FUNC PyInit__ecos(void)
931 | {
932 | import_array(); /* for numpy arrays */
933 | return moduleinit();
934 | }
935 | #else
936 | PyMODINIT_FUNC init_ecos(void)
937 | {
938 | import_array(); /* for numpy arrays */
939 | moduleinit();
940 | }
941 | #endif
942 |
--------------------------------------------------------------------------------
/src/test_interface.py:
--------------------------------------------------------------------------------
1 | import platform
2 | import pytest
3 | import ecos
4 | import numpy as np
5 | import scipy.sparse as sp
6 |
7 | # global data structures for problem
8 | c = np.array([-1.])
9 | h = np.array([4., -0.])
10 | G = (sp.csc_matrix([1., -1.]).T).tocsc()
11 | A = sp.csc_matrix([1.])
12 | b = np.array([3.])
13 | dims = {'q': [], 'l': 2}
14 |
15 |
16 | def check_solution(solution, expected):
17 | np.testing.assert_almost_equal(solution, expected, decimal=5)
18 |
19 | @pytest.mark.parametrize("inputs,expected", [
20 | ((c, G, h, dims, {'feastol': 2e-8, 'reltol': 2e-8, 'abstol': 2e-8, 'verbose': False}), 4),
21 | ((c, G, h, dims, A, b, {'feastol': 2e-8, 'reltol': 2e-8, 'abstol': 2e-8, 'verbose': False}), 3),
22 | ((c, G, h, {'q': [2], 'l': 0}, {'feastol': 2e-8, 'reltol': 2e-8, 'abstol': 2e-8, 'verbose': False}), 2)
23 | ])
24 | def test_problems(inputs, expected):
25 | sol = ecos.solve(*inputs[:-1], **inputs[-1])
26 | check_solution(sol['x'][0], expected)
27 |
28 |
29 | def test_call_failures():
30 | with pytest.raises(TypeError):
31 | ecos.solve()
32 |
33 | with pytest.raises(TypeError):
34 | ecos.solve(c, G, h, dims, A)
35 |
36 | with pytest.raises(ValueError):
37 | ecos.solve(c, G, h, {'q':[], 'l':0})
38 |
39 | with pytest.raises(TypeError):
40 | ecos.solve(c, G, h, {'q':[4], 'l':-2})
41 |
42 |
43 | @pytest.mark.parametrize("error_type,keyword,value", [
44 | (TypeError, 'verbose', 0),
45 | (ValueError, 'feastol', 0),
46 | (ValueError, 'abstol', 0),
47 | (ValueError, 'reltol', 0),
48 | (ValueError, 'feastol_inacc', 0),
49 | (ValueError, 'abstol_inacc', 0),
50 | (ValueError, 'reltol_inacc', 0),
51 | (ValueError, 'max_iters', -1),
52 | (TypeError, 'max_iters', 1.1),
53 | ])
54 | def test_keyword_errors(error_type, keyword, value):
55 | with pytest.raises(error_type):
56 | ecos.solve(c, G, h, dims, **{keyword: value})
57 |
--------------------------------------------------------------------------------
/src/test_interface_bb.py:
--------------------------------------------------------------------------------
1 | import ecos
2 | import numpy as np
3 | import scipy.sparse as sp
4 |
5 | c = np.array([-1., -1.])
6 | h = np.array([ 4., 12., 0., 0.])
7 | bool_idx = [1]
8 | G = sp.csc_matrix((
9 | np.array([2.0, 3.0, -1.0, 1.0, 4.0, -1.0]),
10 | np.array([0, 1, 2, 0, 1, 3]),
11 | np.array([0, 3, 6]),
12 | ))
13 |
14 | dims = dict()
15 | dims['l'] = 4
16 |
17 | sol = ecos.solve(c, G, h, dims, verbose=False, mi_verbose=False, int_vars_idx=bool_idx)
18 |
19 | c = np.array([-1., -1.])
20 | h = np.array([ 4., 12., 0., 0.])
21 | bool_idx = []
22 | G = sp.csc_matrix((
23 | np.array([2.0, 3.0, -1.0, 1.0, 4.0, -1.0]),
24 | np.array([0, 1, 2, 0, 1, 3]),
25 | np.array([0, 3, 6]),
26 | ))
27 |
28 | dims = dict()
29 | dims['l'] = 4
30 |
31 | sol = ecos.solve(c, G, h, dims, verbose=False, mi_verbose=False, int_vars_idx=bool_idx)
32 |
33 | c = np.array([-1., -1.1])
34 | h = np.array([ 4., 12., 0., 0.])
35 | bool_idx = [1,0]
36 | G = sp.csc_matrix((
37 | np.array([2.0, 3.0, -1.0, 1.0, 4.0, -1.0]),
38 | np.array([0, 1, 2, 0, 1, 3]),
39 | np.array([0, 3, 6]),
40 | ))
41 |
42 | dims = dict()
43 | dims['l'] = 4
44 |
45 | sol = ecos.solve(c, G, h, dims, verbose=False, mi_verbose=False, int_vars_idx=bool_idx)
46 |
47 |
48 | c = np.array([-1., -1.5])
49 | h = np.array([ 4., 12., 0. , 0.])
50 | bool_idx = [1]
51 | G = sp.csc_matrix((
52 | np.array([2.0, 3.0, -1.0, 1.0, 4.0, -1.0]),
53 | np.array([0, 1, 2, 0, 1, 3]),
54 | np.array([0, 3, 6]),
55 | ))
56 |
57 | dims = dict()
58 | dims['l'] = 4
59 |
60 | sol = ecos.solve(c, G, h, dims, verbose=False, mi_verbose=True, bool_vars_idx=bool_idx)
--------------------------------------------------------------------------------