network_operation function

(Shortest import: from brian2 import network_operation)


Decorator to make a function get called every time step of a simulation.

The function being decorated should either have no arguments, or a single argument which will be called with the current time t.


dt : Quantity, optional

The time step to be used for the simulation. Cannot be combined with the clock argument.

clock : Clock, optional

The update clock to be used. If neither a clock, nor the dt argument is specified, the defaultclock will be used.

when : str, optional

In which scheduling slot to execute the operation during a time step. Defaults to 'start'.

order : int, optional

The priority of this operation for operations occurring at the same time step and in the same scheduling slot. Defaults to 0.


Converts the function into a NetworkOperation.

If using the form:

def f():

Then the arguments to network_operation must be keyword arguments.


Print something each time step: >>> from brian2 import * >>> @network_operation … def f(): … print(‘something’) … >>> net = Network(f)

Print the time each time step:

>>> @network_operation
... def f(t):
...   print('The time is', t)
>>> net = Network(f)

Specify a dt, etc.:

>>> @network_operation(dt=0.5*ms, when='end')
... def f():
...   print('This will happen at the end of each timestep.')
>>> net = Network(f)