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 error #129

Closed
angelicaps opened this issue Jan 28, 2021 · 7 comments
Closed

Multiprocessing error #129

angelicaps opened this issue Jan 28, 2021 · 7 comments

Comments

@angelicaps
Copy link

Hi Patricio,

I am a PhD student of Monika Lendl and I work my work I use Monikas photometric routine CONAN that uses MC3. When I started using it in my Mac (previously in UBUNTU) I keep having the following error:

    RuntimeError: 
    An attempt has been made to start a new process before the
    current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

The error originates fro the multiprocessing package that MC3 uses. Do you know how I can solve this issue?
Thank you very much in advance!

Best,
Angelica

@pcubillos
Copy link
Owner

Hi Angelica,
Hmm, I've never seen this before. I'll look around. Could you paste the entire error log, please?
Also, could you tell me which python version are you using?

@angelicaps
Copy link
Author

Hi Patricio,

Thank you for that quick response!
I am using Python 3.8.5 .


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  Multi-core Markov-chain Monte Carlo (MC3).
  Version 3.0.5.
  Copyright (c) 2015-2021 Patricio Cubillos and collaborators.
  MC3 is open-source software under the MIT license (see LICENSE).
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Yippee Ki Yay Monte Carlo!
Start MCMC chains  (Thu Jan 28 17:16:42 2021)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/spawn.py", line 125, in _main
    prepare(preparation_data)
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/runpy.py", line 265, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/angelicapsaridi/Documents/Geneva/CONAN/WASP-19/conan/conan_v26_BATMAN.py", line 762, in <module>
    mc3_output = mc3.sample(data=farr, uncert=earr, func=func, params=newparams, indparams=indparams,
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/site-packages/mc3/utils/utils.py", line 31, in new_func
    return func(*args, **kwargs)
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/site-packages/mc3/sampler_driver.py", line 453, in sample
    output = mcmc(data, uncert, func, params, indparams, pmin, pmax, pstep,
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/site-packages/mc3/mcmc_driver.py", line 252, in mcmc
    chain.start()
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "/Users/angelicapsaridi/anaconda3/lib/python3.8/multiprocessing/spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.


@pcubillos
Copy link
Owner

Hi Angelica,
It seems that the issue some change in the multiprocessing implementation in Python3.8 for OS X. I tested a few things using python3.8 (OS X on 3.6 was fine) and got a different error, but also related to multiprocessing. Similar to this one:
pymc-devs/pymc#3844

Their solution was to use dill for serialization. I will take a look at that, but it might take me a few days to see if it works and then to test everything.

@angelicaps
Copy link
Author

Hi Patricio,

I downgraded to 3.6 and everything works fine now so no need to worry about it and spend time on it. Thank you very much for your help!

@pcubillos
Copy link
Owner

Hi @angelicaps
OK, I found a fix to get the code working on OSX with Python 3.6 to 3.9, in case you need it in the future. Thanks for raising this issue!

@angelicaps
Copy link
Author

angelicaps commented Oct 27, 2021 via email

@pcubillos
Copy link
Owner

Here,
d4c7581#diff-05fa61dd812d17e9ed003c5a0984fb734557085a79ee4f7e2713591ca1e39779

The change was to enforce using 'fork' as the multiprocessing starting method instead of 'spawn' (OSX's default since Python 3.8).

Are you still seeing the same issue from before?
Could you double-check that you are now using vesion >= 3.0.9? (typing mc3 --version)

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

2 participants