def generate_kernel_buffers_(self, neuron, equations_block): """ For every occurrence of a convolution of the form `convolve(var, spike_buf)`: add the element `(kernel, spike_buf)` to the set, with `kernel` being the kernel that contains variable `var`. """ kernel_buffers = set() convolve_calls = OdeTransformer.get_convolve_function_calls( equations_block) for convolve in convolve_calls: el = (convolve.get_args()[0], convolve.get_args()[1]) sym = convolve.get_args()[0].get_scope().resolve_to_symbol( convolve.get_args()[0].get_variable().name, SymbolKind.VARIABLE) if sym is None: raise Exception( "No initial value(s) defined for kernel with variable \"" + convolve.get_args()[0].get_variable().get_complete_name() + "\"") if sym.block_type == BlockType.INPUT_BUFFER_SPIKE: el = (el[1], el[0]) # find the corresponding kernel object var = el[0].get_variable() assert var is not None kernel = neuron.get_kernel_by_name(var.get_name()) assert kernel is not None, "In convolution \"convolve(" + str( var.name) + ", " + str( el[1]) + ")\": no kernel by name \"" + var.get_name( ) + "\" found in neuron." el = (kernel, el[1]) kernel_buffers.add(el) return kernel_buffers
def get_delta_factors_(self, neuron, equations_block): r""" For every occurrence of a convolution of the form `x^(n) = a * convolve(kernel, inport) + ...` where `kernel` is a delta function, add the element `(x^(n), inport) --> a` to the set. """ delta_factors = {} for ode_eq in equations_block.get_ode_equations(): var = ode_eq.get_lhs() expr = ode_eq.get_rhs() conv_calls = OdeTransformer.get_convolve_function_calls(expr) for conv_call in conv_calls: assert len( conv_call.args ) == 2, "convolve() function call should have precisely two arguments: kernel and spike buffer" kernel = conv_call.args[0] if is_delta_kernel( neuron.get_kernel_by_name( kernel.get_variable().get_name())): inport = conv_call.args[1].get_variable() expr_str = str(expr) sympy_expr = sympy.parsing.sympy_parser.parse_expr( expr_str) sympy_expr = sympy.expand(sympy_expr) sympy_conv_expr = sympy.parsing.sympy_parser.parse_expr( str(conv_call)) factor_str = [] for term in sympy.Add.make_args(sympy_expr): if term.find(sympy_conv_expr): factor_str.append( str(term.replace(sympy_conv_expr, 1))) factor_str = " + ".join(factor_str) delta_factors[(var, inport)] = factor_str return delta_factors