Open Jayshil opened 2 years ago
Hi @Jayshil! Thanks for this. Can you confirm that the way you propose to do multiprocesing is the way to make this work? Also, to change this, would imply to also test on non-M1-chip computers to ensure this is not going to fix the M1-chip users, but make everyone else's code to break.
I'll leave it as an enhancement for now, but if this is investigated further, I would be happy to change the way in which pool
is handled.
N.
Hi @nespinoza,
I am not really sure if this is the only way to make this work or not. There may be other ways to resolve this issue that I am unaware of. But I can confirm that this is at least one way to make it work for M1 chip computers (working smoothly on my machine). I also don't know if this would work for non-M1-chip computers or not. Unfortunately, I do not have enough time to thoroughly investigate this.
I think your suggestion is appropriate to leave this as an enhancement for now. This will let users know that there is an issue with pool
in M1 chip Macs and there is a possible way to resolve this.
Cheers, Jayshil
Hi @nespinoza,
A colleague of mine pointed out that instead of editing the juliet
source code, one can simply add the following two lines in their code to make multiprocessing work with M1 chip macs:
import multiprocessing
multiprocessing.set_start_method('fork')
This is at least working with dynesty
.
So, I suggest we leave juliet
source code as it is, but put this "hack" somewhere in the documentation. We can close this issue after that.
Cheers, Jayshil
Hi @nespinoza,
If I try to use
nthreads
option injuliet.fit
for using multiprocessing withdynesty
, I would get the following error:At first, I thought it is the multiprocessing implemented in
dynesty
that is causing this issue. However, upon digging into the details I found that this has rather do with how multiprocessing is implemented injuliet
: the culprit is line 1723. A proper way to do this (according to this StackOverflow answer) is following:(instead of directly calling
Pool
frommultiprocessing
, one should call it frommultiprocessing.get_context("fork").Pool
). Making this change would solve the above issue.However, I am not opening a pull request since it looks like this issue is specific to Mac users with an M1 chip. And I have no idea how implementing this would affect other systems which don't have M1. Also since this is the issue with
Pool
implementation, it should also affectemcee
andzeus
samplers which also usePool
for multiprocessing (though I haven't tested for samplers other thandynesty
).Cheers, Jayshil