bodono / scs-python

Python interface for SCS
MIT License
41 stars 33 forks source link

x64 linux `test_solve_feasible[True-False]` unit test fails with scipy 1.12.0 #81

Closed ghost closed 8 months ago

ghost commented 8 months ago

Specifications

Description

x64 linux unit test is failing on upgrade of scipy. x64 darwin passes all tests.

old scipy was: 1.11.4 and all tests were passing. new scipy is: 1.12.0 and generates the failure below on x64 linux.

unittest test_solve_feasible[True-False] fails with Arrays are not almost equal to 4 decimals

=================================== FAILURES ===================================
_______________________ test_solve_feasible[True-False] ________________________

use_indirect = True, gpu = False

    @pytest.mark.parametrize("use_indirect,gpu", flags)
    def test_solve_feasible(use_indirect, gpu):
        data, p_star = tools.gen_feasible(K, n=m // 3, density=0.1)
        solver = scs.SCS(data, K, use_indirect=use_indirect, gpu=gpu, **params)
        sol = solver.solve()
        x = sol["x"]
        y = sol["y"]
        s = sol["s"]
        np.testing.assert_almost_equal(np.dot(data["c"], x), p_star, decimal=3)
        np.testing.assert_almost_equal(np.dot(data["c"], x), p_star, decimal=3)
        np.testing.assert_array_less(
            np.linalg.norm(data["A"] @ x - data["b"] + s), 1e-3
        )
        np.testing.assert_array_less(
            np.linalg.norm(data["A"].T @ y + data["c"]), 1e-3
        )
        np.testing.assert_almost_equal(s.T @ y, 0.0)
        np.testing.assert_almost_equal(s, tools.proj_cone(s, K), decimal=4)
>       np.testing.assert_almost_equal(y, tools.proj_dual_cone(y, K), decimal=4)

test/test_solve_random_cone_prob.py:66: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/nix/store/w4fvvhkzb0ssv0fw5j34pw09f0qw84w8-python3-3.11.7/lib/python3.11/contextlib.py:81: in inner
    return func(*args, **kwds)
/nix/store/w4fvvhkzb0ssv0fw5j34pw09f0qw84w8-python3-3.11.7/lib/python3.11/contextlib.py:81: in inner
    return func(*args, **kwds)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<function assert_array_almost_equal.<locals>.compare at 0x7ffef0cec4a0>, array([-3.12461867e-01,  4.57536263e-01,  1....,  5.61349002e-01,
        1.34370747e-02, -3.87453822e-01,  6.34520625e-02,  1.13037626e+00,
       -4.36984994e-01]))
kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 4 decimals', 'precision': 4, 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Arrays are not almost equal to 4 decimals
E           
E           Mismatched elements: 1 / 185 (0.541%)
E           Max absolute difference: 0.00029399
E           Max relative difference: 1.
E            x: array([-3.1246e-01,  4.5754e-01,  1.2536e+00, -4.1173e-01,  1.5191e+00,
E                  -1.7570e-01,  6.6589e-01, -1.0639e+00, -1.6155e+00,  1.2538e+00,
E                   0.0000e+00,  0.0000e+00,  7.8325e-01,  1.2515e+00,  0.0000e+00,...
E            y: array([-3.1246e-01,  4.5754e-01,  1.2536e+00, -4.1173e-01,  1.5191e+00,
E                  -1.7570e-01,  6.6589e-01, -1.0639e+00, -1.6155e+00,  1.2538e+00,
E                   0.0000e+00,  0.0000e+00,  7.8325e-01,  1.2515e+00,  0.0000e+00,...

/nix/store/w4fvvhkzb0ssv0fw5j34pw09f0qw84w8-python3-3.11.7/lib/python3.11/contextlib.py:81: AssertionError
----------------------------- Captured stdout call -----------------------------
------------------------------------------------------------------
           SCS v3.2.4 - Splitting Conic Solver
    (c) Brendan O'Donoghue, Stanford University, 2012
------------------------------------------------------------------
problem:  variables n: 61, constraints m: 185
cones:    z: primal zero / dual free vars: 10
      l: linear vars: 15
      q: soc vars: 16, qsize: 4
      s: psd vars: 72, ssize: 6
      e: exp vars: 30, dual exp vars: 30
      p: primal + dual power vars: 12
settings: eps_abs: 1.0e-05, eps_rel: 1.0e-05, eps_infeas: 1.0e-05
      alpha: 1.50, scale: 1.00e-01, adaptive_scale: 1
      max_iters: 100000, normalize: 1, rho_x: 1.00e-06
      acceleration_lookback: 10, acceleration_interval: 10
lin-sys:  sparse-indirect-scs
      nnz(A): 1128, nnz(P): 0
------------------------------------------------------------------
 iter | pri res | dua res |   gap   |   obj   |  scale  | time (s)
------------------------------------------------------------------
     0| 7.69e+01  7.91e+00  1.17e+03 -6.05e+02  1.00e-01  1.38e-03 
   250| 1.51e-02  5.83e-04  3.73e-02 -1.41e+01  3.65e-01  1.49e-02 
   500| 4.94e-04  3.09e-05  1.12e-03 -1.40e+01  1.89e+00  2.87e-02 
   750| 2.45e-04  1.74e-05  6.81e-04 -1.40e+01  1.89e+00  4.41e-02 
  1000| 1.43e-04  9.52e-06  4.39e-04 -1.40e+01  1.89e+00  5.89e-02 
  1250| 8.17e-05  6.12e-06  2.91e-04 -1.40e+01  1.89e+00  7.48e-02 
  1400| 1.82e-05  2.48e-05  6.86e-05 -1.40e+01  1.89e+00  8.48e-02 
------------------------------------------------------------------
status:  solved
timings: total: 8.48e-02s = setup: 6.54e-04s + solve: 8.41e-02s
     lin-sys: 6.36e-02s, cones: 1.80e-02s, accel: 1.52e-04s
------------------------------------------------------------------
objective = -14.039517
------------------------------------------------------------------
=========================== short test summary info ============================
FAILED test/test_solve_random_cone_prob.py::test_solve_feasible[True-False] - AssertionError: 
================= 1 failed, 15 passed, 10 deselected in 0.37s ==================

How to reproduce

on github.com/NixOS/nixpkgs master branch on x64 linux. nix-build -A python311Packages.scs

bodono commented 8 months ago

From the looks of it the outputs are almost identical, but clearly something has changed to violate the tolerances. We can probably fix this by simply decreasing the tolerance a bit.

ghost commented 8 months ago

fixed with https://github.com/bodono/scs-python/pull/82