# BrianObject class

(Shortest import: `from brian2 import BrianObject)`

class brian2.core.base.BrianObject(*args, **kw)

  Bases: `Nameable`

  All Brian objects derive from this class, defines magic tracking and update.

  See the documentation for `Network` for an explanation of which objects get updated in which order.

  Parameters:

    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 simulate the object during a time step. Defaults to `'start'`. See Scheduling for possible values.

    order : int, optional

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

    namespace: dict, optional :

    > A dictionary mapping identifier names to objects. If not given, the namespace will be filled in at the time of the call of `Network.run`, with either the values from the `namespace` argument of the `Network.run` method or from the local context, if no such argument is given.

    name : str, optional

    > A unique name for the object - one will be assigned automatically if not provided (of the form `brianobject_1`, etc.).

    Notes :

    —– :

    The set of all `BrianObject` objects is stored in ``BrianObject.__instances__()``. :

  Attributes

  `_clock` | The clock used for simulating this object
  `_creation_stack` | A string indicating where this object was created (traceback with any parts of Brian code removed)
  `_network` | Used to remember the `Network` in which this object has been included before, to raise an error if it is included in a new `Network`
  `_scope_current_key` | Global key value for ipython cell restrict magic
  `_scope_key` | The scope key is used to determine which objects are collected by magic
  `active` | Whether or not the object should be run.
  `add_to_magic_network` | Whether or not the object should be added to a `MagicNetwork`.
  `clock` | The `Clock` determining when the object should be updated.
  `code_objects` | The list of `CodeObject` contained within the `BrianObject`.
  `contained_objects` | The list of objects contained within the `BrianObject`.
  `invalidates_magic_network` | Whether or not `MagicNetwork` is invalidated when a new `BrianObject` of this type is added
  `name` | The unique name for this object.
  `namespace` | The group-specific namespace
  `order` | The order in which objects with the same clock and `when` should be updated
  `updaters` | The list of `Updater` that define the runtime behaviour of this object.
  `when` | The ID string determining when the object should be updated in `Network.run`.

  Methods

  `add_dependency`(obj) | Add an object to the list of dependencies.
  `after_run`() | Optional method to do work after a run is finished.
  `before_run`(run_namespace) | Optional method to prepare the object before a run.
  `run`() |

  Details

  _clock

    The clock used for simulating this object

  _creation_stack

    A string indicating where this object was created (traceback with any parts of Brian code removed)

  _network

    Used to remember the `Network` in which this object has been included before, to raise an error if it is included in a new `Network`

  _scope_current_key

    Global key value for ipython cell restrict magic

  _scope_key

    The scope key is used to determine which objects are collected by magic

  active

    Whether or not the object should be run.

    Inactive objects will not have their `update` method called in `Network.run`. Note that setting or unsetting the `active` attribute will set or unset it for all `contained_objects`.

  add_to_magic_network

    Whether or not the object should be added to a `MagicNetwork`. Note that all objects in `BrianObject.contained_objects` are automatically added when the parent object is added, therefore e.g. `NeuronGroup` should set `add_to_magic_network` to `True`, but it should not be set for all the dependent objects such as `StateUpdater`

  clock

    The `Clock` determining when the object should be updated.

    Note that this cannot be changed after the object is created.

  code_objects

    The list of `CodeObject` contained within the `BrianObject`.

    TODO: more details.

    Note that this attribute cannot be set directly, you need to modify the underlying list, e.g. `obj.code_objects.extend([A, B])`.

  contained_objects

    The list of objects contained within the `BrianObject`.

    When a `BrianObject` is added to a `Network`, its contained objects will be added as well. This allows for compound objects which contain a mini-network structure.

    Note that this attribute cannot be set directly, you need to modify the underlying list, e.g. `obj.contained_objects.extend([A, B])`.

  invalidates_magic_network

    Whether or not `MagicNetwork` is invalidated when a new `BrianObject` of this type is added

  name

    The unique name for this object.

    Used when generating code. Should be an acceptable variable name, i.e. starting with a letter character and followed by alphanumeric characters and `_`.

  namespace

    The group-specific namespace

  order

    The order in which objects with the same clock and `when` should be updated

  updaters

    The list of `Updater` that define the runtime behaviour of this object.

    TODO: more details.

    Note that this attribute cannot be set directly, you need to modify the underlying list, e.g. `obj.updaters.extend([A, B])`.

  when

    The ID string determining when the object should be updated in `Network.run`.

  add_dependency(obj)

    Add an object to the list of dependencies. Takes care of handling subgroups correctly (i.e., adds its parent object).

    Parameters:

      obj : `BrianObject`

      > The object that this object depends on.

  after_run()

    Optional method to do work after a run is finished.

    Called by `Network.after_run` after the main simulation loop terminated.

  before_run(run_namespace)

    Optional method to prepare the object before a run.

    Called by `Network.after_run` before the main simulation loop starts.

  run()