def test_big_mip_single_node(s_single, flushcache, restore_fs_cache): flushcache() initial_option = constants.SINGLE_NODES_WITH_SELFLOOPS_HAVE_PHI constants.SINGLE_NODES_WITH_SELFLOOPS_HAVE_PHI = True assert compute.big_mip(s_single).phi == 0.5 constants.SINGLE_NODES_WITH_SELFLOOPS_HAVE_PHI = False assert compute.big_mip(s_single).phi == 0.0 constants.SINGLE_NODES_WITH_SELFLOOPS_HAVE_PHI = initial_option
def test_big_mip_single_node(s_single, flushcache, restore_fs_cache): flushcache() initial_option = config.SINGLE_NODES_WITH_SELFLOOPS_HAVE_PHI config.SINGLE_NODES_WITH_SELFLOOPS_HAVE_PHI = True assert compute.big_mip(s_single).phi == 0.5 config.SINGLE_NODES_WITH_SELFLOOPS_HAVE_PHI = False assert compute.big_mip(s_single).phi == 0.0 config.SINGLE_NODES_WITH_SELFLOOPS_HAVE_PHI = initial_option
def test_big_mip_wrappers(reducible, flushcache, restore_fs_cache): flushcache() assert (compute.big_mip(reducible) == models.BigMip(subsystem=reducible, cut_subsystem=reducible, phi=0.0, unpartitioned_constellation=[], partitioned_constellation=[])) assert compute.big_phi(reducible) == 0.0
def test_big_mip_empty_subsystem(s_empty, flushcache, restore_fs_cache): flushcache() assert (compute.big_mip(s_empty) == models.BigMip(phi=0.0, unpartitioned_constellation=[], partitioned_constellation=[], subsystem=s_empty, cut_subsystem=s_empty))
def test_big_mip_empty_subsystem(s_empty, flushcache, restore_fs_cache): flushcache() assert (compute.big_mip(s_empty) == models.BigMip(phi=0.0, unpartitioned_constellation=(), partitioned_constellation=(), subsystem=s_empty, cut_subsystem=s_empty))
def test_big_mip_standard_example_sequential(s, flushcache, restore_fs_cache): flushcache() initial = constants.PARALLEL_CUT_EVALUATION constants.PARALLEL_CUT_EVALUATION = False mip = compute.big_mip(s) check_mip(mip, standard_answer) constants.PARALLEL_CUT_EVALUATION = initial
def test_big_mip_standard_example_parallel(s, flushcache, restore_fs_cache): flushcache() initial = (constants.PARALLEL_CUT_EVALUATION, constants.NUMBER_OF_CORES) constants.PARALLEL_CUT_EVALUATION, constants.NUMBER_OF_CORES = True, -2 mip = compute.big_mip(s) check_mip(mip, standard_answer) constants.PARALLEL_CUT_EVALUATION, constants.NUMBER_OF_CORES = initial
def test_expand_cause_repertoire(micro_s_all_off): mip = big_mip(micro_s_all_off) A = mip.unpartitioned_constellation[0] cause = A.cause.mip.unpartitioned_repertoire assert np.all(abs(A.expand_cause_repertoire(CD) - cause) < EPSILON) assert np.all(abs( A.expand_cause_repertoire(BCD).flatten(order='F') - np.array([1/6 if i < 6 else 0 for i in range(8)])) < EPSILON) assert np.all(abs( A.expand_cause_repertoire(ABCD).flatten(order='F') - np.array([1/12 if i < 12 else 0 for i in range(16)])) < EPSILON) assert np.all(abs(A.expand_cause_repertoire(ABCD) - A.expand_cause_repertoire()) < EPSILON)
def test_expand_effect_repertoire(micro_s_all_off): mip = big_mip(micro_s_all_off) A = mip.unpartitioned_constellation[0] effect = A.effect.mip.unpartitioned_repertoire assert np.all(abs(A.expand_effect_repertoire(CD) - effect) < EPSILON) assert np.all(abs(A.expand_effect_repertoire(BCD).flatten(order='F') - np.array([.25725, .23275, .11025, .09975, .11025, .09975, .04725, .04275])) < EPSILON) assert np.all(abs( A.expand_effect_repertoire(ABCD).flatten(order='F') - np.array([.13505625, .12219375, .12219375, .11055625, .05788125, .05236875, .05236875, .04738125, .05788125, .05236875, .05236875, .04738125, .02480625, .02244375, .02244375, .02030625])) < EPSILON) assert np.all(abs(A.expand_effect_repertoire(ABCD) - A.expand_effect_repertoire()) < EPSILON)
def test_expand_cause_repertoire(micro_s_all_off): mip = big_mip(micro_s_all_off) A = mip.unpartitioned_constellation[0] cause = A.cause.mip.unpartitioned_repertoire assert np.all(abs(A.expand_cause_repertoire(CD) - cause) < EPSILON) assert np.all( abs( A.expand_cause_repertoire(BCD).flatten(order='F') - np.array([1 / 6 if i < 6 else 0 for i in range(8)])) < EPSILON) assert np.all( abs( A.expand_cause_repertoire(ABCD).flatten(order='F') - np.array([1 / 12 if i < 12 else 0 for i in range(16)])) < EPSILON) assert np.all( abs(A.expand_cause_repertoire(ABCD) - A.expand_cause_repertoire()) < EPSILON)
def test_expand_effect_repertoire(micro_s_all_off): mip = big_mip(micro_s_all_off) A = mip.unpartitioned_constellation[0] effect = A.effect.mip.unpartitioned_repertoire assert np.all(abs(A.expand_effect_repertoire(CD) - effect) < EPSILON) assert np.all( abs( A.expand_effect_repertoire(BCD).flatten(order='F') - np.array([ .25725, .23275, .11025, .09975, .11025, .09975, .04725, .04275 ])) < EPSILON) assert np.all( abs( A.expand_effect_repertoire(ABCD).flatten(order='F') - np.array([ .13505625, .12219375, .12219375, .11055625, .05788125, .05236875, .05236875, .04738125, .05788125, .05236875, .05236875, .04738125, .02480625, .02244375, .02244375, .02030625 ])) < EPSILON) assert np.all( abs(A.expand_effect_repertoire(ABCD) - A.expand_effect_repertoire()) < EPSILON)
def test_big_mip_disconnected_network(reducible, flushcache, restore_fs_cache): flushcache() assert (compute.big_mip(reducible) == models.BigMip(subsystem=reducible, cut_subsystem=reducible, phi=0.0, unpartitioned_constellation=[], partitioned_constellation=[]))
def test_big_mip_complete_graph_standard_example(s_complete): mip = compute.big_mip(s_complete) check_mip(mip, standard_answer)
def test_big_mip_complete_graph_s_noised(s_noised_complete): mip = compute.big_mip(s_noised_complete) check_mip(mip, noised_answer)
def test_big_mip_complete_graph_big_subsys_all(big_subsys_all_complete): mip = compute.big_mip(big_subsys_all_complete) check_mip(mip, big_answer)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from pyphi.compute import big_mip from pyphi import Subsystem import numpy as np import example_networks from pyphi.constants import EPSILON micro = example_networks.micro() micro.current_state = (0, 0, 0, 0) micro.past_state = (0, 0, 0, 0) micro_subsystem = Subsystem(range(micro.size), micro) mip = big_mip(micro_subsystem) CD = micro_subsystem.nodes[2:4] BCD = micro_subsystem.nodes[1:4] ABCD = micro_subsystem.nodes[0:4] A = mip.unpartitioned_constellation[0] cause = A.cause.mip.unpartitioned_repertoire effect = A.effect.mip.unpartitioned_repertoire def test_expand_cause_repertoire(): assert np.all(abs(A.expand_cause_repertoire(CD) - cause) < EPSILON) assert np.all( abs( A.expand_cause_repertoire(BCD).flatten(order='F') - np.array([1 / 6 if i < 6 else 0 for i in range(8)])) < EPSILON)
def test_big_mip_macro(macro_s, flushcache, restore_fs_cache): flushcache() mip = compute.big_mip(macro_s) check_mip(mip, macro_answer)
def test_big_mip_big_network_0_thru_3(big_subsys_0_thru_3, flushcache, restore_fs_cache): flushcache() mip = compute.big_mip(big_subsys_0_thru_3) check_mip(mip, big_subsys_0_thru_3_answer)
def test_big_mip_big_network(big_subsys_all, flushcache, restore_fs_cache): flushcache() mip = compute.big_mip(big_subsys_all) check_mip(mip, big_answer)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from pyphi.compute import big_mip from pyphi import Subsystem import numpy as np import example_networks from pyphi.constants import EPSILON micro = example_networks.micro() micro.current_state = (0, 0, 0, 0) micro.past_state = (0, 0, 0, 0) micro_subsystem = Subsystem(range(micro.size), micro) mip = big_mip(micro_subsystem) CD = micro_subsystem.nodes[2:4] BCD = micro_subsystem.nodes[1:4] ABCD = micro_subsystem.nodes[0:4] A = mip.unpartitioned_constellation[0] cause = A.cause.mip.unpartitioned_repertoire effect = A.effect.mip.unpartitioned_repertoire def test_expand_cause_repertoire(): assert np.all(abs(A.expand_cause_repertoire(CD) - cause) < EPSILON) assert np.all(abs( A.expand_cause_repertoire(BCD).flatten(order='F') - np.array([1/6 if i < 6 else 0 for i in range(8)])) < EPSILON) assert np.all(abs(
def test_big_mip_complete_graph_rule152_s(rule152_s_complete): mip = compute.big_mip(rule152_s_complete) check_mip(mip, rule152_answer)
def test_big_mip_rule152(rule152_s, flushcache, restore_fs_cache): flushcache() mip = compute.big_mip(rule152_s) check_mip(mip, rule152_answer)
def test_jsonify_big_mip(s, flushcache, restore_fs_cache): flushcache() jsonify.loads(jsonify.dumps(compute.big_mip(s)))
def test_big_mip_single_node_selfloops_dont_have_phi(s_single, flushcache, restore_fs_cache): flushcache() assert compute.big_mip(s_single).phi == 0.0