Exemplo n.º 1
0
def check_concept_caching(net, states, flushcache):
    flushcache()

    # Build the networks for each state.
    networks = {s: Network(net.tpm, net.connectivity_matrix) for s in states}

    # Empty the cache.
    flushcache()

    # Get the complexes for each state with no concept caching.
    constants.CACHE_CONCEPTS = False
    no_caching_results = []
    for s in states:
        no_caching_results.append(list(compute.complexes(networks[s], s)))

    # Empty the cache.
    flushcache()

    # Get the complexes for each state with concept caching.
    constants.CACHE_CONCEPTS = True
    caching_results = []
    for s in states:
        caching_results.append(list(compute.complexes(networks[s], s)))

    assert caching_results == no_caching_results
Exemplo n.º 2
0
def check_concept_caching(net, states, flushcache):
    flushcache()

    # Build the networks for each state.
    networks = {
        s: Network(net.tpm, net.connectivity_matrix) for s in states
    }

    # Empty the cache.
    flushcache()

    # Get the complexes for each state with no concept caching.
    constants.CACHE_CONCEPTS = False
    no_caching_results = []
    for s in states:
        no_caching_results.append(list(compute.complexes(networks[s], s)))

    # Empty the cache.
    flushcache()

    # Get the complexes for each state with concept caching.
    constants.CACHE_CONCEPTS = True
    caching_results = []
    for s in states:
        caching_results.append(list(compute.complexes(networks[s], s)))

    assert caching_results == no_caching_results
Exemplo n.º 3
0
def test_rule152_complexes_no_caching(rule152):
    net = rule152
    # Mapping from index of a PyPhi subsystem in network.subsystems to the
    # index of the corresponding subsystem in the Matlab list of subsets
    perm = {0: 0, 1: 1, 2: 3, 3: 7, 4: 15, 5: 2, 6: 4, 7: 8, 8: 16, 9: 5, 10:
            9, 11: 17, 12: 11, 13: 19, 14: 23, 15: 6, 16: 10, 17: 18, 18: 12,
            19: 20, 20: 24, 21: 13, 22: 21, 23: 25, 24: 27, 25: 14, 26: 22, 27:
            26, 28: 28, 29: 29, 30: 30}
    with open('test/data/rule152_results.pkl', 'rb') as f:
        results = pickle.load(f)

    # Don't use concept caching for this test.
    constants.CACHE_CONCEPTS = False

    for k, result in results.items():
        print(net.current_state, net.past_state)
        # Empty the DB.
        _flushdb()
        # Unpack the current/past state from the results key.
        current_state, past_state = k
        # Generate the network with the current and past state we're testing.
        net = Network(rule152.tpm, current_state, past_state,
                      connectivity_matrix=rule152.connectivity_matrix)
        # Comptue all the complexes, leaving out the first (empty) subsystem
        # since Matlab doesn't include it in results.
        complexes = list(compute.complexes(net))[1:]
        # Check the phi values of all complexes.
        zz = [(bigmip.phi, result['subsystem_phis'][perm[i]]) for i, bigmip in
            list(enumerate(complexes))]
        diff = [utils.phi_eq(bigmip.phi, result['subsystem_phis'][perm[i]]) for
                i, bigmip in list(enumerate(complexes))]
        assert all(utils.phi_eq(bigmip.phi, result['subsystem_phis'][perm[i]])
                for i, bigmip in list(enumerate(complexes))[:])
        # Check the main complex in particular.
        main = compute.main_complex(net)
        # Check the phi value of the main complex.
        assert utils.phi_eq(main.phi, result['phi'])
        # Check that the nodes are the same.
        assert (main.subsystem.node_indices ==
                complexes[result['main_complex'] - 1].subsystem.node_indices)
        # Check that the concept's phi values are the same.
        result_concepts = [c for c in result['concepts'] if c['is_irreducible']]
        z = list(zip([c.phi for c in main.unpartitioned_constellation],
                    [c['phi'] for c in result_concepts]))
        diff = [i for i in range(len(z)) if not utils.phi_eq(z[i][0], z[i][1])]
        assert all(list(utils.phi_eq(c.phi, result_concepts[i]['phi']) for i, c
                        in enumerate(main.unpartitioned_constellation)))
        # Check that the minimal cut is the same.
        assert main.cut == result['cut']
Exemplo n.º 4
0
def test_rule152_complexes_no_caching(rule152):
    net = rule152
    # Mapping from index of a PyPhi subsystem in network.subsystems to the
    # index of the corresponding subsystem in the Matlab list of subsets
    perm = {0: 0, 1: 1, 2: 3, 3: 7, 4: 15, 5: 2, 6: 4, 7: 8, 8: 16, 9: 5, 10:
            9, 11: 17, 12: 11, 13: 19, 14: 23, 15: 6, 16: 10, 17: 18, 18: 12,
            19: 20, 20: 24, 21: 13, 22: 21, 23: 25, 24: 27, 25: 14, 26: 22, 27:
            26, 28: 28, 29: 29, 30: 30}
    with open('test/data/rule152_results.pkl', 'rb') as f:
        results = pickle.load(f)

    # Don't use concept caching for this test.
    constants.CACHE_CONCEPTS = False

    for k, result in results.items():
        print(net.current_state, net.past_state)
        # Empty the DB.
        _flushdb()
        # Unpack the current/past state from the results key.
        current_state, past_state = k
        # Generate the network with the current and past state we're testing.
        net = Network(rule152.tpm, current_state, past_state,
                      connectivity_matrix=rule152.connectivity_matrix)
        # Comptue all the complexes, leaving out the first (empty) subsystem
        # since Matlab doesn't include it in results.
        complexes = list(compute.complexes(net))[1:]
        # Check the phi values of all complexes.
        zz = [(bigmip.phi, result['subsystem_phis'][perm[i]]) for i, bigmip in
            list(enumerate(complexes))]
        diff = [utils.phi_eq(bigmip.phi, result['subsystem_phis'][perm[i]]) for
                i, bigmip in list(enumerate(complexes))]
        assert all(utils.phi_eq(bigmip.phi, result['subsystem_phis'][perm[i]])
                for i, bigmip in list(enumerate(complexes))[:])
        # Check the main complex in particular.
        main = compute.main_complex(net)
        # Check the phi value of the main complex.
        assert utils.phi_eq(main.phi, result['phi'])
        # Check that the nodes are the same.
        assert (main.subsystem.node_indices ==
                complexes[result['main_complex'] - 1].subsystem.node_indices)
        # Check that the concept's phi values are the same.
        result_concepts = [c for c in result['concepts'] if c['is_irreducible']]
        z = list(zip([c.phi for c in main.unpartitioned_constellation],
                    [c['phi'] for c in result_concepts]))
        diff = [i for i in range(len(z)) if not utils.phi_eq(z[i][0], z[i][1])]
        assert all(list(utils.phi_eq(c.phi, result_concepts[i]['phi']) for i, c
                        in enumerate(main.unpartitioned_constellation)))
        # Check that the minimal cut is the same.
        assert main.cut == result['cut']
Exemplo n.º 5
0
def test_complexes_standard(standard, flushcache, restore_fs_cache):
    flushcache()
    complexes = list(compute.complexes(standard))
    check_mip(complexes[7], standard_answer)
Exemplo n.º 6
0
def test_complexes_standard(s):
    complexes = list(compute.complexes(s.network, s.state))
    check_sia(complexes[0], standard_answer)
Exemplo n.º 7
0
def test_rule152_complexes_no_caching(rule152):
    net = rule152
    # Mapping from index of a PyPhi subsystem in network.subsystems to the
    # index of the corresponding subsystem in the Matlab list of subsets
    perm = {
        0: 0,
        1: 1,
        2: 3,
        3: 7,
        4: 15,
        5: 2,
        6: 4,
        7: 8,
        8: 16,
        9: 5,
        10: 9,
        11: 17,
        12: 11,
        13: 19,
        14: 23,
        15: 6,
        16: 10,
        17: 18,
        18: 12,
        19: 20,
        20: 24,
        21: 13,
        22: 21,
        23: 25,
        24: 27,
        25: 14,
        26: 22,
        27: 26,
        28: 28,
        29: 29,
        30: 30,
    }
    with open("test/data/rule152_results.pkl", "rb") as f:
        results = pickle.load(f)

    # Don't use concept caching for this test.
    constants.CACHE_CONCEPTS = False

    for state, result in results.items():
        # Empty the DB.
        _flushdb()
        # Unpack the state from the results key.
        # Generate the network with the state we're testing.
        net = Network(rule152.tpm, state, cm=rule152.cm)
        # Comptue all the complexes, leaving out the first (empty) subsystem
        # since Matlab doesn't include it in results.
        complexes = list(compute.complexes(net))[1:]
        # Check the phi values of all complexes.
        zz = [(sia.phi, result["subsystem_phis"][perm[i]])
              for i, sia in list(enumerate(complexes))]
        diff = [
            utils.eq(sia.phi, result["subsystem_phis"][perm[i]])
            for i, sia in list(enumerate(complexes))
        ]
        assert all(
            utils.eq(sia.phi, result["subsystem_phis"][perm[i]])
            for i, sia in list(enumerate(complexes))[:])
        # Check the major complex in particular.
        major = compute.major_complex(net)
        # Check the phi value of the major complex.
        assert utils.eq(major.phi, result["phi"])
        # Check that the nodes are the same.
        assert (major.subsystem.node_indices == complexes[
            result["major_complex"] - 1].subsystem.node_indices)
        # Check that the concept's phi values are the same.
        result_concepts = [
            c for c in result["concepts"] if c["is_irreducible"]
        ]
        z = list(
            zip([c.phi for c in major.ces],
                [c["phi"] for c in result_concepts]))
        diff = [i for i in range(len(z)) if not utils.eq(z[i][0], z[i][1])]
        assert all(
            list(
                utils.eq(c.phi, result_concepts[i]["phi"])
                for i, c in enumerate(major.ces)))
        # Check that the minimal cut is the same.
        assert major.cut == result["cut"]
Exemplo n.º 8
0
def test_jsonify_complexes(s, flushcache, restore_fs_cache):
    flushcache()
    complexes = compute.complexes(s.network, s.state)
    jsonify.loads(jsonify.dumps(complexes))
Exemplo n.º 9
0
def test_complexes_standard(standard, flushcache, restore_fs_cache):
    flushcache()
    complexes = list(compute.complexes(standard))
    check_mip(complexes[2], standard_answer)
Exemplo n.º 10
0
def test_complexes_standard(s, flushcache, restore_fs_cache):
    flushcache()
    complexes = list(compute.complexes(s.network, s.state))
    check_sia(complexes[0], standard_answer)
Exemplo n.º 11
0
def test_complexes_standard(s, flushcache, restore_fs_cache):
    flushcache()
    complexes = list(compute.complexes(s.network, s.state))
    check_mip(complexes[2], standard_answer)