zasim.cagen.bases - Base classes for cagen

Inheritance diagram of zasim.cagen.bases

class zasim.cagen.bases.StepFuncVisitor[source]

Bases: object

Base class for step function visitor objects.

category = 'base'

The category this object and its subclasses belong to.

code = None

The StepFunc instance this visitor is bound to.

target = None

The configuration object that is being targetted.

requires_features = []
provides_features = []
incompatible_features = []

Bind the visitor to a StepFunc.


Once bound, the visitor object will refuse to be rebound.


Adds code to the bound step func.

This will be called directly after bind.


Never call this function on your own. This method will be called by StepFunc.__init__().


Target a CA instance


Once a target has been set, the visitor object will refuse to retarget.


Initialize data on the target.

This function will be called when the StepFunc has first had its target set.


Check and sanitize a new config.

This is pure python code that runs when a new config is loaded. it only changes the current configuration “cconf” of the automaton. after all new_config hooks have been run, they are multiplied.


Add text to the name of the StepFunc for easy identification of what’s going on.

class zasim.cagen.bases.StateAccessor[source]

Bases: zasim.cagen.bases.StepFuncVisitor

A StateAccessor will supply read and write access to the state array.

It also knows things about how the config space is shaped and sized and how to handle swapping or history of configs.

Additionally, it knows how far to offset reads and writes, so that cells at the lowest coordinates will have a border of data around them.

category = 'accessor'

The category this object and its subclasses belong to.


Generate a bit of C code for reading from the old config at pos.


Generate a code bit to write to the new config at pos.

write_to(pos, value)[source]

Directly write to the next config at pos.

write_to_current(pos, value)[source]

Directly write a value to the current config at pos.


Directly read from the current config at pos.


Directly read from the next config at pos.


Generate a code bit to get the size of the config space in the specified dimension


Get the size of the config space in the specified dimension.


Take the current config “cconf” and multiply it over all history slots that need to have duplicates at the beginning.


Swap out all configs


Set the size of the target.

This is supposed to be called exactly once by StepFunc.


Generate a bit of C code to copy the current field over from the old config. This is necessary for instance for nondeterministic step funcs combined with swapping two confs around.


Generate a bit of py code to copy the current field over from the old config.

class zasim.cagen.bases.CellLoop[source]

Bases: zasim.cagen.bases.StepFuncVisitor

A CellLoop is responsible for looping over cell space and giving access to the current position.

category = 'loop'

Returns a code bit to get the current position in config space.


Returns an iterator for iterating over the config space in python.

class zasim.cagen.bases.Neighbourhood[source]

Bases: zasim.cagen.bases.StepFuncVisitor

A Neighbourhood is responsible for getting states from neighbouring cells.

names and offsets are sorted by the position of the offset, starting at the top-left (negative X, negative Y), going down through ascending Y values, then to the next X value.


If you subclass from Neighbourhood, all you have to do to get the sorting right is to call _sort_names_offsets().

category = 'neighbourhood'
names = ()

The names of neighbourhood fields.

offsets = ()

The offsets of neighbourhood fields.


Recalculate the bounding box.


Find out, how many cells, at most, have to be read after a number of steps have been done.

It will return a tuple of tuples with relative values where 0 is the index of the current cell. It will have a format like:

((minX, maxX),
(minY, maxY), (minZ, maxZ), ...)
class zasim.cagen.bases.BorderHandler[source]

Bases: zasim.cagen.bases.StepFuncVisitor

The BorderHandler is responsible for treating the borders of the configuration. One example is copying the leftmost border to the rightmost border and vice versa or ensuring the border cells are always 0.

category = 'borderhandler'

Returns whether a position is inside the valid region.


Returns a wrapped position that is inside the valid region, if possible.

class zasim.cagen.bases.Computation[source]

Bases: zasim.cagen.bases.StepFuncVisitor

The Computation is responsible for calculating the result from the data gathered from the neighbourhood.

category = 'computation'
class zasim.cagen.bases.ExtraStats[source]

Bases: zasim.cagen.bases.StepFuncVisitor

Empty base class for histograms, activity counters, ...

category = 'extrastats'

Previous topic

zasim.cagen.stepfunc - The StepFunc class

Next topic


This Page