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

Full support for numpy arrays and lists in Connect #1523

Closed
Silmathoron opened this issue Apr 20, 2020 · 2 comments · Fixed by #1539
Closed

Full support for numpy arrays and lists in Connect #1523

Silmathoron opened this issue Apr 20, 2020 · 2 comments · Fixed by #1539
Assignees
Labels
I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) S: Normal Handle this with default priority T: Enhancement New functionality, model or documentation

Comments

@Silmathoron
Copy link
Member

Following a discussion in #1429, I am adding an issue here regarding the support of lists and arrays in Connect.

Is your feature request related to a problem? Please describe.
Currently, many forms of Connect are not supported, or require superfluous arguments:

  • list objects are not supported
  • using numpy arrays require both inputs to be numpy arrays and the syn_spec argument
import nest
import numpy as np

# create neurons and devices
neuron = nest.Create("iaf_psc_alpha", 10)

vm = nest.Create("voltmeter", 10)

# set weights
weights = np.ones(len(neuron))
delays = np.ones(len(neuron))

# numpy version
arr_vm  = np.array(vm.tolist(), dtype=int)
arr_nrn = np.array(neuron.tolist(), dtype=int)

# works
nest.Connect(arr_vm, arr_nrn, syn_spec={'weight': weights, 'delay': delays, 'synapse_model': 'static_synapse'})

# does not work (but should)
nest.Connect(arr_vm, neuron.tolist(), syn_spec={'weight': weights, 'delay': delays, 'synapse_model': 'static_synapse'})
nest.Connect(vm.tolist(), neuron.tolist(), syn_spec={'weight': weights, 'delay': delays, 'synapse_model': 'static_synapse'})

nest.Connect(arr_vm, arr_nrn)
nest.Connect(arr_vm, neuron, syn_spec={'weight': weights, 'delay': delays, 'synapse_model': 'static_synapse'})
nest.Connect(arr_vm, neuron)
nest.Connect(vm.tolist(), neuron)

Describe the solution you'd like
All examples shown above should be accepted.

Describe alternatives you've considered
We are currently already checking the type of the input in Connect, thus, the solution to automatically convert to NodeCollection if the ids are unique would only require a very minor overhead and no additional code complexity (just a check_input_nodes function that would replace the current test).
I am not sure why syn_spec is currently required, but, to me, when input nodes are not unique, we should be able to switch to the "data connect" without any additional argument...

@stinebuu
Copy link
Contributor

@Silmathoron This is very interesting. Is the reason for

nest.Connect(vm.tolist(), neuron.tolist(), syn_spec={'weight': weights, 'delay': delays, 'synapse_model': 'static_synapse'})

that you want lists to be supported? Because or else you can just use the NodeCollections.

@Silmathoron
Copy link
Member Author

Yes, of course, sorry for the potentially confusing syntax.
All examples are just to show whether the type/combination of types is accepted, so I used .tolist() for simplicity.

@heplesser heplesser added I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) S: Normal Handle this with default priority T: Enhancement New functionality, model or documentation labels Apr 22, 2020
@jessica-mitchell jessica-mitchell moved this to Done in Kernel Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) S: Normal Handle this with default priority T: Enhancement New functionality, model or documentation
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants