File: equations_namespaces.rst

package info (click to toggle)
brian 2.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,872 kB
  • sloc: python: 51,820; cpp: 2,033; makefile: 108; sh: 72
file content (36 lines) | stat: -rw-r--r-- 1,682 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Equations and namespaces
========================

Equation parsing
----------------
Parsing is done via `pyparsing`_, for now find the grammar at the top of the
`brian2.equations.equations` file.

.. _pyparsing: https://pythonhosted.org/pyparsing/pyparsing-module.html

Variables
----------
Each Brian object that saves state variables (e.g. `NeuronGroup`, `Synapses`,
`StateMonitor`) has a ``variables`` attribute, a dictionary mapping variable
names to `Variable` objects (in fact a `Variables` object, not a simple
dictionary). `Variable` objects contain information *about*
the variable (name, dtype, units) as well as access to the variable's value via
a ``get_value`` method. Some will also allow setting the values via a
corresponding ``set_value`` method. These objects can therefore act as proxies
to the variables' "contents".

`Variable` objects provide the "abstract namespace" corresponding to a chunk
of "abstract code", they are all that is needed to check for syntactic
correctness, unit consistency, etc.

Namespaces
----------
The `namespace` attribute of a group can contain information about the external
(variable or function) names used in the equations. It specifies a
group-specific namespace used for resolving names in that group. At run time,
this namespace is combined with a "run namespace". This namespace is either
explicitly provided to the `Network.run` method, or the implicit namespace
consisting of the locals and globals around the point where the run function is
called is used. This namespace is then passed down to all the objects via
`Network.before_fun` which calls all the individual `BrianObject.before_run`
methods with this namespace.