NeuralEnsemble / PyNN

A Python package for simulator-independent specification of neuronal network models.
Other
276 stars 126 forks source link

List with homogeneous array-like parameter entries only work for the corresponding default parameter type #709

Open AvidusMauch opened 3 years ago

AvidusMauch commented 3 years ago

Lists of array-like parameters, e.g. spike_times in SpikeSourceArray, with homogeneous entries will be simplified and converted to ArrayParameter if they are not the same type as the corresponding default type (Sequence for spike_times).

Minimal example:

#!/usr/bin/env python

import pyNN.mock as sim
import numpy
from pyNN.parameters import Sequence

sim.setup()

spike_times = [1, 2, 3]
spike_sequence = [Sequence(spike_times)] * 2
spike_numpy = [numpy.array(spike_times)] * 2
spike_plain = [spike_times] * 2
pop_sequence = sim.Population(2, sim.SpikeSourceArray(spike_times=spike_sequence))
pop_numpy = sim.Population(2, sim.SpikeSourceArray(spike_times=spike_numpy))
pop_plain = sim.Population(2, sim.SpikeSourceArray(spike_times=spike_plain))

# works
pop_sequence.get("spike_times")
# fails
pop_numpy.get("spike_times")
pop_plain.get("spike_times")

sim.end()
AvidusMauch commented 3 years ago

This can be workaroundend by changing the default type from Seqeuence to ArrayParameter

apdavison commented 2 years ago

I may be misunderstanding what the problem is, but the problem you're describing is why the Sequence class was introduced - to avoid confusion over how to interpret arrays/lists of arrays.

Although for simple cases, plain NumPy arrays or lists do work for setting spike times, it is safest to always use Sequence.