diff --git a/docs/project/changelog.md b/docs/project/changelog.md index 8c733e2d7..ff4ad5dc0 100644 --- a/docs/project/changelog.md +++ b/docs/project/changelog.md @@ -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` diff --git a/packages/clarabel/meta.yaml b/packages/clarabel/meta.yaml new file mode 100644 index 000000000..21deb2d75 --- /dev/null +++ b/packages/clarabel/meta.yaml @@ -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 diff --git a/packages/clarabel/test_clarabel.py b/packages/clarabel/test_clarabel.py new file mode 100644 index 000000000..e745af68d --- /dev/null +++ b/packages/clarabel/test_clarabel.py @@ -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 diff --git a/packages/cvxpy-base/meta.yaml b/packages/cvxpy-base/meta.yaml new file mode 100644 index 000000000..960be70c1 --- /dev/null +++ b/packages/cvxpy-base/meta.yaml @@ -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 diff --git a/packages/cvxpy-base/test_cvxpy.py b/packages/cvxpy-base/test_cvxpy.py new file mode 100644 index 000000000..1c889fe72 --- /dev/null +++ b/packages/cvxpy-base/test_cvxpy.py @@ -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