File: simulation.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (86 lines) | stat: -rw-r--r-- 3,740 bytes parent folder | download | duplicates (2)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
.. currentmodule:: brian

.. index::
	pair: simulation; control

Simulation control
==================

.. index::
	single: simulation; update schedule

The update schedule
-------------------
When a simulation is run, the operations are done in the following order by default:

#. Update every :class:`NeuronGroup`, this typically performs an integration time step for the differential equations defining the neuron model.
#. Check the threshold condition and propagate the spikes to the target neurons.
#. Update every :class:`Synapses`, this may include updating the state of targeted :class:`NeuronGroup` objects
#. Reset all neurons that spiked.
#. Call all user-defined operations and state monitors.

The user-defined operations and state monitors can be placed at other places in this schedule, by
using the keyword ``when``. The values can be ``start``, ``before_groups``, ``after_groups``,
``middle``, ``before_connections``, ``after_connections``, ``before_resets``, ``after_resets`` or
``end`` (default: end). For example, to call a function ``f`` at the beginning of every timestep::

  @network_operation(when='start')
  def f():
    do_something()
    
or to record the value of a state variable just before the resets::

  M=StateMonitor(group,'x',record=True,when='before_resets')
  
Basic simulation control
------------------------
The simulation is run simply as follows::

  run(1000*ms)
  
where 1000 ms is the duration of the run. It can be stopped during the simulation with the instruction
:func:`stop`, and the network can be reinitialised with the instruction :func:`reinit`.
The :func:`run` function also has some options for reporting the progress of the
simulation as it runs, for example this will print out the elapsed time,
percentage of the simulation this is complete, and an estimate of the
remaining time every 10s::

	run(100*second, report='text')

When the :func:`run` function is called, Brian looks for all relevant
objects in the namespace (groups, connections, monitors, user operations), and runs them.
In complex scripts, the user might want to run only selected objects. In that
case, there are two options. The first is to create a :class:`Network` object
(see next section). The second is to use the :func:`forget` function on objects
you want to exclude from being used. These can then be later added back using
the :func:`recall` function.

Users of ``ipython`` may also want to make use of the :func:`clear` function which removes all Brian objects
and deletes their data. This is useful because ``ipython`` keeps persistent references to these objects
which stops memory from being freed.

The Network class
-----------------
A :class:`Network` object holds a collection of objets that can be run, i.e., objects with class :class:`NeuronGroup`,
:class:`Connection`, :class:`SpikeMonitor`, :class:`StateMonitor` (or subclasses) or any user-defined operation with the decorator
:func:`network_operation`. Thoses objects can then be simulated. Example::

  G = NeuronGroup(...)
  C = Connection(...)
  net = Network(G,C)
  net.run(1*second)

You can also pass lists of objects. The simulation can be controlled with the methods
``stop`` and ``reinit``.

The :class:`MagicNetwork` object
--------------------------------

When :func:`run`, :func:`reinit` and :func:`stop` are called, they act on the "magic network" (the network
consisting of all relevant objects such as groups, connections, monitors and user operations). This "magic
network" can be explicitly constructed using the :class:`MagicNetwork` object::

  G = NeuronGroup(...)
  C = Connection(...)
  net = MagicNetwork()
  net.run(1*second)