GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
pygenn.genn_model Namespace Reference

This module provides the GeNNModel class to simplify working with pygenn module and helper functions to derive custom model classes. More...

Classes

class  GeNNModel
 GeNNModel class This class helps to define, build and run a GeNN model from python. More...
 

Functions

def init_var (init_var_snippet, param_space)
 This helper function creates a VarInit object to easily initialise a variable using a snippet. More...
 
def init_connectivity (init_sparse_connect_snippet, param_space)
 This helper function creates a InitSparseConnectivitySnippet::Init object to easily initialise connectivity using a snippet. More...
 
def init_toeplitz_connectivity (init_toeplitz_connect_snippet, param_space)
 This helper function creates a InitToeplitzConnectivitySnippet::Init object to easily initialise connectivity using a snippet. More...
 
def create_var_ref (pop, var_name)
 This helper function creates a Models::VarReference pointing to a neuron or current source variable for initialising variable references. More...
 
def create_psm_var_ref (sg, var_name)
 This helper function creates a Models::VarReference pointing to a postsynaptic model variable for initialising variable references. More...
 
def create_wu_pre_var_ref (sg, var_name)
 This helper function creates a Models::VarReference pointing to a presynaptic weight update model variable for initialising variable references. More...
 
def create_wu_post_var_ref (sg, var_name)
 This helper function creates a Models::VarReference pointing to a postsynaptic weight update model variable for initialising variable references. More...
 
def create_wu_var_ref (g, var_name, tp_sg=None, tp_var_name=None)
 This helper function creates a Models::WUVarReference pointing to a weight update model variable for initialising variable references. More...
 
def create_egp_ref (pop, egp_name)
 This helper function creates a Models::EGPReference pointing to a neuron, current source or custom update extra global parameter for initialising references. More...
 
def create_psm_egp_ref (sg, egp_name)
 This helper function creates a Models::EGPReference pointing to a postsynaptic model extra global parameter for initialising references. More...
 
def create_wu_egp_ref (sg, egp_name)
 This helper function creates a Models::EGPReference pointing to a weight update model extra global parameter for initialising references. More...
 
def create_custom_neuron_class (class_name, param_names=None, var_name_types=None, derived_params=None, sim_code=None, threshold_condition_code=None, reset_code=None, support_code=None, extra_global_params=None, additional_input_vars=None, is_auto_refractory_required=None, custom_body=None)
 This helper function creates a custom NeuronModel class. More...
 
def create_custom_postsynaptic_class (class_name, param_names=None, var_name_types=None, derived_params=None, decay_code=None, apply_input_code=None, support_code=None, extra_global_params=None, custom_body=None)
 This helper function creates a custom PostsynapticModel class. More...
 
def create_custom_weight_update_class (class_name, param_names=None, var_name_types=None, pre_var_name_types=None, post_var_name_types=None, derived_params=None, sim_code=None, event_code=None, learn_post_code=None, synapse_dynamics_code=None, event_threshold_condition_code=None, pre_spike_code=None, post_spike_code=None, pre_dynamics_code=None, post_dynamics_code=None, sim_support_code=None, learn_post_support_code=None, synapse_dynamics_suppport_code=None, extra_global_params=None, is_pre_spike_time_required=None, is_post_spike_time_required=None, is_pre_spike_event_time_required=None, is_prev_pre_spike_time_required=None, is_prev_post_spike_time_required=None, is_prev_pre_spike_event_time_required=None, custom_body=None)
 This helper function creates a custom WeightUpdateModel class. More...
 
def create_custom_current_source_class (class_name, param_names=None, var_name_types=None, derived_params=None, injection_code=None, extra_global_params=None, custom_body=None)
 This helper function creates a custom NeuronModel class. More...
 
def create_custom_custom_update_class (class_name, param_names=None, var_name_types=None, derived_params=None, var_refs=None, update_code=None, extra_global_params=None, extra_global_param_refs=None, custom_body=None)
 This helper function creates a custom CustomUpdate class. More...
 
def create_custom_model_class (class_name, base, param_names, var_name_types, derived_params, extra_global_params, custom_body)
 This helper function completes a custom model class creation. More...
 
def create_dpf_class (dp_func)
 Helper function to create derived parameter function class. More...
 
def create_cmlf_class (cml_func)
 Helper function to create function class for calculating sizes of matrices initialised with sparse connectivity initialisation snippet. More...
 
def create_cksf_class (cks_func)
 Helper function to create function class for calculating sizes of kernels from connectivity initialiser parameters. More...
 
def create_custom_init_var_snippet_class (class_name, param_names=None, derived_params=None, var_init_code=None, extra_global_params=None, custom_body=None)
 This helper function creates a custom InitVarSnippet class. More...
 
def create_custom_sparse_connect_init_snippet_class (class_name, param_names=None, derived_params=None, row_build_code=None, row_build_state_vars=None, col_build_code=None, col_build_state_vars=None, calc_max_row_len_func=None, calc_max_col_len_func=None, calc_kernel_size_func=None, extra_global_params=None, custom_body=None)
 This helper function creates a custom InitSparseConnectivitySnippet class. More...
 
def create_custom_toeplitz_connect_init_snippet_class (class_name, param_names=None, derived_params=None, diagonal_build_code=None, diagonal_build_state_vars=None, calc_max_row_len_func=None, calc_kernel_size_func=None, extra_global_params=None, custom_body=None)
 This helper function creates a custom InitToeplitzConnectivitySnippet class. More...
 

Variables

 backend_modules = OrderedDict()
 
 m = import_module(".genn_wrapper." + b + "Backend", "pygenn")
 
 GeNNType = namedtuple("GeNNType", ["np_dtype", "assign_ext_ptr_array", "assign_ext_ptr_single"])
 

Detailed Description

This module provides the GeNNModel class to simplify working with pygenn module and helper functions to derive custom model classes.

GeNNModel should be used to configure a model, build, load and finally run it. Recording is done manually by pulling from the population of interest and then copying the values from Variable.view attribute. Each simulation step must be triggered manually by calling step_time function.

Examples

The following example shows in a (very) simplified manner how to build and
run a simulation using GeNNModel::
from pygenn.genn_model import GeNNModel
gm = GeNNModel("float", "test")
# add populations
neuron_pop = gm.add_neuron_population(_parameters_truncated_)
syn_pop = gm.add_synapse_population(_parameters_truncated_)
# build and load model
gm.build()
gm.load()
Vs = numpy.empty((simulation_length, population_size))
# Variable.view provides a view into a raw C array
# here a Variable call V (voltage) will be recorded
v_view = neuron_pop.vars["V"].view
# run a simulation for 1000 steps
for i in range 1000:
# manually trigger one simulation step
gm.step_time()
# when you pull state from device, views of all variables
# are updated and show current simulated values
neuron_pop.pull_state_from_device()
# finally, record voltage by copying form view into array.
Vs[i,:] = v_view

Function Documentation

◆ create_cksf_class()

def pygenn.genn_model.create_cksf_class (   cks_func)

Helper function to create function class for calculating sizes of kernels from connectivity initialiser parameters.

Parameters
cks_funca function which computes the kernel size and takes one arg "pars" (vector of double)

◆ create_cmlf_class()

def pygenn.genn_model.create_cmlf_class (   cml_func)

Helper function to create function class for calculating sizes of matrices initialised with sparse connectivity initialisation snippet.

Parameters
cml_funca function which computes the length and takes three args "num_pre" (unsigned int), "num_post" (unsigned int) and "pars" (vector of double)

◆ create_custom_current_source_class()

def pygenn.genn_model.create_custom_current_source_class (   class_name,
  param_names = None,
  var_name_types = None,
  derived_params = None,
  injection_code = None,
  extra_global_params = None,
  custom_body = None 
)

This helper function creates a custom NeuronModel class.

See also
create_custom_neuron_class
create_custom_weight_update_class
create_custom_current_source_class
create_custom_init_var_snippet_class
create_custom_sparse_connect_init_snippet_class
Parameters
class_namename of the new class
param_nameslist of strings with param names of the model
var_name_typeslist of pairs of strings with varible names and types of the model
derived_paramslist of pairs, where the first member is string with name of the derived parameter and the second should be a functor returned by create_dpf_class
injection_codestring with the current injection code
extra_global_paramslist of pairs of strings with names and types of additional parameters
custom_bodydictionary with additional attributes and methods of the new class

◆ create_custom_custom_update_class()

def pygenn.genn_model.create_custom_custom_update_class (   class_name,
  param_names = None,
  var_name_types = None,
  derived_params = None,
  var_refs = None,
  update_code = None,
  extra_global_params = None,
  extra_global_param_refs = None,
  custom_body = None 
)

This helper function creates a custom CustomUpdate class.

See also
create_custom_neuron_class
create_custom_weight_update_class
create_custom_current_source_class
create_custom_init_var_snippet_class
create_custom_sparse_connect_init_snippet_class
Parameters
class_namename of the new class
param_nameslist of strings with param names of the model
var_name_typeslist of tuples of strings with varible names and types of the variable
derived_paramslist of tuples, where the first member is string with name of the derived parameter and the second should be a functor returned by create_dpf_class
var_refslist of tuples of strings with varible names and types of variabled variable
update_codestring with the current injection code
extra_global_paramslist of pairs of strings with names and types of additional parameters
extra_global_param_refslist of pairs of strings with names and types of extra global parameter references
custom_bodydictionary with additional attributes and methods of the new class

◆ create_custom_init_var_snippet_class()

def pygenn.genn_model.create_custom_init_var_snippet_class (   class_name,
  param_names = None,
  derived_params = None,
  var_init_code = None,
  extra_global_params = None,
  custom_body = None 
)

This helper function creates a custom InitVarSnippet class.

See also
create_custom_neuron_class
create_custom_weight_update_class
create_custom_postsynaptic_class
create_custom_current_source_class
create_custom_sparse_connect_init_snippet_class
Parameters
class_namename of the new class
param_nameslist of strings with param names of the model
derived_paramslist of pairs, where the first member is string with name of the derived parameter and the second MUST be an instance of the pygenn.genn_wrapper.DerivedParamFunc class
var_init_codestring with the variable initialization code
extra_global_paramslist of pairs of strings with names and types of additional parameters
custom_bodydictionary with additional attributes and methods of the new class

◆ create_custom_model_class()

def pygenn.genn_model.create_custom_model_class (   class_name,
  base,
  param_names,
  var_name_types,
  derived_params,
  extra_global_params,
  custom_body 
)

This helper function completes a custom model class creation.

This part is common for all model classes and is nearly useless on its own unless you specify custom_body.

See also
create_custom_neuron_class
create_custom_weight_update_class
create_custom_postsynaptic_class
create_custom_current_source_class
create_custom_init_var_snippet_class
create_custom_sparse_connect_init_snippet_class
Parameters
class_namename of the new class
basebase class
param_nameslist of strings with param names of the model
var_name_typeslist of pairs of strings with varible names and types of the model
derived_paramslist of pairs, where the first member is string with name of the derived parameter and the second should be a functor returned by create_dpf_class
extra_global_paramslist of pairs of strings with names and types of additional parameters
custom_bodydictionary with attributes and methods of the new class

◆ create_custom_neuron_class()

def pygenn.genn_model.create_custom_neuron_class (   class_name,
  param_names = None,
  var_name_types = None,
  derived_params = None,
  sim_code = None,
  threshold_condition_code = None,
  reset_code = None,
  support_code = None,
  extra_global_params = None,
  additional_input_vars = None,
  is_auto_refractory_required = None,
  custom_body = None 
)

This helper function creates a custom NeuronModel class.

See also
create_custom_postsynaptic_class
create_custom_weight_update_class
create_custom_current_source_class
create_custom_init_var_snippet_class
create_custom_sparse_connect_init_snippet_class
Parameters
class_namename of the new class
param_nameslist of strings with param names of the model
var_name_typeslist of pairs of strings with varible names and types of the model
derived_paramslist of pairs, where the first member is string with name of the derived parameter and the second should be a functor returned by create_dpf_class
sim_codestring with the simulation code
threshold_condition_codestring with the threshold condition code
reset_codestring with the reset code
support_codestring with the support code
extra_global_paramslist of pairs of strings with names and types of additional parameters
additional_input_varslist of tuples with names and types as strings and initial values of additional local input variables
is_auto_refractory_requireddoes this model require auto-refractory logic to be generated?
custom_bodydictionary with additional attributes and methods of the new class

◆ create_custom_postsynaptic_class()

def pygenn.genn_model.create_custom_postsynaptic_class (   class_name,
  param_names = None,
  var_name_types = None,
  derived_params = None,
  decay_code = None,
  apply_input_code = None,
  support_code = None,
  extra_global_params = None,
  custom_body = None 
)

This helper function creates a custom PostsynapticModel class.

See also
create_custom_neuron_class
create_custom_weight_update_class
create_custom_current_source_class
create_custom_init_var_snippet_class
create_custom_sparse_connect_init_snippet_class
Parameters
class_namename of the new class
param_nameslist of strings with param names of the model
var_name_typeslist of pairs of strings with varible names and types of the model
derived_paramslist of pairs, where the first member is string with name of the derived parameter and the second should be a functor returned by create_dpf_class
decay_codestring with the decay code
apply_input_codestring with the apply input code
support_codestring with the support code
extra_global_paramslist of pairs of strings with names and types of additional parameters
custom_bodydictionary with additional attributes and methods of the new class

◆ create_custom_sparse_connect_init_snippet_class()

def pygenn.genn_model.create_custom_sparse_connect_init_snippet_class (   class_name,
  param_names = None,
  derived_params = None,
  row_build_code = None,
  row_build_state_vars = None,
  col_build_code = None,
  col_build_state_vars = None,
  calc_max_row_len_func = None,
  calc_max_col_len_func = None,
  calc_kernel_size_func = None,
  extra_global_params = None,
  custom_body = None 
)

This helper function creates a custom InitSparseConnectivitySnippet class.

See also
create_custom_neuron_class
create_custom_weight_update_class
create_custom_postsynaptic_class
create_custom_current_source_class
create_custom_init_var_snippet_class
Parameters
class_namename of the new class
param_nameslist of strings with param names of the model
derived_paramslist of pairs, where the first member is string with name of the derived parameter and the second MUST be an instance of the class which inherits from pygenn.genn_wrapper.DerivedParamFunc
row_build_codestring with row building initialization code
row_build_state_varslist of tuples of state variables, their types and their initial values to use across row building loop
col_build_codestring with column building initialization code
col_build_state_varslist of tuples of state variables, their types and their initial values to use across column building loop
calc_max_row_len_funcinstance of class inheriting from CalcMaxLengthFunc used to calculate maximum row length of synaptic matrix
calc_max_col_len_funcinstance of class inheriting from CalcMaxLengthFunc used to calculate maximum col length of synaptic matrix
calc_kernel_size_funcinstance of class inheriting from CalcKernelSizeFunc used to calculate kernel dimensions
extra_global_paramslist of pairs of strings with names and types of additional parameters
custom_bodydictionary with additional attributes and methods of the new class

◆ create_custom_toeplitz_connect_init_snippet_class()

def pygenn.genn_model.create_custom_toeplitz_connect_init_snippet_class (   class_name,
  param_names = None,
  derived_params = None,
  diagonal_build_code = None,
  diagonal_build_state_vars = None,
  calc_max_row_len_func = None,
  calc_kernel_size_func = None,
  extra_global_params = None,
  custom_body = None 
)

This helper function creates a custom InitToeplitzConnectivitySnippet class.

See also
create_custom_neuron_class
create_custom_weight_update_class
create_custom_postsynaptic_class
create_custom_current_source_class
create_custom_init_var_snippet_class
Parameters
class_namename of the new class
param_nameslist of strings with param names of the model
derived_paramslist of pairs, where the first member is string with name of the derived parameter and the second MUST be an instance of the class which inherits from pygenn.genn_wrapper.DerivedParamFunc
diagonal_build_codestring with diagonal building initialization code
diagonal_build_state_varslist of tuples of state variables, their types and their initial values to use across diagonal building loop
calc_max_row_len_funcinstance of class inheriting from CalcMaxLengthFunc used to calculate maximum row length of synaptic matrix
calc_kernel_size_funcinstance of class inheriting from CalcKernelSizeFunc used to calculate kernel dimensions
extra_global_paramslist of pairs of strings with names and types of additional parameters
custom_bodydictionary with additional attributes and methods of the new class

◆ create_custom_weight_update_class()

def pygenn.genn_model.create_custom_weight_update_class (   class_name,
  param_names = None,
  var_name_types = None,
  pre_var_name_types = None,
  post_var_name_types = None,
  derived_params = None,
  sim_code = None,
  event_code = None,
  learn_post_code = None,
  synapse_dynamics_code = None,
  event_threshold_condition_code = None,
  pre_spike_code = None,
  post_spike_code = None,
  pre_dynamics_code = None,
  post_dynamics_code = None,
  sim_support_code = None,
  learn_post_support_code = None,
  synapse_dynamics_suppport_code = None,
  extra_global_params = None,
  is_pre_spike_time_required = None,
  is_post_spike_time_required = None,
  is_pre_spike_event_time_required = None,
  is_prev_pre_spike_time_required = None,
  is_prev_post_spike_time_required = None,
  is_prev_pre_spike_event_time_required = None,
  custom_body = None 
)

This helper function creates a custom WeightUpdateModel class.

See also
create_custom_neuron_class
create_custom_postsynaptic_class
create_custom_current_source_class
create_custom_init_var_snippet_class
create_custom_sparse_connect_init_snippet_class
Parameters
class_namename of the new class
param_nameslist of strings with param names of the model
var_name_typeslist of pairs of strings with variable names and types of the model
pre_var_name_typeslist of pairs of strings with presynaptic variable names and types of the model
post_var_name_typeslist of pairs of strings with postsynaptic variable names and types of the model
derived_paramslist of pairs, where the first member is string with name of the derived parameter and the second should be a functor returned by create_dpf_class
sim_codestring with the simulation code
event_codestring with the event code
learn_post_codestring with the code to include in learn_synapse_post kernel/function
synapse_dynamics_codestring with the synapse dynamics code
event_threshold_condition_codestring with the event threshold condition code
pre_spike_codestring with the code run once per spiking presynaptic neuron
post_spike_codestring with the code run once per spiking postsynaptic neuron
pre_dynamics_codestring with the code run every timestep on presynaptic neuron
post_dynamics_codestring with the code run every timestep on postsynaptic neuron
sim_support_codestring with simulation support code
learn_post_support_codestring with support code for learn_synapse_post kernel/function
synapse_dynamics_suppport_codestring with synapse dynamics support code
extra_global_paramslist of pairs of strings with names and types of additional parameters
is_pre_spike_time_requiredboolean, is presynaptic spike time required in any weight update kernels?
is_post_spike_time_requiredboolean, is postsynaptic spike time required in any weight update kernels?
is_pre_spike_event_time_requiredboolean, is presynaptic spike-like-event time required in any weight update kernels?
is_prev_pre_spike_time_requiredboolean, is previous presynaptic spike time required in any weight update kernels?
is_prev_post_spike_time_requiredboolean, is previous postsynaptic spike time required in any weight update kernels?
is_prev_pre_spike_event_time_requiredboolean, is previous presynaptic spike-like-event time required in any weight update kernels?
custom_bodydictionary with additional attributes and methods of the new class

◆ create_dpf_class()

def pygenn.genn_model.create_dpf_class (   dp_func)

Helper function to create derived parameter function class.

Parameters
dp_funca function which computes the derived parameter and takes two args "pars" (vector of double) and "dt" (double)

◆ create_egp_ref()

def pygenn.genn_model.create_egp_ref (   pop,
  egp_name 
)

This helper function creates a Models::EGPReference pointing to a neuron, current source or custom update extra global parameter for initialising references.

Parameters
poppopulation, either a NeuronGroup or CurrentSource object
egp_namename of extra global parameter in population to reference

◆ create_psm_egp_ref()

def pygenn.genn_model.create_psm_egp_ref (   sg,
  egp_name 
)

This helper function creates a Models::EGPReference pointing to a postsynaptic model extra global parameter for initialising references.

Parameters
sgSynapseGroup object
egp_namename of postsynaptic model extra global parameter in synapse group to reference

◆ create_psm_var_ref()

def pygenn.genn_model.create_psm_var_ref (   sg,
  var_name 
)

This helper function creates a Models::VarReference pointing to a postsynaptic model variable for initialising variable references.

Parameters
sgSynapseGroup object
var_namename of postsynaptic model variable in synapse group to reference

◆ create_var_ref()

def pygenn.genn_model.create_var_ref (   pop,
  var_name 
)

This helper function creates a Models::VarReference pointing to a neuron or current source variable for initialising variable references.

Parameters
poppopulation, either a NeuronGroup or CurrentSource object
var_namename of variable in population to reference

◆ create_wu_egp_ref()

def pygenn.genn_model.create_wu_egp_ref (   sg,
  egp_name 
)

This helper function creates a Models::EGPReference pointing to a weight update model extra global parameter for initialising references.

Parameters
sgSynapseGroup object
egp_namename of weight update model extra global parameter in synapse group to reference

◆ create_wu_post_var_ref()

def pygenn.genn_model.create_wu_post_var_ref (   sg,
  var_name 
)

This helper function creates a Models::VarReference pointing to a postsynaptic weight update model variable for initialising variable references.

Parameters
sgSynapseGroup object
var_namename of postsynaptic weight update model variable in synapse group to reference

◆ create_wu_pre_var_ref()

def pygenn.genn_model.create_wu_pre_var_ref (   sg,
  var_name 
)

This helper function creates a Models::VarReference pointing to a presynaptic weight update model variable for initialising variable references.

Parameters
sgSynapseGroup object
var_namename of presynaptic weight update model variable in synapse group to reference

◆ create_wu_var_ref()

def pygenn.genn_model.create_wu_var_ref (   g,
  var_name,
  tp_sg = None,
  tp_var_name = None 
)

This helper function creates a Models::WUVarReference pointing to a weight update model variable for initialising variable references.

Parameters
gSynapseGroup or CustomUpdate object
var_namename of weight update model variable in synapse group to reference
tp_sg(optional) SynapseGroup object to copy transpose of variable to
tp_var_name(optional) name of weight update model variable in tranpose synapse group to copy transpose to

◆ init_connectivity()

def pygenn.genn_model.init_connectivity (   init_sparse_connect_snippet,
  param_space 
)

This helper function creates a InitSparseConnectivitySnippet::Init object to easily initialise connectivity using a snippet.

Parameters
init_sparse_connect_snippettype of the InitSparseConnectivitySnippet class as string or instance of class derived from InitSparseConnectivitySnippet::Custom.
param_spacedict with param values for the InitSparseConnectivitySnippet class

◆ init_toeplitz_connectivity()

def pygenn.genn_model.init_toeplitz_connectivity (   init_toeplitz_connect_snippet,
  param_space 
)

This helper function creates a InitToeplitzConnectivitySnippet::Init object to easily initialise connectivity using a snippet.

Parameters
init_toeplitz_connect_snippettype of the InitToeplitzConnectivitySnippet class as string or instance of class derived from InitSparseConnectivitySnippet::Custom.
param_spacedict with param values for the InitToeplitzConnectivitySnippet class

◆ init_var()

def pygenn.genn_model.init_var (   init_var_snippet,
  param_space 
)

This helper function creates a VarInit object to easily initialise a variable using a snippet.

Parameters
init_var_snippettype of the InitVarSnippet class as string or instance of class derived from InitVarSnippet::Custom class.
param_spacedict with param values for the InitVarSnippet class

Variable Documentation

◆ backend_modules

pygenn.genn_model.backend_modules = OrderedDict()

◆ GeNNType

pygenn.genn_model.GeNNType = namedtuple("GeNNType", ["np_dtype", "assign_ext_ptr_array", "assign_ext_ptr_single"])

◆ m

pygenn.genn_model.m = import_module(".genn_wrapper." + b + "Backend", "pygenn")