hyperopt
hyperopt copied to clipboard
AttributeError when calling fmin with trials.
I get the following error when calling fmin. It only occurs when I specify a trials object, otherwise it runs just fine. I'm on ubuntu 14.04 using python 3.4.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-1eb552add6c6> in <module>()
----> 1 optimize(trials)
<ipython-input-11-de171de4b3a2> in optimize(trials)
14
15 best = fmin(boost, space, tpe.suggest, max_evals = 5,
---> 16 trials=trials)
17 return best
/opt/anaconda/lib/python3.4/site-packages/hyperopt/fmin.py in fmin(fn, space, algo, max_evals, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin)
304 verbose=verbose,
305 catch_eval_exceptions=catch_eval_exceptions,
--> 306 return_argmin=return_argmin,
307 )
308
/opt/anaconda/lib/python3.4/site-packages/hyperopt/base.py in fmin(self, fn, space, algo, max_evals, rstate, verbose, pass_expr_memo_ctrl, catch_eval_exceptions, return_argmin)
623 # but for now it's still sitting in another file.
624 from . import fmin as fmin_module
--> 625 return fmin_module.fmin(
626 fn, space, algo, max_evals,
627 trials=self,
AttributeError: 'function' object has no attribute 'fmin'
in package init.py line 20
from .fmin import fmin
might introduce name shadow and see fmin as function object instead of module
A quick and dirty fix,
I commented out all import statements in init.py and only left version statement, I don't have this problem so far (but might have other problems....)
in package base.py line 624 and 625,I just modified it as follows: 624: from . import fmin as fmin_module ---> from . import fmin as fmin_function 625: return fmin_module.fmin( ---> return fmin_function( this may fix you problem!
I tried both of these approaches, however the error is still the same. Any solution for this
AttributeError: 'function' object has no attribute 'fmin'
In package base.py line 625 write fmin_module() instead of fmin_module.fmin(). It solved this issue for me.
got the same error. ghost's solution works. thanks!
@ghost solution works for me as well.
Still unfixed in the master branch :S
I think base.py is still not changed in the 0.03dev version.
I've got the same bug and fixed it via the ghost solution
I think this may differ between python3 and python2, the fix that was committed broke it for one, then reverting it broke the other again.
The problem is that the fmin function is imported into the hyperopt package namespace, but there's also an fmin module underneath that package. (The from .fmin import fmin
in hyperopt/__init__.py
)
Under python3 this seems to fix it for me, and is less ambiguous:
from .fmin import fmin
return fmin(
Not able to check it easily under python2 right now but perhaps someone else could check?
I used ghost's solution, now I get:
File "/home/manuel/hyperopt/build/lib/hyperopt/base.py", line 388, in assert_valid_trial bson.BSON.encode(trial) AttributeError: module 'bson' has no attribute 'BSON'
According to the api, the module bson do have ab Attribute BSON, so I'm a little bit confused. Any idea how to fix it? Thanks
@mancap314 did you resolve the issue?
I've added the following code and it works, BUT I don't know the side effects of this.
from hyperopt import base
base.have_bson = False
I've fixed this issue by uninstall bson. This seems similar to yoavoexp's answer. The issue below may help you. https://github.com/hyperopt/hyperopt/issues/547