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

Building objects with unhashable parameters #1252

Open
hunse opened this issue Jan 3, 2017 · 0 comments
Open

Building objects with unhashable parameters #1252

hunse opened this issue Jan 3, 2017 · 0 comments

Comments

@hunse
Copy link
Collaborator

hunse commented Jan 3, 2017

I've encountered the error below. When building a model, one object in the model (a Node with a Conv2d process as output) could not be built due to the following error. Essentially, the object gets hashed to determine if it's in the builder's params, and because the Conv2d had non-contiguous filters in it, this failed.

My suggestion is to make params something that doesn't need to hash the objects, maybe our own WeakKeyIDDictionary. I'm not sure if this would have any adverse repercussions, but I can't think of any off the top of my head. It wouldn't work with pickling, since then things come back with different IDs, but I'm guessing that the builder doesn't work with pickling anyway.

/home/ehunsber/workspace/nengo/nengo/builder/builder.pyc in build(cls, model, obj, *args, **kwargs)
    202             The object to build into the model.
    203         """
--> 204         if model.has_built(obj):
    205             # TODO: Prevent this at pre-build validation time.
    206             warnings.warn("Object %s has already been built." % obj)

/home/ehunsber/workspace/nengo/nengo/builder/builder.pyc in has_built(self, obj)
    140             The object to query.
    141         """
--> 142         return obj in self.params
    143 
    144 

/home/ehunsber/workspace/nengo/nengo/params.pyc in __hash__(self)
    481     def __hash__(self):
    482         return hash((type(self), tuple(
--> 483             p.hashvalue(self) for p in self._params)))
    484 
    485     def __getstate__(self):

/home/ehunsber/workspace/nengo/nengo/params.pyc in <genexpr>((p,))
    481     def __hash__(self):
    482         return hash((type(self), tuple(
--> 483             p.hashvalue(self) for p in self._params)))
    484 
    485     def __getstate__(self):

/home/ehunsber/workspace/nengo/nengo/params.pyc in hashvalue(self, instance)
    360 
    361     def hashvalue(self, instance):
--> 362         return array_hash(self.__get__(instance, None))
    363 
    364     def validate(self, instance, ndarray):  # noqa: C901

/home/ehunsber/workspace/nengo/nengo/utils/numpy.pyc in array_hash(a, n)
     72         v = a.view()
     73         v.setflags(write=False)
---> 74         return hash(v.data if PY2 else v.data.tobytes())
     75     else:
     76         # pick random elements to hash

AttributeError: cannot get single-segment buffer for discontiguous array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant