| 1 |
Namespaces |
| 2 |
========== |
| 3 |
|
| 4 |
`Equations` can contain references to |
| 5 |
external parameters or functions. During the initialisation of a `NeuronGroup` |
| 6 |
or a `Synapses` object, this *namespace* can be provided as an argument. This |
| 7 |
is a group-specific namespace that will only be used for names in the context |
| 8 |
of the respective group. Note that units and a set of standard functions are |
| 9 |
always provided and should not be given explicitly. |
| 10 |
This namespace does not necessarily need to be exhaustive at the time of the |
| 11 |
creation of the `NeuronGroup`/`Synapses`, entries can be added (or modified) |
| 12 |
at a later stage via the `namespace` attribute (e.g. |
| 13 |
``G.namespace['tau'] = 10*ms``). |
| 14 |
|
| 15 |
At the point of the call to the `Network.run` namespace, any group-specific |
| 16 |
namespace will be augmented by the "run namespace". This namespace can be |
| 17 |
either given explicitly as an argument to the `~Network.run` method or it will |
| 18 |
be taken from the locals and globals surrounding the call. A warning will be |
| 19 |
emitted if a name is defined in more than one namespace. |
| 20 |
|
| 21 |
To summarize: an external identifier will be looked up in the context of an |
| 22 |
object such as `NeuronGroup` or `Synapses`. It will follow the following |
| 23 |
resolution hierarchy: |
| 24 |
|
| 25 |
1. Default unit and function names. |
| 26 |
2. Names defined in the explicit group-specific namespace. |
| 27 |
3. Names in the run namespace which is either explicitly given or the implicit |
| 28 |
namespace surrounding the run call. |
| 29 |
|
| 30 |
Note that if you completely specify your namespaces at the `Group` level, you |
| 31 |
should probably pass an empty dictionary as the namespace argument to the |
| 32 |
`~Network.run` call -- this will completely switch off the "implicit namespace" |
| 33 |
mechanism. |
| 34 |
|
| 35 |
The following three examples show the different ways of providing external |
| 36 |
variable values, all having the same effect in this case:: |
| 37 |
|
| 38 |
# Explicit argument to the NeuronGroup |
| 39 |
G = NeuronGroup(1, 'dv/dt = -v / tau : 1', namespace={'tau': 10*ms}) |
| 40 |
net = Network(G) |
| 41 |
net.run(10*ms) |
| 42 |
|
| 43 |
# Explicit argument to the run function |
| 44 |
G = NeuronGroup(1, 'dv/dt = -v / tau : 1') |
| 45 |
net = Network(G) |
| 46 |
net.run(10*ms, namespace={'tau': 10*ms}) |
| 47 |
|
| 48 |
# Implicit namespace from the context |
| 49 |
G = NeuronGroup(1, 'dv/dt = -v / tau : 1') |
| 50 |
net = Network(G) |
| 51 |
tau = 10*ms |
| 52 |
net.run(10*ms) |
| 53 |
|
| 54 |
External variables are free to change between runs (but not during one run), |
| 55 |
the value at the time of the `run` call is used in the simulation. |