Multiprocessing-related issue
chclam opened this issue · 2 comments
chclam commented
After applying fix #148 on a local copy of GAMA
I get a multiprocessing-related error when running it on some OpenML
data sets. I tried running the following code:
import openml
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from gama import GamaClassifier
dataset = openml.datasets.get_dataset(10)
X, y, categorical_indicator, attribute_names = dataset.get_data(
target=dataset.default_target_attribute, dataset_format="dataframe"
)
y = LabelEncoder().fit_transform(y)
X_train , X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
automl = GamaClassifier(max_total_time=180, store="nothing")
print("GAMA is fitting.")
automl.fit(X_train, y_train)
And this is the error I get, for multiple OpenML
data sets.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 125, in _main
prepare(preparation_data)
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/chris/Documents/graduation-project/issues/gama/test.py", line 17, in <module>
automl.fit(X_train, y_train)
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/GamaClassifier.py", line 134, in fit
super().fit(x, y, *args, **kwargs)
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/gama.py", line 523, in fit
self._search_phase(warm_start, timeout=fit_time)
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/gama.py", line 581, in _search_phase
self._search_method.search(self._operator_set, start_candidates=pop)
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/search_methods/async_ea.py", line 66, in search
self.output = async_ea(
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/search_methods/async_ea.py", line 112, in async_ea
with AsyncEvaluator() as async_:
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/utilities/generic/async_evaluator.py", line 108, in __init__
self._queue_manager = multiprocessing.Manager()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 57, in Manager
m.start()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/managers.py", line 554, in start
self._process.start()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
return Popen(process_obj)
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
super().__init__(process_obj)
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 42, in _launch
prep_data = spawn.get_preparation_data(process_obj._name)
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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.
Traceback (most recent call last):
File "/Users/chris/Documents/graduation-project/issues/gama/./test.py", line 17, in <module>
automl.fit(X_train, y_train)
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/GamaClassifier.py", line 134, in fit
super().fit(x, y, *args, **kwargs)
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/gama.py", line 523, in fit
self._search_phase(warm_start, timeout=fit_time)
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/gama.py", line 581, in _search_phase
self._search_method.search(self._operator_set, start_candidates=pop)
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/search_methods/async_ea.py", line 66, in search
self.output = async_ea(
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/search_methods/async_ea.py", line 112, in async_ea
with AsyncEvaluator() as async_:
File "/Users/chris/Documents/graduation-project/issues/gama/env/lib/python3.9/site-packages/gama/utilities/generic/async_evaluator.py", line 108, in __init__
self._queue_manager = multiprocessing.Manager()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 57, in Manager
m.start()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/managers.py", line 558, in start
self._address = reader.recv()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/connection.py", line 255, in recv
buf = self._recv_bytes()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/connection.py", line 419, in _recv_bytes
buf = self._recv(4)
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/connection.py", line 388, in _recv
raise EOFError
EOFError
chclam commented
This problem can easily be fixed by putting the code under if __name__ == "__main__":
. My bad!
PGijsbers commented
No problem :) it's not related to the change, it's a python multiprocessing on Windows thing