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

AttributeError when calling fmin with trials. #234

Open
stratejake opened this issue Aug 1, 2015 · 14 comments
Open

AttributeError when calling fmin with trials. #234

stratejake opened this issue Aug 1, 2015 · 14 comments

Comments

@stratejake
Copy link

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'
@renewang
Copy link

renewang commented Aug 6, 2015

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

@duthchao
Copy link

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!

@joshij1979
Copy link

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

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

@ghost
Copy link

ghost commented Sep 22, 2015

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

@yitang
Copy link

yitang commented Nov 21, 2015

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

@itdxer
Copy link

itdxer commented Jan 26, 2016

@ghost solution works for me as well.

@antoniomo
Copy link

Still unfixed in the master branch :S

@sjhddh
Copy link

sjhddh commented Apr 4, 2016

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

@amdouni
Copy link

amdouni commented Apr 11, 2016

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

Laurae2 added a commit to Laurae2/hyperopt that referenced this issue Apr 16, 2016
@mjwillson
Copy link

mjwillson commented Aug 19, 2016

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?

lefant added a commit to lefant/hyperopt that referenced this issue Sep 8, 2016
wenyangfu added a commit to wenyangfu/hyperopt that referenced this issue Oct 26, 2016
@mancap314
Copy link

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

@Henrilin28
Copy link

@mancap314 did you resolve the issue?

@ghost
Copy link

ghost commented Oct 22, 2019

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

@Frag17
Copy link

Frag17 commented Feb 23, 2021

I've fixed this issue by uninstall bson.
This seems similar to yoavoexp's answer.
The issue below may help you.
#547

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