Network class
(Shortest import: from brian2 import Network)
-
class
brian2.core.network.
Network
(*objs, name='network*')[source] Bases:
brian2.core.names.Nameable
The main simulation controller in Brian
Network
handles the running of a simulation. It contains a set of Brian objects that are added withadd
. Therun
method actually runs the simulation. The main run loop, determining which objects get called in what order is described in detail in the notes below. The objects in theNetwork
are accesible via their names, e.g.net['neurongroup']
would return theNeuronGroup
with this name.Attributes
_stored_state
Stored state of objects (store/restore) objects
The set of objects in the Network, should not normally be modified directly. profiling_info
The time spent in executing the various CodeObject
s.schedule
List of when
slots in the order they will be updated, can be modified.sorted_objects
The sorted objects of this network in the order defined by the schedule. t
Current simulation time in seconds ( Quantity
)t_
Current time as a float Methods
add
(*objs)Add objects to the Network
after_run
()before_run
(namespace)Prepares the Network
for a run.check_dependencies
()get_profiling_info
()The only reason this is not directly implemented in profiling_info
is to allow devices (e.g.get_states
([units, format, subexpressions, …])Return a copy of the current state variable values of objects in the network.. remove
(*objs)Remove an object or sequence of objects from a Network
.restore
([name, filename, restore_random_state])Retore the state of the network and all included objects. run
(duration[, report, report_period, …])Runs the simulation for the given duration. scheduling_summary
()Return a SchedulingSummary
object, representing the scheduling information for all objects included in the network.set_states
(values[, units, format, level])Set the state variables of objects in the network. stop
()Stops the network from running, this is reset the next time Network.run
is called.store
([name, filename])Store the state of the network and all included objects. Details
-
_stored_state
Stored state of objects (store/restore)
-
objects
The set of objects in the Network, should not normally be modified directly. Note that in a
MagicNetwork
, this attribute only contains the objects during a run: it is filled inbefore_run
and emptied inafter_run
-
profiling_info
The time spent in executing the various
CodeObject
s.A list of
(name, time)
tuples, containing the name of theCodeObject
and the total execution time for simulations of this object (as aQuantity
with unitsecond
). The list is sorted descending with execution time.Profiling has to be activated using the
profile
keyword inrun()
orNetwork.run
.
-
schedule
List of
when
slots in the order they will be updated, can be modified.See notes on scheduling in
Network
. Note that additionalwhen
slots can be added, but the schedule should contain at least all of the names in the default schedule:['start', 'groups', 'thresholds', 'synapses', 'resets', 'end']
.The schedule can also be set to
None
, resetting it to the default schedule set by the core.network.default_schedule preference.
-
sorted_objects
The sorted objects of this network in the order defined by the schedule.
Objects are sorted first by their
when
attribute, and secondly by theorder
attribute. The order of thewhen
attribute is defined by theschedule
. In addition to the slot names defined in the schedule, automatic slot names starting withbefore_
andafter_
can be used (e.g. the slots['groups', 'thresholds']
allow to use['before_groups', 'groups', 'after_groups', 'before_thresholds', 'thresholds', 'after_thresholds']
).Final ties are resolved using the objects’ names, leading to an arbitrary but deterministic sorting.
-
t_
Current time as a float
-
before_run
(namespace)[source] Prepares the
Network
for a run.Objects in the
Network
are sorted into the correct running order, and theirBrianObject.before_run
methods are called.
-
get_profiling_info
()[source] The only reason this is not directly implemented in
profiling_info
is to allow devices (e.g.CPPStandaloneDevice
) to overwrite this.
-
get_states
(units=True, format='dict', subexpressions=False, read_only_variables=True, level=0)[source] Return a copy of the current state variable values of objects in the network.. The returned arrays are copies of the actual arrays that store the state variable values, therefore changing the values in the returned dictionary will not affect the state variables.
-
restore
(name='default', filename=None, restore_random_state=False)[source] Retore the state of the network and all included objects.
-
run
(duration, report=None, report_period=60*second, namespace=None, level=0) Runs the simulation for the given duration.
-
scheduling_summary
()[source] Return a
SchedulingSummary
object, representing the scheduling information for all objects included in the network.
-
set_states
(values, units=True, format='dict', level=0)[source] Set the state variables of objects in the network.
-
stop
()[source] Stops the network from running, this is reset the next time
Network.run
is called.
-