How to use the scs.solve function in scs

To help you get started, we’ve selected a few scs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cvxgrp / scs / python / test_scs_sdp.py View on Github external
def test_feasible():
    for i in range(num_feas):
        data, p_star = genFeasible(K, n = m // 3, density = 0.1)
        
        sol = scs.solve(data, K, use_indirect=False, **opts)
        yield check_solution, dot(data['c'],sol['x']), p_star
        yield check_solution, dot(-data['b'],sol['y']), p_star

        sol = scs.solve(data, K, use_indirect=True, **opts)
        yield check_solution, dot(data['c'],sol['x']), p_star
        yield check_solution, dot(-data['b'],sol['y']), p_star
github cvxgrp / scs / python / test_scs_sdp.py View on Github external
def test_unbounded():
    for i in range(num_unb):
        data = genUnbounded(K, n = m // 2)
        
        yield check_unbounded, scs.solve(data, K, use_indirect=False, **opts)
        yield check_unbounded, scs.solve(data, K, use_indirect=True, **opts)
github cvxgrp / scs / examples / python / test_anderson.py View on Github external
data, p_star = gen_feasible(K, n=m // 3, density=0.01)
  params = {
      'normalize': True,
      'scale': 5,
      'cg_rate': 2,
      'acceleration_lookback': 0
  }

  sol_i = scs.solve(data, K, use_indirect=True, **params)
  xi = sol_i['x']
  yi = sol_i['y']
  print('p*  = ', p_star)
  print('pri error = ', (dot(data['c'], xi) - p_star) / p_star)
  print('dual error = ', (-dot(data['b'], yi) - p_star) / p_star)
  # direct:
  sol_d = scs.solve(data, K, use_indirect=False, **params)
  xd = sol_d['x']
  yd = sol_d['y']
  print('p*  = ', p_star)
  print('pri error = ', (dot(data['c'], xd) - p_star) / p_star)
  print('dual error = ', (-dot(data['b'], yd) - p_star) / p_star)

  params['acceleration_lookback'] = 30
  sol_i = scs.solve(data, K, use_indirect=True, **params)
  xi = sol_i['x']
  yi = sol_i['y']
  print('p*  = ', p_star)
  print('pri error = ', (dot(data['c'], xi) - p_star) / p_star)
  print('dual error = ', (-dot(data['b'], yi) - p_star) / p_star)

  params['acceleration_lookback'] = 0
  sol_i = scs.solve(data, K, use_indirect=True, **params)
github cvxgrp / scs / examples / python / solveRandomConeProbGpu.py View on Github external
def solveUnbounded():
  K = {
      'f': 10,
      'l': 15,
      'q': [5, 10, 0, 1],
      's': [3, 4, 0, 0, 1],
      'ep': 10,
      'ed': 10,
      'p': [-0.25, 0.5, 0.75, -0.33]
  }
  m = getScsConeDims(K)
  data = genUnbounded(K, n=m // 3)
  params = {'eps': 1e-4, 'normalize': True, 'scale': 0.5, 'cg_rate': 2}
  sol_i = scs.solve(data, K, gpu=True, **params)
github cvxgrp / scs / examples / python / test_anderson.py View on Github external
xd = sol_d['x']
  yd = sol_d['y']
  print('p*  = ', p_star)
  print('pri error = ', (dot(data['c'], xd) - p_star) / p_star)
  print('dual error = ', (-dot(data['b'], yd) - p_star) / p_star)

  params['acceleration_lookback'] = 30
  sol_i = scs.solve(data, K, use_indirect=True, **params)
  xi = sol_i['x']
  yi = sol_i['y']
  print('p*  = ', p_star)
  print('pri error = ', (dot(data['c'], xi) - p_star) / p_star)
  print('dual error = ', (-dot(data['b'], yi) - p_star) / p_star)

  params['acceleration_lookback'] = 0
  sol_i = scs.solve(data, K, use_indirect=True, **params)
  xi = sol_i['x']
  yi = sol_i['y']
  print('p*  = ', p_star)
  print('pri error = ', (dot(data['c'], xi) - p_star) / p_star)
  print('dual error = ', (-dot(data['b'], yi) - p_star) / p_star)
github cvxgrp / scs / examples / python / solveRandomConeProb.py View on Github external
def solveUnbounded():
    K = {'f':10, 'l':15, 'q':[5, 10, 0 ,1], 's':[3, 4, 0, 0, 1], 'ep':10, 'ed':10, 'p':[-0.25, 0.5, 0.75, -0.33]}
    m = getScsConeDims(K)
    data = genUnbounded(K, n = m//3)
    params = {'normalize':True, 'scale':0.5, 'cg_rate':2}
    sol_i = scs.solve(data, K, use_indirect=True, **params)
    sol_d = scs.solve(data, K, use_indirect=False, **params)
github cvxgrp / scs / examples / python / solveRandomConeProb.py View on Github external
def solveInfeasible():
    K = {'f':10, 'l':15, 'q':[5, 10, 0 ,1], 's':[3, 4, 0, 0, 1], 'ep':10, 'ed':10, 'p':[-0.25, 0.5, 0.75, -0.33]}
    m = getScsConeDims(K)
    data = genInfeasible(K, n = m//3)
    params = {'normalize':True, 'scale':0.5, 'cg_rate':2}
    sol_i = scs.solve(data, K, use_indirect=True, **params)
    sol_d = scs.solve(data, K, use_indirect=False, **params)
github cvxgrp / diffcp / diffcp / cone_program.py View on Github external
# eliminate explicit zeros in A, we no longer need them
    A.eliminate_zeros()

    data = {
        "A": A,
        "b": b,
        "c": c
    }

    if warm_start is not None:
        data["x"] = warm_start[0]
        data["y"] = warm_start[1]
        data["s"] = warm_start[2]

    kwargs.setdefault("verbose", False)
    result = scs.solve(data, cone_dict, **kwargs)

    status = result["info"]["status"]
    if status == "Solved/Inaccurate" and "acceleration_lookback" not in kwargs:
        # anderson acceleration is sometimes unstable
        result = scs.solve(data, cone_dict, acceleration_lookback=0, **kwargs)
        status = result["info"]["status"]

    if status == "Solved/Inaccurate":
        warnings.warn("Solved/Inaccurate.")
    elif status != "Solved":
        if raise_on_error:
            raise SolverError("Solver scs returned status %s" % status)
        else:
            result["D"] = None
            result["DT"] = None
            return result
github cvxgrp / scs / examples / python / solveRandomConeProb.py View on Github external
def solveFeasible():
    # cone:
    K = {'f':10, 'l':15, 'q':[5, 10, 0 ,1], 's':[3, 4, 0, 0, 1], 'ep':10, 'ed':10, 'p':[-0.25, 0.5, 0.75, -0.33]}
    m = getScsConeDims(K) 
    data, p_star = genFeasible(K, n = m//3, density = 0.01)
    params = {'normalize':True, 'scale':5, 'cg_rate':2}
    
    sol_i = scs.solve(data, K, use_indirect=True, **params)
    xi = sol_i['x']
    yi = sol_i['y']
    print('p*  = ', p_star)
    print('pri error = ', (dot(data['c'], xi) - p_star) / p_star)
    print('dual error = ', (-dot(data['b'], yi) - p_star) / p_star)
    # direct:
    sol_d = scs.solve(data, K, use_indirect=False, **params)
    xd = sol_d['x']
    yd = sol_d['y']
    print('p*  = ', p_star)
    print('pri error = ', (dot(data['c'], xd) - p_star) / p_star)
    print('dual error = ', (-dot(data['b'], yd) - p_star) / p_star)