Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Breaks with networkx v2. setup.py requirement needs adjustment #333

Description

@marcj

networkx v2 has been released recently, which broke my code with hyperopt.

Test script

from hyperopt import hp, base, tpe, Trials, rand
import numpy as np
import json

space = {
    "optimizer": hp.choice("optimizer", [
        {
            "$value": "sgd",
            "lr": 0.1,
            "momentum": 0.5
        },
        {
            "$value": "adadelta",
            "lr": 1
        }
    ])
}
suggestions = []

for i in range(0, 1):
    trials = Trials()
    seed = np.random.RandomState().randint(2 ** 31 - 1)
    domain = base.Domain(None, space)
    new_ids = [len(trials._dynamic_trials) + 1]
    new_trials = rand.suggest(new_ids, domain, trials, seed)
    suggestions.append(new_trials[0]['misc']['vals'])

print(json.dumps(suggestions))

Error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from hyperopt import hp, base, tpe, Trials, rand
  File "/usr/lib/python2.7/site-packages/hyperopt/__init__.py", line 21, in <module>
    from .fmin import fmin
  File "/usr/lib/python2.7/site-packages/hyperopt/fmin.py", line 20, in <module>
    standard_library.install_aliases()
  File "/usr/lib/python2.7/site-packages/future/standard_library/__init__.py", line 483, in install_aliases
    import test
  File "/app/aetros-trainer/test.py", line 26, in <module>
    domain = base.Domain(None, space)
  File "/usr/lib/python2.7/site-packages/hyperopt/base.py", line 786, in __init__
    pyll.toposort(self.expr)
  File "/usr/lib/python2.7/site-packages/hyperopt/pyll/base.py", line 717, in toposort
    assert order[-1] == expr
TypeError: 'generator' object has no attribute '__getitem__'

Error is that in hyperopt/pyll/base.py+714: nx.topological_sort(G) returns a generator without __getitem__ method since version 2, but the assert line below requires that.

When I install networkx:1.11 everything works fine.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions