Add packages cvxpy, clarabel (#4587)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Philipp Schiele 2024-03-21 21:00:50 -07:00 committed by GitHub
parent 654204775b
commit 61c0180ff6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 136 additions and 1 deletions

View File

@ -71,7 +71,8 @@ myst:
- New Packages: `cysignals`, `ppl`, `pplpy` {pr}`4407`, `flint`, `python-flint` {pr}`4410`,
`memory_allocator` {pr}`4393`, `primesieve`, `primecount`, `primecountpy` {pr}`4477`,
`pyxirr` {pr}`4513`, `ipython`, `asttokens`, `executing`, `prompt_toolkit`,
`pure_eval`, `stack_data`, `traitlets`, `wcwidth` {pr}`4452`, `altair` {pr}`4580`
`pure_eval`, `stack_data`, `traitlets`, `wcwidth` {pr}`4452`, `altair` {pr}`4580`,
`cvxpy` {pr}`4587`, `clarabel` {pr}`4587`
- Upgraded `scikit-learn` to 1.4.1.post1 {pr}`4409` and {pr}`4534`

View File

@ -0,0 +1,23 @@
package:
name: clarabel
version: 0.7.0
top-level:
- clarabel
source:
url: https://files.pythonhosted.org/packages/26/06/c95621d326ea8533ed7ece68eb0ef66e69bf49acf72647b53f685371b937/clarabel-0.7.0.tar.gz
sha256: b9da56f522806a847f3ece08f5f21fab7506eec3148b22446190de5206dd1e6f
about:
home: https://github.com/oxfordcontrol/Clarabel.rs
PyPI: https://pypi.org/project/clarabel
summary: Clarabel Conic Interior Point Solver for Rust / Python
license: Apache-2.0
requirements:
run:
# Dependencies that are needed to run the package
- numpy
- scipy
executable:
- rustup
extra:
recipe-maintainers:
- phschiele

View File

@ -0,0 +1,37 @@
import pytest
from pytest_pyodide import run_in_pyodide
@pytest.mark.xfail_browsers(firefox="slow")
@run_in_pyodide(packages=["clarabel", "scipy", "numpy"])
def test_clarabel(selenium):
import clarabel
import numpy as np
from scipy import sparse
# Define problem data
P = sparse.csc_matrix([[0.0, 0.0], [0, 0]])
P = sparse.triu(P).tocsc()
q = np.array([-1.0, -4.0])
A = sparse.csc_matrix(
[
[1.0, -2.0], # <-- LHS of equality constraint (lower bound)
[1.0, 0.0], # <-- LHS of inequality constraint (upper bound)
[0.0, 1.0], # <-- LHS of inequality constraint (upper bound)
[-1.0, 0.0], # <-- LHS of inequality constraint (lower bound)
[0.0, -1.0],
]
) # <-- LHS of inequality constraint (lower bound)
b = np.array([0.0, 1.0, 1.0, 1.0, 1.0])
cones = [clarabel.ZeroConeT(1), clarabel.NonnegativeConeT(4)]
settings = clarabel.DefaultSettings()
solver = clarabel.DefaultSolver(P, q, A, b, cones, settings)
solution = solver.solve()
assert solution.status == clarabel.SolverStatus.Solved

View File

@ -0,0 +1,25 @@
package:
name: cvxpy-base
version: 1.5.0
top-level:
- cvxpy
source:
# TODO: replace with cvxpy-base from PyPI after 1.5 release
url: https://github.com/cvxpy/cvxpy/archive/23f1eaa.zip
sha256: 4b2a0d982a810d0fdb9f189ab5faa4dbef39679921335e54d737e1b57c555673
requirements:
run:
# Dependencies that are needed to run the package
- numpy
- scipy
- clarabel
about:
home: https://github.com/cvxpy/cvxpy
PyPI: https://pypi.org/project/cvxpy-base
summary:
A domain-specific language for modeling convex optimization problems in
Python.
license: Apache License, Version 2.0
extra:
recipe-maintainers:
- phschiele

View File

@ -0,0 +1,49 @@
import pytest
from pytest_pyodide import run_in_pyodide
@pytest.mark.xfail_browsers(firefox="slow")
@run_in_pyodide(packages=["cvxpy-base"])
def test_cvxpy_clarabel(selenium):
import cvxpy as cp
P = [[3.0, 1.0, -1.0], [1.0, 4.0, 2.0], [-1.0, 2.0, 5.0]]
q = [1.0, 2.0, -3.0]
# Create optimization variables
x = cp.Variable(3)
constraints = [x[0] + x[1] - x[2] == 1, x[1] <= 2, x[2] <= 2, cp.SOC(x[0], x[1:])]
# Form objective.
obj = cp.Minimize(0.5 * cp.quad_form(x, P) + q @ x)
# Form and solve problem.
prob = cp.Problem(obj, constraints)
prob.solve(solver=cp.CLARABEL)
assert prob.status == cp.OPTIMAL
@run_in_pyodide(packages=["cvxpy-base"])
def test_cvxpy_scipy(selenium):
import cvxpy as cp
q = [1.0, 2.0, -3.0]
# Create optimization variables
x = cp.Variable(3)
constraints = [
x[0] + x[1] - x[2] == 1,
x[1] >= 2,
x[2] <= 2,
]
# Form objective.
obj = cp.Minimize(q @ x)
# Form and solve problem.
prob = cp.Problem(obj, constraints)
prob.solve(solver=cp.SCIPY)
assert prob.status == cp.OPTIMAL