zasim.cagen.stepfunc - The StepFunc class

Inheritance diagram of zasim.cagen.stepfunc

For an in-depth description of how the StepFunc class works, see the tutorial section about StepFunc

class zasim.cagen.stepfunc.StepFunc(target, loop, accessor, neighbourhood, border=None, visitors=[], **kwargs)[source]

Bases: object

The StepFunc composes different parts into a functioning step function.

The Constructor creates a weave-based step function from the specified parts.

  • target – The object to target.
  • loop – A CellLoop, that adds a loop at loop_begin and loop_end.
  • accessor – A StateAccessor, that handles accesses to the state array as well as setting the cell value during the loop.
  • neighbourhood – A Neighbourhood, that fetches neighbouring cell values into known variables.
  • border – A BorderHandler, that handles wrapping etc. Can be elided.
  • visitors – Further StepFuncVisitor instances, that add more behaviour. This usually includes a Computation.

loop, accessor, neighbourhood, and border are special cases, because they get names that other visitors can later access.

acc = None
add_py_code(hook, code)[source]

Add a string of python code to the section “hook”.

StepFuncVisitor subclasses call this method in their visit method.

  • hook – the section to append the code to.
  • code – the python code to add (as a string).
add_weave_code(hook, code)[source]

Add a snippet of C code to the section “hook”.

StepFuncVisitor subclasses call this method in their visit method.

  • hook – the section to append the code to.
  • code – the C source code to add.

Add a support function to the head of the C result.

Parameters:code – The C code to include. should be a self-contained function.
features = set([])

Generate the C and python code from the bits.


Once this function is run, no more visitors can be added.


Initialise all the visitors after a configuration has been set.

loop = None
neigh = None

Handle a changed config in the target.

Call this after setting the targets cconf attribute to something new.

possible_values = ()
prepared = False
pysections = ['init', 'pre_compute', 'compute', 'post_compute', 'loop_end', 'after_step', 'finalize']
sections = ['localvars', 'loop_begin', 'pre_compute', 'compute', 'post_compute', 'loop_end', 'after_step']
set_config_value(pos, value=None)[source]

Set the value of the configuration at pos to value. If value is None, flip the value that’s already there.


Set the target of the step function. The target contains, among other things, the configurations.


Run a step of the simulator using weave.inline and the generated C code.

If no C code was generated (cf. no_weave_code), this method will be replaced with a function that just raises an Exception.


Run a step using the compiled python code.


This function will be generated by gen_code.

target = None
visitors = None

Previous topic

zasim.cagen - Programmatically generating CAs

Next topic

zasim.cagen.bases - Base classes for cagen

This Page