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

TypeError: 'generator' object is not subscriptable #125

Closed
brunoklein99 opened this issue Oct 21, 2017 · 6 comments
Closed

TypeError: 'generator' object is not subscriptable #125

brunoklein99 opened this issue Oct 21, 2017 · 6 comments

Comments

@brunoklein99
Copy link

from hyperas import optim
from hyperopt import Trials, tpe


def data():
    return 1, 2, 3, 4


def model(a, b, c, d):
    pass


if __name__ == "__main__":

    trials = Trials()
    bla = optim.minimize(model=model, data=data, algo=tpe.suggest,
                         max_evals=5,
                         trials=trials)

C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\python.exe G:/Source/untitled4/main.py
Using TensorFlow backend.
Traceback (most recent call last):
>>> Imports:
  File "G:/Source/untitled4/main.py", line 18, in <module>
#coding=utf-8
    trials=trials)

try:
    from hyperas import optim
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperas\optim.py", line 67, in minimize
except:
    pass
    verbose=verbose)

  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperas\optim.py", line 133, in base_minimizer
try:
    return_argmin=True),
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\fmin.py", line 307, in fmin
    from hyperopt import Trials, tpe
    return_argmin=return_argmin,
except:
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\base.py", line 635, in fmin
    pass

    return_argmin=return_argmin)
>>> Hyperas search space:

def get_space():
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\fmin.py", line 314, in fmin
    return {
    }
    pass_expr_memo_ctrl=pass_expr_memo_ctrl)

  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\base.py", line 786, in __init__
>>> Data
    pyll.toposort(self.expr)
1: 
2: 
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\pyll\base.py", line 715, in toposort
3: 
4: 
    assert order[-1] == expr
>>> Resulting replaced keras model:
TypeError: 'generator' object is not subscriptable

 1: def keras_fmin_fnct(space):
 2: 
 3:     pass
 4: 

Process finished with exit code 1

Windows
Python 3.5.2

@peachyDinosaur
Copy link

try
pip3 install networkx==1.11

I would only do this in virtual env as the current networkx version is 2.0

Doc here:
https://networkx.github.io/

@ghost
Copy link

ghost commented Nov 15, 2017

Hi @maxpumperla
As you might know, it's the temporary solution. Do you have any idea to update Hyperopt to be compatible with this version of netwrokx? As I know you have the full access to modify the hyperopt repo. :)

@flexthink
Copy link

flexthink commented Jan 13, 2018

Not only is this a temporary solution, but it also happens to be one that only works on Python 2.x. The set-up script for networkx 1.1 has a print statement!

(tensorflow) Epictetus:notebooks artem$ pip3 install networkx==1.1
Collecting networkx==1.1
  Downloading networkx-1.1.zip (813kB)
    100% |████████████████████████████████| 819kB 982kB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/38/w_gkw9l57ysgm1whbwngyf3w0000gn/T/pip-build-84uqyau_/networkx/setup.py", line 18
        print "To install, run 'python setup.py install'"
\

@jhmenke
Copy link

jhmenke commented Jun 7, 2018

Networkx 2.0 uses generators instead of lists.
Just change line 714 in pyll/base.py to:
order = list(nx.topological_sort(G))

@CoderCoderCoder
Copy link

CoderCoderCoder commented Aug 11, 2018

@jhmenke
Thanks for the hint, but it results in the following error afterwards:

File "\hyperopt\pyll\base.py", line 320, in arg
fn = scope._impls[self.name]

KeyError: 'hyperopt_param'

Any ideas how to solve it?.. Thanks!
EDIT: btw, even with networkx==1.11 the sample code doesn't work, I just get another error message (this time from networkx).

@jhmenke
Copy link

jhmenke commented Aug 12, 2018

that's an unrelated issue then. you should open a new issue with reproduceable code so people can help.

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

6 participants