The Seeds (xentica.seeds)

The package for the initial CA state (seed) generation.

Classes from modules below are intended for use in Experiment classes.

For example, to initialize the whole board with random values:

from xentica import core, seeds

class MyExperiment(core.Experiment):
    # ...
    seed = seeds.patterns.PrimordialSoup(
        vals={
            "state": seeds.random.RandInt(0, 1),
        }
   )

Patterns (xentica.seeds.patterns)

The module containing different patterns for CA seed initialization.

Each pattern class have one mandatory method generate() which is called automatically at the initialization stage.

Patterns are intended for use in Experiment classes. See the example of general usage above.

class xentica.seeds.patterns.RandomPattern(vals)

Bases: object

The base class for random patterns.

Parameters:vals – Dictionary with mixed values. May contain descriptor classes.
generate(cells, bsca)

Generate the entire initial state.

This is an abstract method, you must implement it in RandomPattern subclasses.

Parameters:
  • cells – NumPy array with cells’ states as items. The seed will be generated over this array.
  • bscaxentica.core.CellularAutomaton instance, to access the field’s size and other attributes.
random

Get the random stream.

class xentica.seeds.patterns.BigBang(vals, pos=None, size=None)

Bases: xentica.seeds.patterns.RandomPattern

Random init pattern, known as “Big Bang”.

Citation from The Concept:

“A small area of space is initialized with a high amount of energy and random parameters per each quantum. Outside the area, quanta has either zero or minimum possible amount of energy. This is a good test for the ability of energy to spread in empty space.”

The current implementation generates a value for every cell inside a specified N-cube area. Cells outside the area remain unchanged.

Parameters:
  • vals – Dictionary with mixed values. May contain descriptor classes.
  • pos – A tuple with the coordinates of the lowest corner of the Bang area.
  • size – A tuple with the size of the Bang area per each dimension.
generate(cells, bsca)

Generate the entire initial state.

See RandomPattern.generate() for details.

class xentica.seeds.patterns.PrimordialSoup(vals)

Bases: xentica.seeds.patterns.RandomPattern

Random init pattern, known as “Primordial Soup”.

Citation from The Concept:

“Each and every quantum initially has an equally small amount of energy, other parameters are random. This is a good test for the ability of energy to self-organize in clusters from the completely uniform distribution.”

The current implementation populates the entire board with generated values.

Parameters:vals – Dictionary with mixed values. May contain descriptor classes.
generate(cells, bsca)

Generate the entire initial state.

See RandomPattern.generate() for details.

class xentica.seeds.patterns.ValDict(dct, parent=None)

Bases: object

A wrapper over the Python dictionary.

It can keep descriptor classes along with regular values. When you get the item, the necessary value is automatically obtaining either directly or via descriptor logic.

Read-only, you should set all dictionary values at the class initialization.

The example of usage:

>>> from xentica.seeds.random import RandInt
>>> from xentica.seeds.patterns import ValDict
>>> d = {'a': 2, 's': RandInt(11, 23), 'd': 3.3}
>>> vd = ValDict(d)
>>> vd['a']
2
>>> vd['s']
14
>>> vd['d']
3.3
Parameters:
  • dct – Dictionary with mixed values. May contain descriptor classes.
  • parent – A reference to the class holding the dictionary. Optional.
items()

Iterate over dictionary items.

keys()

Iterate over dictionary keys.

RNG (xentica.seeds.random)

The module for package-wide RNG.

The main intention is to keep separate deterministic random streams for every CellularAutomaton instance. So, if you’ve initialized RNG for a particular CA with some seed, you’re geting the guarantee that the random sequence will be the same, no matter how many other CA’s you’re running in parallel.

class xentica.seeds.random.LocalRandom(seed=None)

Bases: object

The holder class for the RNG sequence.

It is encapsulating both standard Python random stream and NumPy one.

Once instantiated, you can use them as follows:

from xentica.seeds.random import LocalRandom

random = LocalRandom()
# get random number from standard stream
val = random.standard.randint(1, 10)
# get 100 random numbers from NumPy stream
vals = random.numpy.randint(1, 10, 100)
load(rng)

Load a random state from the class.

Parameters:rngLocalRandom instance.
class xentica.seeds.random.RandInt(min_val, max_val, constant=False)

Bases: xentica.core.expressions.PatternExpression

Class, generating a sequence of random integers in some interval.

It is intended for use in Experiment seeds. See the example of initializing CA property above.

Parameters:
  • min_val – Lower bound for a random value.
  • max_val – Upper bound for a random value.
  • constant – If True, will force the use of the standard random stream.