scikit-optimize / scikit-optimize

Sequential model-based optimization with a `scipy.optimize` interface
https://scikit-optimize.github.io
BSD 3-Clause "New" or "Revised" License
2.74k stars 546 forks source link

AttributeError: module 'skopt.callbacks' has no attribute 'CheckpointSaver' (dumping/loading results object) #678

Closed jolespin closed 6 years ago

jolespin commented 6 years ago

Am I loading this incorrectly? It dumped without error but I'm not able to retrieve the results.

skopt.__version__
'0.5.2'
# Optimization
n_calls = 1000
kappa = 5.0
delta = 0.001
name = "forest.clustering"
callbacks = [skopt.callbacks.VerboseCallback(n_total=n_calls),
 skopt.callbacks.CheckpointSaver(f"./bayesian_optimization/{name}.result.pkl"),
 skopt.callbacks.DeltaYStopper(n_best=200, delta=delta)
 ]
res = skopt.forest_minimize(objective, dimensions=dimensions, random_state=random_state, 
n_calls=n_calls, n_jobs=n_jobs, callback=callbacks, acq_func="LCB", kappa=kappa)

# Dumped results
skopt.dump(res, f"./bayesian_optimization/{name}.res.pkl.gz")

# Loaded results 
res = skopt.load("./Data/Models/Bayesian_Clustering/forest.clustering.res.pkl.gz")

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<timed exec> in <module>()

~/anaconda/envs/python3/lib/python3.6/site-packages/skopt/utils.py in load(filename, **kwargs)
    170         Reconstructed OptimizeResult instance.
    171     """
--> 172     return load_(filename, **kwargs)
    173 
    174 

~/anaconda/envs/python3/lib/python3.6/site-packages/sklearn/externals/joblib/numpy_pickle.py in load(filename, mmap_mode)
    576                     return load_compatibility(fobj)
    577 
--> 578                 obj = _unpickle(fobj, filename, mmap_mode)
    579 
    580     return obj

~/anaconda/envs/python3/lib/python3.6/site-packages/sklearn/externals/joblib/numpy_pickle.py in _unpickle(fobj, filename, mmap_mode)
    506     obj = None
    507     try:
--> 508         obj = unpickler.load()
    509         if unpickler.compat_mode:
    510             warnings.warn("The file '%s' has been generated with a "

~/anaconda/envs/python3/lib/python3.6/pickle.py in load(self)
   1048                     raise EOFError
   1049                 assert isinstance(key, bytes_types)
-> 1050                 dispatch[key[0]](self)
   1051         except _Stop as stopinst:
   1052             return stopinst.value

~/anaconda/envs/python3/lib/python3.6/pickle.py in load_global(self)
   1336         module = self.readline()[:-1].decode("utf-8")
   1337         name = self.readline()[:-1].decode("utf-8")
-> 1338         klass = self.find_class(module, name)
   1339         self.append(klass)
   1340     dispatch[GLOBAL[0]] = load_global

~/anaconda/envs/python3/lib/python3.6/pickle.py in find_class(self, module, name)
   1390             return _getattribute(sys.modules[module], name)[0]
   1391         else:
-> 1392             return getattr(sys.modules[module], name)
   1393 
   1394     def load_reduce(self):

AttributeError: module 'skopt.callbacks' has no attribute 'CheckpointSaver'
jolespin commented 6 years ago
pip uninstall scikit-optimize
pip install git+https://github.com/scikit-optimize/scikit-optimize/

This solved my problem. There must have been a non-fatal error during installation that I didn't catch.

MonkeyDNoppu commented 6 years ago

What's solution in conda ??

jolespin commented 6 years ago

I use conda so all of that is in a virtual environment. I don’t think there is a conda packed version anyways. You can use both pip and conda .

MonkeyDNoppu commented 6 years ago

I mean I would not like to use pip to solve this problem while I use only conda, so I prefer need some conda command to help to fix this problem.

Anyway, I fixed it already by just downloading zip from git, unzip it, then copy only skopt folder replace anaconda3/lib/python3.6/site-packages/skopt (which is from conda install -c conda-forge scikit-optimize)

jolespin commented 6 years ago

Nice. Good to know! I might need to use something like that in the future.

the21st commented 6 years ago

I am seeing the same issue. I think this should be re-opened as using a standard pip install scikit-optimize should work.

ghostandthemachine commented 6 years ago

Also seeing this in pipenv and agree a standard install would ideally be supported.

janosh commented 5 years ago

@jolespin There was definitely no error during my installation. I tried with both conda and pip. In both cases the reported version was 0.5.2 and in both cases I got the error

AttributeError: module 'skopt.callbacks' has no attribute 'CheckpointSaver'

Installing directly from GitHub solved the problem. How come this is still an issue nearly a year later?

jolespin commented 5 years ago

Did you try this installation?

pip install git+https://github.com/scikit-optimize/scikit-optimize/

If not, try to completely remove it from your sitepackages and then try again. That's what worked for me.

janosh commented 5 years ago

@jolespin Yes, like I said installing directly from GitHub with which I meant pip install git+https://github.com/scikit-optimize/scikit-optimize solved the problem for me too. Thanks for that advice.