Error when running with synapse of 0-connections loaded from a file

When running with synapse of 0-connections loaded from a file, I encounter the error the following error in runtime mode:

"synapses' does not do anything   ...."

This error, however, doesn’t show up in cpp_standalone mode. Is it possible to avoid this error in runtime mode?

Here is the code to demonstrate the issue:

    from brian2 import *
    import numpy as np

    #set_device('cpp_standalone')

    eqs = '''
    dv/dt = (I-v)/tau : 1
    I : 1
    tau : second
    '''
    G = NeuronGroup(3, eqs, threshold='v>1', reset='v = 0', method='exact')
    G.I = [2, 0, 0]
    G.tau = [10, 100, 100]*ms

    t = np.load('test.npz')
    S = Synapses(G, G, 'w : 1', on_pre='v_post += w')
    if len(t['i'])>0:
        S.connect(i=t['i'], j=t['j'])
        S.w = t['w']
        S.delay = t['delay']*ms

    net = Network()
    net.add(G)
    net.add(S)

    run(50*ms)

After removing the comment on “set_device(‘cpp_standalone’)”, the run will be successful. I also noticed that without “Network()”, the code can run in both mode, but I will need the Network() in the actual application.

The code to produce the input file “test.npz” is the following:

    from brian2 import *
    import numpy as np

    eqs = '''
    dv/dt = (I-v)/tau : 1
    I : 1
    tau : second
    '''
    G = NeuronGroup(3, eqs, threshold='v>1', reset='v = 0', method='exact')
    G.I = [2, 0, 0]
    G.tau = [10, 100, 100]*ms

    S = Synapses(G, G, 'w : 1', on_pre='v_post += w')
    S.connect(p=0.0)
    S.w = 'j*0.2'
    S.delay = 'j*2*ms'

    # save the file, load it and run
    np.savez('test', i=S.i[:], j=S.j[:], w=S.w[:], delay=S.delay[:])

    run(50*ms)

Thanks

Hi @DavidKing2020 , thanks for the report. This is a bit of a bug: the error message is correct (you shouldn’t be able to use Synapses where connect has never been called), but calling S.connect(i=..., j=...) with empty arrays should work (so there should be no need for the if len(...) statement). As a workaround, you can add an explicit empty connect after the block, i.e.:

if len(t['i'])>0:
    ...
else:
    S.connect(False)

It should then work in either mode.

Using a Network or not shouldn’t make a difference with respect to the two modes, but note that here:

You are creating a network net but you are not using it – instead you run the default “magic network” composed of all objects visible at the location of the run call. You probably want to use net.run(50*ms) instead.

1 Like