cvxgrp / scs

Splitting Conic Solver
MIT License
553 stars 136 forks source link

2 tests fail #273

Closed yurivict closed 5 months ago

yurivict commented 5 months ago

Specifications

Description

========================================================================================= FAILURES ==========================================================================================
___________________________________________________________________________________ test_warm_start[True] ___________________________________________________________________________________

use_indirect = True

    @pytest.mark.parametrize("use_indirect", [False, True])
    def test_warm_start(use_indirect):
        # max x
        # s.t 0 <= x <= 1
        solver = scs.SCS(data, cone, use_indirect=use_indirect, verbose=False)
        sol = solver.solve()
        assert_almost_equal(sol["x"][0], 1.0, decimal=2)

        sol = solver.solve()
        assert_almost_equal(sol["x"][0], 1.0, decimal=2)
        assert_array_less(sol["info"]["iter"], 10)

        sol = solver.solve(x=None)
        sol = solver.solve(x=np.array([7.0]), y=None, s=None)
        sol = solver.solve(
            x=np.array([7.0]), y=np.array([1.0, 2.0]), s=np.array([3.0, 4.0])
        )

>       with pytest.raises(ValueError):
E       Failed: DID NOT RAISE <class 'ValueError'>

test/test_scs_object.py:93: Failed
----------------------------------------------------------------------------------- Captured stderr call ------------------------------------------------------------------------------------
Error parsing warm-start input
__________________________________________________________________________________ test_warm_start[False] ___________________________________________________________________________________

use_indirect = False

    @pytest.mark.parametrize("use_indirect", [False, True])
    def test_warm_start(use_indirect):
        # max x
        # s.t 0 <= x <= 1
        solver = scs.SCS(data, cone, use_indirect=use_indirect, verbose=False)
        sol = solver.solve()
        assert_almost_equal(sol["x"][0], 1.0, decimal=2)

        sol = solver.solve()
        assert_almost_equal(sol["x"][0], 1.0, decimal=2)
        assert_array_less(sol["info"]["iter"], 10)

        sol = solver.solve(x=None)
        sol = solver.solve(x=np.array([7.0]), y=None, s=None)
        sol = solver.solve(
            x=np.array([7.0]), y=np.array([1.0, 2.0]), s=np.array([3.0, 4.0])
        )

>       with pytest.raises(ValueError):
E       Failed: DID NOT RAISE <class 'ValueError'>

test/test_scs_object.py:93: Failed
----------------------------------------------------------------------------------- Captured stderr call ------------------------------------------------------------------------------------
Error parsing warm-start input
=============================================================================== 2 failed, 24 passed in 16.94s ===============================================================================

How to reproduce

Regular tests.

Additional information

Tests were run in the FreeBSD port.

bodono commented 5 months ago

This is very strange, I cannot reproduce this. Would you mind running the test after setting verbose to True here. And run with pytest -vv .

yurivict commented 5 months ago

The latest release 3.2.4.post3 has more failures:

legacy_setup.py::ruff PASSED                                                                                                                                                          [  1%]
legacy_setup.py::ruff::format FAILED                                                                                                                                                  [  3%]
.::project PASSED                                                                                                                                                                     [  4%]
scs/__init__.py::ruff PASSED                                                                                                                                                          [  6%]
scs/__init__.py::ruff::format FAILED                                                                                                                                                  [  8%]
scs_source/docs/src/conf.py::ruff PASSED                                                                                                                                              [  9%]
scs_source/docs/src/conf.py::ruff::format PASSED                                                                                                                                      [ 11%]
scs_source/docs/src/examples/python/entropy.py::ruff FAILED                                                                                                                           [ 13%]
scs_source/docs/src/examples/python/entropy.py::ruff::format PASSED                                                                                                                   [ 14%]
scs_source/docs/src/examples/python/lasso.py::ruff FAILED                                                                                                                             [ 16%]
scs_source/docs/src/examples/python/lasso.py::ruff::format PASSED                                                                                                                     [ 18%]
scs_source/docs/src/examples/python/mat_completion.py::ruff FAILED                                                                                                                    [ 19%]
scs_source/docs/src/examples/python/mat_completion.py::ruff::format FAILED                                                                                                            [ 21%]
scs_source/docs/src/examples/python/mpc.py::ruff FAILED                                                                                                                               [ 22%]
scs_source/docs/src/examples/python/mpc.py::ruff::format FAILED                                                                                                                       [ 24%]
scs_source/docs/src/examples/python/qp.py::ruff PASSED                                                                                                                                [ 26%]
scs_source/docs/src/examples/python/qp.py::ruff::format PASSED                                                                                                                        [ 27%]
test/gen_random_cone_prob.py::ruff FAILED                                                                                                                                             [ 29%]
test/gen_random_cone_prob.py::ruff::format FAILED                                                                                                                                     [ 31%]
test/solve_random_cone_prob.py::ruff FAILED                                                                                                                                           [ 32%]
test/solve_random_cone_prob.py::ruff::format PASSED                                                                                                                                   [ 34%]
test/test_scs_basic.py::ruff FAILED                                                                                                                                                   [ 36%]
test/test_scs_basic.py::ruff::format FAILED                                                                                                                                           [ 37%]
test/test_scs_basic.py::test_problems[cone0-False-1] PASSED                                                                                                                           [ 39%]
test/test_scs_basic.py::test_problems[cone1-True-1] PASSED                                                                                                                            [ 40%]
test/test_scs_basic.py::test_problems[cone2-False-0.5] PASSED                                                                                                                         [ 42%]
test/test_scs_basic.py::test_problems[cone3-True-0.5] PASSED                                                                                                                          [ 44%]
test/test_scs_basic.py::test_failures PASSED                                                                                                                                          [ 45%]
test/test_scs_object.py::ruff FAILED                                                                                                                                                  [ 47%]
test/test_scs_object.py::ruff::format PASSED                                                                                                                                          [ 49%]
test/test_scs_object.py::test_backwards_compatibility[False] PASSED                                                                                                                   [ 50%]
test/test_scs_object.py::test_backwards_compatibility[True] PASSED                                                                                                                    [ 52%]
test/test_scs_object.py::test_update[False] PASSED                                                                                                                                    [ 54%]
test/test_scs_object.py::test_update[True] PASSED                                                                                                                                     [ 55%]
test/test_scs_object.py::test_warm_start[False] PASSED                                                                                                                                [ 57%]
test/test_scs_object.py::test_warm_start[True] PASSED                                                                                                                                 [ 59%]
test/test_scs_quad.py::ruff FAILED                                                                                                                                                    [ 60%]
test/test_scs_quad.py::ruff::format PASSED                                                                                                                                            [ 62%]
test/test_scs_rand.py::ruff FAILED                                                                                                                                                    [ 63%]
test/test_scs_rand.py::ruff::format PASSED                                                                                                                                            [ 65%]
test/test_scs_rand.py::test_feasible[False] PASSED                                                                                                                                    [ 67%]
test/test_scs_rand.py::test_feasible[True] PASSED                                                                                                                                     [ 68%]
test/test_scs_rand.py::test_infeasible[False] PASSED                                                                                                                                  [ 70%]
test/test_scs_rand.py::test_infeasible[True] PASSED                                                                                                                                   [ 72%]
test/test_scs_rand.py::test_unbounded[False] PASSED                                                                                                                                   [ 73%]
test/test_scs_sdp.py::ruff FAILED                                                                                                                                                     [ 75%]
test/test_scs_sdp.py::ruff::format PASSED                                                                                                                                             [ 77%]
test/test_scs_sdp.py::test_feasible[False] PASSED                                                                                                                                     [ 78%]
test/test_scs_sdp.py::test_feasible[True] PASSED                                                                                                                                      [ 80%]
test/test_scs_sdp.py::test_infeasible[False] PASSED                                                                                                                                   [ 81%]
test/test_scs_sdp.py::test_infeasible[True] PASSED                                                                                                                                    [ 83%]
test/test_scs_sdp.py::test_unbounded[False] PASSED                                                                                                                                    [ 85%]
test/test_solve_random_cone_prob.py::ruff FAILED                                                                                                                                      [ 86%]
test/test_solve_random_cone_prob.py::ruff::format FAILED                                                                                                                              [ 88%]
test/test_solve_random_cone_prob.py::test_solve_feasible[False-False] PASSED                                                                                                          [ 90%]
test/test_solve_random_cone_prob.py::test_solve_feasible[True-False] PASSED                                                                                                           [ 91%]
test/test_solve_random_cone_prob.py::test_solve_infeasible[False-False] PASSED                                                                                                        [ 93%]
test/test_solve_random_cone_prob.py::test_solve_infeasible[True-False] PASSED                                                                                                         [ 95%]
test/test_solve_random_cone_prob.py::test_solve_unbounded[False-False] PASSED                                                                                                         [ 96%]
test/test_solve_random_cone_prob_mkl.py::ruff FAILED                                                                                                                                  [ 98%]
test/test_solve_random_cone_prob_mkl.py::ruff::format FAILED                                                                                                                          [100%]

========================================================================================= FAILURES ==========================================================================================
_______________________________________________________________________________________ test session ________________________________________________________________________________________
File would be reformatted
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
Would reformat: legacy_setup.py
_______________________________________________________________________________________ test session ________________________________________________________________________________________
File would be reformatted
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
Would reformat: scs/__init__.py
_______________________________________________________________________________________ test session ________________________________________________________________________________________
scs_source/docs/src/examples/python/entropy.py:67:7: F541 [*] f-string without any placeholders
   |
65 | x_cvxpy = x.value
66 | 
67 | print(f"CVXPY optimal value is:", prob.value)
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^ F541
68 | print(f"Solution norm difference: {np.linalg.norm(x_scs - x_cvxpy, np.inf)}")
   |
   = help: Remove extraneous `f` prefix

_______________________________________________________________________________________ test session ________________________________________________________________________________________
scs_source/docs/src/examples/python/lasso.py:47:7: F541 [*] f-string without any placeholders
   |
45 | cone = dict(z=m, l=2 * n)
46 | 
47 | print(f"Solving for lambda = 0")
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^ F541
48 | # Setup workspace
49 | solver = scs.SCS(
   |
   = help: Remove extraneous `f` prefix

_______________________________________________________________________________________ test session ________________________________________________________________________________________
scs_source/docs/src/examples/python/mat_completion.py:3:17: F401 [*] `scipy` imported but unused
  |
1 | import scs
2 | import numpy as np
3 | import scipy as sp
  |                 ^^ F401
4 | from scipy import sparse
  |
  = help: Remove unused import: `scipy`

scs_source/docs/src/examples/python/mat_completion.py:86:7: F541 [*] f-string without any placeholders
   |
84 | # Setup workspace
85 | solver = scs.SCS(data, cone, eps_abs=1e-6, eps_rel=1e-6)
86 | print(f"Solving for lambda = 0")
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^ F541
87 | sol = solver.solve()  # lambda = 0
88 | X_hat = mat(sol["x"][:vlen])
   |
   = help: Remove extraneous `f` prefix

_______________________________________________________________________________________ test session ________________________________________________________________________________________
File would be reformatted
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
Would reformat: scs_source/docs/src/examples/python/mat_completion.py
_______________________________________________________________________________________ test session ________________________________________________________________________________________
scs_source/docs/src/examples/python/mpc.py:3:17: F401 [*] `scipy` imported but unused
  |
1 | import scs
2 | import numpy as np
3 | import scipy as sp
  |                 ^^ F401
4 | from scipy import sparse
  |
  = help: Remove unused import: `scipy`

_______________________________________________________________________________________ test session ________________________________________________________________________________________
File would be reformatted
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
Would reformat: scs_source/docs/src/examples/python/mpc.py
_______________________________________________________________________________________ test session ________________________________________________________________________________________
test/gen_random_cone_prob.py:63:5: E741 Ambiguous variable name: `l`
   |
62 | def get_scs_cone_dims(K):
63 |     l = K["z"] + K["l"]
   |     ^ E741
64 |     for i in range(0, len(K["q"])):
65 |         l = l + K["q"][i]
   |

test/gen_random_cone_prob.py:65:9: E741 Ambiguous variable name: `l`
   |
63 |     l = K["z"] + K["l"]
64 |     for i in range(0, len(K["q"])):
65 |         l = l + K["q"][i]
   |         ^ E741
66 | 
67 |     for i in range(0, len(K["s"])):
   |

test/gen_random_cone_prob.py:68:9: E741 Ambiguous variable name: `l`
   |
67 |     for i in range(0, len(K["s"])):
68 |         l = l + get_sd_cone_size(K["s"][i])
   |         ^ E741
69 | 
70 |     l = l + K["ep"] * 3
   |

test/gen_random_cone_prob.py:70:5: E741 Ambiguous variable name: `l`
   |
68 |         l = l + get_sd_cone_size(K["s"][i])
69 | 
70 |     l = l + K["ep"] * 3
   |     ^ E741
71 |     l = l + K["ed"] * 3
72 |     l = l + len(K["p"]) * 3
   |

test/gen_random_cone_prob.py:71:5: E741 Ambiguous variable name: `l`
   |
70 |     l = l + K["ep"] * 3
71 |     l = l + K["ed"] * 3
   |     ^ E741
72 |     l = l + len(K["p"]) * 3
73 |     return int(l)
   |

test/gen_random_cone_prob.py:72:5: E741 Ambiguous variable name: `l`
   |
70 |     l = l + K["ep"] * 3
71 |     l = l + K["ed"] * 3
72 |     l = l + len(K["p"]) * 3
   |     ^ E741
73 |     return int(l)
   |

_______________________________________________________________________________________ test session ________________________________________________________________________________________
File would be reformatted
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
Would reformat: test/gen_random_cone_prob.py
_______________________________________________________________________________________ test session ________________________________________________________________________________________
test/solve_random_cone_prob.py:4:19: F401 [*] `scipy.sparse` imported but unused
  |
2 | import scs
3 | import numpy as np
4 | from scipy import sparse, randn
  |                   ^^^^^^ F401
5 | import gen_random_cone_prob as tools
  |
  = help: Remove unused import

test/solve_random_cone_prob.py:4:27: F401 [*] `scipy.randn` imported but unused
  |
2 | import scs
3 | import numpy as np
4 | from scipy import sparse, randn
  |                           ^^^^^ F401
5 | import gen_random_cone_prob as tools
  |
  = help: Remove unused import

test/solve_random_cone_prob.py:15:16: F401 `_scs_gpu` imported but unused; consider using `importlib.util.find_spec` to test for availability
   |
13 |     flags = [(False, False), (True, False)]
14 |     try:
15 |         import _scs_gpu
   |                ^^^^^^^^ F401
16 | 
17 |         flags += [(True, True)]
   |
   = help: Remove unused import: `_scs_gpu`

test/solve_random_cone_prob.py:64:5: F841 Local variable `sol` is assigned to but never used
   |
62 |     data = tools.gen_infeasible(K, n=m // 3)
63 |     params = {"normalize": True, "scale": 0.5}
64 |     sol = scs.solve(data, K, use_indirect=use_indirect, gpu=gpu, **params)
   |     ^^^ F841
   |
   = help: Remove assignment to unused variable `sol`

test/solve_random_cone_prob.py:80:5: F841 Local variable `sol` is assigned to but never used
   |
78 |     data = tools.gen_unbounded(K, n=m // 3)
79 |     params = {"normalize": True, "scale": 0.5}
80 |     sol = scs.solve(data, K, use_indirect=use_indirect, gpu=gpu, **params)
   |     ^^^ F841
   |
   = help: Remove assignment to unused variable `sol`

_______________________________________________________________________________________ test session ________________________________________________________________________________________
test/test_scs_basic.py:65:29: F821 Undefined name `long`
   |
63 |         "cone,use_indirect,expected",
64 |         [
65 |             ({"q": [], "l": long(2)}, False, 1),
   |                             ^^^^ F821
66 |             ({"q": [], "l": long(2)}, True, 1),
67 |             ({"q": [long(2)], "l": 0}, False, 0.5),
   |

test/test_scs_basic.py:66:29: F821 Undefined name `long`
   |
64 |         [
65 |             ({"q": [], "l": long(2)}, False, 1),
66 |             ({"q": [], "l": long(2)}, True, 1),
   |                             ^^^^ F821
67 |             ({"q": [long(2)], "l": 0}, False, 0.5),
68 |             ({"q": [long(2)], "l": 0}, True, 0.5),
   |

test/test_scs_basic.py:67:21: F821 Undefined name `long`
   |
65 |             ({"q": [], "l": long(2)}, False, 1),
66 |             ({"q": [], "l": long(2)}, True, 1),
67 |             ({"q": [long(2)], "l": 0}, False, 0.5),
   |                     ^^^^ F821
68 |             ({"q": [long(2)], "l": 0}, True, 0.5),
69 |         ],
   |

test/test_scs_basic.py:68:21: F821 Undefined name `long`
   |
66 |             ({"q": [], "l": long(2)}, True, 1),
67 |             ({"q": [long(2)], "l": 0}, False, 0.5),
68 |             ({"q": [long(2)], "l": 0}, True, 0.5),
   |                     ^^^^ F821
69 |         ],
70 |     )
   |

test/test_scs_basic.py:95:9: F841 Local variable `sol` is assigned to but never used
   |
94 |     with pytest.raises(ValueError):
95 |         sol = scs.solve(data, {"q": [1], "l": 0}, verbose=False)
   |         ^^^ F841
   |
   = help: Remove assignment to unused variable `sol`

_______________________________________________________________________________________ test session ________________________________________________________________________________________
File would be reformatted
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
Would reformat: test/test_scs_basic.py
_______________________________________________________________________________________ test session ________________________________________________________________________________________
test/test_scs_object.py:2:8: F401 [*] `platform` imported but unused
  |
1 | from __future__ import print_function
2 | import platform
  |        ^^^^^^^^ F401
  |
  = help: Remove unused import: `platform`

_______________________________________________________________________________________ test session ________________________________________________________________________________________
test/test_scs_quad.py:3:8: F401 [*] `platform` imported but unused
  |
1 | # nost test suite copied initially from ECOS project
2 | from __future__ import print_function
3 | import platform
  |        ^^^^^^^^ F401
4 | 
5 | import numpy as np
  |
  = help: Remove unused import: `platform`

_______________________________________________________________________________________ test session ________________________________________________________________________________________
test/test_scs_rand.py:2:8: F401 [*] `platform` imported but unused
  |
1 | from __future__ import print_function
2 | import platform
  |        ^^^^^^^^ F401
3 | 
4 | ## import utilities to generate random cone probs:
  |
  = help: Remove unused import: `platform`

test/test_scs_rand.py:5:8: F401 [*] `sys` imported but unused
  |
4 | ## import utilities to generate random cone probs:
5 | import sys
  |        ^^^ F401
6 | import gen_random_cone_prob as tools
  |
  = help: Remove unused import: `sys`

test/test_scs_rand.py:35:28: F401 `scipy.sparse` imported but unused; consider using `importlib.util.find_spec` to test for availability
   |
34 | try:
35 |     import scipy.sparse as sp
   |                            ^^ F401
36 | except ImportError:
37 |     import_error("Please install scipy.")
   |
   = help: Remove unused import: `scipy.sparse`

_______________________________________________________________________________________ test session ________________________________________________________________________________________
test/test_scs_sdp.py:2:8: F401 [*] `platform` imported but unused
  |
1 | from __future__ import print_function
2 | import platform
  |        ^^^^^^^^ F401
3 | 
4 | ## import utilities to generate random cone probs:
  |
  = help: Remove unused import: `platform`

test/test_scs_sdp.py:5:8: F401 [*] `sys` imported but unused
  |
4 | ## import utilities to generate random cone probs:
5 | import sys
  |        ^^^ F401
6 | import gen_random_cone_prob as tools
  |
  = help: Remove unused import: `sys`

test/test_scs_sdp.py:35:28: F401 `scipy.sparse` imported but unused; consider using `importlib.util.find_spec` to test for availability
   |
34 | try:
35 |     import scipy.sparse as sp
   |                            ^^ F401
36 | except ImportError:
37 |     import_error("Please install scipy.")
   |
   = help: Remove unused import: `scipy.sparse`

_______________________________________________________________________________________ test session ________________________________________________________________________________________
test/test_solve_random_cone_prob.py:4:19: F401 [*] `scipy.sparse` imported but unused
  |
2 | import scs
3 | import numpy as np
4 | from scipy import sparse
  |                   ^^^^^^ F401
5 | import gen_random_cone_prob as tools
  |
  = help: Remove unused import: `scipy.sparse`

test/test_solve_random_cone_prob.py:26:12: F401 `_scs_gpu` imported but unused; consider using `importlib.util.find_spec` to test for availability
   |
24 | flags = [(False, False), (True, False)]
25 | try:
26 |     import _scs_gpu
   |            ^^^^^^^^ F401
27 | 
28 |     flags += [(True, True)]
   |
   = help: Remove unused import: `_scs_gpu`

_______________________________________________________________________________________ test session ________________________________________________________________________________________
File would be reformatted
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
Would reformat: test/test_solve_random_cone_prob.py
_______________________________________________________________________________________ test session ________________________________________________________________________________________
test/test_solve_random_cone_prob_mkl.py:4:19: F401 [*] `scipy.sparse` imported but unused
  |
2 | import scs
3 | import numpy as np
4 | from scipy import sparse
  |                   ^^^^^^ F401
5 | import gen_random_cone_prob as tools
  |
  = help: Remove unused import: `scipy.sparse`

test/test_solve_random_cone_prob_mkl.py:19:12: F401 `pytest` imported but unused; consider using `importlib.util.find_spec` to test for availability
   |
18 | try:
19 |     import pytest
   |            ^^^^^^ F401
20 | except ImportError:
21 |     import_error("Please install pytest to run tests.")
   |
   = help: Remove unused import: `pytest`

test/test_solve_random_cone_prob_mkl.py:41:12: F401 `_scs_mkl` imported but unused; consider using `importlib.util.find_spec` to test for availability
   |
40 | try:
41 |     import _scs_mkl
   |            ^^^^^^^^ F401
42 | 
43 |     def test_solve_feasible():
   |
   = help: Remove unused import: `_scs_mkl`

_______________________________________________________________________________________ test session ________________________________________________________________________________________
File would be reformatted
----------------------------------------------------------------------------------- Captured stdout call ------------------------------------------------------------------------------------
Would reformat: test/test_solve_random_cone_prob_mkl.py

-------- coverage: platform freebsd14, python 3.11.9-final-0 ---------
Name                                      Stmts   Miss  Cover
-------------------------------------------------------------
scs/__init__.py                              94     28    70%
test/gen_random_cone_prob.py                212      0   100%
test/test_scs_basic.py                       52     19    63%
test/test_scs_object.py                      62     15    76%
test/test_scs_quad.py                        15      0   100%
test/test_scs_rand.py                        66     16    76%
test/test_scs_sdp.py                         66     16    76%
test/test_solve_random_cone_prob.py          58      7    88%
test/test_solve_random_cone_prob_mkl.py      53     34    36%
-------------------------------------------------------------
TOTAL                                       678    135    80%

========================================================================= 21 failed, 40 passed in 204.01s (0:03:24) =========================================================================
yurivict commented 5 months ago

The above failures are the result of the pytest-ruff plugin that was accidentally installed. You have these linting issues. Please consider fixing them.

Otherwise I can't reproduce the issues from my original message. All tests pass.

bodono commented 5 months ago

Ok thanks @yurivict , we use the black formatter, which is presumably a little different to what ruff expects (though it might be there are some unused imports I can clean up).