analyse_identifiers function

(Shortest import: from brian2.codegen.translation import analyse_identifiers)

brian2.codegen.translation.analyse_identifiers(code, variables, recursive=False)[source]

Analyses a code string (sequence of statements) to find all identifiers by type.

In a given code block, some variable names (identifiers) must be given as inputs to the code block, and some are created by the code block. For example, the line:

a = b+c

This could mean to create a new variable a from b and c, or it could mean modify the existing value of a from b or c, depending on whether a was previously known.

Parameters:

code : str

The code string, a sequence of statements one per line.

variables : dict of Variable, set of names

Specifiers for the model variables or a set of known names

recursive : bool, optional

Whether to recurse down into subexpressions (defaults to False).

Returns:

newly_defined : set

A set of variables that are created by the code block.

used_known : set

A set of variables that are used and already known, a subset of the known parameter.

unknown : set

A set of variables which are used by the code block but not defined by it and not previously known. Should correspond to variables in the external namespace.