Skip to content

Commit

Permalink
Merge branch 'master' into interactive_tutorial
Browse files Browse the repository at this point in the history
Conflicts:
	.gitignore
	tox.ini
  • Loading branch information
timo committed May 6, 2012
2 parents fdf7929 + 1d24472 commit d4c0880
Show file tree
Hide file tree
Showing 95 changed files with 724 additions and 464 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ coverage.xml
htmlcov
junit*.xml
.ropeproject
docs/_templates/logo.png
zasim/idle.png
build/
dist/
7 changes: 0 additions & 7 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ or with
cd docs
make html

In order to get a complete documentation, you still need to generate the logo
image from the svg using inkscape with the following commands:

# create the compilation animation picture like this:
inkscape -f docs/logo.svg -i snake -j -C -e zasim/idle.png
# create the logo for the documentation with this command:
inkscape -e docs/_templates/logo.png -C -w 175 -h 175 docs/logo.svg

Visit the homepage of zasim at http://zasim.wakelift.de/, which is basically
just the generated html documentation put up on a webserver.
Expand Down
Binary file added docs/_templates/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions docs/gallery.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.. _screenshot_gallery:

Screenshot gallery
==================

.. figure:: gallery/zasim_gallery_1.png
:alt: Running a four-color one-dimensional CA

Running a four-color one-dimensional CA with a histogram, activity chart and the basic rule editor open.


.. figure:: gallery/zasim_gallery_2.png
:alt: Running Conway's Game of Life

Running Conway's Game of Life.


.. figure:: gallery/zasim_gallery_3.png
:alt: Game of Life with nondeterministic step function

Running Game of Life with a nondeterministic step function gives mazes/noodles.

.. figure:: gallery/zasim_gallery_4.png
:alt: zasim in the interactive ipython qtconsole

Using the ipython qtconsole, you can display configurations inline.

.. figure:: gallery/zasim_gallery_5.png
:alt: zasim gui elements in the interactive ipython qtconsole

IPythons magic `%gui qt` command will run an event loop allowing us to use qt widgets like the ones zasim offers at the same time as running code.

.. figure:: gallery/zasim_gallery_6.png
:alt: Interactive tutorial

Zasim comes with a IPython notebook based interactive tutorial.

Binary file added docs/gallery/zasim_gallery_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gallery/zasim_gallery_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gallery/zasim_gallery_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gallery/zasim_gallery_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gallery/zasim_gallery_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gallery/zasim_gallery_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ The zasim code can be `found on github <http://github.com/timo/zasim/>`_.
Additionally, this documentation is built with "view source" links for
the files.

Examples
========

Have a look at the :ref:`Example Gallery <screenshot_gallery>` for a few
interesting things zasim can do.

.. toctree::
:hidden:

gallery

Running zasim
=============

Expand Down
7 changes: 6 additions & 1 deletion docs/tutorial/simulator_without_cagen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ list for a `~zasim.config.RandomInitialConfiguration`::
# call parents init so that Qt Signals can work
super(TuringTapeSimulator, self).__init__()

# use the palette for a character-boxes based renderer
self.palette_info = {
'cboxes': palette
}

# set the size of the tape, as per the Simulator interface.
self.shape = (25,)
self.cconf = RandomInitialConfiguration(12, *probabs).generate((self.shape))
Expand All @@ -173,7 +178,7 @@ When the `TuringTapeSimulator` class is done, with its step function from above,
can be used quite simply::

tape = TuringTapeSimulator()
painter = MultilineOneDimConsolePainter(tape, palette, compact_boxes=True)
painter = MultilineOneDimConsolePainter(tape, compact_boxes=True)

painter.after_step()
print
Expand Down
Binary file removed images/vonNeumann/C00.jpg
Binary file not shown.
Binary file added images/vonNeumann/C00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/vonNeumann/C01.jpg
Binary file not shown.
Binary file added images/vonNeumann/C01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/vonNeumann/C10.jpg
Binary file not shown.
Binary file added images/vonNeumann/C10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/vonNeumann/C11.jpg
Binary file not shown.
Binary file added images/vonNeumann/C11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/vonNeumann/S.jpg
Binary file not shown.
Binary file added images/vonNeumann/S.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/vonNeumann/S0.jpg
Binary file not shown.
Binary file added images/vonNeumann/S0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/vonNeumann/S00.jpg
Binary file not shown.
Binary file added images/vonNeumann/S00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/vonNeumann/S000.jpg
Binary file not shown.
Binary file added images/vonNeumann/S000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/vonNeumann/S01.jpg
Binary file not shown.
Binary file added images/vonNeumann/S01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/vonNeumann/S1.jpg
Diff not rendered.
Binary file added images/vonNeumann/S1.png
Binary file removed images/vonNeumann/S10.jpg
Diff not rendered.
Binary file added images/vonNeumann/S10.png
Binary file removed images/vonNeumann/S11.jpg
Diff not rendered.
Binary file added images/vonNeumann/S11.png
Binary file removed images/vonNeumann/T000.jpg
Diff not rendered.
Binary file added images/vonNeumann/T000.png
Binary file removed images/vonNeumann/T001.jpg
Diff not rendered.
Binary file added images/vonNeumann/T001.png
Binary file removed images/vonNeumann/T010.jpg
Diff not rendered.
Binary file added images/vonNeumann/T010.png
Binary file removed images/vonNeumann/T011.jpg
Diff not rendered.
Binary file added images/vonNeumann/T011.png
Binary file removed images/vonNeumann/T020.jpg
Diff not rendered.
Binary file added images/vonNeumann/T020.png
Binary file removed images/vonNeumann/T021.jpg
Diff not rendered.
Binary file added images/vonNeumann/T021.png
Binary file removed images/vonNeumann/T030.jpg
Diff not rendered.
Binary file added images/vonNeumann/T030.png
Binary file removed images/vonNeumann/T031.jpg
Diff not rendered.
Binary file added images/vonNeumann/T031.png
Binary file removed images/vonNeumann/T100.jpg
Diff not rendered.
Binary file added images/vonNeumann/T100.png
Binary file removed images/vonNeumann/T101.jpg
Diff not rendered.
Binary file added images/vonNeumann/T101.png
Binary file removed images/vonNeumann/T110.jpg
Diff not rendered.
Binary file added images/vonNeumann/T110.png
Binary file removed images/vonNeumann/T111.jpg
Diff not rendered.
Binary file added images/vonNeumann/T111.png
Binary file removed images/vonNeumann/T120.jpg
Diff not rendered.
Binary file added images/vonNeumann/T120.png
Binary file removed images/vonNeumann/T121.jpg
Diff not rendered.
Binary file added images/vonNeumann/T121.png
Binary file removed images/vonNeumann/T130.jpg
Diff not rendered.
Binary file added images/vonNeumann/T130.png
Binary file removed images/vonNeumann/T131.jpg
Diff not rendered.
Binary file added images/vonNeumann/T131.png
Binary file removed images/vonNeumann/U.jpg
Diff not rendered.
Binary file added images/vonNeumann/U.png
5 changes: 5 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# make py.test use coredumps.

def pytest_sessionstart(*args, **kwargs):
import resource
resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
10 changes: 7 additions & 3 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from .testutil import assert_arrays_equal

from zasim import config
from zasim.features import HAVE_MULTIDIM
from zasim.features import HAVE_MULTIDIM, HAVE_DTYPE_AS_INDEX

import sys
IS_PYPY = "pypy_version_info" in dir(sys)

import pytest

Expand Down Expand Up @@ -98,6 +101,7 @@ def test_random_2d_probabilities(self):
assert (crr == 2).any()

@pytest.mark.skipif("not HAVE_MULTIDIM")
@pytest.mark.skipif("IS_PYPY")
def test_export_import_conf_ascii(self):
from zasim.cagen import ElementarySimulator
from zasim.display.console import TwoDimConsolePainter
Expand All @@ -111,7 +115,7 @@ def test_export_import_conf_ascii(self):
nconf_imp = config.AsciiInitialConfiguration(tmpfile.name)
assert_arrays_equal(nconf_imp.generate(), s.get_config())

@pytest.mark.skipif("not HAVE_MULTIDIM")
@pytest.mark.skipif("IS_PYPY")
def test_export_import_conf_png(self, scale):
from zasim.cagen import GameOfLife
from zasim.display.qt import TwoDimQImagePainter
Expand All @@ -127,7 +131,6 @@ def test_export_import_conf_png(self, scale):
nconf_imp = config.ImageInitialConfiguration(tmpfile.name, scale=scale)
assert_arrays_equal(nconf_imp.generate(), s.get_config())


def test_probability_distribution_1d(self):
zero_fun = 1
one_fun = lambda x, w: 0 if x <= w/2 else 5
Expand All @@ -140,6 +143,7 @@ def test_probability_distribution_1d(self):
assert not conf[50:].all()

@pytest.mark.skipif("not HAVE_MULTIDIM")
@pytest.mark.xfail("not HAVE_DTYPE_AS_INDEX")
def test_probability_distribution_2d(self):
zero_fun = 1
one_fun = lambda x, y, w, h: 0 if x <= w/2 else 5
Expand Down
5 changes: 5 additions & 0 deletions test/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import pytest
import tempfile

import sys
IS_PYPY = "pypy_version_info" in dir(sys)

class TestDisplay:
@pytest.mark.skipif("not HAVE_MULTIDIM")
@pytest.mark.xfail("IS_PYPY")
def test_pretty_print_config_2d(self, capsys):
gconf = GLIDER[0]
simo = cagen.GameOfLife(config=gconf)
Expand All @@ -37,6 +41,7 @@ def test_pretty_print_config_2d(self, capsys):
"""

@pytest.mark.xfail("IS_PYPY")
def test_pretty_print_config_1d(self, capsys):
conf = np.array([1,0,1,1,0])
br = cagen.BinRule(config=conf, rule=204)
Expand Down
75 changes: 75 additions & 0 deletions test/test_display_qt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
try:
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtTest import *

app = qApp or QApplication([])
HAVE_QT = True
except ImportError:
HAVE_QT = False

if HAVE_QT:
from zasim.display.qt import *
from zasim.config import *
from zasim.cagen import jvn

import pytest

import numpy as np

import sys
import signal
import traceback

_exceptions = []
def my_except_hook(cls, instance, traceback):
print "oh god, an exception!"
print cls
print instance
print traceback
print
traceback.print_exception(cls, instance, traceback)
_exceptions.append((cls, instance, traceback))

_aborts = []
def my_abort_hook():
print "oh god, sigabort!"
print
print traceback.print_stack()
print
_aborts.append(True)

def fail_on_exceptions():
exc = _exceptions[:]
[_exceptions.remove(a) for a in exc]
aborts = _aborts[:]
[_aborts.remove(a) for a in aborts]
if exc:
pytest.fail("There were exceptions in the base.\n%s" % (exc[0]))
if aborts:
pytest.fail("There were abort signals in the tests.")

def setup_module():
sys.excepthook = my_except_hook
signal.signal(signal.SIGABRT, my_abort_hook)

def teardown_module():
sys.excepthook = sys.__excepthook__
signal.signal(signal.SIGABRT, signal.SIG_DFL)

@pytest.mark.skipif("not HAVE_QT")
class TestDisplayQt:
def test_tiled_display(self):
test_conf = RandomInitialConfigurationFromPalette(jvn.states)
conf = test_conf.generate((10, 10))

img = render_state_array_tiled(conf, jvn.PALETTE_JVN_IMAGE, jvn.PALETTE_JVN_RECT)

img2 = render_state_array_tiled(conf, jvn.PALETTE_JVN_IMAGE, jvn.PALETTE_JVN_RECT,region=(2, 2, 6, 6))

def test_tiled_display_1d(self):
test_conf = RandomInitialConfigurationFromPalette(jvn.states)
conf = test_conf.generate((10,))

img = render_state_array_tiled(conf, jvn.PALETTE_JVN_IMAGE, jvn.PALETTE_JVN_RECT)
img2 = render_state_array_tiled(conf, jvn.PALETTE_JVN_IMAGE, jvn.PALETTE_JVN_RECT,region=(2, 0, 6, 1))
4 changes: 4 additions & 0 deletions test/test_dualrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytest

class TestDualRule:
@pytest.mark.xfail("not HAVE_DTYPE_AS_INDEX")
def test_run_nondeterministic_pure(self):
# implement nazim fatès density classifier
compu = cagen.DualRuleCellularAutomaton(184, 232, 0.1)
Expand All @@ -30,6 +31,7 @@ def test_run_nondeterministic_weave(self):
for i in range(50):
simu.step_inline()

@pytest.mark.xfail("not HAVE_DTYPE_AS_INDEX")
def test_compare_nondeterministic_pure(self):
compu = cagen.DualRuleCellularAutomaton(184, 232, 0)
sf = cagen.automatic_stepfunc(size=(100,), computation=compu, histogram=True, needs_random_generator=True)
Expand Down Expand Up @@ -59,6 +61,7 @@ def test_compare_nondeterministic_weave(self):

assert_arrays_equal(simu.get_config(), br.get_config())

@pytest.mark.xfail("not HAVE_DTYPE_AS_INDEX")
def test_compare_evil_random_pure(self):
rando = ZerosThenOnesRandom(1000)
compu = cagen.DualRuleCellularAutomaton(184, 232, 0.5)
Expand All @@ -84,6 +87,7 @@ def test_compare_evil_random_pure(self):

assert_arrays_equal(simu.get_config(), br2.get_config())

@pytest.mark.xfail("not HAVE_DTYPE_AS_INDEX")
def test_dualrail_prettyprint(self):
compu = cagen.DualRuleCellularAutomaton(184, 232, 0.2)
sf = cagen.automatic_stepfunc(size=(100,), computation=compu, histogram=True, needs_random_generator=True)
Expand Down
39 changes: 25 additions & 14 deletions test/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtTest import *

app = qApp or QApplication([])
HAVE_QT = True
except ImportError:
HAVE_QT = False
Expand Down Expand Up @@ -66,6 +64,19 @@ def teardown_module():

@pytest.mark.skipif("not HAVE_QT")
class TestGui:
def setup_method(self, method):
try:
self.app = QApplication([])
except RuntimeError:
self.app = QCoreApplication.instance()
self.app.setQuitOnLastWindowClosed(True)

def teardown_method(self, method):
self.app.closeAllWindows()
self.app.quit()
self.app.exit(0)
del self.app

def test_start_stop_binrule(self, size, base, scale, histogram):
print size, base, scale, histogram
sim_obj = cagen.ElementarySimulator(size, copy_borders=True, base=base, histogram=histogram)
Expand All @@ -85,20 +96,20 @@ def test_start_stop_binrule(self, size, base, scale, histogram):
QTest.mouseClick(display.control.start_button, Qt.LeftButton)

for execution in seconds(0.1):
app.processEvents()
self.app.processEvents()
assert not display.control.start_button.isVisible()
for execution in seconds(0.1):
app.processEvents()
self.app.processEvents()
QTest.mouseClick(display.control.stop_button, Qt.LeftButton)
for execution in seconds(0.1):
app.processEvents()
self.app.processEvents()
assert not display.control.stop_button.isVisible()

app.closeAllWindows()
self.app.closeAllWindows()
fail_on_exceptions()

def test_reset_button(self):
sim_obj = cagen.ElementarySimulator((1000, 100), copy_borders=True, base=3)
sim_obj = cagen.ElementarySimulator((100, 100), copy_borders=True, base=3)

display = ZasimDisplay(sim_obj)
display.set_scale(1)
Expand Down Expand Up @@ -131,11 +142,11 @@ def test_reset_button(self):
def find_message_box(self, timeout=10):
end = time.time() + timeout
while time.time() < end:
widgets = app.allWidgets()
widgets = self.app.allWidgets()
for widget in widgets:
if isinstance(widget, QMessageBox):
return widget
app.processEvents()
self.app.processEvents()

def test_elementary_gui(self, base):
sim_obj = cagen.ElementarySimulator((10, 10), copy_borders=True, base=base)
Expand All @@ -153,9 +164,9 @@ def test_elementary_gui(self, base):
elementary_action.trigger()

for execution in seconds(0.1):
app.processEvents()
self.app.processEvents()

elementary_window = app.activeWindow()
elementary_window = self.app.activeWindow()
assert elementary_window is not None

actions = [act for act in elementary_window.findChildren(QPushButton)
Expand All @@ -164,9 +175,9 @@ def test_elementary_gui(self, base):
for action in actions:
QTest.mouseClick(action, Qt.LeftButton)
for execution in seconds(0.1):
app.processEvents()
self.app.processEvents()

app.closeAllWindows()
self.app.closeAllWindows()

fail_on_exceptions()

Expand All @@ -186,7 +197,7 @@ def test_animation(self):
anim = WaitAnimationWindow()

for execution in seconds(1):
app.processEvents()
self.app.processEvents()

fail_on_exceptions()

Expand Down
1 change: 1 addition & 0 deletions test/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_compare_sparse_life_weave(self):
self.body_compare_sparse_life(True)

@pytest.mark.skipif("not HAVE_MULTIDIM")
@pytest.mark.xfail("not HAVE_DTYPE_AS_INDEX")
def test_compare_sparse_life_pure(self):
self.body_compare_sparse_life(False)

Expand Down
Loading

0 comments on commit d4c0880

Please sign in to comment.