zasim.cagen.nondeterministic - Nondeterministic step function execution

Inheritance diagram of zasim.cagen.nondeterministic

This module offers CellLoop classes for nondeterministic step function execution.

The idea behind this is, that in a physical realisation of a cellular automaton, the single cells may not update with the exact same frequency, so that the order in which the cells execute may be arbitrary and asynchronous.

This is formally defined with a probability that decides, for each cell in turn, if it may update or not.

See also

zasim.cagen.beta_async implements a different kind of asynchronous execution. While the formal definitions are compatible, the implementations in nondeterministic should not be mixed with the implementations in beta_async.

Implementation details

This implementation offers the NondeterministicCellLoopMixin, which you can add as a first base class next to any kind of CellLoop. For your convenience, the classes OneDimNondeterministicCellLoop and TwoDimNondeterministicCellLoop are already composed for you.

class zasim.cagen.nondeterministic.RandomGenerator(random_generator=None, **kwargs)[source]

Bases: zasim.cagen.bases.StepFuncVisitor

Add this StepFuncVisitor to your stepfunc, so that random generators can be used by python and c code in a proper manner. Supply the random_generator argument to define the seed, that is used at the beginnig.

Note

The random generator will be used directly by the python code, but the C code is a bit more complex.

The C code carries a randseed with it that gets seeded by the Python random number generator at the very beginning, then it uses the randseed attribute in the target to seed srand. After the computation, randseed will be set to rand(), so that the same starting seed will still give the same result.

Warning

If reproducible randomness sequences are desired, do NOT mix the pure python and weave inline step functions!

provides_features = ['random_generator']
visit()[source]

Add code to C and python

set_target(target)[source]

Adds the randseed attribute to the target.

bind(code)[source]
class zasim.cagen.nondeterministic.NondeterministicCellLoopMixin(probab=0.5, **kwargs)[source]

Bases: zasim.cagen.bases.StepFuncVisitor

Deriving from a CellLoop and this Mixin will cause every cell to be skipped with a given probability

Parameters:
  • probab – The probability of a cell to be computed.
  • random_generator – If supplied, use this Random object for random values.
requires_features = ['random_generator']
probab = 0.5

The probability with which to execute each cell.

visit()[source]

Adds C code for handling the skipping.

bind(code)[source]
build_name(parts)[source]
class zasim.cagen.nondeterministic.OneDimNondeterministicCellLoop(probab=0.5, **kwargs)[source]

Bases: zasim.cagen.nondeterministic.NondeterministicCellLoopMixin, zasim.cagen.loops.OneDimCellLoop

This Nondeterministic Cell Loop loops over one dimension, skipping cells with a probability of probab.

Parameters:
  • probab – The probability of a cell to be computed.
  • random_generator – If supplied, use this Random object for random values.
class zasim.cagen.nondeterministic.TwoDimNondeterministicCellLoop(probab=0.5, **kwargs)[source]

Bases: zasim.cagen.nondeterministic.NondeterministicCellLoopMixin, zasim.cagen.loops.TwoDimCellLoop

This Nondeterministic Cell Loop loops over two dimensions, skipping cells with a probability of probab.

Parameters:
  • probab – The probability of a cell to be computed.
  • random_generator – If supplied, use this Random object for random values.