pynestml.utils package

Submodules

pynestml.utils.ast_mechanism_information_collector module

class pynestml.utils.ast_mechanism_information_collector.ASTFunctionCallCollectorVisitor

Bases: ASTVisitor

endvisit_function_call(node)

Private method: Used to endvisit a single function call and update its corresponding scope. :param node: a function call object. :type node: ASTFunctionCall

visit_function_call(node)

Private method: Used to visit a single function call and update its corresponding scope. :param node: a function call object. :type node: ASTFunctionCall

class pynestml.utils.ast_mechanism_information_collector.ASTFunctionCollectorVisitor

Bases: ASTVisitor

endvisit_function(node)

Used to endvisit a single function block. :param node: a function block object. :type node: ASTFunction

visit_function(node)

Used to visit a single function block. :param node: a function block object. :type node: ASTFunction

class pynestml.utils.ast_mechanism_information_collector.ASTInlineEquationCollectorVisitor

Bases: ASTVisitor

endvisit_inline_expression(node)

Used to endvisit a single inline expression. :param node: a single inline expression :type node: ASTInlineExpression

visit_inline_expression(node)

Used to visit a single inline expression. :param node: a single inline expression. :type node: ASTInlineExpression

class pynestml.utils.ast_mechanism_information_collector.ASTKernelCollectorVisitor

Bases: ASTVisitor

endvisit_kernel(node)

Used to endvisit a single kernel. :param node: a single kernel. :type node: ASTKernel

visit_kernel(node)

Used to visit a single kernel. :param node: a single kernel. :type node: ASTKernel

class pynestml.utils.ast_mechanism_information_collector.ASTMechanismInformationCollector(neuron)

Bases: object

This class contains all basic mechanism information collection. Further collectors may be implemented to collect further information for specific mechanism types (example: ASTSynapseInformationCollector)

Collects all parts of the nestml code the root expressions previously collected depend on. search is cut at other mechanisms root expressions

collector_visitor = None
classmethod detect_mechs(mech_type: str)

Detects the root expressions (either ode or inline) of the given type and returns the initial info dictionary

classmethod extend_function_call_list_name_based_restricted(extended_list, appending_list, restrictor_list)

go through appending_list and append every variable that is not in restrictor_list to extended_list for the purpose of not re-searching the same function

classmethod extend_variable_list_name_based_restricted(extended_list, appending_list, restrictor_list)

go through appending_list and append every variable that is not in restrictor_list to extended_list for the purpose of not re-searching the same variable

classmethod extend_variables_with_initialisations(neuron, mechs_info)

collects initialization expressions for all variables and parameters contained in mechs_info

neuron = None
class pynestml.utils.ast_mechanism_information_collector.ASTMechanismInformationCollectorVisitor

Bases: ASTVisitor

endvisit_equations_block(node)

Used to endvisit a single equations block. :param node: a single equations block. :type node: ASTEquationsBlock

visit_equations_block(node)

Used to visit a single equations block. :param node: a single equations block. :type node: ASTEquationsBlock

visit_inline_expression(node)

Used to visit a single inline expression. :param node: a single inline expression. :type node: ASTInlineExpression

visit_ode_equation(node)

Used to visit a single ode-equation. :param node: a single ode-equation. :type node: ASTOdeEquation

class pynestml.utils.ast_mechanism_information_collector.ASTODEEquationCollectorVisitor

Bases: ASTVisitor

endvisit_ode_equation(node)

Used to endvisit a single ode-equation. :param node: a single ode-equation. :type node: ASTOdeEquation

visit_ode_equation(node)

Used to visit a single ode-equation. :param node: a single ode-equation. :type node: ASTOdeEquation

class pynestml.utils.ast_mechanism_information_collector.ASTVariableCollectorVisitor

Bases: ASTVisitor

endvisit_block_with_variables(node)

Used to endvisit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

endvisit_variable(node)

Used to endvisit a single variable. :param node: a single variable. :type node: ASTVariable

visit_block_with_variables(node)

Used to visit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

visit_variable(node)

Used to visit a single variable. :param node: a single variable. :type node: ASTVariable

class pynestml.utils.ast_mechanism_information_collector.VariableInitializationVisitor(channel_info)

Bases: ASTVisitor

endvisit_block_with_variables(node)

Used to endvisit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

endvisit_declaration(node)

Used to endvisit a single declaration. :param node: a declaration object. :type node: ASTDeclaration

endvisit_variable(node)

Used to endvisit a single variable. :param node: a single variable. :type node: ASTVariable

visit_block_with_variables(node)

Used to visit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

visit_declaration(node)

Used to visit a single declaration. :param node: a declaration object. :type node: ASTDeclaration

visit_variable(node)

Used to visit a single variable. :param node: a single variable. :type node: ASTVariable

pynestml.utils.ast_source_location module

class pynestml.utils.ast_source_location.ASTSourceLocation(start_line, start_column, end_line, end_column)

Bases: object

This class is used to store information regarding the source position of an element. .. attribute:: start_line = 0

start_column = 0
end_line = 0
end_column = 0
before(source_position)

Checks if the handed over position is smaller than this. :param source_position: a source position. :type source_position: ASTSourceLocation :return: True if smaller, otherwise False :rtype: bool

encloses(source_position)
Checks if the handed over position is enclosed in this source position, e.g.,

line 0 to 10 encloses lines 0 to 9 etc.

Parameters:

source_position (ASTSourceLocation) – a source position

Returns:

True if enclosed, otherwise False.

Return type:

bool

equals(source_position)

Checks if the handed over position is equal to this. :param source_position: a source position. :type source_position: ASTSourceLocation :return: True if equal, otherwise False. :rtype: bool

classmethod get_added_source_position()

Returns a source position which symbolize that the corresponding element has been added by the solver. :return: a source position. :rtype: ASTSourceLocation

get_end_column()

Returns the end column of the element. :return: the end column as int :rtype: int

get_end_line()

Returns the end line of the element. :return: the end line as int :rtype: int

classmethod get_predefined_source_position()

Returns a source position which symbolizes that the corresponding element is predefined. :return: a source position :rtype: ASTSourceLocation

get_start_column()

Returns the start column of the element. :return: the start column as int :rtype: int

get_start_line()

Returns the start line of the element. :return: the start line as int :rtype: int

is_added_source_position()

Indicates whether this represents an artificially added source position.. :return: a source position. :rtype: ASTSourceLocation

is_predefined_source_position()

Indicates whether this represents a predefined source position. :return: True if predefined, otherwise False. :rtype: bool

classmethod make_ast_source_position(start_line, start_column, end_line, end_column)

Factory method of the ASTSourceLocation class. :param start_line: The start line of the object :type start_line: int :param start_column: The start column of the object :type start_column: int :param end_line: The end line of the object :type end_line: int :param end_column: The end column of the object :type end_column: int :return: a new ASTSourceLocation object :rtype: ASTSourceLocation

pynestml.utils.ast_synapse_information_collector module

class pynestml.utils.ast_synapse_information_collector.ASTSynapseInformationCollector

Bases: ASTVisitor

for each inline expression inside the equations block, collect all synapse relevant information

static construct_kernel_X_spike_buf_name(kernel_var_name: str, spike_input_port, order: int, diff_order_symbol='__d')
endvisit_block_with_variables(node)

Used to endvisit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

endvisit_declaration(node)

Used to endvisit a single declaration. :param node: a declaration object. :type node: ASTDeclaration

endvisit_equations_block(node)

Used to endvisit a single equations block. :param node: a single equations block. :type node: ASTEquationsBlock

endvisit_expression(node)

Used to endvisit a single rhs. :param node: an rhs. :type node: ASTExpression

endvisit_function_call(node)

Private method: Used to endvisit a single function call and update its corresponding scope. :param node: a function call object. :type node: ASTFunctionCall

endvisit_inline_expression(node)

Used to endvisit a single inline expression. :param node: a single inline expression :type node: ASTInlineExpression

endvisit_input_block(node)

Used to endvisit a single input block. :param node: a single input block. :type node: ASTInputBlock

endvisit_kernel(node)

Used to endvisit a single kernel. :param node: a single kernel. :type node: ASTKernel

endvisit_simple_expression(node)

Used to endvisit a single simple rhs. :param node: a simple rhs. :type node: ASTSimpleExpression

get_basic_kernel_variable_names(synapse_inline)

for every occurence of convolve(port, spikes) generate “port__X__spikes” variable gather those variables for this synapse inline and return their list

note that those variables will occur as substring in other kernel variables i.e “port__X__spikes__d” or “__P__port__X__spikes__port__X__spikes”

so we can use the result to identify all the other kernel variables related to the specific synapse inline declaration

get_extracted_kernel_args(inline_expression: ASTInlineExpression) set
get_inline_expressions_with_kernels()
get_inline_function_calls(inline: ASTInlineExpression)
get_input_port_by_name(name)
get_kernel_by_name(name: str)
get_kernel_function_calls(kernel: ASTKernel)
get_state_declaration(variable_name)
get_synapse_specific_internal_declarations(synapse_inline: ASTInlineExpression) defaultdict
get_synapse_specific_parameter_declarations(synapse_inline: ASTInlineExpression) defaultdict
get_synapse_specific_state_declarations(synapse_inline: ASTInlineExpression) defaultdict
get_used_kernel_names(inline_expression: ASTInlineExpression)
get_used_spike_names(inline_expression: ASTInlineExpression)
get_variable_declaration(variable_name)
get_variable_names_of_synapse(synapse_inline: ASTInlineExpression, exclude_names: set = {}, exclude_ignorable=True) set

extracts all variables specific to a single synapse (which is defined by the inline expression containing kernels) independently of what block they are declared in it also cascades over all right hand side variables until all variables are included

classmethod get_variable_names_to_ignore()
visit_block_with_variables(node)

Used to visit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

visit_declaration(node)

Used to visit a single declaration. :param node: a declaration object. :type node: ASTDeclaration

visit_equations_block(node)

Used to visit a single equations block. :param node: a single equations block. :type node: ASTEquationsBlock

visit_expression(node)

Used to visit a single rhs. :param node: an rhs. :type node: ASTExpression

visit_function_call(node)

Private method: Used to visit a single function call and update its corresponding scope. :param node: a function call object. :type node: ASTFunctionCall

visit_inline_expression(node)

Used to visit a single inline expression. :param node: a single inline expression. :type node: ASTInlineExpression

visit_input_block(node)

Used to visit a single input block. :param node: a single input block. :type node: ASTInputBlock

visit_input_port(node)

Used to visit a single input port. :param node: a single input port. :type node: ASTInputPort

visit_kernel(node)

Used to visit a single kernel. :param node: a single kernel. :type node: ASTKernel

visit_simple_expression(node)

Used to visit a single simple rhs. :param node: a simple rhs. :type node: ASTSimpleExpression

visit_variable(node)

Used to visit a single variable. :param node: a single variable. :type node: ASTVariable

pynestml.utils.ast_utils module

class pynestml.utils.ast_utils.ASTUtils

Bases: object

A collection of helpful methods for AST manipulation.

classmethod add_assignment_to_update_block(assignment: ASTAssignment, neuron: ASTNeuron) ASTNeuron

Adds a single assignment to the end of the update block of the handed over neuron. At most one update block should be present.

Parameters:
  • assignment – a single assignment

  • neuron – a single neuron instance

Returns:

the modified neuron

classmethod add_declaration_to_internals(neuron: ASTNeuron, variable_name: str, init_expression: str) ASTNeuron

Adds the variable as stored in the declaration tuple to the neuron. The declared variable is of type real. :param neuron: a single neuron instance :param variable_name: the name of the variable to add :param init_expression: initialization expression :return: the neuron extended by the variable

classmethod add_declaration_to_state_block(neuron: ASTNeuron, variable: str, initial_value: str, type_str: str = 'real') ASTNeuron

Adds a single declaration to an arbitrary state block of the neuron. The declared variable is of type real. :param neuron: a neuron :param variable: state variable to add :param initial_value: corresponding initial value :return: a modified neuron

classmethod add_declaration_to_update_block(declaration: ASTDeclaration, neuron: ASTNeuron) ASTNeuron

Adds a single declaration to the end of the update block of the handed over neuron. :param declaration: ASTDeclaration node to add :param neuron: a single neuron instance :return: a modified neuron

classmethod add_declarations_to_internals(neuron: ASTNeuron, declarations: Mapping[str, str]) ASTNeuron

Adds the variables as stored in the declaration tuples to the neuron. :param neuron: a single neuron instance :param declarations: a map of variable names to declarations :return: a modified neuron

classmethod add_declarations_to_state_block(neuron: ASTNeuron, variables: List, initial_values: List) ASTNeuron

Adds a single declaration to the state block of the neuron. :param neuron: a neuron :param variables: list of variables :param initial_values: list of initial values :return: a modified neuron

classmethod add_kernel_to_variable(kernel: ASTKernel)

Adds the kernel as the defining equation.

If the definition of the kernel is e.g. g’’ = … then variable symbols g and g’ will have their kernel definition and variable type set.

Parameters:

kernel – a single kernel object.

classmethod add_ode_to_variable(ode_equation: ASTOdeEquation)

Resolves to the corresponding symbol and updates the corresponding ode-declaration.

Parameters:

ode_equation – a single ode-equation

classmethod add_state_updates(neuron: ASTNeuron, update_expressions: Mapping[str, str]) ASTNeuron

Adds all update instructions as contained in the solver output to the update block of the neuron. :param neuron: a single neuron :param update_expressions: map of variables to corresponding updates during the update step. :return: a modified version of the neuron

classmethod add_suffix_to_decl_lhs(decl, suffix: str)

add suffix to the left-hand side of a declaration

classmethod add_suffix_to_variable_name(var_name: str, astnode: ASTNode, suffix: str, scope=None)

add suffix to variable by given name recursively throughout astnode

classmethod add_suffix_to_variable_names(astnode: ASTNode | List, suffix: str)

add suffix to variable names recursively throughout astnode

classmethod add_timestep_symbol(neuron: ASTNeuron) None

Add timestep variable to the internals block

classmethod all_variables_defined_in_block(blocks: ASTBlock | List[ASTBlock]) List[ASTVariable]

return a list of all variable declarations in a block or blocks

classmethod assign_numeric_non_numeric_state_variables(neuron, numeric_state_variable_names, numeric_update_expressions, update_expressions)

For each ASTVariable, set the node._is_numeric member to True or False based on whether this variable will be solved with the analytic or numeric solver.

Ideally, this would not be a property of the ASTVariable as it is an implementation detail (that only emerges during code generation) and not an intrinsic part of the model itself. However, this approach is preferred over setting it as a property of the variable printers as it would have to make each printer aware of all models and variables therein.

classmethod assign_ode_to_variables(ode_block: ASTEquationsBlock)

Adds for each variable symbol the corresponding ode declaration if present.

Parameters:

ode_block – a single block of ode declarations.

classmethod collect_variable_names_in_expression(expr: ASTNode) List[ASTVariable]

Collect all occurrences of variables (ASTVariable), kernels (ASTKernel) XXX … :param expr: expression to collect the variables from :return: a list of variables

classmethod collects_vars_used_in_equation(state_var, from_block)
classmethod compute_type_name(data_type)

Computes the representation of the data type. :param data_type: a single data type. :type data_type: ast_data_type :return: the corresponding representation. :rtype: str

classmethod construct_kernel_X_spike_buf_name(kernel_var_name: str, spike_input_port: ASTInputPort, order: int, diff_order_symbol='__d')

Construct a kernel-buffer name as <KERNEL_NAME__X__INPUT_PORT_NAME>

For example, if the kernel is .. code-block:

kernel I_kernel = exp(-t / tau_x)

and the input port is .. code-block:

pre_spikes nS <- spike

then the constructed variable will be ‘I_kernel__X__pre_pikes’

classmethod contains_convolve_call(variable: VariableSymbol) bool

Indicates whether the declaring rhs of this variable symbol has a convolve() in it. :return: True if contained, otherwise False.

classmethod contains_convolve_function_call(ast: ASTNode) bool

Indicates whether _ast or one of its child nodes contains a sum call. :param ast: a single meta_model :return: True if sum is contained, otherwise False.

classmethod create_equations_block(neuron: ASTNeuron) ASTNeuron

Creates a single equations block in the handed over neuron. :param neuron: a single neuron :return: the modified neuron

classmethod create_initial_values_for_kernels(neuron: ASTNeuron, solver_dicts: List[dict], kernels: List[ASTKernel]) None

Add the variables used in kernels from the ode-toolbox result dictionary as ODEs in NESTML AST

classmethod create_internal_block(neuron)

Creates a single internal block in the handed over neuron. :param neuron: a single neuron :type neuron: ast_neuron :return: the modified neuron :rtype: ast_neuron

classmethod create_state_block(neuron)

Creates a single internals block in the handed over neuron. :param neuron: a single neuron :type neuron: ast_neuron :return: the modified neuron :rtype: ast_neuron

classmethod declaration_in_state_block(neuron: ASTNeuron, variable_name: str) bool

Checks if the variable is declared in the state block :param neuron: :param variable_name: :return:

classmethod deconstruct_assignment(lhs=None, is_plus=False, is_minus=False, is_times=False, is_divide=False, _rhs=None)

From lhs and rhs it constructs a new rhs which corresponds to direct assignment. E.g.: a += b*c -> a = a + b*c :param lhs: a lhs rhs :type lhs: ast_expression or ast_simple_expression :param is_plus: is plus assignment :type is_plus: bool :param is_minus: is minus assignment :type is_minus: bool :param is_times: is times assignment :type is_times: bool :param is_divide: is divide assignment :type is_divide: bool :param _rhs: a rhs rhs :type _rhs: ASTExpression or ASTSimpleExpression :return: a new direct assignment rhs. :rtype: ASTExpression

classmethod equations_from_block_to_block(state_var, from_block, to_block, var_name_suffix, mode) List[ASTDeclaration]
classmethod extract_delay_parameter(node: ASTFunctionCall) str

Extracts the delay parameter from the delayed variable :param node: The delayed variable parsed as a function call

classmethod find_model_by_name(model_name: str, models: Iterable[ASTNeuron | ASTSynapse]) ASTNeuron | ASTSynapse | None
classmethod generate_kernel_buffers_(neuron: ASTNeuron, equations_block: ASTEquationsBlock | List[ASTEquationsBlock]) Mapping[ASTKernel, ASTInputPort]

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.

classmethod get_all(ast, node_type)

Finds all meta_model which are part of the tree as spanned by the handed over meta_model. The type has to be specified. :param ast: a single meta_model node :type ast: AST_ :param node_type: the type :type node_type: AST_ :return: a list of all meta_model of the specified type :rtype: list(AST_)

classmethod get_all_neurons(list_of_compilation_units)

For a list of compilation units, it returns a list containing all neurons defined in all compilation units. :param list_of_compilation_units: a list of compilation units. :type list_of_compilation_units: list(ASTNestMLCompilationUnit) :return: a list of neurons :rtype: list(ASTNeuron)

classmethod get_all_nodes(list_of_compilation_units)

For a list of compilation units, it returns a list containing all nodes defined in all compilation units. :param list_of_compilation_units: a list of compilation units. :type list_of_compilation_units: list(ASTNestMLCompilationUnit) :return: a list of nodes :rtype: list(ASTNode)

classmethod get_all_synapses(list_of_compilation_units)

For a list of compilation units, it returns a list containing all synapses defined in all compilation units. :param list_of_compilation_units: a list of compilation units. :type list_of_compilation_units: list(ASTNestMLCompilationUnit) :return: a list of synapses :rtype: list(ASTSynapse)

classmethod get_all_variables(node: ASTNode) List[str]

Make a list of all variable symbol names that are in node

classmethod get_all_variables_used_in_convolutions(nodes: ASTEquationsBlock | List[ASTEquationsBlock], parent_node: ASTNode) List[str]

Make a list of all variable symbol names that are in one of the equation blocks in nodes and used in a convolution

classmethod get_convolve_function_calls(nodes: ASTNode | List[ASTNode])

Returns all sum function calls in the handed over meta_model node or one of its children. :param nodes: a single or list of AST nodes.

classmethod get_declaration_by_name(blocks: ASTBlock | List[ASTBlock], var_name: str) ASTDeclaration | None

Get a declaration by variable name. :param blocks: the block or blocks to look for the variable in :param var_name: name of the variable to look for (including single quotes indicating differential order)

classmethod get_declarations_from_block(var_name: str, block: ASTBlock) List[ASTDeclaration]

Get declarations from the given block containing the given variable. :param var_name: variable name :param block: block to collect the variable declarations :return: a list of declarations

classmethod get_delay_variable_symbol(node: ASTFunctionCall)

Returns the variable symbol for the corresponding delayed variable :param node: The delayed variable parsed as a function call

classmethod get_delta_factors_(neuron: ASTNeuron, equations_block: ASTEquationsBlock) dict

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.

classmethod get_expr_from_kernel_var(kernel: ASTKernel, var_name: str) ASTExpression | ASTSimpleExpression

Get the expression using the kernel variable

classmethod get_function_call(ast, function_name)

Collects for a given name all function calls in a given meta_model node. :param ast: a single node :type ast: ast_node :param function_name: the name of the function :type function_name: str :return: a list of all function calls contained in _ast :rtype: list(ASTFunctionCall)

classmethod get_function_calls(ast_node: ASTNode, function_list: List[str]) List[ASTFunctionCall]

For a handed over list of function names, this method retrieves all function calls in the meta_model. :param ast_node: a single meta_model node :param function_list: a list of function names :return: a list of all functions in the meta_model

classmethod get_initial_value_from_ode_toolbox_result(var_name: str, solver_dicts: List[dict]) str

Get the initial value of the variable with the given name from the ode-toolbox results JSON.

N.B. the variable name is given in ode-toolbox notation.

classmethod get_inline_expression_by_name(node, name: str) ASTInlineExpression | None
classmethod get_inline_expression_symbols(ast: ASTNode) List[VariableSymbol]

For the handed over AST node, this method collects all inline expression variable symbols in it. :param ast: a single AST node :return: a list of all inline expression variable symbols

classmethod get_input_port_by_name(input_blocks: List[ASTInputBlock], port_name: str) ASTInputPort

Get the input port given the port name :param input_block: block to be searched :param port_name: name of the input port :return: input port object

classmethod get_internal_by_name(node: ASTNeuronOrSynapse, var_name: str) ASTDeclaration

Get the declaration based on the name of the internal parameter :param node: the neuron or synapse containing the parameter :param var_name: variable name to be searched :return: declaration containing the variable

classmethod get_internal_variable_by_name(node: ASTVariable, var_name: str) ASTVariable

Get the internal parameter node based on the name of the internal parameter :param node: the neuron or synapse containing the parameter :param var_name: variable name to be searched :return: declaration containing the variable

classmethod get_kernel_by_name(node, name: str) ASTKernel | None
classmethod get_kernel_var_order_from_ode_toolbox_result(kernel_var: str, solver_dicts: List[dict]) int

Get the differential order of the variable with the given name from the ode-toolbox results JSON.

N.B. the variable name is given in NESTML notation, e.g. “g_in$”; convert to ode-toolbox export format notation (e.g. “g_in__DOLLAR”).

classmethod get_numeric_vector_size(variable: VariableSymbol) int

Returns the numerical size of the vector by resolving any variable used as a size parameter in declaration :param variable: vector variable :return: the size of the vector as a numerical value

classmethod get_parameter_by_name(node: ASTNeuronOrSynapse, var_name: str) ASTDeclaration

Get the declaration based on the name of the parameter :param node: the neuron or synapse containing the parameter :param var_name: variable name to be searched :return: declaration containing the variable

classmethod get_parameter_variable_by_name(node: ASTNeuronOrSynapse, var_name: str) ASTVariable

Get a parameter node based on the name of the parameter :param node: the neuron or synapse containing the parameter :param var_name: variable name to be searched :return: the parameter node

classmethod get_spike_input_ports_in_pairs(neuron: ASTNeuron) Dict[int, List[VariableSymbol]]

Returns a list of spike input ports in pairs in case of input port qualifiers. The result of this function is used to construct a vector that provides a mapping to the NESTML spike buffer index. The vector looks like below: .. code-block:

[ {AMPA_SPIKES, GABA_SPIKES}, {NMDA_SPIKES, -1} ]

where the vector index is the NEST rport number. The value is a tuple containing the NESTML index(es) to the spike buffer. In case if the rport is shared between two NESTML buffers, the vector element contains the tuple of the form (excitatory_port_index, inhibitory_port_index). Otherwise, the tuple is of the form (spike_port_index, -1).

classmethod get_state_variable_by_name(node: ASTNeuronOrSynapse, var_name: str) ASTVariable | None

Get a state variable node based on the name :param node: the neuron or synapse containing the parameter :param var_name: variable name to be searched :return: the node if found, otherwise None

classmethod get_state_variable_declaration_by_name(node: ASTNeuronOrSynapse, var_name: str) ASTDeclaration | None

Get the declaration based on the name of the parameter :param node: the neuron or synapse containing the parameter :param var_name: variable name to be searched :return: declaration containing the variable if found, otherwise None

classmethod get_statements_from_block(var_name, block)

XXX: only simple statements such as assignments are supported for now. if..then..else compound statements and so are not yet supported.

classmethod get_tuple_from_single_dict_entry(dict_entry)

For a given dict of length 1, this method returns a tuple consisting of (key,value) :param dict_entry: a dict of length 1 :type dict_entry: dict :return: a single tuple :rtype: tuple

classmethod get_unit_name(variable: ASTVariable) str
classmethod get_variable_by_name(node: ASTNeuronOrSynapse, var_name: str) ASTVariable | None

Get a variable or parameter node based on the name :param node: the neuron or synapse containing the parameter :param var_name: variable name to be searched :return: the node if found, otherwise None

classmethod get_vectorized_variable(ast, scope)

Returns all variable symbols which are contained in the scope and have a size parameter. :param ast: a single meta_model :type ast: AST_ :param scope: a scope object :type scope: Scope :return: the first element with the size parameter :rtype: variable_symbol

classmethod has_continuous_input(body: ASTNeuronOrSynapseBody) bool

Checks if the handed over neuron contains a continuous time input port. :param body: a single body element. :return: True if continuous time input port is contained, otherwise False.

classmethod has_equation_with_delay_variable(equations_with_delay_vars: ASTOdeEquation, sym: str) bool

Returns true if the given variable has an equation defined with a delayed variable, false otherwise. :param equations_with_delay_vars: a list of equations containing delayed variables :param sym: symbol denoting the lhs of

classmethod has_spike_input(body: ASTNeuronOrSynapseBody) bool

Checks if the handed over neuron contains a spike input port. :param body: a single body element. :return: True if spike input port is contained, otherwise False.

classmethod inline_aliases_convolution(inline_expr: ASTInlineExpression) bool

Returns True if and only if the inline expression is of the form var type = convolve(...).

classmethod is_castable_to(type_a, type_b)

Indicates whether typeA can be casted to type b. E.g., in Nest, a unit is always casted down to real, thus a unit where unit is expected is allowed. :param type_a: a single TypeSymbol :type type_a: type_symbol :param type_b: a single TypeSymbol :type type_b: TypeSymbol :return: True if castable, otherwise False :rtype: bool

classmethod is_compound_stmt(ast)

Indicates whether the handed over meta_model is a compound statement. Used in the template. :param ast: a single meta_model object. :type ast: AST_ :return: True if compound stmt, otherwise False. :rtype: bool

classmethod is_delta_kernel(kernel: ASTKernel) bool

Catches definition of kernel, or reference (function call or variable name) of a delta kernel function.

classmethod is_function_delay_variable(node: ASTFunctionCall) bool

Checks if the given function call is actually a delayed variable. For a function call to be a delayed variable, the function name should be resolved to a state symbol, with one function argument which is an expression. :param node: The function call

classmethod is_integrate(function_call)

Checks if the handed over function call is a ode integration function call. :param function_call: a single function call :type function_call: ASTFunctionCall :return: True if ode integration call, otherwise False. :rtype: bool

classmethod is_ode_variable(var_base_name: str, neuron: ASTNeuron) bool

Checks if the variable is present in an ODE

classmethod is_small_stmt(ast)

Indicates whether the handed over meta_model is a small statement. Used in the template. :param ast: a single meta_model object. :type ast: AST_ :return: True if small stmt, otherwise False. :rtype: bool

classmethod make_inline_expressions_self_contained(inline_expressions: List[ASTInlineExpression]) List[ASTInlineExpression]

Make inline_expressions self contained, i.e. without any references to other inline_expressions.

TODO: it should be a method inside of the ASTInlineExpression TODO: this should be done by means of a visitor

Parameters:

inline_expressions – A sorted list with entries ASTInlineExpression.

Returns:

A list with ASTInlineExpressions. Defining expressions don’t depend on each other.

classmethod move_decls(var_name, from_block, to_block, var_name_suffix: str, block_type: BlockType, mode='move') List[ASTDeclaration]

Move or copy declarations from from_block to to_block.

classmethod needs_arguments(ast_function_call)

Indicates whether a given function call has any arguments :param ast_function_call: a function call :type ast_function_call: ASTFunctionCall :return: True if arguments given, otherwise false :rtype: bool

Collect all the variable names used in the defining expressions of a list of variables. :param vars: list of variable names moved from synapse to neuron :param node: ASTNode to perform the recursive search :return: list of variable names from the recursive search

classmethod remove_initial_values_for_kernels(neuron: ASTNeuron) None

Remove initial values for original declarations (e.g. g_in, g_in’, V_m); these might conflict with the initial value expressions returned from ODE-toolbox.

classmethod remove_kernel_definitions_from_equations_block(neuron: ASTNeuron) ASTDeclaration

Removes all kernels in equations blocks.

classmethod remove_ode_definitions_from_equations_block(model: ASTNeuronOrSynapse) None

Removes all ODE definitions from all equations blocks in the model.

classmethod replace_convolution_aliasing_inlines(neuron: ASTNeuron) None

Replace all occurrences of kernel names (e.g. I_dend and I_dend' for a definition involving a second-order kernel inline kernel I_dend = convolve(kern_name, spike_buf)) with the ODE-toolbox generated variable kern_name__X__spike_buf.

classmethod replace_convolve_calls_with_buffers_(neuron: ASTNeuron, equations_block: ASTEquationsBlock) None

Replace all occurrences of convolve(kernel[‘]^n, spike_input_port) with the corresponding buffer variable, e.g. g_E__X__spikes_exc[__d]^n for a kernel named g_E and a spike input port named spikes_exc.

classmethod replace_inline_expressions_through_defining_expressions(definitions: Sequence[ASTOdeEquation], inline_expressions: Sequence[ASTInlineExpression]) Sequence[ASTOdeEquation]

Replaces symbols from inline_expressions in definitions with corresponding defining expressions from inline_expressions.

Parameters:
  • definitions – A list of ODE definitions (updated in-place).

  • inline_expressions – A list of inline expression definitions.

Returns:

A list of updated ODE definitions (same as the definitions parameter).

classmethod replace_rhs_variable(expr: ASTExpression, variable_name_to_replace: str, kernel_var: ASTVariable, spike_buf: ASTInputPort)

Replace variable names in definitions of kernel dynamics :param expr: expression in which to replace the variables :param variable_name_to_replace: variable name to replace in the expression :param kernel_var: kernel variable instance :param spike_buf: input port instance :return:

classmethod replace_rhs_variables(expr: ASTExpression, kernel_buffers: Mapping[ASTKernel, ASTInputPort])

Replace variable names in definitions of kernel dynamics.

Say that the kernel is

G = -G / tau

Its variable symbol might be replaced by “G__X__spikesEx”:

G__X__spikesEx = -G / tau

This function updates the right-hand side of expr so that it would also read (in this example):

G__X__spikesEx = -G__X__spikesEx / tau

These equations will later on be fed to ode-toolbox, so we use the symbol “’” to indicate differential order.

Note that for kernels/systems of ODE of dimension > 1, all variable orders and all variables for this kernel will already be present in kernel_buffers.

classmethod replace_variable_names_in_expressions(neuron: ASTNeuron, solver_dicts: List[dict]) None

Replace all occurrences of variables names in NESTML format (e.g. g_ex$’’)` with the ode-toolbox formatted variable name (e.g. g_ex__DOLLAR__d__d).

Variables aliasing convolutions should already have been covered by replace_convolution_aliasing_inlines().

classmethod replace_with_external_variable(var_name, node: ASTNode, suffix, new_scope, alternate_name=None)

Replace all occurrences of variables (ASTVariable``s) (e.g. ``post_trace') in the node with ``ASTExternalVariable``s, indicating that they are moved to the postsynaptic neuron.

classmethod resolve_to_variable_symbol_in_blocks(variable_name: str, blocks: List[ASTBlock])

Resolve a variable (by name) to its corresponding Symbol within the AST blocks in blocks.

classmethod to_ode_toolbox_name(name: str) str

Convert to a name suitable for ode-toolbox input

classmethod to_ode_toolbox_processed_name(name: str) str

Convert name in the same way as ode-toolbox does from input to output, i.e. returned names are compatible with ode-toolbox output

classmethod transform_ode_and_kernels_to_json(neuron: ASTNeuron, parameters_blocks: Sequence[ASTBlockWithVariables], kernel_buffers: Mapping[ASTKernel, ASTInputPort], printer: ASTPrinter) Dict

Converts AST node to a JSON representation suitable for passing to ode-toolbox.

Each kernel has to be generated for each spike buffer convolve in which it occurs, e.g. if the NESTML model code contains the statements

convolve(G, exc_spikes)
convolve(G, inh_spikes)

then kernel_buffers will contain the pairs (G, exc_spikes) and (G, inh_spikes), from which two ODEs will be generated, with dynamical state (variable) names G__X__exc_spikes and G__X__inh_spikes.

Parameters:
  • parameters_block

  • kernel_buffers

  • neuron

Returns:

Dict

classmethod update_blocktype_for_common_parameters(node)

Change the BlockType for all homogeneous parameters to BlockType.COMMON_PARAMETER

classmethod update_delay_parameter_in_state_vars(neuron: ASTNeuron, state_vars_before_update: List[VariableSymbol]) None

Updates the delay parameter in state variables after the symbol table update :param neuron: AST neuron :param state_vars_before_update: State variables before the symbol table update

classmethod update_initial_values_for_odes(neuron: ASTNeuron, solver_dicts: List[dict]) None

Update initial values for original ODE declarations (e.g. V_m’, g_ahp’’) that are present in the model before ODE-toolbox processing, with the formatted variable names and initial values returned by ODE-toolbox.

classmethod variable_in_kernels(var_name: str, kernels: List[ASTKernel]) bool

Check if a variable by this name (in ode-toolbox style) is defined in the ode-toolbox solver results

classmethod variable_in_solver(kernel_var: str, solver_dicts: List[dict]) bool

Check if a variable by this name is defined in the ode-toolbox solver results,

pynestml.utils.chan_info_enricher module

class pynestml.utils.chan_info_enricher.ChanInfoEnricher(params)

Bases: MechsInfoEnricher

Class extends MechsInfoEnricher by the computation of the inline derivative. This hasn’t been done in the channel processing because it would cause a circular dependency through the coco checks used by the ModelParser which we need to use.

classmethod compute_expression_derivative(chan_info)
classmethod enrich_mechanism_specific(neuron, mechs_info)

pynestml.utils.channel_processing module

class pynestml.utils.channel_processing.ChannelProcessing(params)

Bases: MechanismProcessing

Extends MechanismProcessing. Searches for Variables that if 0 lead to the root expression always beeing zero so that the computation can be skipped during the simulation

classmethod check_if_key_zero_var_for_expression(rhs_expression_str, var_str)

check if var being zero leads to the expression always being zero so that the computation may be skipped if this is determined to be the case during simulation.

classmethod collect_information_for_specific_mech_types(neuron, mechs_info)
mechType = 'channel'
classmethod search_for_key_zero_parameters_for_expression(rhs_expression_str, parameters)

Searching for parameters in the root-expression that if zero lead to the expression always being zero so that the computation may be skipped.

classmethod write_key_zero_parameters_for_root_inlines(chan_info)

pynestml.utils.cloning_helpers module

pynestml.utils.cloning_helpers.clone_numeric_literal(numeric_literal)

pynestml.utils.conc_info_enricher module

class pynestml.utils.conc_info_enricher.ConcInfoEnricher(params)

Bases: MechsInfoEnricher

Just created for consistency. No more than the base-class enriching needs to be done

pynestml.utils.concentration_processing module

class pynestml.utils.concentration_processing.ConcentrationProcessing(params)

Bases: MechanismProcessing

The default Processing ignores the root expression when solving the odes which in case of the concentration mechanism is a ode that needs to be solved. This is added here.

classmethod check_if_key_zero_var_for_expression(rhs_expression_str, var_str)

check if var being zero leads to the expression always being zero so that the computation may be skipped if this is determined to be the case during simulation.

classmethod collect_information_for_specific_mech_types(neuron, mechs_info)
mechType = 'concentration'
classmethod ode_toolbox_processing_for_root_expression(neuron, conc_info)

applies the ode_toolbox_processing to the root_expression since that was never appended to the list of ODEs in the base processing and thereby also never went through the ode_toolbox processing

classmethod search_for_key_zero_parameters_for_expression(rhs_expression_str, parameters)
classmethod write_key_zero_parameters_for_root_odes(conc_info)

pynestml.utils.error_listener module

class pynestml.utils.error_listener.NestMLErrorListener

Bases: ErrorListener

helper class to listen for parser errors and record whether an error has occurred

property error_occurred
syntaxError(recognizer, offendingSymbol, line, column, msg, e)

pynestml.utils.error_strings module

class pynestml.utils.error_strings.ErrorStrings

Bases: object

These error strings are part of the type calculation system and are kept separated from the message class for the sake of a clear and direct maintenance of type system as an individual component.

SEPARATOR = ' : '
classmethod code(_origin=None)

Helper method returning a unique identifier for the various classes that produce and log error messages :param _origin: the class reporting an error :return: identifier unique to that class :rtype: str

classmethod message_add_sub_type_mismatch(origin, lhs_type_text, rhs_type_text, result_type_text, source_position)

construct an message indicating that the types of an addition/subtraction are not compatible and that the result is implicitly cast to a different type :param origin: the class reporting the error :param lhs_type_text: plain text of Lhs type :type lhs_type_text: str :param rhs_type_text: plain text of Rhs type :type rhs_type_text: str :param result_type_text: plain text of resulting type (implicit cast) :type result_type_text: str :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_cannot_calculate_convolve_type(origin, source_position)

construct an error message indicating that the type of a convolve() call is ill-defined :param origin: the class reporting the error :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_comparison(origin, source_position)

construct an error message indicating that an a comparison operation has incompatible operands :param origin: the class reporting the error :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_expected_bool(origin, source_position)

construct an error message indicating that an expected bool value was not found :param origin: the class reporting the error :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_expected_int(origin, source_position)

construct an error message indicating that an expected int value was not found :param origin: the class reporting the error :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_implicit_magnitude_conversion(origin, parent_node)

Construct an warning for implicit conversion from parent_node.rhs to parent_node.lhs :param origin: the class dropping the warning :param parent_node: the addition,subtraction or assignment that requires implicit conversion :type: an ASTExpression that is either an Addition or a Subtraction for which an implicit conversion has already been determined :return: the warning message

classmethod message_logic_operands_not_bool(origin, source_position)

construct an error message indicating that an a comparison operation has incompatible operands :param origin: the class reporting the error :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_no_semantics(origin, expr_text, source_position)

construct an error message indicating that an rhs is not implemented :param origin: the class reporting the error :param expr_text: plain text of the unimplemented rhs :type expr_text: str :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_non_constant_exponent(origin, source_position)

construct an error message indicating that the exponent given to a unit base is not a constant value :param origin: the class reporting the error :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_non_numeric_type(origin, type_name, source_position)

construct an error message indicating an expected numeric type is not, in fact, numeric :param origin: the class reporting the error :param type_name: plain text representation of the wrong type that was encountered :type type_name: str :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_resolve_fail(origin, symbol_name, source_position)

construct an error message indicating that a symbol could not be resolved :param origin: the class reporting the error :param symbol_name: the name of the symbol :type symbol_name: str :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_ternary(origin, source_position)

construct an error message indicating that an a comparison operation has incompatible operands :param origin: the class reporting the error :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_ternary_mismatch(origin, if_true_text, if_not_text, source_position)

construct an error message indicating that an a comparison operation has incompatible operands :param origin: the class reporting the error :param if_true_text: plain text of the positive branch of the ternary operator :type if_true_text: str :param if_not_text: plain text of the negative branch of the ternary operator :type if_not_text: str :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_type_error(origin, expression_text, source_position)

construct an error message indicating a generic error in rhs type calculation :param origin: the class reporting the error :param expression_text: plain text representation of the offending rhs :type expression_text: str :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_unit_base(origin, source_position)

construct an error message indicating that a non-int type was given as exponent to a unit type :param origin: the class reporting the error :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

classmethod message_void_function_on_rhs(origin, function_name, source_position)

construct an error message indicating that a void function cannot be used on a RHS :param origin: the class reporting the error :param function_name: the offending function :type function_name: str :param source_position: The location where the error was encountered :type source_position: ASTSourceLocation :return: the error message :rtype: str

pynestml.utils.logger module

class pynestml.utils.logger.Logger

Bases: object

This class represents a logger which can be used to print messages to the screen depending on the logging level.

LEVELS:

DEBUG Print all received messages. INFO Print all received information messages, warnings and errors. WARNING Print all received warnings and errors. ERROR Print all received errors. NO Print no messages.

Hereby, errors are the most specific level, thus no warnings and non critical messages are shown. If logging level is set to WARNING, only warnings and errors are printed. Only if level is set to DEBUG, all messages are printed.

log       Stores all messages as received during the execution. Map from id
Type:

int

curr_message A counter indicating the current message, this enables a sorting by the number of message
logging_level Indicates messages of which level shall be printed to the screen.
current_node The currently processed model. This enables to retrieve all messages belonging to a certain model
curr_message = None
current_node = None
classmethod freeze_log(do_freeze: bool = True)

Freeze the log: while log is frozen, all logging requests will be ignored.

classmethod get_all_messages_of_level(level: LoggingLevel) List[Tuple[ASTNode, LoggingLevel, str]]

Returns all messages which have a certain logging level. :param level: a logging level :type level: LoggingLevel :return: a list of messages with their levels. :rtype: list((str,Logging_Level)

classmethod get_all_messages_of_level_and_or_node(node: ASTNode, level: LoggingLevel) List[Tuple[ASTNode, LoggingLevel, str]]

Returns all messages which have a certain logging level, or have been reported for a certain node, or both. :param node: a single node instance :param level: a logging level :type level: LoggingLevel :return: a list of messages with their levels. :rtype: list((str,Logging_Level)

classmethod get_all_messages_of_node(node: ASTNode) List[Tuple[ASTNode, LoggingLevel, str]]

Returns all messages which have been reported for a certain node. :param node: a single node instance :return: a list of messages with their levels. :rtype: list((str,Logging_Level)

classmethod get_json_format() str

Returns the log in a format which can be used to be stored to a file. :return: a string containing the log

classmethod get_log() Mapping[int, Tuple[ASTNode, LoggingLevel, str]]

Returns the overall log of messages. The structure of the log is: (NODE, LEVEL, MESSAGE) :return: mapping from id to ASTNode, log level and message.

classmethod has_errors(node: ASTNode) bool

Indicates whether the handed over node, thus the corresponding model, has errors. :param node: a single node instance. :return: True if errors detected, otherwise False :rtype: bool

classmethod init_logger(logging_level: LoggingLevel)

Initializes the logger. :param logging_level: the logging level as required :type logging_level: LoggingLevel

classmethod level_to_string(level: LoggingLevel) str

Returns a string representation of the handed over logging level. :param level: LoggingLevel to convert. :return: a string representing the logging level.

log = {}
log_frozen = False
classmethod log_message(node: ASTNode | None = None, code: MessageCode | None = None, message: str | None = None, error_position: ASTSourceLocation | None = None, log_level: LoggingLevel | None = None)

Logs the handed over message on the handed over node. If the current logging is appropriate, the message is also printed. :param node: the node in which the error occurred :param code: a single error code :type code: ErrorCode :param error_position: the position on which the error occurred. :type error_position: SourcePosition :param message: a message. :type message: str :param log_level: the corresponding log level. :type log_level: LoggingLevel

logging_level = None
no_print = False
classmethod set_current_node(node: ASTNode | None) None

Sets the handed over node as the currently processed one. This enables a retrieval of messages for a specific node. :param node: a single node instance

classmethod set_log(log, counter)

Restores log from the ‘log’ variable :param log: the log :param counter: the counter

classmethod set_logging_level(level: LoggingLevel) None

Updates the logging level to the handed over one. :param level: a new logging level. :type level: LoggingLevel

classmethod string_to_level(string: str) LoggingLevel

Returns the logging level corresponding to the handed over string. If no such exits, returns None. :param string: a single string representing the level. :type string: str :return: a single logging level. :rtype: LoggingLevel

class pynestml.utils.logger.LoggingLevel(value)

Bases: Enum

Different types of logging levels, this part can be extended.

DEBUG = 0
ERROR = 3
INFO = 1
NO = 4
WARNING = 2

pynestml.utils.logging_helper module

expression : left=expression (plusOp=’+’ | minusOp=’-’) right=expression

class pynestml.utils.logging_helper.LoggingHelper

Bases: object

static drop_missing_type_error(_assignment)

pynestml.utils.mechanism_processing module

class pynestml.utils.mechanism_processing.MechanismProcessing

Bases: object

Manages the collection of basic information necesary for all types of mechanisms and uses the collect_information_for_specific_mech_types interface that needs to be implemented by the specific mechanism type processing classes

classmethod check_co_co(neuron: ASTNeuron)

Checks if mechanism conditions apply for the handed over neuron. :param neuron: a single neuron instance. :type neuron: ASTNeuron

classmethod collect_information_for_specific_mech_types(neuron, mechs_info)
classmethod collect_raw_odetoolbox_output(mechs_info)

calls ode-toolbox for each ode individually and collects the raw output

classmethod determine_dependencies(mechs_info)
first_time_run = {}
classmethod get_mechs_info(neuron: ASTNeuron)

returns previously generated mechs_info as a deep copy so it can’t be changed externally via object references :param neuron: a single neuron instance. :type neuron: ASTNeuron

mechType = ''
mechs_info = {}
classmethod ode_toolbox_processing(neuron, mechs_info)
classmethod prepare_equations_for_ode_toolbox(neuron, mechs_info)

Transforms the collected ode equations to the required input format of ode-toolbox and adds it to the mechs_info dictionary

classmethod print_dictionary(dictionary, rec_step)

Print the mechanisms info dictionaries.

classmethod print_element(name, element, rec_step)

pynestml.utils.mechs_info_enricher module

class pynestml.utils.mechs_info_enricher.ASTEnricherInfoCollectorVisitor

Bases: ASTVisitor

endvisit_block_with_variables(node)

Used to endvisit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

endvisit_declaration(node)

Used to endvisit a single declaration. :param node: a declaration object. :type node: ASTDeclaration

endvisit_variable(node)

Used to endvisit a single variable. :param node: a single variable. :type node: ASTVariable

visit_block_with_variables(node)

Used to visit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

visit_declaration(node)

Used to visit a single declaration. :param node: a declaration object. :type node: ASTDeclaration

visit_variable(node)

Used to visit a single variable. :param node: a single variable. :type node: ASTVariable

class pynestml.utils.mechs_info_enricher.MechsInfoEnricher

Bases: object

Adds information collection that can’t be done in the processing class since that is used in the cocos. Here we use the ModelParser which would lead to a cyclic dependency.

classmethod enrich_mechanism_specific(neuron, mechs_info)
classmethod enrich_with_additional_info(neuron: ASTNeuron, mechs_info: dict)
classmethod transform_ode_solutions(neuron, mechs_info)

pynestml.utils.messages module

class pynestml.utils.messages.MessageCode(value)

Bases: Enum

A mapping between codes and the corresponding messages.

ADD_SUB_TYPE_MISMATCH = 7
ANALYSING_TRANSFORMING_NEURON = 63
ARG_NOT_KERNEL_OR_EQUATION = 19
ARG_NOT_SPIKE_INPUT = 20
ASSIGNING_TO_INLINE = 91
ASTDATATYPE_TYPE_SYMBOL_COULD_NOT_BE_DERIVED = 71
BLOCK_NOT_CORRECT = 24
BUFFER_SET_TO_CONDUCTANCE_BASED = 8
CAST_NOT_POSSIBLE = 5
CM_FUNCTION_BAD_NUMBER_ARGS = 103
CM_FUNCTION_BAD_RETURN_TYPE = 104
CM_FUNCTION_MISSING = 101
CM_NO_GATING_VARIABLES = 100
CM_NO_VALUE_ASSIGNMENT = 106
CM_NO_V_COMP = 108
CM_VARIABLES_NOT_DECLARED = 102
CM_VARIABLE_NAME_MULTI_USE = 105
CODE_SUCCESSFULLY_GENERATED = 13
CONTINUOUS_INPUT_PORT_WITH_QUALIFIERS = 23
CONVOLVE_NEEDS_BUFFER_PARAMETER = 57
CREATING_INSTALL_PATH = 89
CREATING_TARGET_PATH = 90
DELAY_VARIABLE = 84
DELTA_FUNCTION_CANNOT_BE_MIXED = 69
EMIT_SPIKE_FUNCTION_BUT_NO_OUTPUT_PORT = 74
EQUATIONS_DEFINED_BUT_INTEGRATE_ODES_NOT_CALLED = 77
FUNCTION_CALL_TYPE_ERROR = 2
FUNCTION_NOT_DECLARED = 30
FUNCTION_REDECLARED = 29
HARD_INCOMPATIBILITY = 45
IMPLICIT_CAST = 4
INPUT_PATH_NOT_FOUND = 58
INPUT_PORT_SIZE_NOT_GREATER_THAN_ZERO = 87
INPUT_PORT_SIZE_NOT_INTEGER = 86
INSTALL_PATH_INFO = 88
INTERNAL_WARNING = 55
KERNEL_IV_WRONG_TYPE = 73
KERNEL_OUTSIDE_CONVOLVE = 35
KERNEL_WRONG_TYPE = 72
LEXER_ERROR = 59
MECHS_DICTIONARY_INFO = 109
MODEL_CONTAINS_ERRORS = 11
MODEL_REDECLARED = 33
MODULE_NAME_INFO = 66
MODULE_SUCCESSFULLY_GENERATED = 14
MULTIPLE_KEYWORDS = 41
NAME_COLLISION = 36
NEST_COLLISION = 34
NEST_DELAY_DECORATOR_NOT_FOUND = 85
NEURON_SOLVED_BY_GSL = 52
NOT_A_VARIABLE = 40
NOT_LAST_STATEMENT = 47
NOT_NEUROSCIENCE_UNIT = 54
NO_ASSIGNMENT_ALLOWED = 39
NO_CODE_GENERATED = 15
NO_FILES_IN_INPUT_PATH = 75
NO_INIT_VALUE = 32
NO_ODE = 31
NO_RETURN = 46
NO_RHS = 27
NO_SEMANTICS = 51
NO_TYPE_ALLOWED = 38
NO_UNIT = 53
NO_VARIABLE_FOUND = 9
NUMERATOR_NOT_ONE = 21
ODE_FUNCTION_NEEDS_CONSISTENT_UNITS = 68
ODE_NEEDS_CONSISTENT_UNITS = 64
OPERATION_NOT_DEFINED = 56
ORDER_NOT_DECLARED = 22
PARSER_ERROR = 60
PRIORITY_DEFINED_FOR_ONLY_ONE_EVENT_HANDLER = 82
REPEATED_PRIORITY_VALUE = 83
SEVERAL_LHS = 28
SOFT_INCOMPATIBILITY = 44
SPIKE_INPUT_PORT_TYPE_NOT_DEFINED = 10
START_PROCESSING_FILE = 0
START_PROCESSING_MODEL = 12
START_SYMBOL_TABLE_BUILDING = 1
STATE_VARIABLES_NOT_INITIALZED = 76
SYMBOL_NOT_RESOLVED = 48
SYNAPSE_SOLVED_BY_GSL = 49
SYNS_BAD_BUFFER_COUNT = 107
TARGET_PATH_INFO = 67
TEMPLATED_ARG_TYPES_INCONSISTENT = 65
TEMPLATE_ROOT_PATH_CREATED = 78
TYPE_DIFFERENT_FROM_EXPECTED = 6
TYPE_MISMATCH = 50
TYPE_NOT_DERIVABLE = 3
TYPE_NOT_SPECIFIED = 37
UNKNOWN_TARGET = 61
UNKNOWN_TYPE = 70
VALUE_ASSIGNED_TO_BUFFER = 18
VARIABLE_DEFINED_RECURSIVELY = 17
VARIABLE_NOT_IN_STATE_BLOCK = 25
VARIABLE_REDECLARED = 43
VARIABLE_USED_BEFORE_DECLARATION = 16
VARIABLE_WITH_SAME_NAME_AS_UNIT = 62
VECTOR_IN_NON_VECTOR = 42
VECTOR_PARAMETER_WRONG_BLOCK = 79
VECTOR_PARAMETER_WRONG_SIZE = 81
VECTOR_PARAMETER_WRONG_TYPE = 80
WRONG_NUMBER_OF_ARGS = 26
class pynestml.utils.messages.Messages

Bases: object

This class contains a collection of error messages which enables a centralized maintaining and modifications of those.

classmethod astdatatype_type_symbol_could_not_be_derived()

Unknown type or unit literal. :param provided_type_str: the provided type as a string :type provided_type_str: str

classmethod delta_function_cannot_be_mixed()

Delta function cannot be mixed with expressions.

classmethod delta_function_one_arg(deltafunc)

Delta function takes exactly one argument. :param deltafunc: the delta function node :type name: ASTFunctionCall

classmethod get_analysing_transforming_neuron(name)

Indicates start of code generation :param name: the name of the neuron model :type name: ASTNeuron :return: a nes code,message tuple :rtype: (MessageCode,str)

classmethod get_assigning_to_inline()

Cannot assign to inline expression :param name: the name of the neuron model :type name: ASTNeuron :return: a nes code,message tuple :rtype: (MessageCode,str)

classmethod get_assignment_not_allowed(name)

Indicates that an assignment to the given element is not allowed. :param name: the name of variable to which an assignment is not allowed. :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_binary_operation_not_defined(lhs, operator, rhs)
classmethod get_binary_operation_type_could_not_be_derived(lhs, operator, rhs, lhs_type, rhs_type)
classmethod get_block_not_defined_correctly(block, missing)

Indicates that a given block has been defined several times or non. :param block: the name of the block which is not defined or defined multiple times. :type block: str :param missing: True if missing, False if multiple times. :type missing: bool :return: a message :rtype: (MessageCode,str)

classmethod get_buffer_set_to_conductance_based(buffer)

Returns a message indicating that a buffer has been set to conductance based. :param buffer: the name of the buffer :type buffer: str :return: a message :rtype: (MessageCode,str)

classmethod get_cm_inline_expression_variable_used_mulitple_times(cm_inline_expr: ASTInlineExpression, bad_variable_name: str, ion_channel_name: str)
classmethod get_cm_variable_value_missing(varname: str)
classmethod get_code_generated(model_name, path)

Returns a message indicating that code has been successfully generated for a neuron in a certain path. :param model_name: the name of the neuron. :type model_name: str :param path: the path to the file :type path: str :return: a message :rtype: (MessageCode,str)

classmethod get_compilation_unit_name_collision(name, art1, art2)

Indicates that a name collision with the same neuron inside two artifacts. :param name: the name of the neuron which leads to collision :type name: str :param art1: the first artifact name :type art1: str :param art2: the second artifact name :type art2: str :return: a message :rtype: (MessageCode,str)

classmethod get_continuous_input_port_specified(name, keyword)

Indicates that the continuous time input port has been specified with an inputQualifier keyword. :param name: the name of the buffer :type name: str :param keyword: the keyword :type keyword: list(str) :return: a message :rtype: (MessageCode,str)

classmethod get_convolve_needs_buffer_parameter()
classmethod get_could_not_be_solved()

Indicates that the set of equations could not be solved and will remain unchanged. :return: a message :rtype: (MessageCode,str)

classmethod get_could_not_determine_cond_based(type_str, name)
classmethod get_could_not_resolve(name)

Indicates that the handed over name could not be resolved to a symbol. :param name: the name which could not be resolved :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_creating_install_path(install_path: str)
classmethod get_creating_target_path(target_path: str)
classmethod get_data_type_not_specified(name)

Indicates that for a given element no type has been specified. :param name: the name of the variable for which a type has not been specified. :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_different_type_rhs_lhs(rhs_expression, lhs_expression, rhs_type, lhs_type)

Returns a message indicating that the type of the lhs does not correspond to the one of the rhs and can not be cast down to a common type. :param rhs_expression: the rhs rhs :type rhs_expression: ASTExpression or ASTSimpleExpression :param lhs_expression: the lhs rhs :type lhs_expression: ast_expression or ast_simple_expression :param rhs_type: the type of the rhs :type rhs_type: type_symbol :param lhs_type: the type of the lhs :type lhs_type: TypeSymbol :return: a message :rtype:(MessageCode,str)

classmethod get_emit_spike_function_but_no_output_port()

Indicates that an emit_spike() function was called, but no spiking output port has been defined. :return: a (code, message) tuple :rtype: (MessageCode, str)

classmethod get_equation_var_not_in_state_block(variable_name)

Indicates that a variable in the equations block is not defined in the state block. :param variable_name: the name of the variable of an equation which is not defined in an equations block :type variable_name: str :return: a message :rtype: (MessageCode,str)

classmethod get_equations_defined_but_integrate_odes_not_called()
classmethod get_equations_solved_by_gls()

Indicates that the set of ODEs as contained in the model will be solved by the gnu scientific library toolchain. :return: a message :rtype: (MessageCode,str)

classmethod get_equations_solved_exactly()

Indicates that all equations of the neuron are solved exactly by the solver script. :return: a message :rtype: (MessageCode,str)

classmethod get_expected_cm_function_bad_return_type(ion_channel_name: str, astfun: ASTFunction)
classmethod get_expected_cm_function_missing(ion_channel_name: str, variable_name: str, function_name: str)
classmethod get_expected_cm_function_wrong_args_count(ion_channel_name: str, variable_name, astfun: ASTFunction)
classmethod get_expected_cm_variables_missing_in_blocks(missing_variable_to_proper_block: Iterable, expected_variables_to_reason: dict)
classmethod get_first_arg_not_kernel_or_equation(func_name)

Indicates that the first argument of an rhs is not an equation or kernel. :param func_name: the name of the function :type func_name: str :return: a message :rtype: (MessageCode,str)

classmethod get_function_call_implicit_cast(arg_nr, function_call, expected_type, got_type, castable=False)

Returns a message indicating that an implicit cast has been performed. :param arg_nr: the number of the argument which is cast :type arg_nr: int :param function_call: a single function call :type function_call: ast_function_call :param expected_type: the expected type :type expected_type: type_symbol :param got_type: the got-type :type got_type: TypeSymbol :param castable: is the type castable :type castable: bool :return: a message :rtype: (MessageCode,str)

classmethod get_function_is_delay_variable(func)
classmethod get_function_not_declared(name)

Indicates that a function, which is not declared, has been used. :param name: the name of the function. :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_function_redeclared(name, predefined)

Indicates that a function has been redeclared. :param name: the name of the function which has been redeclared. :type name: str :param predefined: True if function is predefined, otherwise False. :type predefined: bool :return: a message :rtype:(MessageCode,str)

classmethod get_implicit_cast_rhs_to_lhs(rhs_type, lhs_type)

Returns a message indicating that the type of the lhs does not correspond to the one of the rhs, but the rhs can be cast down to lhs type. :param rhs_type: the type of the rhs :type rhs_type: str :param lhs_type: the type of the lhs :type lhs_type: str :return: a message :rtype:(MessageCode,str)

classmethod get_implicit_magnitude_conversion(lhs, rhs, conversion_factor)
classmethod get_input_path_not_found(path)
classmethod get_input_port_size_not_greater_than_zero(port_name: str)
classmethod get_input_port_size_not_integer(port_name: str)
classmethod get_input_port_type_not_defined(input_port_name: str)

Returns a message indicating that a input_port type has not been defined, thus nS is assumed. :param input_port_name: a input_port name :return: a message :rtype: (MessageCode,str)

classmethod get_install_path_info(install_path: str)
classmethod get_kernel_iv_wrong_type(iv_name: str, actual_type: str, expected_type: str) Tuple[MessageCode, str]

Returns a message indicating that the type of a kernel initial value is wrong. :param iv_name: the name of the state variable with an initial value :param actual_type: the name of the actual type that was found in the model :param expected_type: the name of the type that was expected

classmethod get_kernel_outside_convolve(name)

Indicates that a kernel variable has been used outside a convolve call. :param name: the name of the kernel :type name: str :return: message :rtype: (MessageCode,str)

classmethod get_kernel_wrong_type(kernel_name: str, differential_order: int, actual_type: str) Tuple[MessageCode, str]

Returns a message indicating that the type of a kernel is wrong. :param kernel_name: the name of the kernel :param differential_order: differential order of the kernel left-hand side, e.g. 2 if the kernel is g’’ :param actual_type: the name of the actual type that was found in the model

classmethod get_lexer_error()
classmethod get_mechs_dictionary_info(chan_info, syns_info, conc_info)
classmethod get_model_contains_errors(model_name: str) Tuple[MessageCode, str]

Returns a message indicating that a model contains errors thus no code is generated. :param model_name: the name of the model :return: a message

classmethod get_model_redeclared(name: str) Tuple[MessageCode, str]

Indicates that a model has been redeclared. :param name: the name of the model which has been redeclared. :return: a message

classmethod get_module_generated(path)

Returns a message indicating that a module has been successfully generated. :param path: the path to the generated file :type path: str :return: a message :rtype: (MessageCode,str)

classmethod get_multiple_keywords(keyword)

Indicates that a buffer has been declared with multiple keywords of the same type, e.g., inhibitory inhibitory :param keyword: the keyword which has been used multiple times :type keyword: str :return: a message :rtype: (MessageCode,str)

classmethod get_nest_collision(name)

Indicates that a collision between a user defined function and a nest function occurred. :param name: the name of the function which collides to nest :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_nest_delay_decorator_not_found()
classmethod get_neuron_solved_by_solver(name)

Indicates that a neuron will be solved by the GSL solver inside the model printing process without any modifications to the initial model. :param name: the name of the neuron :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_no_code_generated()

Returns a message indicating that no code will be generated on this run. :return: a message :rtype: (MessageCode,str)

classmethod get_no_files_in_input_path(path: str)
classmethod get_no_gating_variables(cm_inline_expr: ASTInlineExpression, ion_channel_name: str)

Indicates that if you defined an inline expression inside the equations block that uses no kernels / has no convolution calls then then there must be at least one variable name that ends with _{x} For example an inline “Na” must have at least one variable ending with “_Na” :return: a message :rtype: (MessageCode,str)

classmethod get_no_init_value(name)

Indicates that no initial value has been provided for a given variable. :param name: the name of the variable which does not have a initial value :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_no_ode(name)

Indicates that no ODE has been defined for a variable inside the state block. :param name: the name of the variable which does not have a defined ode :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_no_return()

Indicates that a given function has no return statement although required. :return: a message :rtype: (MessageCode,str)

classmethod get_no_rhs(name)

Indicates that no right-hand side has been declared for the given variable. :param name: the name of the rhs variable :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_no_variable_found(variable_name)

Returns a message indicating that a variable has not been found. :param variable_name: the name of the variable :type variable_name: str :return: a message :rtype: (MessageCode,str)

classmethod get_not_a_variable(name)

Indicates that a given name does not represent a variable. :param name: the name of the variable :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_not_last_statement(name)

Indicates that given statement is not the last statement in a block, e.g., in the case that a return statement is not the last statement. :param name: the statement. :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_not_neuroscience_unit_used(name)

Indicates that a non-neuroscientific unit, e.g., kg, has been used. Those units can not be converted to a corresponding representation in the simulation and are therefore represented by the factor 1. :param name: the name of the variable :type name: str :return: a nes code,message tuple :rtype: (MessageCode,str)

classmethod get_not_type_allowed(name)

Indicates that a type for the given element is not allowed. :param name: the name of the element for which a type is not allowed. :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_ode_function_needs_consistent_units(name, declared_type, expression_type)
classmethod get_ode_needs_consistent_units(name, differential_order, lhs_type, rhs_type)
classmethod get_ode_solution_not_used()

Indicates that an ode has been defined in the model but is not used as part of the neurons solution. :return: a message :rtype: (MessageCode,str)

classmethod get_order_not_declared(lhs)

Indicates that the order has not been declared. :param lhs: the name of the variable :type lhs: str :return: a message :rtype: (MessageCode,str)

classmethod get_parser_error()
classmethod get_priority_defined_for_only_one_receive_block(event_handler_port_name: str)
classmethod get_repeated_priorty_value()
classmethod get_second_arg_not_a_spike_port(func_name: str) Tuple[MessageCode, str]

Indicates that the second argument of the NESTML convolve() call is not a spiking input port. :param func_name: the name of the function :return: a message

classmethod get_several_lhs(names)

Indicates that several left hand sides have been defined. :param names: a list of variables :type names: list(str) :return: a message :rtype: (MessageCode,str)

classmethod get_start_building_symbol_table()

Returns a message that the building for a neuron has been started. :return: a message :rtype: (MessageCode,str)

classmethod get_start_processing_file(file_path)

Returns a message indicating that processing of a file has started :param file_path: the path to the file :type file_path: str :return: message code tuple :rtype: (MessageCode,str)

classmethod get_start_processing_model(model_name: str) Tuple[MessageCode, str]

Returns a message indicating that the processing of a model is started. :param model_name: the name of the model :return: a message

classmethod get_state_variables_not_initialized(var_name: str)
classmethod get_synapse_solved_by_solver(name)

Indicates that a synapse will be solved by the GSL solver inside the model printing process without any modifications to the initial model. :param name: the name of the synapse :type name: str :return: a message :rtype: (MessageCode,str)

classmethod get_syns_bad_buffer_count(buffers: set, synapse_name: str)
classmethod get_target_path_info(target_dir: str)
classmethod get_template_root_path_created(templates_root_dir: str)
classmethod get_type_could_not_be_derived(rhs)

Returns a message indicating that the type of the rhs rhs could not be derived. :param rhs: an rhs :type rhs: ast_expression or ast_simple_expression :return: a message :rtype: (MessageCode,str)

classmethod get_type_different_from_expected(expected_type, got_type)

Returns a message indicating that the received type is different from the expected one. :param expected_type: the expected type :type expected_type: TypeSymbol :param got_type: the actual type :type got_type: type_symbol :return: a message :rtype: (MessageCode,str)

classmethod get_unary_operation_not_defined(operator, term)
classmethod get_unit_does_not_exist(name)

Indicates that a unit does not exist. :param name: the name of the unit. :type name: str :return: a new code,message tuple :rtype: (MessageCode,str)

classmethod get_unknown_target(target)
classmethod get_v_comp_variable_value_missing(neuron_name: str, missing_variable_name)
classmethod get_value_assigned_to_buffer(buffer_name)

Returns a message indicating that a value has been assigned to a buffer. :param buffer_name: a buffer name :type buffer_name: str :return: a message :rtype: (MessageCode,str)

classmethod get_variable_defined_recursively(variable_name)

Returns a message indicating that a variable is defined recursively. :param variable_name: a variable name :type variable_name: str :return: a message :rtype: (MessageCode,str)

classmethod get_variable_not_defined(variable_name)

Returns a message indicating that a variable is not defined . :param variable_name: a variable name :type variable_name: str :return: a message :rtype: (MessageCode,str)

classmethod get_variable_redeclared(name, predefined)

Indicates that a given variable has been redeclared. A redeclaration can happen with user defined functions or with predefined functions (second parameter). :param name: the name of the variable :type name: str :param predefined: True if a pre-defined variable has been redeclared, otherwise False. :type predefined: bool :return: a message :rtype: (MessageCode,str)

classmethod get_variable_used_before_declaration(variable_name)

Returns a message indicating that a variable is used before declaration. :param variable_name: a variable name :type variable_name: str :return: a message :rtype: (MessageCode,str)

classmethod get_variable_with_same_name_as_type(name)

Indicates that a variable has been declared with the same name as a physical unit, e.g. “V mV” :param name: the name of the variable :type name: str :return: a tuple containing message code and message text :rtype: (MessageCode,str)

classmethod get_vector_in_non_vector(vector, non_vector)

Indicates that a vector has been used in a non-vector declaration. :param vector: the vector variable :type vector: str :param non_vector: the non-vector lhs :type non_vector: list(str) :return: a message :rtype: (MessageCode,str)

classmethod get_vector_parameter_wrong_block(var, block)
classmethod get_vector_parameter_wrong_size(var, value)
classmethod get_vector_parameter_wrong_type(var)
classmethod get_wrong_number_of_args(function_call, expected, got)

Indicates that a wrong number of arguments has been provided to the function call. :param function_call: a function call name :type function_call: str :param expected: the expected number of arguments :type expected: int :param got: the given number of arguments :type got: int :return: a message :rtype: (MessageCode,str)

classmethod get_wrong_numerator(unit)

Indicates that the numerator of a unit is not 1. :param unit: the name of the unit :type unit: str :return: a message :rtype: (MessageCode,str)

classmethod templated_arg_types_inconsistent(function_name, failing_arg_idx, other_args_idx, failing_arg_type_str, other_type_str)

For templated function arguments, indicates inconsistency between (formal) template argument types and actual derived types. :param name: the name of the neuron model :type name: ASTNeuron :return: a nes code,message tuple :rtype: (MessageCode,str)

classmethod unknown_type(provided_type_str)

Unknown type or unit literal. :param provided_type_str: the provided type as a string :type provided_type_str: str

pynestml.utils.model_parser module

class pynestml.utils.model_parser.ModelParser

Bases: object

classmethod parse_assignment(string: str) ASTAssignment
classmethod parse_bit_operator(string: str) ASTArithmeticOperator
classmethod parse_block(string: str) ASTBlock
classmethod parse_block_with_variables(string: str) ASTBlockWithVariables
classmethod parse_comparison_operator(string: str) ASTComparisonOperator
classmethod parse_compound_stmt(string: str) ASTCompoundStmt
classmethod parse_data_type(string: str) ASTDataType
classmethod parse_declaration(string: str) ASTDeclaration
classmethod parse_elif_clause(string: str) ASTElifClause
classmethod parse_else_clause(string: str) ASTElseClause
classmethod parse_equations_block(string: str) ASTEquationsBlock
classmethod parse_expression(string: str) ASTExpression
classmethod parse_for_stmt(string: str) ASTForStmt
classmethod parse_function(string: str) ASTFunction
classmethod parse_function_call(string: str) ASTFunctionCall
classmethod parse_if_clause(string: str) ASTIfClause
classmethod parse_if_stmt(string: str) ASTIfStmt
classmethod parse_inline_expression(string: str) ASTInlineExpression
classmethod parse_input_block(string: str) ASTInputBlock
classmethod parse_input_port(string: str) ASTInputPort
classmethod parse_input_qualifier(string: str) ASTInputQualifier
classmethod parse_kernel(string: str) ASTKernel
classmethod parse_logic_operator(string: str) ASTLogicalOperator
classmethod parse_model(file_path=None)

Parses a handed over model and returns the meta_model representation of it. :param file_path: the path to the file which shall be parsed. :type file_path: str :return: a new ASTNESTMLCompilationUnit object. :rtype: ASTNestMLCompilationUnit

classmethod parse_nestml_compilation_unit(string: str) ASTNestMLCompilationUnit
classmethod parse_neuron(string: str) ASTNeuron
classmethod parse_neuron_or_synapse_body(string: str) ASTNeuronOrSynapseBody
classmethod parse_ode_equation(string: str) ASTOdeEquation
classmethod parse_output_block(string: str) ASTOutputBlock
classmethod parse_parameter(string: str) ASTParameter
classmethod parse_return_stmt(string: str) ASTReturnStmt
classmethod parse_simple_expression(string: str) ASTSimpleExpression
classmethod parse_small_stmt(string: str) ASTSmallStmt
classmethod parse_stmt(string: str) ASTStmt
classmethod parse_synapse(string: str) ASTSynapse
classmethod parse_unary_operator(string: str) ASTUnaryOperator
classmethod parse_unit_type(string: str) ASTUnitType
classmethod parse_update_block(string: str) ASTUpdateBlock
classmethod parse_variable(string: str) ASTVariable
classmethod parse_while_stmt(string: str) ASTWhileStmt
pynestml.utils.model_parser.log_set_added_source_position(node)
pynestml.utils.model_parser.tokenize(string: str) Tuple[ASTBuilderVisitor, PyNestMLParser]

pynestml.utils.ode_toolbox_utils module

class pynestml.utils.ode_toolbox_utils.ODEToolboxUtils

Bases: object

A collection of helpful methods for interfacing with ODE-toolbox.

pynestml.utils.port_signal_type module

class pynestml.utils.port_signal_type.PortSignalType(value)

Bases: Enum

This enum is used to describe the type of the received or emitted signal.

CONTINUOUS = 2
SPIKE = 1

pynestml.utils.stack module

class pynestml.utils.stack.Stack

Bases: object

This class represents a simple version of a stack.

is_empty()

Returns true if this stack is empty. :return: True if empty, otherwise False. :rtype: bool

pop()

Returns the last element on the stack. :return: a single object if not empty, otherwise None :rtype: object

pop_first()

Returns the first element on the stack. :return: a single object if not empty, otherwise None :rtype: object

pop_n_first_to_list(n)

Pops the first n items and returns them in a list :param n: the number of items :return: int

pop_n_to_list(n)

Pops the first n items and returns them in a list :param n: the number of items :return: int

push(elem)

Pushes an element to the stack :param elem: a single element :type elem: object

top()

pynestml.utils.string_utils module

pynestml.utils.string_utils.removeprefix(s: str, prefix: str) str
pynestml.utils.string_utils.removesuffix(s: str, suffix: str) str

pynestml.utils.synapse_processing module

class pynestml.utils.synapse_processing.SynapseProcessing(params)

Bases: MechanismProcessing

classmethod collect_additional_base_infos(neuron, syns_info)

Collect internals, kernels, inputs and convolutions associated with the synapse.

classmethod collect_and_check_inputs_per_synapse(syns_info: dict)
classmethod collect_information_for_specific_mech_types(neuron, mechs_info)
classmethod convolution_ode_toolbox_processing(neuron, syns_info)
classmethod create_ode_indict(neuron: ASTNeuron, parameters_block: ASTBlockWithVariables, kernel_buffer)
mechType = 'receptor'
classmethod ode_solve_convolution(neuron: ASTNeuron, parameters_block: ASTBlockWithVariables, kernel_buffer)
classmethod transform_ode_and_kernels_to_json(neuron: ASTNeuron, parameters_block, kernel_buffers)

Converts AST node to a JSON representation suitable for passing to ode-toolbox.

Each kernel has to be generated for each spike buffer convolve in which it occurs, e.g. if the NESTML model code contains the statements

convolve(G, ex_spikes) convolve(G, in_spikes)

then kernel_buffers will contain the pairs (G, ex_spikes) and (G, in_spikes), from which two ODEs will be generated, with dynamical state (variable) names G__X__ex_spikes and G__X__in_spikes.

Parameters:

parameters_block – ASTBlockWithVariables

Returns:

Dict

pynestml.utils.syns_info_enricher module

class pynestml.utils.syns_info_enricher.ASTUsedVariableNamesExtractor(node)

Bases: ASTVisitor

visit_variable(node)

Used to visit a single variable. :param node: a single variable. :type node: ASTVariable

class pynestml.utils.syns_info_enricher.SynsInfoEnricher(params)

Bases: MechsInfoEnricher

input: a neuron after ODE-toolbox transformations

the kernel analysis solves all kernels at the same time this splits the variables on per kernel basis

classmethod compute_expression_derivative(inline_expression: ASTInlineExpression) ASTExpression
classmethod enrich_mechanism_specific(neuron, mechs_info)
classmethod get_all_synapse_variables(single_synapse_info)

returns all variable names referenced by the synapse inline and by the analytical solution assumes that the model has already been transformed

classmethod get_analytic_helper_variable_declarations(single_synapse_info)
classmethod get_analytic_helper_variable_names(single_synapse_info)

get new variables that only occur on the right hand side of analytic solution Expressions but for wich analytic solution does not offer any values this can isolate out additional variables that suddenly appear such as __h whose initial values are not inlcuded in the output of analytic solver

classmethod get_new_variables_after_transformation(single_synapse_info)
classmethod get_variable_names_used(node) set
classmethod restore_order_internals(neuron: ASTNeuron, cm_syns_info: dict)

orders user defined internals back to the order they were originally defined this is important if one such variable uses another user needs to have control over the order assign each variable a rank that corresponds to the order in SynsInfoEnricher.declarations_ordered

classmethod transform_convolutions_analytic_solutions(neuron: ASTNeuron, cm_syns_info: dict)
class pynestml.utils.syns_info_enricher.SynsInfoEnricherVisitor

Bases: ASTVisitor

declarations_ordered = []
endvisit_block_with_variables(node)

Used to endvisit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

endvisit_declaration(node)

Used to endvisit a single declaration. :param node: a declaration object. :type node: ASTDeclaration

endvisit_inline_expression(node)

Used to endvisit a single inline expression. :param node: a single inline expression :type node: ASTInlineExpression

endvisit_simple_expression(node)

Used to endvisit a single simple rhs. :param node: a simple rhs. :type node: ASTSimpleExpression

inline_name_to_transformed_inline = {}
internal_variable_name_to_variable = {}
variables_to_internal_declarations = {}
visit_block_with_variables(node)

Used to visit a single block of variables. :param node: a block with declared variables. :type node: ASTBlockWithVariables

visit_declaration(node)

Used to visit a single declaration. :param node: a declaration object. :type node: ASTDeclaration

visit_inline_expression(node)

Used to visit a single inline expression. :param node: a single inline expression. :type node: ASTInlineExpression

visit_simple_expression(node)

Used to visit a single simple rhs. :param node: a simple rhs. :type node: ASTSimpleExpression

pynestml.utils.type_caster module

class pynestml.utils.type_caster.TypeCaster

Bases: object

static do_magnitude_conversion_rhs_to_lhs(_rhs_type_symbol, _lhs_type_symbol, _containing_expression)

determine conversion factor from rhs to lhs, register it with the relevant expression

static try_to_recover_or_error(_lhs_type_symbol, _rhs_type_symbol, _containing_expression)

pynestml.utils.type_dictionary module

class pynestml.utils.type_dictionary.TypeDictionary

Bases: dict

pynestml.utils.unit_type module

class pynestml.utils.unit_type.UnitType(name, unit)

Bases: object

This class is used to encapsulate the functionality of astropy.units in a new layer which provided additional functionality as required during context checks.

Attr name:

The name of this unit.

Attr unit:

The corresponding astropy Unit.

equals(_obj=None)

Compares this to the handed object and checks if they are semantically equal. :param _obj: a single object :type _obj: object :return: True if equal, otherwise false. :rtype: bool

get_name()

Returns the name of this unit. :return: the name of the unit. :rtype: str

get_unit()

Returns the astropy unit of this unit. :return: the astropy unit :rtype: astropy.units.core.Unit

print_unit()

Returns a string representation of this unit symbol. :return: a string representation. :rtype: str

pynestml.utils.with_options module

class pynestml.utils.with_options.WithOptions(options: Mapping[str, Any] | None = None)

Bases: object

This class allows options (indexed by strings) to be set and retrieved. A set of default options may be supplied by overriding the _default_options member in the inheriting class.

add_options(options: Mapping[str, Any]) None

Extend the current options dictionary with extra options.

get_option(k: str) Any

Get the value of a given option.

option_exists(k: str) bool

Test whether an option exists.

set_options(options: Mapping[str, Any]) Mapping[str, Any]

Set options. “Eats off” any options that it knows how to set, and returns the rest as “unhandled” options.