Skip to main content

glider pyCells

Whilst being very bored recently I started playing around with simulating cellular automata once again. But to challenge myself a bit more than usual I set three specific limitations that made this a bit harder than I was used to:

  1. The simulation functions should be able to handle n-dimensional rules and states.
  2. The rules should be given as integers.
  3. The state should be represented as an integer, making use of the fact that the whole state consists of a n-dimensional array of booleans that can be flattened.

Another additional burden I put on to myself was to implement multiple unique styles of rules:

  1. Pattern based rules, such as the popular 110 or 30.
  2. Neighbor count based rules, such as Conway's Game of Life.

Usage

From PyPi

  1. run pip install pycells
  2. run pycells and check what options you have

From source

  1. clone this repo
  2. setup virtualenv using python > 3.7 and ./requirements.txt
  3. run python simulate.py

I implemented both a cli and a file-based simulation configuration system. The cli is structured as follows:

$ python simulation.py

Usage: simulate.py [OPTIONS]

  Simulate n-dimensional cellular automata using some of the most common
  methods.

Options:
  -p, --preset [conway|elementary]
                                  simulation preset to use
  -f, --file FILENAME             file to load simulation config from
  -d, --dimensions TEXT           dimensions of the simulation, format:
                                  N[xN[xN[...]]
  -m, --method [count|pattern]    simulation method
  -r, --rule INTEGER              rule to simulate
  -i, --iterations INTEGER        iterations to simulate
  -n, --neighborhood-radius INTEGER
                                  neighborhood radius to use
  -o, --out FILE                  path to save the output to
  --initial-state INTEGER         initial simulation state
  --skip-initial-state            skip the initial state
  --parallelize                   enabled parallel calculation of cells per
                                  state transition
  --scaling INTEGER               scaling to apply to output
  --format [gif|png|npy|txt]      format to output as, this skips the default
                                  which is to simply use the most suitable for
                                  the given number of dimensions
  --help                          Show this message and exit.

To make use of file based configuration options simply write a YAML file that contains all the necessary parameters. For some examples have a look in the ./examples directory. If you want to write binary numbers in these files I've added two tags to the yaml-parser !b and !br (reverse). Using these files is as simple as running:

python simulate.py -f examples/glider.yml

Using the predefined presets is also similar, to use them simply make use of the -p option and fill in the rest of the undefined parameters:

python simulate.py -p conway -d 64x64 -i 32

Notice

Though this implementation can handle n-dimensional states as of now I have only implemented graphical visualizations for 1D and 2D automata. If you want to create your own visualization you can specify one of the text based formats (e.g. txt, npy).

Examples

For some more examples have a look at rendered outputs here.

Metadata

Release files for pycells 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycells 0.1.7
File Size Uploaded
pycells-0.1.7.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycells 0.1.7
File Interpreter ABI Platform
pycells-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 19.3 kB

Release files / pycells-0.1.7.tar.gz

Download URL pycells-0.1.7.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c3779127eb302872e267403ac73ad451ee844ac1b19a85d3f82ab8507ed6aa63
BLAKE2b-256 checksum
How to use checksums
2d557f6c7fa908b0ae6eb1143f7003ff2cd1773393f2717440fe7fda978f3d38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0

Release files / pycells-0.1.7-py3-none-any.whl

Download URL pycells-0.1.7-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e41081b6fe3a8da7f762cd41e9425daa448a7d9e70f5b3eca9d8be5e77ff4104
BLAKE2b-256 checksum
How to use checksums
569cc187c5c3cc8355ca2c743e5ea83e8d7737a73ebb6a15455fc7b369d4f9c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page