Download Example - Read the Docs

Transcript
Brian Documentation, Release 1.4.1
11.4.1 Namespace construction
The namespaces are stored in eq._namespace. Each equation (string) has a specific namespace.
Proposition for a simplification: there could be just one namespace per Equation object rather than per string. Possible
conflicts would be dealt with when equations are added (with prefix as when inserting static variables, see below).
Variable substitution
These are simply string substitutions.
• Equation(‘dv/dt=-v/tau:volt’,tau=’taum’)
The name of the variable (tau) is changed in the string to taum.
• Equation(‘dv/dt=-v/tau:volt’,tau=None)
The name of the variable (tau) is changed in the string to a unique identifier.
Explicit namespace
• Equation(‘dv/dt=-v/tau:volt’,tau=2*ms)
The namespace is explicitly given: {‘tau’:2*ms}. In this case, Brian does not try to build a namespace “magically”,
so the namespace must be exhaustive. Units need not be passed.
Implicit namespace
• Equation(‘dv/dt=-v/tau:volt’)
The namespace is built from the globals and locals in the caller’s frame. For each identifier in the string, the name is
looked up in: 1) locals of caller, 2) globals of caller, 3) globals of equations.py module (typically units). Identifiers
can be any Python object (for example functions).
Issues
• Special variables (xi and t) are not taken into account at this stage, i.e., they are integrated in the namespace
if present. This should probably be fixed and a warning should be raised. A warning is raised for t at the
preparation stage (see below).
• If identifiers are not found, then no error is raised. This is to allow equations to be built in several pieces, which
is useful in particular for library objects.
• If an identifier is found whose name is the same as the name of a variable, then no error is raised here and it is
included in the namespace. This is difficult to avoid in the case when equations are built in several pieces (e.g.
the conflict appears only when the pieces are put together). A warning is issued at the preparation stage (see
below).
11.4.2 Attributes after initialisation
After initialisation, an Equation object contains:
• a namespace (_namespace)
• a dictionary of units for all variables (_units)
11.4. Equations
355