Ejemplo n.º 1
0
def test_simneuronsmerger_warning(rng):
    nt = nengo.PoissonSpiking(nengo.Tanh())
    op1 = SimNeurons(
        nt, J=Signal(shape=(1,)), output=Signal(shape=(1,)), state={"rng": rng}
    )

    op2 = SimNeurons(
        nt, J=Signal(shape=(1,)), output=Signal(shape=(1,)), state={"rng": rng}
    )
    assert SimNeuronsMerger.is_mergeable(op1, op2)
    with pytest.warns(UserWarning, match="Extra state has been modified"):
        SimNeuronsMerger.merge([op1, op2])
Ejemplo n.º 2
0
def test_random_spiking(Simulator, inference_only, seed):
    with nengo.Network() as net:
        config.configure_settings(inference_only=inference_only)

        inp = nengo.Node([1])
        ens0 = nengo.Ensemble(100, 1, neuron_type=nengo.Tanh(), seed=seed)
        ens1 = nengo.Ensemble(
            100,
            1,
            neuron_type=nengo.StochasticSpiking(nengo.Tanh()),
            seed=seed,
        )
        ens2 = nengo.Ensemble(
            100,
            1,
            neuron_type=nengo.PoissonSpiking(nengo.Tanh()),
            seed=seed,
        )

        nengo.Connection(inp, ens0, synapse=None)
        nengo.Connection(inp, ens1, synapse=None)
        nengo.Connection(inp, ens2, synapse=None)

        p0 = nengo.Probe(ens0.neurons)
        p1 = nengo.Probe(ens1.neurons)
        p2 = nengo.Probe(ens2.neurons)

    with pytest.warns(None) as recwarns:
        with Simulator(net, seed=seed) as sim:
            sim.run_steps(10000)

    assert not any("native TensorFlow implementation" in str(w.message)
                   for w in recwarns)

    assert np.allclose(sim.data[p0][0],
                       np.mean(sim.data[p1], axis=0),
                       atol=1,
                       rtol=2e-1)
    assert np.allclose(sim.data[p0],
                       np.mean(sim.data[p2], axis=0),
                       atol=1,
                       rtol=1e-1)
Ejemplo n.º 3
0
def test_spikes_to_spikes_warning():
    with pytest.warns(UserWarning, match="type 'LIF', which is a spiking"):
        nengo.PoissonSpiking(nengo.LIF())
Ejemplo n.º 4
0
        nengo.Probe(c)

    with Simulator(net, seed=seed) as sim:
        sim.check_gradients()


@pytest.mark.eager_only
@pytest.mark.parametrize(
    "rate, spiking",
    [
        (nengo.RectifiedLinear, nengo.SpikingRectifiedLinear),
        (nengo.LIFRate, nengo.LIF),
        (SoftLIFRate, nengo.LIF),
        pytest.param(
            nengo.LIFRate,
            lambda **kwargs: nengo.PoissonSpiking(nengo.LIFRate(**kwargs)),
            marks=pytest.mark.skipif(
                version.parse(nengo.__version__) < version.parse("3.1.0dev0"),
                reason="PoissonSpiking does not exist",
            ),
        ),
        pytest.param(
            nengo.LIFRate,
            lambda **kwargs: nengo.RegularSpiking(nengo.LIFRate(), **kwargs),
            marks=pytest.mark.skipif(
                version.parse(nengo.__version__) < version.parse("3.1.0dev0"),
                reason="RegularSpiking does not exist",
            ),
        ),
    ],
)