How to use scs - 10 common examples

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 celery / cyme / scs / agent.py View on Github external
def run(self):
        state.is_agent = True
        self.prepare_signals()
        setup_logging(self.loglevel, self.logfile)
        self.info("Starting with id %r", self.id)
        [g.start() for g in self.components]
        self.exit_request.wait()
github celery / cyme / scs / intsup.py View on Github external
from time import sleep

from cl.g import Event

from scs.thread import gThread

SUP_ERROR_NOT_STARTED = """\
found thread not able to start?\
"""

SUP_ERROR_PING_TIMEOUT = """\
suspected thread crash or blocking: %r\
"""


class gSup(gThread):

    def __init__(self, thread, signal, interval=5, timeout=600):
        self.thread = thread
        self.interval = interval
        self.timeout = timeout
        self.signal = signal
        super(gSup, self).__init__()

    def start_wait_child(self):
        self._ready_event = Event()
        self.signal.connect(self._on_thread_ready, sender=self.thread)
        self.thread.start()
        self._ready_event.wait()
        assert self._ready_event.ready()
        return self.thread
github celery / cyme / scs / supervisor.py View on Github external
def _verify_all(self, force=False):
        if self._last_update and self._last_update.ready():
            try:
                self._last_update.wait()  # collect result
            except self.GreenletExit:
                pass
            force = True
        if not self._last_update or force:
            self._last_update = self.verify(Node.objects.all(), ratelimit=True)
github celery / cyme / scs / agent.py View on Github external
for component in reversed(self.components):
            if self._components_ready[component.thread]:
                try:
                    component.stop()
                except KeyboardInterrupt:
                    pass
                except BaseException, exc:
                    component.error("Error in shutdown: %r", exc)


def maybe_wait(g, nowait):
    not nowait and g.wait()


class Cluster(object):
    Nodes = Node._default_manager
    Brokers = Broker._default_manager

    def get(self, nodename):
        return self.Nodes.get(name=nodename)

    def add(self, nodename=None, queues=None,
            max_concurrency=1, min_concurrency=1, broker=None,
            pool=None, app=None, nowait=False, **kwargs):
        broker = self.Brokers.get_or_create(url=broker)[0] if broker else None
        node = self.Nodes.add(nodename, queues, max_concurrency,
                              min_concurrency, broker, pool, app)
        maybe_wait(self.sup.verify([node]), nowait)
        return node

    def remove(self, nodename, nowait=False):
        node = self.Nodes.remove(nodename)
github celery / cyme / scs / views.py View on Github external
@web.simple_get
def task_wait(self, request, app, uuid):
    return {"result": AsyncResult(uuid).get()}