Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiprocessing failure on MacOS and python3.8+ #88

Open
johnveitch opened this issue Dec 1, 2022 · 3 comments
Open

Multiprocessing failure on MacOS and python3.8+ #88

johnveitch opened this issue Dec 1, 2022 · 3 comments

Comments

@johnveitch
Copy link
Owner

johnveitch commented Dec 1, 2022

CPNest currently doesn't work on MacOS with python 3.8 or above.
The failure may be related to the change to the way multiprocessing creates new processes on this platform, which changed in v3.8. See the issue here.

The error I see is

  File "/opt/anaconda3/envs/cpnest_py38/lib/python3.8/site-packages/cpnest/sampler.py", line 116, in reset
    for n in tqdm(range(self.poolsize), desc='SMPLR {} init draw'.format(self.thread_id),
AttributeError: 'MetropolisHastingsSampler' object has no attribute 'thread_id'
@wdpozzo
Copy link
Collaborator

wdpozzo commented Dec 5, 2022

I managed to have a look at the issue, and I came to the conclusion that the getstate and setstate functions that we wrote for the checkpointing of the sampler class is interfering with the serialisation necessary for the multiprocessing module. Something changed under the hood, and I cannot really track down what it is. Hence, I think we either rewrite the code or move on to a different architecture for the parallelism as in massively_parallel.

@dylaghi
Copy link

dylaghi commented Jul 29, 2023

I have reproduced this error several times on different Apple M1 laptops, where it is not possible to directly install python 3.7 (see https://stackoverflow.com/questions/70205633/cannot-install-python-3-7-on-osx-arm64).

A workaround that worked for me is to install cpnest in a conda environment that simulates the x86_64 architecture, as detailed in the link above.

@SimonMaenaut
Copy link
Contributor

From my understanding, it would be recommended to adapt the code in order for CPNest to work with the spawn start method.

In Python 3.14 the default start method will also change for Linux from fork to spawn, which is generally considered safer.

As mentioned in the Python 3.12 documentation on Multiprocessing specifically:

The default start method will change away from fork in Python 3.14. Code that requires fork should explicitly specify that via get_context() or set_start_method().

Changed in version 3.12: If Python is able to detect that your process has multiple threads, the os.fork() function that this start method calls internally will raise a DeprecationWarning. Use a different start method. See the os.fork() documentation for further explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants