Cvxpy: support for multithreading

Created on 9 May 2020  Â·  7Comments  Â·  Source: cvxgrp/cvxpy

Is your feature request related to a problem? Please describe.
it would be nice if the documentation could be improved for the multi-threading. The two examples in the documentation do not seem to run and the appear to have some confusing logic.

Describe the solution you'd like
Update or removal of the multithreading examples in the documentation

Describe alternatives you've considered
None

Additional context
I wanted to solve the same problem over and over again with different input parameters and collect the best 10 results along with the optimized values. It was not clear if this was possible with cvxpy.

Most helpful comment

This is a code snippet I've actually used.

import dask

def ecossolve(cvxprob):
    cvxprob.solve(solver='ECOS')
    return cvxprob


def parallel_ecossolve(problist):
    dasklist = [dask.delayed(ecossolve)(prob) for prob in problist]
    results = dask.compute(*dasklist, scheduler='processes')
    return results

I don't remember exactly why I created the ecossolve function. I probably needed it because of something with how dask.delayed(fxn)(arg) passes arg to fxn, but there is also a chance that I wrote awkward code based on a poor understanding of dask.

All 7 comments

CVXPY is not threadsafe. Can you link to the offending documentation?

You can definitely spawn multiple processes, each of which solves its own problem, since processes don’t share memory. That’s just standard Python, and is not CVXPY specific.

It’s possible the examples don’t work, though. Can you paste the entire error messages you saw when trying to run them?

OK, thanks I will work on these later.

When I need parallelism with CVXPY I just use Dask. They have a “delay” feature where you pass it a reference to a function handle (can be an instance method, like “.solve” for a CVXPY Problem). You can specify that the parallelism should be localized to different threads.

https://docs.dask.org/en/latest/delayed.html

Sent with GitHawk

@rileyjmurray : can you post a short snippet how you/to use dask with .solve()?

This is a code snippet I've actually used.

import dask

def ecossolve(cvxprob):
    cvxprob.solve(solver='ECOS')
    return cvxprob


def parallel_ecossolve(problist):
    dasklist = [dask.delayed(ecossolve)(prob) for prob in problist]
    results = dask.compute(*dasklist, scheduler='processes')
    return results

I don't remember exactly why I created the ecossolve function. I probably needed it because of something with how dask.delayed(fxn)(arg) passes arg to fxn, but there is also a chance that I wrote awkward code based on a poor understanding of dask.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dave31415 picture dave31415  Â·  7Comments

wfrece picture wfrece  Â·  9Comments

GiorgioBalestrieri picture GiorgioBalestrieri  Â·  10Comments

wrossmorrow picture wrossmorrow  Â·  5Comments

ShreyasFadnavis picture ShreyasFadnavis  Â·  11Comments