PyNN icon indicating copy to clipboard operation
PyNN copied to clipboard

Setting array parameter for synapse

Open anandtrex opened this issue 7 years ago • 1 comments

I have a custom synapse model that takes in an array as one of its parameters (the same array for all the parameters). Is it possible to set this using PyNN? Trying to set this naively produces an assertion error from lazyarray:

~/source/PyNN-0.9.1/pyNN/models.py in __init__(self, **parameters)
    106         self.parameter_space = ParameterSpace(all_parameters,
    107                                               self.get_schema(),
--> 108                                               shape=None)

~/source/PyNN-0.9.1/pyNN/parameters.py in __init__(self, parameters, schema, shape, component)
    237         self._shape = shape
    238         self.component = component
--> 239         self.update(**parameters)
    240         self._evaluated = False
    241 

~/source/PyNN-0.9.1/pyNN/parameters.py in update(self, **parameters)
    306                     # print("B3M", expected_dtype)
    307                     self._parameters[name] = LazyArray(value, shape=self._shape,
--> 308                                                        dtype=expected_dtype)
    309                 except (TypeError, errors.InvalidParameterValueError):
    310                     raise errors.InvalidParameterValueError("For parameter %s expected %s, got %s" % (name, expected_dtype, type(value)))

~/source/PyNN-0.9.1/pyNN/parameters.py in __init__(self, value, shape, dtype)
     61                 raise errors.InvalidParameterValueError(errmsg + str(err))
     62         # print("B4M", value, shape, dtype)
---> 63         super(LazyArray, self).__init__(value, shape, dtype)
     64 
     65     def __setitem__(self, addr, new_value):

~/.local/lib/python3.5/site-packages/lazyarray.py in __init__(self, value, shape, dtype)
    179                 value = numpy.array(value, dtype=dtype)
    180             elif dtype is not None:
--> 181                 assert value.dtype == dtype  # or could convert value to the provided dtype
    182             if shape and value.shape != shape:
    183                 raise ValueError("Array has shape %s, value has shape %s" % (shape, value.shape))

The code that produces this resembles this:

stdp = native_synapse_type("my_synapse_model")(**dict(
            array_parameter=np.arange(1,10, 1.),
        ))

anandtrex avatar Sep 26 '17 18:09 anandtrex

PyNN now has an ArrayParameter class, which I think should solve the problem.

apdavison avatar Apr 07 '19 14:04 apdavison