| 1 |
Equations and namespaces |
| 2 |
======================== |
| 3 |
|
| 4 |
Equation parsing |
| 5 |
---------------- |
| 6 |
Parsing is done via `pyparsing`_, for now find the grammar at the top of the |
| 7 |
`brian2.equations.equations` file. |
| 8 |
|
| 9 |
.. _pyparsing: https://pythonhosted.org/pyparsing/pyparsing-module.html |
| 10 |
|
| 11 |
Variables |
| 12 |
---------- |
| 13 |
Each Brian object that saves state variables (e.g. `NeuronGroup`, `Synapses`, |
| 14 |
`StateMonitor`) has a ``variables`` attribute, a dictionary mapping variable |
| 15 |
names to `Variable` objects (in fact a `Variables` object, not a simple |
| 16 |
dictionary). `Variable` objects contain information *about* |
| 17 |
the variable (name, dtype, units) as well as access to the variable's value via |
| 18 |
a ``get_value`` method. Some will also allow setting the values via a |
| 19 |
corresponding ``set_value`` method. These objects can therefore act as proxies |
| 20 |
to the variables' "contents". |
| 21 |
|
| 22 |
`Variable` objects provide the "abstract namespace" corresponding to a chunk |
| 23 |
of "abstract code", they are all that is needed to check for syntactic |
| 24 |
correctness, unit consistency, etc. |
| 25 |
|
| 26 |
Namespaces |
| 27 |
---------- |
| 28 |
The `namespace` attribute of a group can contain information about the external |
| 29 |
(variable or function) names used in the equations. It specifies a |
| 30 |
group-specific namespace used for resolving names in that group. At run time, |
| 31 |
this namespace is combined with a "run namespace". This namespace is either |
| 32 |
explicitly provided to the `Network.run` method, or the implicit namespace |
| 33 |
consisting of the locals and globals around the point where the run function is |
| 34 |
called is used. This namespace is then passed down to all the objects via |
| 35 |
`Network.before_fun` which calls all the individual `BrianObject.before_run` |
| 36 |
methods with this namespace. |