nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 numpy,
9 pybind11,
10 setuptools,
11
12 # dependencies
13 clarabel,
14 cvxopt,
15 highspy,
16 osqp,
17 scipy,
18 scs,
19
20 # tests
21 hypothesis,
22 pytestCheckHook,
23
24 useOpenmp ? (!stdenv.hostPlatform.isDarwin),
25}:
26
27buildPythonPackage (finalAttrs: {
28 pname = "cvxpy";
29 version = "1.8.0";
30 pyproject = true;
31
32 src = fetchFromGitHub {
33 owner = "cvxpy";
34 repo = "cvxpy";
35 tag = "v${finalAttrs.version}";
36 hash = "sha256-RBRosw7mNQNdVxXU5aW0ehwM0OV2krPqP+ULBGGhrxM=";
37 };
38
39 postPatch =
40 # too tight tolerance in tests (AssertionError)
41 ''
42 substituteInPlace cvxpy/tests/test_constant_atoms.py \
43 --replace-fail \
44 "CLARABEL: 1e-7," \
45 "CLARABEL: 1e-6,"
46 '';
47
48 build-system = [
49 numpy
50 pybind11
51 setuptools
52 ];
53
54 dependencies = [
55 clarabel
56 cvxopt
57 highspy
58 numpy
59 osqp
60 scipy
61 scs
62 ];
63
64 nativeCheckInputs = [
65 hypothesis
66 pytestCheckHook
67 ];
68
69 # Required flags from https://github.com/cvxpy/cvxpy/releases/tag/v1.1.11
70 preBuild = lib.optionalString useOpenmp ''
71 export CFLAGS="-fopenmp"
72 export LDFLAGS="-lgomp"
73 '';
74
75 enabledTestPaths = [ "cvxpy" ];
76
77 disabledTests = [
78 # Disable the slowest benchmarking tests, cuts test time in half
79 "test_tv_inpainting"
80 "test_diffcp_sdp_example"
81 "test_huber"
82 "test_partial_problem"
83
84 # cvxpy.error.SolverError: Solver 'CVXOPT' failed. Try another solver, or solve with verbose=True for more information.
85 # https://github.com/cvxpy/cvxpy/issues/1588
86 "test_oprelcone_1_m1_k3_complex"
87 "test_oprelcone_1_m3_k1_complex"
88 "test_oprelcone_2"
89 ];
90
91 pythonImportsCheck = [ "cvxpy" ];
92
93 meta = {
94 description = "Domain-specific language for modeling convex optimization problems in Python";
95 homepage = "https://www.cvxpy.org/";
96 downloadPage = "https://github.com/cvxpy/cvxpy//releases";
97 changelog = "https://github.com/cvxpy/cvxpy/releases/tag/${finalAttrs.src.tag}";
98 license = lib.licenses.asl20;
99 maintainers = [ lib.maintainers.GaetanLepage ];
100 };
101})