MagicNetwork class

(Shortest import: from brian2 import MagicNetwork)

class brian2.core.magic.MagicNetwork[source]

Bases: brian2.core.network.Network

Network that automatically adds all Brian objects

In order to avoid bugs, this class will occasionally raise MagicError when the intent of the user is not clear. See the notes below for 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 a Network object and call Network.run() explicitly.

Note that this class cannot be instantiated by the user, there can be only one instance magic_network of MagicNetwork.

Notes

All Brian objects that are visible at the point of the run() call will be included in the network. This class is designed to work in the following two major use cases:

  1. You create a collection of Brian objects, and call run() to run the simulation. Subsequently, you may call run() again to run it again for a further duration. In this case, the Network.t time will start at 0 and for the second call to run() will continue from the end of the previous run.
  2. You have a loop in which at each iteration, you create some Brian objects and run a simulation using them. In this case, time is reset to 0 for each call to run().

In any other case, you will have to explicitly create a Network object yourself and call Network.run() on this object. Brian has a built in system to guess which of the cases above applies and behave correctly. When it is not possible to safely guess which case you are in, it raises MagicError. The rules for this guessing system are explained below.

If a simulation consists only of objects that have not been run, it will assume that you want to start a new simulation. If a simulation only consists of objects that have been simulated in the previous run() call, it will continue that simulation at the previous time.

If neither of these two situations apply, i.e., the network consists of a mix of previously run objects and new objects, an error will be raised.

In these checks, “non-invalidating” objects (i.e. objects that have BrianObject.invalidates_magic_network set to False) are ignored, e.g. creating new monitors is always possible.

Methods

add(*objs) You cannot add objects directly to MagicNetwork
after_run()
check_dependencies()
get_states([units, format, subexpressions, …]) See Network.get_states().
remove(*objs) You cannot remove objects directly from MagicNetwork
restore([name, filename, level]) See Network.store().
run(duration[, report, report_period, …])
set_states(values[, units, format, level]) See Network.set_states().
store([name, filename, level]) See Network.store().

Details

add(*objs)[source]

You cannot add objects directly to MagicNetwork

after_run()[source]
check_dependencies()[source]
get_states(units=True, format='dict', subexpressions=False, level=0)[source]

See Network.get_states().

remove(*objs)[source]

You cannot remove objects directly from MagicNetwork

restore(name='default', filename=None, level=0)[source]

See Network.store().

run(duration, report=None, report_period=10. * second, namespace=None, profile=False, level=0)[source]
set_states(values, units=True, format='dict', level=0)[source]

See Network.set_states().

store(name='default', filename=None, level=0)[source]

See Network.store().