Ejemplo n.º 1
0
def test_cluster_graph():
    network = nengo.Network()

    with network:
        node = nengo.Node(0.5, label='Node 0')
        A = nengo.Ensemble(50, 1, label='A')
        B = nengo.Ensemble(50, 1, label='B')

        nengo.Connection(node, A)
        nengo.Connection(A, B)

    bp = make_boundary_predicate(network)

    component0, cluster_graph = network_to_cluster_graph(network, bp)
    assert len(cluster_graph) == 2

    component0, cluster_graph = network_to_cluster_graph(
        network, bp, merge_nengo_nodes=False)
    assert len(cluster_graph) == 3

    with network:
        node = nengo.Node(lambda x: 0.5, label='Node 1')

    component0, cluster_graph = network_to_cluster_graph(network, bp)
    assert len(cluster_graph) == 2
    assert component0 is not None

    component0, cluster_graph = network_to_cluster_graph(
        network, bp, merge_nengo_nodes=False)
    assert len(cluster_graph) == 4
    assert component0 is not None

    with network:
        node = nengo.Node(lambda x: 0.7, label='Node 2')
        nengo.Connection(node, A, synapse=None)

    component0, cluster_graph = network_to_cluster_graph(network, bp)
    assert len(cluster_graph) == 2

    component0, cluster_graph = network_to_cluster_graph(
        network, bp, merge_nengo_nodes=False)
    assert len(cluster_graph) == 3

    with network:
        C = nengo.Ensemble(100, 1, label='C')
        nengo.Connection(C, A)

    component0, cluster_graph = network_to_cluster_graph(network, bp)
    assert len(cluster_graph) == 3

    component0, cluster_graph = network_to_cluster_graph(
        network, bp, merge_nengo_nodes=False)
    assert len(cluster_graph) == 4
Ejemplo n.º 2
0
def test_default(simple_network, n_components):

    # Save the network to a file so that an MpiSimulator is not created.
    save_file = 'test.net'

    component0, cluster_graph = network_to_cluster_graph(simple_network)

    partitioner = Partitioner(n_components)

    sim = Simulator(
        simple_network, partitioner=partitioner, save_file=save_file)

    assert sim.n_components == min(len(cluster_graph), n_components)
    assert os.path.isfile(save_file)
    os.remove(save_file)
Ejemplo n.º 3
0
def test_insufficient_chunks(simple_network):
    """
    Test the case where the network contains too few chunks to use the
    specified number of components.
    """

    component0, cluster_graph = network_to_cluster_graph(simple_network)

    partitioner = Partitioner(len(cluster_graph) + 10)

    save_file = 'test.net'
    sim = Simulator(
        simple_network, partitioner=partitioner, save_file=save_file)

    assert sim.n_components == len(cluster_graph)
    assert os.path.isfile(save_file)
    os.remove(save_file)
Ejemplo n.º 4
0
def test_default(simple_network, n_components):

    # Save the network to a file so that an MpiSimulator is not created.
    save_file = 'test.net'

    bp = make_boundary_predicate(simple_network)
    component0, cluster_graph = network_to_cluster_graph(simple_network, bp)

    partitioner = Partitioner(n_components)

    sim = Simulator(
        simple_network, partitioner=partitioner, save_file=save_file)

    try:
        assert sim.n_components == min(len(cluster_graph), n_components)
        assert os.path.isfile(save_file)
    finally:
        try:
            os.remove(save_file)
        except:
            pass
Ejemplo n.º 5
0
def test_insufficient_chunks(simple_network):
    """
    Test the case where the network contains too few chunks to use the
    specified number of components.
    """

    bp = make_boundary_predicate(simple_network)
    component0, cluster_graph = network_to_cluster_graph(simple_network, bp)

    partitioner = Partitioner(len(cluster_graph) + 10)

    save_file = 'test.net'

    try:
        sim = Simulator(
            simple_network, partitioner=partitioner, save_file=save_file)
        assert sim.n_components == len(cluster_graph)
        assert os.path.isfile(save_file)
    finally:
        try:
            os.remove(save_file)
        except:
            pass