def test_sequential_left_to_right(self): expected = self._convert_to_numpy_matrix( "rule60_sequential_simple_init.ca") cellular_automaton = cpl.init_simple(21) r = cpl.AsynchronousRule( apply_rule=lambda n, c, t: cpl.nks_rule(n, 60), update_order=range(1, 20)) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=19 * 20, apply_rule=r.apply_rule) np.testing.assert_equal(expected.tolist(), cellular_automaton[::19].tolist())
def test_sequential_random(self): expected = self._convert_to_numpy_matrix( "rule90_sequential_simple_init.ca") cellular_automaton = cpl.init_simple(21) update_order = [ 19, 11, 4, 9, 6, 16, 10, 2, 17, 1, 12, 15, 5, 3, 8, 18, 7, 13, 14 ] r = cpl.AsynchronousRule( apply_rule=lambda n, c, t: cpl.nks_rule(n, 90), update_order=update_order) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=19 * 20, apply_rule=r.apply_rule) np.testing.assert_equal(expected.tolist(), cellular_automaton[::19].tolist())
import cellpylib as cpl cellular_automaton = cpl.init_simple(200) # cellular_automaton = cpl.init_random(200) # evolve the cellular automaton for 100 time steps cellular_automaton = cpl.evolve(cellular_automaton, timesteps=100, memoize=True, apply_rule=lambda n, c, t: cpl.nks_rule(n, 30)) cpl.plot(cellular_automaton)
import cellpylib as cpl # implements the rule 60 sequential automaton from the NKS Notes on # Chapter 9, section 10: "Sequential cellular automata" # http://www.wolframscience.com/nks/notes-9-10--sequential-cellular-automata/ cellular_automaton = cpl.init_simple(21) apply_rule = cpl.AsynchronousRule(apply_rule=lambda n, c, t: cpl.nks_rule(n, 60), update_order=range(1, 20)) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=19*20, apply_rule=apply_rule) # get every 19th row, including the first, as a cycle is completed every 19 rows cpl.plot(cellular_automaton[::19])
def _create_ca(self, expected, rule): rows, _ = expected.shape cellular_automaton = expected[0] return cpl.evolve(cellular_automaton, timesteps=rows, apply_rule=lambda n, c, t: cpl.nks_rule(n, rule))
import cellpylib as cpl # implements the rule 60 sequential automaton from the NKS Notes on # Chapter 9, section 10: "Sequential cellular automata" # http://www.wolframscience.com/nks/notes-9-10--sequential-cellular-automata/ cellular_automaton = cpl.init_simple(21) r = cpl.AsynchronousRule(apply_rule=lambda n, c, t: cpl.nks_rule(n, 60), update_order=range(1, 20)) cellular_automaton = cpl.evolve(cellular_automaton, timesteps=19 * 20, apply_rule=r.apply_rule) # get every 19th row, including the first, as a cycle is completed every 19 rows cpl.plot(cellular_automaton[::19])