run function¶
(Shortest import: from brian2 import run)
- brian2.core.magic.run(duration, report=None, report_period=10 * second, namespace=None, level=0)[source]¶
Runs a simulation with all “visible” Brian objects for the given duration. Calls
collect()to gather all the objects, the simulation can be stopped by calling the globalstop()function.In order to avoid bugs, this function will occasionally raise
MagicErrorwhen the intent of the user is not clear. See the notes toMagicNetworkfor more details on this point. If you persistently see this error, then Brian is not able to safely guess what you intend to do, and you should use aNetworkobject and callNetwork.runexplicitly.- Parameters
duration :
QuantityThe amount of simulation time to run for. If the network consists of new objects since the last time
run()was called, the start time will be reset to 0. Ifrun()is called twice or more without changing the set of objects, the second and subsequent runs will start from the end time of the previous run. To explicitly reset the time to 0, domagic_network.t = 0*second.report : {None, ‘text’, ‘stdout’, ‘stderr’, function}, optional
How to report the progress of the simulation. If
None, do not report progress. If'text'or'stdout'is specified, print the progress to stdout. If'stderr'is specified, print the progress to stderr. Alternatively, you can specify a callbackcallable(elapsed, completed, start, duration)which will be passed the amount of time elapsed as aQuantity, the fractioncompletedfrom 0.0 to 1.0, thestarttime of the simulation as aQuantityand the total duration of the simulation (in biological time) as aQuantity. The function will always be called at the beginning and the end (i.e. for fractions 0.0 and 1.0), regardless of thereport_period.report_period :
QuantityHow frequently (in real time) to report progress.
profile : bool, optional
Whether to record profiling information (see
Network.profiling_info). Defaults toNone(which will use the value set byset_device, if any).namespace : dict-like, optional
A namespace in which objects which do not define their own namespace will be run. If not namespace is given, the locals and globals around the run function will be used.
level : int, optional
How deep to go down the stack frame to look for the locals/global (see
namespaceargument). Only necessary under particular circumstances, e.g. when calling the run function as part of a function call or lambda expression. This is used in tests, e.g.:assert_raises(MagicError, lambda: run(1*ms, level=3)).
Raises
MagicErrorError raised when it was not possible for Brian to safely guess the intended use. See
MagicNetworkfor more details.
See also