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

Bind the visitor to a StepFunc.

Note

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

visit()[source]

Adds code to the bound step func.

This will be called directly after bind.

Note

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

set_target(target)[source]

Target a CA instance

Note

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

init_once()[source]

Initialize data on the target.

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

new_config()[source]

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.

build_name(parts)[source]

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.

read_access(pos)[source]

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

write_access(pos)[source]

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.

read_from(pos)[source]

Directly read from the current config at pos.

read_from_next(pos)[source]

Directly read from the next config at pos.

get_size(dimension=0)[source]

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

get_size_of(dimension=0)[source]

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

multiplicate_config()[source]

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

swap_configs()[source]

Swap out all configs

set_size(size)[source]

Set the size of the target.

This is supposed to be called exactly once by StepFunc.

gen_copy_code()[source]

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.

gen_copy_py_code()[source]

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'
get_pos()[source]

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

get_iter()[source]

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.

Note

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.

recalc_bounding_box()[source]

Recalculate the bounding box.

bounding_box(steps=1)[source]

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'
is_position_valid(pos)[source]

Returns whether a position is inside the valid region.

correct_position(pos)[source]

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

zasim.cagen.loops

This Page