CaltechExperimentalGravity / CaltechExperimentalGravity/OptimalBragg

Error running example on MacOS

Open
#13 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

I got this error running the second example ("Optimize an existing anti-reflective (AR) coating") in the readme:

```
File "/Users/sean.leavey/work/wip/2024-04-optimal-bragg/tmp.py", line 49, in
optimization_result = diff_evo(stack, multi_target)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/site-packages/OptimalBragg/optimizer.py", line 53, in diff_evo
opt_res = devopt(
^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/site-packages/scipy/optimize/_differentialevolution.py", line 487, in differential_evolution
with DifferentialEvolutionSolver(func, bounds, args=args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/site-packages/scipy/optimize/_differentialevolution.py", line 800, in __init__
self._mapwrapper = MapWrapper(workers)
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/site-packages/scipy/_lib/_util.py", line 473, in __init__
self.pool = Pool()
^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/context.py", line 119, in Pool
return Pool(processes, initializer, initargs, maxtasksperchild,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/pool.py", line 215, in __init__
self._repopulate_pool()
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/pool.py", line 306, in _repopulate_pool
return self._repopulate_pool_static(self._ctx, self.Process,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/pool.py", line 329, in _repopulate_pool_static
w.start()
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/context.py", line 289, in _Popen
return Popen(process_obj)
^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/popen_spawn_posix.py", line 32, in __init__
super().__init__(process_obj)
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/popen_spawn_posix.py", line 42, in _launch
prep_data = spawn.get_preparation_data(process_obj._name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/spawn.py", line 164, in get_preparation_data
_check_not_importing_main()
File "/opt/homebrew/Caskroom/miniforge/base/envs/optimalbragg/lib/python3.12/multiprocessing/spawn.py", line 140, 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.

To fix this issue, refer to the "Safe importing of main module"
section in https://docs.python.org/3/library/multiprocessing.html
```

I think forking in multiprocessing is tricky on MacOS.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.