pynestml.transformers package

Submodules

pynestml.transformers.illegal_variable_name_transformer module

class pynestml.transformers.illegal_variable_name_transformer.IllegalVariableNameTransformer(options: Mapping[str, Any] | None = None)

Bases: Transformer

Perform a model transformation step, for instance, rewriting disallowed variable names like “lambda” because it conflicts with a keyword.

class VariableNameRewriterVisitor(forbidden_names: List[str], fix_name_func: Callable[[str], str])

Bases: ASTVisitor

fix_name_func_: Callable[[str], str]
forbidden_names_: List[str]
visit_assignment(node)

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

visit_declaration(node)

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

visit_expression(node)

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

visit_ode_equation(node)

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

visit_simple_expression(node)

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

fix_name_append_underscores_(name: str) str
fix_name_func_: Callable[[str], str]
rewritten_names_: List[Tuple[str, str]]
transform(models: ASTNode | Sequence[ASTNode]) ASTNode | Sequence[ASTNode]

pynestml.transformers.inline_expression_expansion_transformer module

class pynestml.transformers.inline_expression_expansion_transformer.InlineExpressionExpansionTransformer(options: Mapping[str, Any] | None = None)

Bases: Transformer

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

Additionally, replace variable symbols referencing inline expressions in defining expressions of ODEs with the corresponding defining expressions from the inline expressions.

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.

Parameters:

inline_expressions – A sorted list with entries ASTInlineExpression.

Returns:

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

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

Replace variable symbols referencing inline expressions in defining expressions of ODEs with the corresponding defining expressions from the 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).

transform(models: ASTNode | Sequence[ASTNode]) ASTNode | Sequence[ASTNode]

pynestml.transformers.synapse_post_neuron_transformer module

class pynestml.transformers.synapse_post_neuron_transformer.SynapsePostNeuronTransformer(options: Mapping[str, Any] | None = None)

Bases: Transformer

In a (pre neuron, synapse, post neuron) tuple, process (synapse, post_neuron) to move all variables that are only triggered by postsynaptic events to the postsynaptic neuron.

get_all_variables_assigned_to(node)

Return a list of all variables that are assigned to in node.

get_convolve_with_not_post_vars(nodes: ASTEquationsBlock | Sequence[ASTEquationsBlock], neuron_name: str, synapse_name: str, parent_node: ASTNode)
get_neuron_var_name_from_syn_port_name(port_name: str, neuron_name: str, synapse_name: str) str | None

Check if a port by the given name is specified as connecting to the postsynaptic neuron. Only makes sense for synapses.

get_post_port_names(synapse, neuron_name: str, synapse_name: str)
get_spiking_post_port_names(synapse, neuron_name: str, synapse_name: str)
get_vt_port_names(synapse, neuron_name: str, synapse_name: str)
is_continuous_port(port_name: str, parent_node: ASTModel)
is_post_port(port_name: str, neuron_name: str, synapse_name: str) bool
is_special_port(special_type: str, port_name: str, neuron_name: str, synapse_name: str) bool

Check if a port by the given name is specified as connecting to the postsynaptic neuron. Only makes sense for synapses.

is_vt_port(port_name: str, neuron_name: str, synapse_name: str) bool
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.

transform(models: ASTNode | Sequence[ASTNode]) ASTNode | Sequence[ASTNode]
transform_neuron_synapse_pair_(neuron: ASTModel, synapse: ASTModel)

“Co-generation” or in-tandem generation of neuron and synapse code.

Does not modify existing neurons or synapses, but returns lists with additional elements representing new pair neuron and synapse

pynestml.transformers.synapse_remove_post_port module

class pynestml.transformers.synapse_remove_post_port.SynapseRemovePostPortTransformer(options: Mapping[str, Any] | None = None)

Bases: Transformer

get_post_port_names(synapse, neuron_name: str, synapse_name: str)
get_spiking_post_port_names(synapse, neuron_name: str, synapse_name: str)
get_vt_port_names(synapse, neuron_name: str, synapse_name: str)
is_post_port(port_name: str, neuron_name: str, synapse_name: str) bool
is_special_port(special_type: str, port_name: str, neuron_name: str, synapse_name: str) bool

Check if a port by the given name is specified as connecting to the postsynaptic neuron. Only makes sense for synapses.

is_vt_port(port_name: str, neuron_name: str, synapse_name: str) bool
transform(models: ASTNode | Sequence[ASTNode]) ASTNode | Sequence[ASTNode]
transform_neuron_synapse_pair_(neuron, synapse)

pynestml.transformers.transformer module

class pynestml.transformers.transformer.Transformer(options: Mapping[str, Any] | None = None)

Bases: WithOptions

Perform a transformation step on models, for instance, rewriting disallowed variable names like “lambda” because it conflicts with a keyword.

Some transformers operate on individual models, and some operate on tuples of models (for instance, a pair (neuron, synapse)).

abstract transform(model: ASTNode | Sequence[ASTNode]) ASTNode | Sequence[ASTNode]