The update schedule¶
When a simulation is run, the operations are done in the following order by default:
- Update every
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
Synapses, this may include updating the state of targeted
- 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
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:
Basic simulation control¶
The simulation is run simply as follows:
where 1000 ms is the duration of the run. It can be stopped during the simulation with the instruction
stop(), and the network can be reinitialised with the instruction
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() 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
(see next section). The second is to use the
forget() function on objects
you want to exclude from being used. These can then be later added back using
ipython may also want to make use of the
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¶
Network object holds a collection of objets that can be run, i.e., objects with class
StateMonitor (or subclasses) or any user-defined operation with the decorator
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() 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
G = NeuronGroup(...) C = Connection(...) net = MagicNetwork() net.run(1*second)