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.
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.
Most helpful comment
This is a code snippet I've actually used.
I don't remember exactly why I created the
ecossolvefunction. I probably needed it because of something with howdask.delayed(fxn)(arg)passesargtofxn, but there is also a chance that I wrote awkward code based on a poor understanding of dask.