# CodeRunner class

(Shortest import: `from brian2 import CodeRunner)`

class brian2.groups.group.CodeRunner(*args, **kw)

  Bases: `BrianObject`

  A “code runner” that runs a `CodeObject` every timestep and keeps a reference to the `Group`. Used in `NeuronGroup` for `Thresholder`, `Resetter` and `StateUpdater`.

  On creation, we try to run the before_run method with an empty additional namespace (see `Network.before_run`). If the namespace is already complete this might catch unit mismatches.

  Parameters:

    group : `Group`

    > The group to which this object belongs.

    template : `Template`

    > The template that should be used for code generation

    code : str, optional

    > The abstract code that should be executed every time step. The `update_abstract_code` method might generate this code dynamically before every run instead.

    dt : `Quantity`, optional

    > The time step to be used for the simulation. Cannot be combined with the `clock` argument.

    user_code : str, optional

    > The abstract code as specified by the user, i.e. without any additions of internal code that the user not necessarily knows about. This will be used for warnings and error messages.

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

    order : int, optional

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

    name : str, optional

    > The name for this object.

    check_units : bool, optional

    > Whether the units should be checked for consistency before a run. Is activated (`True`) by default but should be switched off for state updaters (units are already checked for the equations and the generated abstract code might have already replaced variables with their unit-less values)

    template_kwds : dict, optional

    > A dictionary of additional information that is passed to the template.

    needed_variables: list of str, optional :

    > A list of variables that are neither present in the abstract code, nor in the `USES_VARIABLES` statement in the template. This is only rarely necessary, an example being a `StateMonitor` where the names of the variables are neither known to the template nor included in the abstract code statements.

    override_conditional_write: list of str, optional :

    > A list of variable names which are used as conditions (e.g. for refractoriness) which should be ignored.

    codeobj_class : class, optional

    > The `CodeObject` class to run code with. If not specified, defaults to the `group`’s `codeobj_class` attribute.

    generate_empty_code : bool, optional

    > Whether to generate a `CodeObject` if there is no abstract code to execute. Defaults to `True` but should be switched off e.g. for a `StateUpdater` when there is nothing to do.

  Methods

  `before_run`(run_namespace) | Optional method to prepare the object before a run.
  `create_code_objects`(run_namespace) |
  `create_default_code_object`(run_namespace) |
  `update_abstract_code`(run_namespace) | Update the abstract code for the code object.

  Details

  before_run(run_namespace)

    Optional method to prepare the object before a run.

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

  create_code_objects(run_namespace)
  create_default_code_object(run_namespace)
  update_abstract_code(run_namespace)

    Update the abstract code for the code object. Will be called in `before_run` and should update the `CodeRunner.abstract_code` attribute.

    Does nothing by default.