pynestml.cocos package

Submodules

pynestml.cocos.co_co module

class pynestml.cocos.co_co.CoCo

Bases: object

This class represents an abstract super-class for all concrete context conditions to check. All context condition checks inherit from this class.

CoCos do not return values or raise exceptions; in case of issues, they messages are logged at the appropriate level.

abstract classmethod check_co_co(node: ASTNode)

Check the coco.

Parameters:

node – a single ASTNode instance on which the coco will be checked.

description = None

pynestml.cocos.co_co_all_variables_defined module

class pynestml.cocos.co_co_all_variables_defined.ASTExpressionCollectorVisitor

Bases: ASTVisitor

traverse_expression(node)
traverse_simple_expression(node)
visit_assignment(node)

Used to visit a single assignment. :param node: an assignment object. :type node: ASTAssignment

visit_expression(node)

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

visit_simple_expression(node)

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

class pynestml.cocos.co_co_all_variables_defined.CoCoAllVariablesDefined

Bases: CoCo

This class represents a constraint condition which ensures that all elements as used in expressions have been previously defined. Not allowed:

state:

V_m mV = V_m + 10mV # <- recursive definition V_m mV = V_n # <- not defined reference

classmethod check_co_co(node: ASTModel)

Checks if this coco applies for the handed over neuron. Models which contain undefined variables are not correct. :param node: a single neuron instance.

pynestml.cocos.co_co_cm_channel_model module

class pynestml.cocos.co_co_cm_channel_model.CoCoCmChannelModel

Bases: CoCo

classmethod check_co_co(model: ASTModel)

Checks if this compartmental condition applies to the handed over neuron. If yes, it checks the presence of expected functions and declarations. :param model: a single neuron instance.

pynestml.cocos.co_co_cm_concentration_model module

class pynestml.cocos.co_co_cm_concentration_model.CoCoCmConcentrationModel

Bases: CoCo

classmethod check_co_co(model: ASTModel)

Check if this compartmental condition applies to the handed over neuron. If yes, it checks the presence of expected functions and declarations. :param model: a single neuron instance.

pynestml.cocos.co_co_cm_continuous_input_model module

class pynestml.cocos.co_co_cm_continuous_input_model.CoCoCmContinuousInputModel

Bases: CoCo

classmethod check_co_co(neuron: ASTModel)

Checks if this compartmental condition applies to the handed over neuron. If yes, it checks the presence of expected functions and declarations. :param neuron: a single neuron instance. :type neuron: ast_neuron

pynestml.cocos.co_co_cm_synapse_model module

class pynestml.cocos.co_co_cm_synapse_model.CoCoCmSynapseModel

Bases: CoCo

classmethod check_co_co(model: ASTModel)

Checks if this compartmental condition applies to the handed over neuron. If yes, it checks the presence of expected functions and declarations. :param model: a single neuron instance.

pynestml.cocos.co_co_convolve_cond_correctly_built module

class pynestml.cocos.co_co_convolve_cond_correctly_built.CoCoConvolveCondCorrectlyBuilt

Bases: CoCo

This coco ensures that convolve is correctly called, i.e. that the first argument is the variable from the state block and the second argument is a spiking input port.

Allowed:

inline I_syn_exc pA = convolve(g_exc, exc_spikes) * ( V_m - E_exc )

Not allowed:

inline I_syn_exc pA = convolve(g_exc, g_exc) * ( V_m - E_exc ) inline I_syn_exc pA = convolve(exc_spikes, g_exc) * ( V_m - E_exc )

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_convolve_cond_correctly_built.ConvolveCheckerVisitor

Bases: ASTVisitor

Visits a function call and checks that if the function call is a convolve, the parameters are correct.

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

pynestml.cocos.co_co_convolve_has_correct_parameter module

class pynestml.cocos.co_co_convolve_has_correct_parameter.CoCoConvolveHasCorrectParameter

Bases: CoCo

This coco ensures that convolve gets only simple variable references as inputs.

Not allowed:

V mV = convolve(g_in + g_ex, spikes_in)
classmethod check_co_co(model)

Ensures the coco for the handed over model. :param model: a single model instance.

=

class pynestml.cocos.co_co_convolve_has_correct_parameter.ConvolveParametersCorrectVisitor

Bases: ASTVisitor

visit_function_call(node: ASTFunctionCall)

Checks the coco on the current function call. :param node: a single function call.

pynestml.cocos.co_co_correct_numerator_of_unit module

class pynestml.cocos.co_co_correct_numerator_of_unit.CoCoCorrectNumeratorOfUnit

Bases: CoCo

This coco ensures that all units which consist of a dividend and divisor, where the numerator is a numeric value, have 1 as the numerator. Allowed:

V_m 1/mV = …

Not allowed:

V_m 2/mV = …

classmethod check_co_co(model: ASTModel)

Ensures the coco for the handed over neuron. :param model: a single neuron instance.

class pynestml.cocos.co_co_correct_numerator_of_unit.NumericNumeratorVisitor

Bases: ASTVisitor

Visits a numeric numerator and checks if the value is 1.

visit_unit_type(node)

Check if the coco applies, :param node: a single unit type object. :type node: ast_unit_type

pynestml.cocos.co_co_correct_order_in_equation module

class pynestml.cocos.co_co_correct_order_in_equation.CoCoCorrectOrderInEquation

Bases: CoCo

This coco ensures that whenever a ode-equation is assigned to a variable, it have a differential order of at leas one. Allowed:

equations:

V_m’ = …

Not allowed:
equations:

V_m = …

classmethod check_co_co(model: ASTModel)

Ensures the coco for the handed over neuron. :param model: a single neuron instance.

class pynestml.cocos.co_co_correct_order_in_equation.OrderOfEquationVisitor

Bases: ASTVisitor

This visitor checks that all differential equations have a differential order.

visit_ode_equation(node)

Checks the coco. :param node: A single ode equation. :type node: ast_ode_equation

pynestml.cocos.co_co_each_block_defined_at_most_once module

class pynestml.cocos.co_co_each_block_defined_at_most_once.CoCoEachBlockDefinedAtMostOnce

Bases: CoCo

This context condition ensures that each block is defined at most once.

Not allowed:

state:
    ...
...
state:
    ...
classmethod check_co_co(node: ASTModel)

Checks whether each block is define at most once. :param node: a single neuron or synapse.

pynestml.cocos.co_co_emit_spike_function_arguments module

class pynestml.cocos.co_co_emit_spike_function_arguments.CoCoEmitSpikeFunctionArguments

Bases: CoCo

This context condition checker ensures that all calls to the emit_spike() function contain zero or one parameter.

classmethod check_co_co(node: ASTNode)

Checks the coco for the handed over neuron. :param node: a single neuron instance. :type node: ASTModel

class pynestml.cocos.co_co_emit_spike_function_arguments.EmitSpikeFunctionArgumentsVisitor

Bases: ASTVisitor

visit_function_call(node: ASTFunctionCall)

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

pynestml.cocos.co_co_equations_only_for_init_values module

class pynestml.cocos.co_co_equations_only_for_init_values.CoCoEquationsOnlyForInitValues

Bases: CoCo

This coco ensures that ode equations are only provided for variables which have been defined in the state block. Allowed:

Not allowed:

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_equations_only_for_init_values.EquationsOnlyForInitValues

Bases: ASTVisitor

This visitor ensures that for all ode equations exists an initial value in the state block.

visit_ode_equation(node)

Ensures the coco. :param node: a single equation object. :type node: ast_ode_equation

pynestml.cocos.co_co_function_argument_template_types_consistent module

class pynestml.cocos.co_co_function_argument_template_types_consistent.CoCoFunctionArgumentTemplateTypesConsistent

Bases: CoCo

This coco checks that if template types are used for function parameters, the types are mutually consistent.

classmethod check_co_co(neuron)

Ensures the coco for the handed over neuron. :param neuron: a single neuron instance. :type neuron: ASTModel

class pynestml.cocos.co_co_function_argument_template_types_consistent.CorrectTemplatedArgumentTypesVisitor

Bases: ASTVisitor

This visitor checks that all expression correspond to the expected type.

visit_simple_expression(node)

Visits a single function call as stored in a simple expression and, if template types are used for function parameters, checks if all actual parameter types are mutually consistent.

Parameters:

node (ASTSimpleExpression) – a simple expression

Rtype None:

pynestml.cocos.co_co_function_calls_consistent module

class pynestml.cocos.co_co_function_calls_consistent.CoCoFunctionCallsConsistent

Bases: CoCo

This context condition checker ensures that for all function calls in the handed over neuron, if the called function has been declared, whether the number and types of arguments correspond to the declaration, etc.

classmethod check_co_co(node)

Checks the coco for the handed over neuron. :param node: a single neuron instance. :type node: ASTModel

class pynestml.cocos.co_co_function_calls_consistent.FunctionCallConsistencyVisitor

Bases: ASTVisitor

This visitor ensures that all function calls are consistent.

visit_function_call(node)

Check consistency for a single function call: check if the called function has been declared, whether the number and types of arguments correspond to the declaration, etc.

Parameters:

node (ASTFunctionCall) – a single function call.

pynestml.cocos.co_co_function_unique module

class pynestml.cocos.co_co_function_unique.CoCoFunctionUnique

Bases: CoCo

This Coco ensures that each function is defined exactly once (thus no redeclaration occurs).

classmethod check_co_co(model: ASTModel)

Checks if each function is defined uniquely. :param node: a single neuron

pynestml.cocos.co_co_illegal_expression module

class pynestml.cocos.co_co_illegal_expression.CoCoIllegalExpression

Bases: CoCo

This coco checks that all expressions are correctly typed.

classmethod check_co_co(neuron)

Ensures the coco for the handed over neuron. :param neuron: a single neuron instance. :type neuron: ASTModel

class pynestml.cocos.co_co_illegal_expression.CorrectExpressionVisitor

Bases: ASTVisitor

This visitor checks that all expression correspond to the expected type.

handle_compound_assignment(node)
handle_simple_assignment(node)
visit_assignment(node)

Visits a single expression and assures that type(lhs) == type(rhs). :param node: a single assignment. :type node: ASTAssignment

visit_declaration(node)

Visits a single declaration and asserts that type of lhs is equal to type of rhs. :param node: a single declaration. :type node: ASTDeclaration

visit_elif_clause(node)

Visits a single elif clause and checks that its condition is boolean. :param node: a single elif clause. :type node: ASTElifClause

visit_for_stmt(node)

Visits a single for stmt and checks that all it parts are correctly defined. :param node: a single for stmt :type node: ASTForStmt

visit_if_clause(node)

Visits a single if clause and checks that its condition is boolean. :param node: a single elif clause. :type node: ASTIfClause

visit_inline_expression(node)

Visits a single inline expression and asserts that type of lhs is equal to type of rhs.

visit_while_stmt(node)

Visits a single while stmt and checks that its condition is of boolean type. :param node: a single while stmt :type node: ASTWhileStmt

pynestml.cocos.co_co_inline_expression_not_assigned_to module

class pynestml.cocos.co_co_inline_expression_not_assigned_to.CoCoInlineExpressionNotAssignedTo

Bases: CoCo

This coco ensures that no values are assigned to inline expressions.

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_inline_expression_not_assigned_to.NoInlineExpressionAssignedToVisitor

Bases: ASTVisitor

visit_assignment(node)

Used to visit a single assignment. :param node: an assignment object. :type node: ASTAssignment

pynestml.cocos.co_co_inline_expressions_have_rhs module

class pynestml.cocos.co_co_inline_expressions_have_rhs.CoCoInlineExpressionsHaveRhs

Bases: CoCo

This coco ensures that all inline expressions have a rhs.

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_inline_expressions_have_rhs.InlineRhsVisitor

Bases: ASTVisitor

This visitor ensures that everything declared as inline expression has a rhs.

visit_declaration(node: ASTDeclaration)

Checks if the coco applies. :param node: a single declaration.

pynestml.cocos.co_co_inline_max_one_lhs module

class pynestml.cocos.co_co_inline_max_one_lhs.CoCoInlineMaxOneLhs

Bases: CoCo

This coco ensures that whenever an inline expression is declared, only one left-hand side is present. Allowed:

inline V_rest mV = V_m - 55mV

Not allowed:

inline V_reset, V_rest mV = V_m - 55mV

classmethod check_co_co(model: ASTModel)

Ensures the coco for the handed over neuron. :param model: a single model instance.

class pynestml.cocos.co_co_inline_max_one_lhs.InlineMaxOneLhs

Bases: ASTVisitor

This visitor ensures that every inline expression has exactly one lhs.

visit_declaration(node: ASTDeclaration)

Checks the coco. :param node: a single declaration.

pynestml.cocos.co_co_input_port_not_assigned_to module

class pynestml.cocos.co_co_input_port_not_assigned_to.CoCoInputPortNotAssignedTo

Bases: CoCo

This coco ensures that no values are assigned to input ports.

Given:

input:
    current_in pA <- continuous

Allowed:

foo = current_in + 10 pA

Not allowed:

current_in = foo + 10 pA
classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_input_port_not_assigned_to.NoInputPortAssignedToVisitor

Bases: ASTVisitor

visit_assignment(node)

Used to visit a single assignment. :param node: an assignment object. :type node: ASTAssignment

pynestml.cocos.co_co_integrate_odes_called_if_equations_defined module

class pynestml.cocos.co_co_integrate_odes_called_if_equations_defined.CoCoIntegrateOdesCalledIfEquationsDefined

Bases: CoCo

This coco ensures that integrate_odes() is called if one or more dynamical equations are defined.

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single model instance.

class pynestml.cocos.co_co_integrate_odes_called_if_equations_defined.EquationsDefinedVisitor

Bases: ASTVisitor

This visitor checks if equations are defined.

equations_defined() bool
visit_ode_equation(node)

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

class pynestml.cocos.co_co_integrate_odes_called_if_equations_defined.IntegrateOdesCalledVisitor

Bases: ASTVisitor

This visitor checks if integrate_odes() is called.

integrate_odes_called() bool
visit_function_call(node: ASTFunctionCall)

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

pynestml.cocos.co_co_integrate_odes_params_correct module

class pynestml.cocos.co_co_integrate_odes_params_correct.CoCoIntegrateODEsParamsCorrect

Bases: CoCo

This coco ensures that integrate_odes() contains either no parameters or only state variable names as parameters.

classmethod check_co_co(model: ASTModel)

Ensures the coco for the handed over model. :param node: a single model instance.

class pynestml.cocos.co_co_integrate_odes_params_correct.IntegrateODEsCheckerVisitor

Bases: ASTVisitor

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

pynestml.cocos.co_co_internals_assigned_only_in_internals_block module

class pynestml.cocos.co_co_internals_assigned_only_in_internals_block.CoCoInternalsAssignedOnlyInInternalsBlock

Bases: CoCo

This coco checks that no internals are assigned outside the internals block.

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_internals_assigned_only_in_internals_block.InternalsAssignmentVisitor

Bases: ASTVisitor

This visitor checks that no internals have been assigned outside the internals block.

visit_assignment(node: ASTAssignment) None

Checks the coco on the current node. :param node: a single node.

pynestml.cocos.co_co_invariant_is_boolean module

class pynestml.cocos.co_co_invariant_is_boolean.CoCoInvariantIsBoolean

Bases: CoCo

This coco checks that all invariants are of type boolean

classmethod check_co_co(model: ASTModel)

Ensures the coco for the handed over model. :param model: a single model instance.

class pynestml.cocos.co_co_invariant_is_boolean.InvariantTypeVisitor

Bases: ASTVisitor

Checks if for each invariant, the type is boolean.

visit_declaration(node)

Checks the coco for a declaration. :param node: a single declaration. :type node: ASTDeclaration

pynestml.cocos.co_co_kernel_type module

class pynestml.cocos.co_co_kernel_type.CoCoKernelType

Bases: CoCo

Ensures that all defined kernels are untyped (for direct functions of time), or have a type equivalent to 1/s**-order, where order is the differential order of the kernel (e.g. 2 for kernel g'' = ...).

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_kernel_type.KernelTypeVisitor

Bases: ASTVisitor

This visitor checks if each kernel has the appropriate data type.

visit_kernel(node)

Checks the coco on the current node. :param node: AST kernel object :type node: ASTKernel

pynestml.cocos.co_co_model_name_unique module

class pynestml.cocos.co_co_model_name_unique.CoCoModelNameUnique

Bases: CoCo

This coco ensures that for all elements in a single compile units, the names of all models are pairwise distinct. Allowed:

model a:

… model b:

Not allowed:
model a:

… model a: <- model with the same name

classmethod check_co_co(compilation_unit)

Checks the coco for the handed over compilation unit. :param compilation_unit: a single compilation unit. :type compilation_unit: ASTCompilationUnit

pynestml.cocos.co_co_nest_random_functions_legally_used module

class pynestml.cocos.co_co_nest_random_functions_legally_used.CoCoNestRandomFunctionsLegallyUsed

Bases: CoCo

This CoCo ensure that the random functions are used only in the update, onReceive, and onCondition blocks. This CoCo is only checked for the NEST Simulator target.

classmethod check_co_co(node: ASTNode)

Checks the coco. :param node: a single node (typically, a neuron or synapse)

class pynestml.cocos.co_co_nest_random_functions_legally_used.CoCoNestRandomFunctionsLegallyUsedVisitor

Bases: ASTVisitor

visit_function_call(node)

Visits a function call :param node: a function call

pynestml.cocos.co_co_nest_synapse_delay_not_assigned_to module

class pynestml.cocos.co_co_nest_synapse_delay_not_assigned_to.CoCoNESTSynapseDelayNotAssignedTo

Bases: CoCo

This coco checks that the delay variable or parameter is not assigned to inside of a NESTML model. (This could be possible in general, but is not supported for now.)

classmethod check_co_co(delay_variable: str, node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_nest_synapse_delay_not_assigned_to.CoCoNESTSynapseDelayNotAssignedToVisitor

Bases: ASTVisitor

visit_assignment(node: ASTAssignment) None

Checks the coco on the current node. :param node: a single node.

pynestml.cocos.co_co_no_duplicate_compilation_unit_names module

class pynestml.cocos.co_co_no_duplicate_compilation_unit_names.CoCoNoDuplicateCompilationUnitNames

Bases: CoCo

This Coco checks that for a handed over list of compilation units, there are not two units that have the same name.

classmethod check_co_co(list_of_compilation_units)

Checks the coco. :param list_of_compilation_units: a list of compilation units. :type list_of_compilation_units: list(ASTNestMLCompilationUnit)

pynestml.cocos.co_co_no_kernels_except_in_convolve module

class pynestml.cocos.co_co_no_kernels_except_in_convolve.CoCoNoKernelsExceptInConvolve

Bases: CoCo

This CoCo ensures that kernel variables do not occur on the right hand side except in convolve(). Allowed:

kernel g_ex = … function I_syn_exc pA = convolve(g_ex, spikeExc) * ( V_m - E_ex )

Not allowed

kernel g_ex = … function I_syn_exc pA = g_ex * ( V_m - E_ex )

classmethod check_co_co(model: ASTModel)

Ensures the coco for the handed over model. :param node: a single model instance.

class pynestml.cocos.co_co_no_kernels_except_in_convolve.KernelCollectingVisitor

Bases: ASTVisitor

collect_kernels(model: ASTModel) List[str]

Collects all kernels in the model. :param neuron: a single model instance :return: a list of kernels.

visit_kernel(node)

Collects the kernel. :param node: a single kernel node. :type node: ASTKernel

class pynestml.cocos.co_co_no_kernels_except_in_convolve.KernelUsageVisitor(_kernels=None)

Bases: ASTVisitor

visit_variable(node: ASTNode)

Visits each kernel and checks if it is used correctly. :param node: a single node.

work_on(neuron)

pynestml.cocos.co_co_no_nest_name_space_collision module

class pynestml.cocos.co_co_no_nest_name_space_collision.CoCoNoNestNameSpaceCollision

Bases: CoCo

This coco tests that no functions are defined which collide with the nest namespace, which are:

“update”, “calibrate”, “handle”, “connect_sender”, “check_connection”, “get_status”, “set_status”, “init_state_”, “init_buffers_

Allowed:

function fun(…)

Not allowed:

function handle(…) <- collision

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

nest_name_space = ['update', 'calibrate', 'handle', 'connect_sender', 'check_connection', 'get_status', 'set_status', 'init_state_', 'init_buffers_']

pynestml.cocos.co_co_ode_functions_have_consistent_units module

class pynestml.cocos.co_co_ode_functions_have_consistent_units.CoCoOdeFunctionsHaveConsistentUnits

Bases: CoCo

This coco ensures that whenever an ODE function is defined, the physical unit of the left-hand side variable matches that of the right-hand side expression.

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_ode_functions_have_consistent_units.OdeFunctionConsistentUnitsVisitor

Bases: ASTVisitor

visit_ode_function(node)

Checks the coco. :param node: A single ode equation. :type node: ast_ode_equation

pynestml.cocos.co_co_odes_have_consistent_units module

class pynestml.cocos.co_co_odes_have_consistent_units.CoCoOdesHaveConsistentUnits

Bases: CoCo

This coco ensures that whenever an ODE is defined, the physical unit of the left-hand side variable matches that of the right-hand side expression.

classmethod check_co_co(node: ASTModel)

Ensures the coco for the handed over neuron. :param node: a single neuron instance.

class pynestml.cocos.co_co_odes_have_consistent_units.OdeConsistentUnitsVisitor

Bases: ASTVisitor

visit_ode_equation(node)

Checks the coco. :param node: A single ode equation. :type node: ast_ode_equation

pynestml.cocos.co_co_on_receive_vectors_should_be_constant_size module

class pynestml.cocos.co_co_on_receive_vectors_should_be_constant_size.CoCoOnReceiveVectorsShouldBeConstantSize

Bases: CoCo

This CoCo is used to test the usage of onReceive blocks for vector ports of variable length.

classmethod check_co_co(node: ASTModel)

Check the coco.

Parameters:

node – a single ASTNode instance on which the coco will be checked.

class pynestml.cocos.co_co_on_receive_vectors_should_be_constant_size.CoCoOnReceiveVectorsShouldBeConstantSizeVisitor

Bases: ASTVisitor

visit_input_port(node: ASTInputPort)

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

pynestml.cocos.co_co_output_port_defined_if_emit_call module

class pynestml.cocos.co_co_output_port_defined_if_emit_call.CoCoOutputPortDefinedIfEmitCall

Bases: CoCo

This context condition checker ensures that if an event is emitted, a corresponding output port is defined with the appropriate type.

classmethod check_co_co(neuron: ASTModel)

Checks the coco for the handed over neuron. :param neuron: a single neuron instance.

class pynestml.cocos.co_co_output_port_defined_if_emit_call.OutputPortDefinedIfEmitCalledVisitor

Bases: ASTVisitor

This visitor ensures that all function calls are consistent.

neuron: ASTModel | None = None
visit_function_call(node: ASTFunctionCall)

If an emit_spike() function is found, check output block exists and has spike type.

Parameters:

node – a single function call.

pynestml.cocos.co_co_parameters_assigned_only_in_parameter_block module

class pynestml.cocos.co_co_parameters_assigned_only_in_parameter_block.CoCoParametersAssignedOnlyInParameterBlock

Bases: CoCo

This coco checks that no parameters are assigned outside the parameters block. Allowed:

parameters:

par mV = 10mV

Not allowed:
parameters:

par mV = 10mV

… update:

par = 20mV

classmethod check_co_co(node)

Ensures the coco for the handed over neuron. :param node: a single neuron instance. :type node: ASTModel

class pynestml.cocos.co_co_parameters_assigned_only_in_parameter_block.ParametersAssignmentVisitor

Bases: ASTVisitor

This visitor checks that no parameters have been assigned outside the parameters block.

visit_assignment(node: ASTAssignment) None

Checks the coco on the current node. :param node: a single node.

pynestml.cocos.co_co_priorities_correctly_specified module

class pynestml.cocos.co_co_priorities_correctly_specified.CoCoPrioritiesCorrectlySpecified

Bases: CoCo

This Coco ensures that priorities for event handlers are correctly specified.

classmethod check_co_co(node: ASTModel)

Checks the context condition. :param node: a single synapse

pynestml.cocos.co_co_resolution_func_legally_used module

class pynestml.cocos.co_co_resolution_func_legally_used.CoCoResolutionFuncLegallyUsed

Bases: CoCo

This Coco ensures that the predefined resolution() function appears only in the update, parameters, internals, or state block.

classmethod check_co_co(node)

Checks the coco. :param node: a single node (typically, a neuron or synapse)

class pynestml.cocos.co_co_resolution_func_legally_used.CoCoResolutionFuncLegallyUsedVisitor

Bases: ASTVisitor

visit_simple_expression(node)

Visits a single function call

Parameters:

node – a simple expression

pynestml.cocos.co_co_resolution_func_used module

class pynestml.cocos.co_co_resolution_func_used.CoCoResolutionOrStepsFuncUsed

Bases: CoCo

This Coco emits a warning in case the resolution() or steps() predefined function is used.

classmethod check_co_co(model: ASTModel)

Checks the coco. :param model: a single neuron

pynestml.cocos.co_co_simple_delta_function module

class pynestml.cocos.co_co_simple_delta_function.CoCoSimpleDeltaFunction

Bases: CoCo

Check that predefined delta function is only used with single argument t.

classmethod check_co_co(model: ASTModel)

Checks if this coco applies for the handed over neuron.

Parameters:

model – a single model instance.

pynestml.cocos.co_co_spike_input_ports_appear_only_in_equation_rhs_and_event_handlers module

class pynestml.cocos.co_co_spike_input_ports_appear_only_in_equation_rhs_and_event_handlers.CoCoSpikeInputPortsAppearOnlyInEquationRHSAndEventHandlers

Bases: CoCo

This coco ensures that spiking input port names appear only in the right-hand side of equations and in the onReceive block declaration.

classmethod check_co_co(node)

Ensures the coco for the handed over node.

class pynestml.cocos.co_co_spike_input_ports_appear_only_in_equation_rhs_and_event_handlers.SpikeInputPortsAppearOnlyInEquationRHSAndEventHandlersVisitor

Bases: ASTVisitor

visit_variable(node: ASTVariable)

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

pynestml.cocos.co_co_state_variables_initialized module

class pynestml.cocos.co_co_state_variables_initialized.CoCoStateVariablesInitialized

Bases: CoCo

This CoCo ensures that all the variables declared in the state block are initialized with a value.

classmethod check_co_co(node: ASTModel)

Checks if the coco applies for the node. All the variables declared in the state block must be initialized with a value. :param node:

pynestml.cocos.co_co_timestep_function_legally_used module

class pynestml.cocos.co_co_timestep_function_legally_used.CoCoTimestepFuncLegallyUsed

Bases: CoCo

This Coco ensures that the predefined timestep() function appears only in the update.

classmethod check_co_co(node)

Checks the coco. :param node: a single node (typically, a neuron or synapse)

class pynestml.cocos.co_co_timestep_function_legally_used.CoCoTimestepFuncLegallyUsedVisitor

Bases: ASTVisitor

visit_simple_expression(node)

Visits a single function call

Parameters:

node – a simple expression

pynestml.cocos.co_co_user_defined_function_correctly_defined module

class pynestml.cocos.co_co_user_defined_function_correctly_defined.CoCoUserDefinedFunctionCorrectlyDefined

Bases: CoCo

This coco ensures that all user defined functions, which are defined with a type, have a return statement and the type of the return statement is consistent with the declaration. Allowed:

function foo(…) bool:

return True

Not allowed:
function foo(…) bool:

return

__processedFunction

A reference to the currently processed function.

Type:

ast_function

classmethod check_co_co(_node=None)

Checks the coco for the handed over node. :param _node: a single node instance. :type _node: ASTModel

processed_function = None

pynestml.cocos.co_co_v_comp_exists module

class pynestml.cocos.co_co_v_comp_exists.CoCoVCompDefined

Bases: CoCo

This class represents a constraint condition which ensures that variable v_comp has been defined if we have compartmental model case. When we start code generation with NEST_COMPARTMENTAL flag the following must exist:

state:

v_comp real = 0

classmethod check_co_co(neuron: ASTModel)

Checks if this coco applies for the handed over neuron. Models which are supposed to be compartmental but do not contain state variable called v_comp are not correct. :param neuron: a single neuron instance.

classmethod log_error(neuron: ASTModel, error_position, missing_variable_name)

pynestml.cocos.co_co_variable_once_per_scope module

class pynestml.cocos.co_co_variable_once_per_scope.CoCoVariableOncePerScope

Bases: CoCo

This coco ensures that each variables is defined at most once per scope, thus no redeclaration occurs.

classmethod check_co_co(node: ASTModel)

Checks if each variable is defined at most once per scope. Obviously, this test does not check if a declaration is shadowed by an embedded scope. :param node: a single model

pynestml.cocos.co_co_vector_declaration_right_size module

class pynestml.cocos.co_co_vector_declaration_right_size.CoCoVectorDeclarationRightSize

Bases: CoCo

This CoCo checks if the size of the vector during vector declaration is an integer and greater than 0, and that the index into a vector is of type integer and non-negative.

classmethod check_co_co(node: ASTModel)

Check the coco.

Parameters:

node – a single ASTNode instance on which the coco will be checked.

class pynestml.cocos.co_co_vector_declaration_right_size.VectorDeclarationVisitor

Bases: ASTVisitor

This visitor checks if the size of the vector during vector declaration is an integer and greater than 0, and that the index into a vector is of type integer and non-negative.

visit_variable(node: ASTVariable)

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

pynestml.cocos.co_co_vector_input_port_correct_size_type module

class pynestml.cocos.co_co_vector_input_port_correct_size_type.CoCoVectorInputPortsCorrectSizeType

Bases: CoCo

This CoCo checks if the size of the vector input port is of the type integer and its value is greater than 0.

classmethod check_co_co(node: ASTModel)

Check the coco.

Parameters:

node – a single ASTNode instance on which the coco will be checked.

class pynestml.cocos.co_co_vector_input_port_correct_size_type.InputPortsVisitor

Bases: ASTVisitor

This visitor checks if the size of the vector input port is of the type integer and its value is greater than 0

visit_input_port(node: ASTInputPort)

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

pynestml.cocos.co_co_vector_parameter_declared_in_right_block module

class pynestml.cocos.co_co_vector_parameter_declared_in_right_block.CoCoVectorParameterDeclaredInRightBlock

Bases: CoCo

This CoCo ensures that the vector parameter is declared in either the parameters or internals block.

classmethod check_co_co(node: ASTModel)

Check the coco.

Parameters:

node – a single ASTNode instance on which the coco will be checked.

class pynestml.cocos.co_co_vector_parameter_declared_in_right_block.VectorDeclarationVisitor

Bases: ASTVisitor

This visitor ensures that the vector parameter is declared in the right block and has an integer type.

visit_declaration(node: ASTDeclaration)

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

pynestml.cocos.co_co_vector_variable_in_non_vector_declaration module

class pynestml.cocos.co_co_vector_variable_in_non_vector_declaration.CoCoVectorVariableInNonVectorDeclaration

Bases: CoCo

This coco ensures that vector variables are not used in non vector declarations. Not allowed:

function three integer[n] = 3 threePlusFour integer = three + 4 <- error: threePlusFour is not a vector

classmethod check_co_co(node)

Ensures the coco for the handed over node. :param node: a single node instance. :type node: ASTModel

class pynestml.cocos.co_co_vector_variable_in_non_vector_declaration.VectorInDeclarationVisitor

Bases: ASTVisitor

This visitor checks if somewhere in a declaration of a non-vector value, a vector is used.

visit_declaration(node)

Checks the coco. :param node: a single declaration. :type node: ast_declaration

pynestml.cocos.co_cos_manager module

class pynestml.cocos.co_cos_manager.CoCosManager

Bases: object

This class provides a set of context conditions which have to hold for each model instance.

classmethod check_co_co_emit_spike_function_arguments(model: ASTModel)

Checks that all calls to the emit_spike() function contain zero or one parameter. :param model: a single model object.

classmethod check_co_co_nest_random_functions_legally_used(model: ASTModel)

Checks if the random number functions are used only in the update block. :param model: a single model object.

classmethod check_co_co_priorities_correctly_specified(model: ASTModel)
Parameters:

model – a single model object.

classmethod check_cocos(model: ASTModel, after_ast_rewrite: bool = False)

Checks all context conditions. :param model: a single model object.

classmethod check_compartmental_model(neuron: ASTModel) None

collects all relevant information for the different compartmental mechanism classes for later code-generation

searches for inlines or odes with decorator @mechanism::<type> and performs a base and, depending on type, specific information collection process. See nestml documentation on compartmental code generation.

classmethod check_convolve_cond_curr_is_correct(model: ASTModel)

Checks if all convolve rhs are correctly provided with arguments. :param model: a single model object.

classmethod check_convolve_has_correct_parameter(model: ASTModel)

Checks that all convolve function calls have variables as arguments. :param model: a single model object.

classmethod check_correct_usage_of_kernels(model: ASTModel)

Checks if all kernels are only used in convolve. :param model: a single model object.

classmethod check_each_block_defined_at_most_once(node: ASTModel)

Checks if in the handed over model, each block is defined at most once and mandatory blocks are defined. :param node: a single model instance

classmethod check_expression_correct(model: ASTModel)

Checks that all rhs in the model are correctly constructed, e.g. type(lhs)==type(rhs). :param model: a single model

classmethod check_function_argument_template_types_consistent(model: ASTModel)

Checks if no declaration a vector value is added to a non vector one. :param model: a single model object.

classmethod check_function_declared_and_correctly_typed(model: ASTModel)

Checks if in the handed over model all function calls use existing functions and the arguments are correctly typed. :param model: a single model instance

classmethod check_function_defined(model: ASTModel)

Checks for the handed over model that each used function it is defined.

classmethod check_initial_ode_initial_values(model: ASTModel)

Checks if variables of odes are declared in the state block. :param model: a single model object.

classmethod check_inline_expression_not_assigned_to(model: ASTModel)

Checks for the handed over model that inline expressions are not assigned to.

classmethod check_inline_expressions_have_rhs(model: ASTModel)

Checks that all inline expressions have a right-hand side. :param model: a single model object

classmethod check_inline_has_max_one_lhs(model: ASTModel)

Checks that all inline expressions have exactly one left-hand side. :param model: a single model object.

classmethod check_input_port_size_type(model: ASTModel)
Parameters:

model – a single model object

classmethod check_input_ports_appear_only_in_equation_rhs_and_event_handlers(node: ASTModel)

Checks if in the handed over model, each block is defined at most once and mandatory blocks are defined. :param node: a single model instance

classmethod check_input_ports_not_assigned_to(model: ASTModel)

Checks that no values are assigned to input ports. :param model: a single model object.

classmethod check_integrate_odes_called_if_equations_defined(model: ASTModel)

Ensures that integrate_odes() is called if one or more dynamical equations are defined.

classmethod check_integrate_odes_params_correct(model: ASTModel)

Checks if all integrate_odes() calls have correct parameters. :param model: a single model object.

classmethod check_internals_not_assigned_outside_internals_block(model: ASTModel)

Checks that internals are not assigned outside the internals block. :param model: a single model object.

classmethod check_invariant_type_correct(model: ASTModel)

Checks if all invariants are of type boolean. :param model: a single model object.

classmethod check_kernel_type(model: ASTModel) None

Checks that all defined kernels have type real.

classmethod check_model_names_unique(compilation_unit)

Checks that all declared models in a compilation unit have a unique name. :param compilation_unit: a single compilation unit. :type compilation_unit: ASTCompilationUnit

classmethod check_no_duplicate_compilation_unit_names(compilation_units)

Checks if in a set of compilation units, two nodes have the same name. :param compilation_units: a list of compilation units :type compilation_units: list(ASTNestMLCompilationUnit)

classmethod check_no_nest_namespace_collisions(model: ASTModel)

Checks that all units which have a numeric numerator use 1. :param model: a single model object.

classmethod check_numerator_of_unit_is_one_if_numeric(model: ASTModel)

Checks that all units which have a numeric numerator use 1. :param model: a single model object.

classmethod check_ode_functions_have_consistent_units(model: ASTModel)

Checks that all ODE function lhs and rhs have consistent units. :param model: a single model object.

classmethod check_odes_have_consistent_units(model: ASTModel)

Checks that all ODE lhs and rhs have consistent units. :param model: a single model object.

classmethod check_on_receive_vectors_should_be_constant_size(model: ASTModel)
Parameters:

model – a single model object

classmethod check_order_of_equations_correct(model: ASTModel)

Checks that all equations specify the order of the variable. :param model: a single model object.

classmethod check_output_port_defined_if_emit_call(model: ASTModel)

Checks that if emit_spike() function is called, an spiking output port is defined. :param model: a single model object.

classmethod check_parameters_not_assigned_outside_parameters_block(model: ASTModel)

Checks that parameters are not assigned outside the parameters block. :param model: a single model object.

classmethod check_resolution_func_legally_used(model: ASTModel)
Parameters:

model – a single model object.

classmethod check_resolution_func_used(model: ASTModel)

Checks if all invariants are of type boolean. :param model: a single model object.

classmethod check_simple_delta_function(model: ASTModel) None
classmethod check_state_variables_initialized(model: ASTModel)

Checks if all the variables declared in state block are initialized with a value :param model: a single model instance

classmethod check_timestep_func_legally_used(model: ASTModel)
Parameters:

model – a single model object.

classmethod check_user_defined_function_correctly_built(model: ASTModel)

Checks that all user defined functions are correctly constructed, i.e., have a return statement if declared and that the type corresponds to the declared one. :param model: a single model object.

classmethod check_v_comp_requirement(neuron: ASTModel)

In compartmental case, checks if v_comp variable was defined :param neuron: a single neuron object

classmethod check_variables_defined_before_usage(model: ASTModel) None

Checks that all variables are defined before being used. :param model: a single model.

classmethod check_variables_unique_in_scope(model: ASTModel)

Checks that all variables have been declared at most once per scope. :param model: a single model instance

classmethod check_vector_declaration_size(model: ASTModel)

Checks if the vector is declared with a size greater than 0 :param model: a single model object

classmethod check_vector_in_non_vector_declaration_detected(model: ASTModel)

Checks if no declaration a vector value is added to a non vector one. :param model: a single model object.

classmethod check_vector_parameter_declaration(model: ASTModel)

Checks if the vector parameter is declared in the right block :param model: a single model object