Network class

(Shortest import: from brian2 import Network)

class brian2.core.network.Network(*objs, name='network*')[source]

Bases: Nameable

The main simulation controller in Brian

Network handles the running of a simulation. It contains a set of Brian objects that are added with add. The run 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 the Network are accesible via their names, e.g. net['neurongroup'] would return the NeuronGroup 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. CPPStandaloneDevice) to overwrite this.

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 in before_run and emptied in after_run

profiling_info

The time spent in executing the various CodeObject s.

A list of (name, time) tuples, containing the name of the CodeObject and the total execution time for simulations of this object (as a Quantity with unit second). The list is sorted descending with execution time.

Profiling has to be activated using the profile keyword in run() or Network.run.

schedule

List of when slots in the order they will be updated, can be modified.

See notes on scheduling in Network. Note that additional when 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 the order attribute. The order of the when attribute is defined by the schedule. In addition to the slot names defined in the schedule, automatic slot names starting with before_ and after_ 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 simulation time in seconds (Quantity)

t_

Current time as a float

add(*objs)[source]

Add objects to the Network

after_run()[source]
before_run(namespace)[source]

Prepares the Network for a run.

Objects in the Network are sorted into the correct running order, and their BrianObject.before_run methods are called.

check_dependencies()[source]
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.

remove(*objs)[source]

Remove an object or sequence of objects from a Network.

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.

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

Store the state of the network and all included objects.