def test_simulate_until_max_t_or_attractor_or_target_substate_B(): """ `simulate_until_attractor_or_target_substate_or_max_t` Feature B: finding attractor at expected time step. """ predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) initial_state = [False, False, False, False, False, False] perturbed_nodes_by_t = dict() # Test for {not storing all states, storing all states}. storing_all_states_1 = False storing_all_states_2 = True # Test for {no time cap, not reaching time cap, reaching time cap}. n_steps_before_max_t_1 = inf n_steps_before_max_t_2 = 1 n_steps_before_max_t_3 = 0 # Test for {no target substate, target substate}. target_node_set_1 = set() target_node_set_2 = {0, 1, 2, 3, 4, 5} expected_attractor_is_found = True expected_target_substate_is_reached = False for storing_all_states, n_steps_before_max_t, target_node_set in product( [storing_all_states_1, storing_all_states_2], [ n_steps_before_max_t_1, n_steps_before_max_t_2, n_steps_before_max_t_3 ], [target_node_set_1, target_node_set_2]): if storing_all_states: update_rules = UPDATE_RULES_B initial_state = [False, False, False, False, False, False] target_state = [True, True, False, False, True, False] else: update_rules = UPDATE_RULES_A initial_state = [False, True, True, False, False] target_state = [True, True, True, True, True] predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(update_rules) _encode_state = partial(encode_state, target_node_set) _, target_substate_code = _encode_state(target_state) target_substate_code = target_substate_code or None expected_t = 7 if storing_all_states else 11 max_t = expected_t + n_steps_before_max_t _, _, t, attractor_is_found, target_substate_is_reached, _ = \ simulate_until_attractor_or_target_substate_or_max_t( storing_all_states, max_t, _encode_state, target_substate_code, initial_state, perturbed_nodes_by_t, predecessor_nodes_lists, truth_tables) test_description = generate_test_description(locals(), 'storing_all_states', 'n_steps_before_max_t', 'target_node_set') assert expected_t == t, test_description assert expected_attractor_is_found == attractor_is_found, test_description assert expected_target_substate_is_reached == target_substate_is_reached, test_description
def test_simulate_until_target_substate_or_max_t_C(): """ `simulate_until_target_substate_or_max_t` Feature C: not finding target substate if time cap is violated. """ predecessor_node_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) initial_state = [False, False, False, False, False, False] substate_node_set = {0, 1, 2, 3, 4, 5} _encode_state, _ = configure_encode_and_simulate( substate_node_set=substate_node_set) _, target_substate_code = _encode_state( [True, True, False, False, False, True]) max_t = 1 _, _simulate_until_attractor_or_target_substate_or_max_t = \ configure_encode_and_simulate(max_t=max_t, substate_node_set=substate_node_set, target_substate_code=target_substate_code) # Test for {no perturbations, perturbations}. perturbed_nodes_by_t_1 = dict() perturbed_nodes_by_t_2 = {1: {3: False}} for perturbed_nodes_by_t in [ perturbed_nodes_by_t_1, perturbed_nodes_by_t_2 ]: simulation_states = simulate_until_target_substate_or_max_t( _simulate_until_attractor_or_target_substate_or_max_t, initial_state, perturbed_nodes_by_t, predecessor_node_lists, truth_tables) test_description = generate_test_description(locals(), 'max_t', 'perturbed_nodes_by_t') assert simulation_states is None
def test_simulate_n_steps_A(): """ `simulate_n_steps` Feature A: evaluating next n states. """ predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) initial_state = [False, False, False, False, False, False] n_steps = 3 # Test for {no perturbations, perturbations}. perturbed_nodes_by_t_1 = dict() perturbed_nodes_by_t_2 = {1: {1: True}} for perturbed_nodes_by_t in [ perturbed_nodes_by_t_1, perturbed_nodes_by_t_2 ]: expected_states = [ initial_state, [True, bool(perturbed_nodes_by_t), False, False, True, False], [True, True, False, False, False, True], [False, True, False, False, False, False] ] states = simulate_n_steps(initial_state, perturbed_nodes_by_t, predecessor_nodes_lists, truth_tables, n_steps) test_description = generate_test_description(locals(), 'perturbed_nodes_by_t') assert expected_states == states
def test_adjust_update_rules_to_fixed_nodes_A(): """ `adjust_update_rules_to_fixed_nodes` Feature A: properly adjusting truth tables for fixed nodes. """ update_rule_dict = {'A': 'not A'} predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(update_rule_dict) fixed_node_state_1 = False fixed_node_state_2 = False expected_adjusted_predecessor_node_lists = [[]] for fixed_node_state in [fixed_node_state_1, fixed_node_state_2]: fixed_nodes = {0: fixed_node_state} expected_adjusted_truth_tables = [{(): fixed_node_state}] adjusted_predecessor_node_lists, adjusted_truth_tables = \ adjust_update_rules_for_fixed_nodes(predecessor_nodes_lists, truth_tables, fixed_nodes) test_description = generate_test_description(locals(), 'fixed_node_state') assert expected_adjusted_predecessor_node_lists == adjusted_predecessor_node_lists, \ test_description assert expected_adjusted_truth_tables == adjusted_truth_tables, test_description
def test_simulate_A(): """ `simulate_until_max_t` Feature A: simulating until the time cap. """ predecessor_node_lists, truth_tables = build_predecessor_nodes_lists_and_truth_tables( UPDATE_RULES_A) initial_state = [False, True, True, False, False] perturbed_nodes_by_t = dict() # Test for {not reaching attractor, reaching attractor}. max_t_1 = 3 max_t_2 = 20 expected_simulation_states_1 = \ [initial_state, [False, False, True, False, True], [True, False, False, False, True], [True, True, False, True, True]] expected_simulation_states_2 = \ 4 * [initial_state, [False, False, True, False, True], [True, False, False, False, True], [True, True, False, True, True], [True, True, True, True, False]] + \ [initial_state] for max_t, expected_simulation_states in zip( [max_t_1, max_t_2], [expected_simulation_states_1, expected_simulation_states_2]): _, _simulate_until_attractor_or_target_substate_or_max_t = \ configure_encode_and_simulate(max_t=max_t) simulation_states = simulate_until_max_t( max_t, _simulate_until_attractor_or_target_substate_or_max_t, initial_state, perturbed_nodes_by_t, predecessor_node_lists, truth_tables) test_description = generate_test_description(locals(), 'max_t') assert expected_simulation_states == simulation_states, test_description
def test_simulate_time_step_A(): """ `simulate_time_step` Feature A: evaluating next state. """ predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) current_state = [False, False, False, False, False, False] # Test for {no perturbations, perturbations}. current_perturbations_1 = dict() current_perturbations_2 = {1: True} for current_perturbations in [ current_perturbations_1, current_perturbations_2 ]: expected_next_state = [ True, bool(current_perturbations), False, False, True, False ] next_state = simulate_step(current_state, predecessor_nodes_lists, truth_tables, current_perturbations) test_description = generate_test_description(locals(), 'current_perturbations') assert expected_next_state == next_state
def test_simulate_until_attractor_or_max_t_storing_all_states_B(): """ `simulate_until_attractor_or_max_t_storing_all_states` Feature B: not finding attractor if time cap is violated. """ initial_state = [False, False, True, False, False, False] max_t = 3 # Test for {no length constraint, length constraint}. max_attractor_l_1 = inf max_attractor_l_2 = 100 # Test for {no perturbations, perturbations}. perturbed_nodes_by_t_1 = dict() perturbed_nodes_by_t_2 = {1: {3: False}} for max_attractor_l, perturbed_nodes_by_t in product( [max_attractor_l_1, max_attractor_l_2], [perturbed_nodes_by_t_1, perturbed_nodes_by_t_2]): predecessor_node_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) _, _simulate_until_attractor_or_target_substate_or_max_t = \ configure_encode_and_simulate(max_t=max_t) attractor = simulate_until_attractor_or_max_t_storing_all_states( max_attractor_l, _simulate_until_attractor_or_target_substate_or_max_t, initial_state, perturbed_nodes_by_t, predecessor_node_lists, truth_tables) test_description = generate_test_description(locals(), 'max_attractor_l', 'perturbed_nodes_by_t') assert attractor is None, test_description
def test_simulate_until_max_t_or_attractor_or_target_substate_G(): """ `simulate_until_attractor_or_target_substate_or_max_t` Feature G: recognizing target substate in initial state. """ predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) initial_state = [False, False, False, False, False, False] perturbed_nodes_by_t = dict() max_t = inf target_node_set = {1, 2, 4, 5} _encode_state = partial(encode_state, target_node_set) _, target_substate_code = _encode_state(initial_state) # Test for {not storing all states, storing all states}. storing_all_states_1 = False storing_all_states_2 = True for storing_all_states in [storing_all_states_1, storing_all_states_2]: _, _, t, *_ = simulate_until_attractor_or_target_substate_or_max_t( storing_all_states, max_t, _encode_state, target_substate_code, initial_state, perturbed_nodes_by_t, predecessor_nodes_lists, truth_tables) test_description = generate_test_description(locals(), 'storing_all_states') assert t == 0, test_description
def test_simulate_until_max_t_or_attractor_or_target_substate_F(): """ `simulate_until_attractor_or_target_substate_or_max_t` Feature F: ignoring target substates before last perturbation. """ predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) initial_state = [False, False, False, False, False, False] perturbed_nodes_by_t = {2: {1: True}} max_t = inf target_node_set = {0, 1, 2, 3, 4, 5} target_state = [True, False, False, False, True, False] _encode_state = partial(encode_state, target_node_set) _, target_substate_code = _encode_state(target_state) # Test for {not storing all states, storing all states}. storing_all_states_1 = False storing_all_states_2 = True for storing_all_states in [storing_all_states_1, storing_all_states_2]: _, _, t, *_ = simulate_until_attractor_or_target_substate_or_max_t( storing_all_states, max_t, _encode_state, target_substate_code, initial_state, perturbed_nodes_by_t, predecessor_nodes_lists, truth_tables) test_description = generate_test_description(locals(), 'storing_all_states') assert t >= 2, test_description
def test_simulate_master_A(): """ `simulate_master` Feature A: performing simulations irrespectively of performance tuning. """ predecessor_node_lists, truth_tables = build_predecessor_nodes_lists_and_truth_tables( UPDATE_RULES_B) initial_state = [False, False, True, False, False, False] fixed_nodes = dict() perturbed_nodes_by_t = dict() max_t = 101 initial_state_variations = [] fixed_nodes_variations = [] perturbed_nodes_by_t_variations = [(40, 0, NodeStateRange.MAYBE_TRUE)] n_simulation_problems = count_simulation_problems( initial_state_variations, fixed_nodes_variations, perturbed_nodes_by_t_variations) # Test for {single batch per process, multiple batches per process}. n_simulation_problem_batches_per_process_1 = 1 n_simulation_problem_batches_per_process_2 = 5 expected_simulation_states_1 = \ [initial_state] + 25 * [[True, False, False, True, True, False], [True, True, False, False, True, True], [False, True, False, False, False, True], [False, False, True, False, False, False]] + \ [[True, False, False, True, True, False]] expected_simulation_1 = Simulation(expected_simulation_states_1, dict(), dict()) expected_simulation_states_2 = \ expected_simulation_states_1[:40] + [[True, False, True, False, False, False], [True, True, False, True, False, False]] + \ 60 * [[True, True, False, False, False, False]] expected_simulation_2 = Simulation(expected_simulation_states_2, dict(), {40: { 0: True }}) expected_simulations = [expected_simulation_1, expected_simulation_2] for n_simulation_problem_batches_per_process in [ n_simulation_problem_batches_per_process_1, n_simulation_problem_batches_per_process_2 ]: db_conn = ZODB.connection(None) init_simulation_db_structure(db_conn) simulate_master(MPICommWrapper(), n_simulation_problem_batches_per_process, (initial_state, fixed_nodes, perturbed_nodes_by_t), (initial_state_variations, fixed_nodes_variations, perturbed_nodes_by_t_variations), predecessor_node_lists, truth_tables, max_t, n_simulation_problems, db_conn, None) test_description = generate_test_description( locals(), 'n_simulation_problem_batches_per_process') assert list(db_conn.root.simulations.values() ) == expected_simulations, test_description assert db_conn.root.n_simulations() == len( expected_simulations), test_description
def test_attract_master_A(): """ `attract_master` Feature A: finding attractors irrespectively of performance tuning. """ predecessor_node_lists, truth_tables = build_predecessor_nodes_lists_and_truth_tables( UPDATE_RULES_A) initial_state = [False, False, False, False, False] max_t = inf max_attractor_l = inf initial_state_variations = [0, 1, 2, 3, 4] fixed_nodes_variations = [] perturbed_nodes_by_t_variations = [] fixed_nodes = {2: True} perturbed_nodes_by_t = {5: {2: True}, 1000: {2: False}} n_simulation_problems = count_simulation_problems( initial_state_variations, fixed_nodes_variations, perturbed_nodes_by_t_variations) # Test for {single batch per process, multiple batches per process}. n_simulation_problem_batches_per_process_1 = 1 n_simulation_problem_batches_per_process_2 = 5 # Test for {not storing all states, storing all states}. storing_all_states_1 = False storing_all_states_2 = True # Test for {not packing DB, packing DB}. packing_db_1 = False packing_db_2 = True expected_attractors = \ {(-32, 23): construct_aggregated_attractor([[True, True, True, False, True]], 32, 1005, 0)} expected_total_frequency = sum( attractor.frequency for attractor in expected_attractors.values()) for n_simulation_problem_batches_per_process, storing_all_states, packing_db in product( [ n_simulation_problem_batches_per_process_1, n_simulation_problem_batches_per_process_2 ], [storing_all_states_1, storing_all_states_2], [packing_db_1, packing_db_2]): db_conn = ZODB.connection(None) init_attractor_db_structure(db_conn) attract_master(MPICommWrapper(), n_simulation_problem_batches_per_process, (initial_state, fixed_nodes, perturbed_nodes_by_t), (initial_state_variations, [], []), predecessor_node_lists, truth_tables, max_t, max_attractor_l, n_simulation_problems, storing_all_states, db_conn, packing_db, None) test_description = generate_test_description( locals(), 'n_simulation_problem_batches_per_process', 'storing_all_states') assert dict(db_conn.root.aggregated_attractors.items()) == expected_attractors, \ test_description assert db_conn.root.n_aggregated_attractors() == len( expected_attractors), test_description assert db_conn.root.total_frequency( ) == expected_total_frequency, test_description
def test_build_input_node_lists_and_truth_tables_A_1_1(self): update_rule_dict = {'A': '1 and not A'} expected_input_node_lists = [[0]] expected_truth_tables = [{(False, ): True, (True, ): False}] input_node_lists, truth_tables = build_predecessor_nodes_lists_and_truth_tables( update_rule_dict) self.assertEqual(input_node_lists, expected_input_node_lists) self.assertEqual(truth_tables, expected_truth_tables)
def test_build_input_node_lists_and_truth_tables_A_0_1(self): update_rule_dict = {'A': '1 '} expected_input_node_lists = [[]] expected_truth_tables = [{(): True}] input_node_lists, truth_tables = build_predecessor_nodes_lists_and_truth_tables( update_rule_dict) self.assertEqual(input_node_lists, expected_input_node_lists) self.assertEqual(truth_tables, expected_truth_tables)
def test_target_master_B(): """ `target_master` Feature B: finding no more than requested number of simulations reaching target state. """ predecessor_node_lists, truth_tables = build_predecessor_nodes_lists_and_truth_tables( UPDATE_RULES_B) initial_state = [False, False, False, False, False, False] substate_node_set = {0, 1, 2, 3, 4, 5} _encode_state, _ = configure_encode_and_simulate( substate_node_set=substate_node_set) _, target_substate_code = _encode_state( [True, True, False, False, False, True]) max_t = inf n_simulations_to_reach_target_substate = 1 initial_state_variations = [0, 1, 2, 3, 4, 5] fixed_nodes_variations = [] perturbed_nodes_by_t_variations = [] fixed_nodes = {0: True, 1: True, 2: False, 3: False, 4: False, 5: True} perturbed_nodes_by_t = dict() n_simulation_problems = count_simulation_problems( initial_state_variations, fixed_nodes_variations, perturbed_nodes_by_t_variations) # Test for {single batch per process, multiple batches per process}. n_simulation_problem_batches_per_process_1 = 1 n_simulation_problem_batches_per_process_2 = 5 expected_simulations = [ Simulation([initial_state] + [[True, True, False, False, False, True]], fixed_nodes, perturbed_nodes_by_t) ] for n_simulation_problem_batches_per_process in [ n_simulation_problem_batches_per_process_1, n_simulation_problem_batches_per_process_2 ]: db_conn = ZODB.connection(None) init_simulation_db_structure(db_conn) target_master(MPICommWrapper(), n_simulation_problem_batches_per_process, (initial_state, fixed_nodes, perturbed_nodes_by_t), (initial_state_variations, fixed_nodes_variations, perturbed_nodes_by_t_variations), target_substate_code, substate_node_set, predecessor_node_lists, truth_tables, n_simulations_to_reach_target_substate, max_t, n_simulation_problems, db_conn, None) test_description = generate_test_description( locals(), 'n_simulation_problem_batches_per_process') assert list(db_conn.root.simulations.values() ) == expected_simulations, test_description assert db_conn.root.n_simulations() == len( expected_simulations), test_description
def test_simulate_until_attractor_or_max_t_storing_all_states_A(): """ `simulate_until_attractor_or_max_t_storing_all_states` Feature A: finding attractor. """ initial_state = [False, False, True, False, False, False] # Test for {no time cap, time cap}. max_t_1 = inf max_t_2 = 10 # Test for {no length constraint, length constraint}. max_attractor_l_1 = inf max_attractor_l_2 = 10 # Test for {no perturbations, perturbations}. perturbed_nodes_by_t_1 = dict() perturbed_nodes_by_t_2 = {1: {3: False}} attractor_states_1 = [[True, False, False, True, True, False], [True, True, False, False, True, True], [False, True, False, False, False, True], [False, False, True, False, False, False]] attractor_states_2 = [[True, True, False, False, False, False]] expected_attractor_states_list = [attractor_states_1, attractor_states_2 ] * 4 expected_trajectory_l_list = [0, 6] * 4 for (max_t, max_attractor_l, perturbed_nodes_by_t), \ (expected_attractor_states, expected_trajectory_l) in zip( product([max_t_1, max_t_2], [max_attractor_l_1, max_attractor_l_2], [perturbed_nodes_by_t_1, perturbed_nodes_by_t_2]), zip(expected_attractor_states_list, expected_trajectory_l_list)): predecessor_node_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) _, _simulate_until_attractor_or_target_substate_or_max_t = \ configure_encode_and_simulate(max_t=max_t) expected_attractor_state_codes = \ [encode_state(set(), state)[0] for state in expected_attractor_states] expected_attractor_key = min(expected_attractor_state_codes) attractor_key, attractor_state_codes, attractor_states, trajectory_l = \ simulate_until_attractor_or_max_t_storing_all_states( max_attractor_l, _simulate_until_attractor_or_target_substate_or_max_t, initial_state, perturbed_nodes_by_t, predecessor_node_lists, truth_tables) test_description = generate_test_description(locals(), 'max_t', 'max_attractor_l', 'perturbed_nodes_by_t') assert expected_attractor_key == attractor_key, test_description assert expected_attractor_state_codes == attractor_state_codes, test_description assert expected_attractor_states == attractor_states, test_description assert expected_trajectory_l == trajectory_l, test_description
def test_apply_update_rules_A(): """ `apply_update_rules` Feature A: properly hashing predecessor node states and updating network state correctly as a result. """ predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) current_state = [True, False, True, False, False, False] expected_next_state = [True, True, False, True, False, False] next_state = apply_update_rules(current_state, predecessor_nodes_lists, truth_tables) assert expected_next_state == next_state
def test_simulate_until_max_t_or_attractor_or_target_substate_D(): """ `simulate_until_attractor_or_target_substate_or_max_t` Feature D: simulating expected states. """ predecessor_nodes_lists, truth_tables = build_predecessor_nodes_lists_and_truth_tables( UPDATE_RULES_A) initial_state = [False, True, True, False, False] max_t = 1 target_node_set = set() _encode_state = partial(encode_state, target_node_set) target_substate_code = None # Test for {not storing all states, storing all states}. storing_all_states_1 = False storing_all_states_2 = True # Test for {stopping at last perturbation, stopping not at last # perturbation}. perturbed_nodes_by_t_1 = {1: {1: True}} perturbed_nodes_by_t_2 = dict() for storing_all_states, perturbed_nodes_by_t in product( [storing_all_states_1, storing_all_states_2], [perturbed_nodes_by_t_1, perturbed_nodes_by_t_2]): expected_last_state = [ False, bool(perturbed_nodes_by_t), True, False, True ] expected_states = [initial_state, expected_last_state] expected_state_codes_since_last_perturbation = \ [_encode_state(state)[0] for state in expected_states[int(bool(perturbed_nodes_by_t)):]] if storing_all_states: expected_attractor_reference_points = None elif not perturbed_nodes_by_t: expected_states.insert(1, None) expected_state_codes_since_last_perturbation.insert(1, None) states, state_codes_since_last_perturbation, *_ = \ simulate_until_attractor_or_target_substate_or_max_t( storing_all_states, max_t, _encode_state, target_substate_code, initial_state, perturbed_nodes_by_t, predecessor_nodes_lists, truth_tables) test_description = generate_test_description(locals(), 'storing_all_states', 'perturbed_nodes_by_t') assert expected_states == states, test_description assert expected_state_codes_since_last_perturbation == state_codes_since_last_perturbation, \ test_description
def test_simulate_until_target_substate_or_max_t_B(): """ `simulate_until_target_substate_or_max_t` Feature B: finding target substate that is part of attractor. """ predecessor_node_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) initial_state = [False, False, False, False, False, False] substate_node_set = {0, 1, 2, 3, 4, 5} _encode_state, _ = configure_encode_and_simulate( substate_node_set=substate_node_set) _, target_substate_code = _encode_state( [True, True, False, False, False, False]) # Test for {no time cap, time cap}. max_t_1 = inf max_t_2 = 10 # Test for {no perturbations, perturbations}. perturbed_nodes_by_t_1 = dict() perturbed_nodes_by_t_2 = {1: {3: False}} expected_simulation_states = [initial_state] + [[ True, False, False, False, True, False ], [True, True, False, False, False, True ], [False, True, False, False, False, False ], [True, False, True, False, False, False ], [True, True, False, True, False, False ], [True, True, False, False, False, False]] for max_t, perturbed_nodes_by_t in product( [max_t_1, max_t_2], [perturbed_nodes_by_t_1, perturbed_nodes_by_t_2]): _, _simulate_until_attractor_or_target_substate_or_max_t = \ configure_encode_and_simulate(max_t=max_t, substate_node_set=substate_node_set, target_substate_code=target_substate_code) simulation_states = simulate_until_target_substate_or_max_t( _simulate_until_attractor_or_target_substate_or_max_t, initial_state, perturbed_nodes_by_t, predecessor_node_lists, truth_tables) test_description = generate_test_description(locals(), 'max_t', 'perturbed_nodes_by_t') assert expected_simulation_states == simulation_states
def test_simulate_until_max_t_or_attractor_or_target_substate_H(): """ `simulate_until_attractor_or_target_substate_or_max_t` Feature H: storing expected reference points when looking for attractors. """ perturbed_nodes_by_t = dict() max_t = inf target_node_set = set() _encode_state = partial(encode_state, target_node_set) target_substate_code = None storing_all_states = False # Test for {attractor detected at a reference point, attractor # detected not at a reference point}. update_rules_1 = UPDATE_RULES_A initial_state_1 = [True, True, True, True, True] expected_attractor_reference_points_dict_1 = \ {0: initial_state_1, 3: [True, False, True, False, True], 6: [True, True, True, False, False]} update_rules_2 = {'A': 'A'} initial_state_2 = [False] expected_attractor_reference_points_dict_2 = {0: initial_state_2} for update_rules, initial_state, expected_attractor_reference_points_dict in zip( [update_rules_1, update_rules_2], [initial_state_1, initial_state_2], [ expected_attractor_reference_points_dict_1, expected_attractor_reference_points_dict_2 ]): expected_attractor_reference_points = \ [(t, state, _encode_state(state)[0]) for t, state in sorted(expected_attractor_reference_points_dict.items())] predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(update_rules) *_, attractor_reference_points = simulate_until_attractor_or_target_substate_or_max_t( storing_all_states, max_t, _encode_state, target_substate_code, initial_state, perturbed_nodes_by_t, predecessor_nodes_lists, truth_tables) test_description = generate_test_description(locals(), 'update_rules', 'initial_state') assert expected_attractor_reference_points == attractor_reference_points, test_description
def test_simulate_until_max_t_or_attractor_or_target_substate_A(): """ `simulate_until_attractor_or_target_substate_or_max_t` Feature A: stopping at the time cap. """ predecessor_nodes_lists, truth_tables = \ build_predecessor_nodes_lists_and_truth_tables(UPDATE_RULES_B) initial_state = [False, False, False, False, False, False] perturbed_nodes_by_t = dict() max_t = 6 # Test for {not storing all states, storing all states}. storing_all_states_1 = False storing_all_states_2 = True # Test for {no target substate, target substate}. target_node_set_1 = set() target_node_set_2 = {0, 1, 2, 3, 4, 5} expected_t = 6 for storing_all_states, target_node_set in product( [storing_all_states_1, storing_all_states_2], [target_node_set_1, target_node_set_2]): _encode_state = partial(encode_state, target_node_set) _, target_substate_code = _encode_state( [True, True, True, True, True, True]) target_substate_code = target_substate_code or None _, _, t, *_ = simulate_until_attractor_or_target_substate_or_max_t( storing_all_states, max_t, _encode_state, target_substate_code, initial_state, perturbed_nodes_by_t, predecessor_nodes_lists, truth_tables) test_description = generate_test_description(locals(), 'storing_all_states', 'target_node_set') assert expected_t == t, test_description