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

Threads close on AttributeError when run in ipython #17

Open
nightvision04 opened this issue Dec 9, 2020 · 4 comments
Open

Threads close on AttributeError when run in ipython #17

nightvision04 opened this issue Dec 9, 2020 · 4 comments

Comments

@nightvision04
Copy link

nightvision04 commented Dec 9, 2020

In jupyter notebook, I can run the following without issue:

estimator = KNeighborsClassifier(n_neighbors=16)
selector = GeneticSelectionCV(estimator,
                                  cv=10,
                                  verbose=1,
                                  scoring="accuracy",
                                  max_features=3,
                                  n_population=1000,
                                  crossover_proba=0.5,
                                  mutation_proba=0.2,
                                  n_generations=40,
                                  crossover_independent_proba=0.5,
                                  mutation_independent_proba=0.05,
                                  tournament_size=3,
                                  n_gen_no_change=10,
                                  caching=True,
                                  n_jobs=4)
selector = selector.fit(X, y)

However, as soon as I run it for a second time in the same ipython cell, all of the deap threads raise an exception. I've included the stack trace below.

Essentially, the above code can't run in a loop in ipython. Are there some threads which are not properly closed due to the interaction between GIL and ipython?

AttributeError: Can't get attribute 'FitnessMulti' on <module 'deap.creator' from 'D:\\anaconda\\envs\\a\\lib\\site-packages\\deap\\creator.py'>
AttributeError: Can't get attribute 'FitnessMulti' on <module 'deap.creator' from 'D:\\anaconda\\envs\\a\\lib\\site-packages\\deap\\creator.py'>
Process SpawnPoolWorker-58:
Traceback (most recent call last):
  File "D:\anaconda\envs\a\lib\multiprocessing\process.py", line 297, in _bootstrap
    self.run()
  File "D:\anaconda\envs\a\lib\multiprocessing\process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "D:\anaconda\envs\a\lib\multiprocessing\pool.py", line 110, in worker
    task = get()
  File "D:\anaconda\envs\a\lib\multiprocessing\queues.py", line 354, in get
    return _ForkingPickler.loads(res)
AttributeError: Can't get attribute 'FitnessMulti' on <module 'deap.creator' from 'D:\\anaconda\\envs\\a\\lib\\site-packages\\deap\\creator.py'>
Process SpawnPoolWorker-60:
Traceback (most recent call last):
  File "D:\anaconda\envs\a\lib\multiprocessing\process.py", line 297, in _bootstrap
    self.run()
  File "D:\anaconda\envs\a\lib\multiprocessing\process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "D:\anaconda\envs\a\lib\multiprocessing\pool.py", line 110, in worker
    task = get()
  File "D:\anaconda\envs\a\lib\multiprocessing\queues.py", line 354, in get
    return _ForkingPickler.loads(res)
AttributeError: Can't get attribute 'FitnessMulti' on <module 'deap.creator' from 'D:\\anaconda\\envs\\a\\lib\\site-packages\\deap\\creator.py'>
@manuel-calzolari
Copy link
Owner

What versions of Python and sklearn-genetic are you using?

@nightvision04
Copy link
Author

nightvision04 commented Dec 12, 2020 via email

@manuel-calzolari
Copy link
Owner

I think it may be related to DEAP's issue #268, but I'm not able to reproduce your specific issue.

I created the following Windows 10 based environment:

  • Python 3.6.12
  • IPython 7.16.1
  • notebook 6.1.4
  • deap 1.3.1
  • sklearn-genetic 0.3.0

Cell 1:

import numpy as np
from sklearn import datasets
from sklearn.neighbors import KNeighborsClassifier
from genetic_selection import GeneticSelectionCV

iris = datasets.load_iris()
E = np.random.uniform(0, 0.1, size=(len(iris.data), 20))
X = np.hstack((iris.data, E))
y = iris.target

Cell 2:

estimator = KNeighborsClassifier(n_neighbors=16)
selector = GeneticSelectionCV(estimator,
                                  cv=10,
                                  verbose=1,
                                  scoring="accuracy",
                                  max_features=3,
                                  n_population=1000,
                                  crossover_proba=0.5,
                                  mutation_proba=0.2,
                                  n_generations=40,
                                  crossover_independent_proba=0.5,
                                  mutation_independent_proba=0.05,
                                  tournament_size=3,
                                  n_gen_no_change=10,
                                  caching=True,
                                  n_jobs=4)
selector = selector.fit(X, y)

However, I don't get any crash when I run the second cell multiple times.

@nightvision04
Copy link
Author

nightvision04 commented Dec 12, 2020 via email

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