def test_many_iter_ecp(): # warm starting with the previously found solution should take 0 iterations data, cone = ex.many_iter_ecp() sol = scs.solve(data, cone) assert sol['info']['iter'] >= 500 sol = scs.solve(data, cone, warm_start = sol) assert sol['info']['iter'] == 0
def test_many_iter_ecp(): # warm starting with the previously found solution should take 0 iterations data, cone = ex.many_iter_ecp() sol = scs.solve(data, cone) assert sol['info']['iter'] >= 500 sol = scs.solve(data, cone, warm_start=sol) assert sol['info']['iter'] == 0
def test_many_iter_ecp_tol(): # warm starting with a solution at a lower tolerance should reduce # the number of iterations needed data, cone = ex.many_iter_ecp() # intially takes ~920 iters for eps 1e-4 sol = scs.solve(data, cone, eps=1e-4) assert sol['info']['iter'] >= 800 # ~640 for eps 1e-3 sol = scs.solve(data, cone, eps=1e-3) assert 500 <= sol['info']['iter'] <= 700 # use 1e-3 sol as warm start for 1e-4 # extra digit only takes ~280 iters more sol = scs.solve(data, cone, warm_start = sol, eps=1e-4) assert sol['info']['iter'] < 300
def test_b_len(): data, cone = ex.simple_lp() b = data['b'] b = np.append(b, b) data['b'] = b with pytest.raises(ValueError): sol = scs.solve(data, cone)
def test_numdim_b(): data, cone = ex.simple_lp() b = data['b'] b = np.array(b, ndmin=2).T data['b'] = b with pytest.raises(ValueError): sol = scs.solve(data, cone)
def test_warm(): data, cone, true_x = ex.simple_pcp() # computing a fresh solution takes some number of iters sol = scs.solve(data, cone) assert sol['info']['iter'] >= 10 # should take 0 iterations sol = scs.solve(data, cone, warm_start = sol) assert sol['info']['iter'] == 0 # change solution a bit sol['x'] *= 2 # perturbing the solution should take a few iterations to correct sol = scs.solve(data, cone, warm_start = sol) assert sol['info']['iter'] >= 3
def test_warm(): data, cone, true_x = ex.simple_pcp() # computing a fresh solution takes some number of iters sol = scs.solve(data, cone) assert sol['info']['iter'] >= 10 # should take 0 iterations sol = scs.solve(data, cone, warm_start=sol) assert sol['info']['iter'] == 0 # change solution a bit sol['x'] *= 2 # perturbing the solution should take a few iterations to correct sol = scs.solve(data, cone, warm_start=sol) assert sol['info']['iter'] >= 3
def test_cone_size(): # test that the solve method recognizes that the length of the cone # does not match the number of rows of A data, cone = ex.simple_lp() cone['l'] = 5 with pytest.raises(ValueError): sol = scs.solve(data, cone)
def test_b_len(): data, cone = ex.simple_lp() b = data['b'] b = np.append(b,b) data['b'] = b with pytest.raises(ValueError): sol = scs.solve(data, cone)
def test_many_iter_ecp_tol(): # warm starting with a solution at a lower tolerance should reduce # the number of iterations needed data, cone = ex.many_iter_ecp() # intially takes ~920 iters for eps 1e-4 sol = scs.solve(data, cone, eps=1e-4) assert sol['info']['iter'] >= 800 # ~640 for eps 1e-3 sol = scs.solve(data, cone, eps=1e-3) assert 500 <= sol['info']['iter'] <= 700 # use 1e-3 sol as warm start for 1e-4 # extra digit only takes ~280 iters more sol = scs.solve(data, cone, warm_start=sol, eps=1e-4) assert sol['info']['iter'] < 300
def test_solve(): data, cone = ex.simple_lp() m,n = data['A'].shape ws = dict(x=np.zeros(n), y=np.zeros(m), s=np.zeros(m)) sol = scs.solve(data, cone, warm_start = ws) # make sure sol and ws contain *different* numpy arrays assert any(ws['x'] != sol['x']) assert any(ws['y'] != sol['y']) assert any(ws['s'] != sol['s'])
def test_solve(): data, cone = ex.simple_lp() m, n = data['A'].shape ws = dict(x=np.zeros(n), y=np.zeros(m), s=np.zeros(m)) sol = scs.solve(data, cone, warm_start=ws) # make sure sol and ws contain *different* numpy arrays assert any(ws['x'] != sol['x']) assert any(ws['y'] != sol['y']) assert any(ws['s'] != sol['s'])
def test_simple_direct(): data, cone = ex.simple_lp() sol = scs.solve(data, cone, use_indirect=False)
def test_extra_arg(): data, cone = ex.simple_lp() sol = scs.solve(data, cone, eps=1e-9, alpha=.1, nonsense_arg='nonsense')
def test_b(): data, cone = ex.simple_lp() data['b'] = data['b'].astype(np.float32) with pytest.raises(ValueError): sol = scs.solve(data, cone)
def test_A_indptr(): data, cone = ex.simple_lp() data['A'].indptr = data['A'].indptr.astype(np.int32) with pytest.warns(UserWarning): sol = scs.solve(data, cone)
def test_simple_lp(): data, cone = ex.simple_lp() sol = scs.solve(data, cone)
def test_simple_pcp(): data, cone, true_x = ex.simple_pcp() sol = scs.solve(data, cone, eps=1e-6) assert np.allclose(sol['x'], true_x)
def test_str_output(): data, cone = ex.simple_lp() sol = scs.solve(data, cone) assert sol['info']['status'] == 'Solved'
def test_A_data(): data, cone = ex.simple_lp() data['A'].data = data['A'].data.astype(np.float32) with pytest.warns(UserWarning): sol = scs.solve(data, cone)