Example #1
0
def test_random_graph(partitioner, refimpl_results):
    m, refimpl_sim, sim_time = refimpl_results

    n_processors = 8
    partitioner = nengo_mpi.Partitioner(n_processors, func=partitioner)

    network_file = "test_nengo_mpi.net"
    log_file = "test_nengo_mpi.h5"
    log_file_1p = "test_nengo_mpi_1p.h5"

    try:
        nengo_mpi.Simulator(m, partitioner=partitioner, save_file=network_file)

        results = run_standalone_mpi(network_file, log_file, n_processors, sim_time)
        results_1p = run_standalone_mpi(network_file, log_file_1p, 1, sim_time)

        for p in m.probes:
            assert np.allclose(refimpl_sim.data[p], results[str(id(p))], atol=0.00001, rtol=0.00)

        for p in m.probes:
            assert np.allclose(refimpl_sim.data[p], results_1p[str(id(p))], atol=0.00001, rtol=0.00)
    finally:
        try:
            os.remove(network_file)
        except:
            pass
Example #2
0
def test_basic_mpi(neuron_type, synapse):
    n_neurons = 40

    m = nengo.Network(seed=1)
    with m:
        A = nengo.Ensemble(
            n_neurons, dimensions=3, neuron_type=neuron_type())

        B = nengo.Ensemble(
            n_neurons, dimensions=3, neuron_type=neuron_type())

        nengo.Connection(A, B, synapse=synapse)

        A_p = nengo.Probe(A)
        B_p = nengo.Probe(B)

        input = nengo.Node([0.1, 0.2, -0.3])
        nengo.Connection(input, A, synapse=0.05)

    sim_time = 1

    refimpl_sim = nengo.Simulator(m)
    refimpl_sim.run(sim_time)

    network_file = "test_nengo_mpi.net"
    log_file = "test_nengo_mpi.h5"
    n_processors = 2

    try:
        nengo_mpi.Simulator(
            m, partitioner=nengo_mpi.Partitioner(n_processors),
            save_file=network_file)

        results = run_standalone_mpi(
            network_file, log_file, n_processors, sim_time)

        assert np.allclose(
            refimpl_sim.data[A_p], results[str(id(A_p))],
            atol=0.00001, rtol=0.00)
        assert np.allclose(
            refimpl_sim.data[B_p], results[str(id(B_p))],
            atol=0.00001, rtol=0.00)
    finally:
        try:
            os.remove(network_file)
        except:
            pass