hyperopt icon indicating copy to clipboard operation
hyperopt copied to clipboard

AttributeError when calling fmin with trials.

Open jakepopham opened this issue 9 years ago • 14 comments

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'

jakepopham avatar Aug 01 '15 19:08 jakepopham

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....)

renewang avatar Aug 06 '15 07:08 renewang

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!

duthchao avatar Aug 18 '15 12:08 duthchao

I tried both of these approaches, however the error is still the same. Any solution for this

AttributeError: 'function' object has no attribute 'fmin'

joshij1979 avatar Aug 27 '15 20:08 joshij1979

In package base.py line 625 write fmin_module() instead of fmin_module.fmin(). It solved this issue for me.

ghost avatar Sep 22 '15 07:09 ghost

got the same error. ghost's solution works. thanks!

yitang avatar Nov 21 '15 21:11 yitang

@ghost solution works for me as well.

itdxer avatar Jan 26 '16 11:01 itdxer

Still unfixed in the master branch :S

antoniomo avatar Feb 18 '16 13:02 antoniomo

I think base.py is still not changed in the 0.03dev version.

sjhddh avatar Apr 04 '16 15:04 sjhddh

I've got the same bug and fixed it via the ghost solution

amdouni avatar Apr 11 '16 11:04 amdouni

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?

mjwillson avatar Aug 19 '16 15:08 mjwillson

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 avatar Nov 01 '16 01:11 mancap314

@mancap314 did you resolve the issue?

Henrilin28 avatar Oct 17 '19 15:10 Henrilin28

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

ghost avatar Oct 22 '19 15:10 ghost

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

Frag17 avatar Feb 23 '21 12:02 Frag17