Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 30 2019 17:07
    mstimberg commented #1047
  • Jan 30 2019 16:53
    thesamovar commented #1047
  • Jan 30 2019 15:40
    mstimberg commented #1047
  • Jan 30 2019 12:16
    daphn3cor closed #1048
  • Jan 30 2019 12:15
    daphn3cor commented #1048
  • Jan 30 2019 10:33
    mstimberg synchronize #1047
  • Jan 30 2019 10:33

    mstimberg on function_compiler_kwds

    Add .c and .pxd to the list of … Make Cython compilation quiet a… (compare)

  • Jan 30 2019 09:57
    mstimberg edited #1047
  • Jan 30 2019 09:56
    mstimberg synchronize #1047
  • Jan 30 2019 09:56

    mstimberg on function_compiler_kwds

    Document the new features for u… (compare)

  • Jan 30 2019 09:56
    mstimberg commented #1048
  • Jan 30 2019 07:59
    daphn3cor commented #1048
  • Jan 29 2019 16:30
    mstimberg commented #1048
  • Jan 29 2019 15:42
    daphn3cor opened #1048
  • Jan 29 2019 14:44
    mstimberg synchronize #1047
  • Jan 29 2019 14:44

    mstimberg on function_compiler_kwds

    Include external source files a… (compare)

  • Jan 29 2019 13:48
    mstimberg synchronize #1047
  • Jan 29 2019 13:48

    mstimberg on function_compiler_kwds

    Minor bug-fixes for new additio… Support external source files f… Add tests for functions with ex… (compare)

  • Jan 25 2019 17:34
    thesamovar commented #1047
  • Jan 25 2019 17:26
    mstimberg opened #1047
wxie2013
@wxie2013

Here is the complete error message:

code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp:71:24: error: "0.5235987666666666" may not appear in macro parameter list

 #define _brian_pow(0.5235987666666666, y) (pow((0.5235987666666666), (y)))
                    ^~~~~~~~~~~~~~~~~~

code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp:71:24: error: "0.5235987666666666" may not appear in macro parameter list

 #define _brian_pow(0.5235987666666666, y) (pow((0.5235987666666666), (y)))
                    ^~~~~~~~~~~~~~~~~~

code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp:15:34: error: expected ',' or '...' before numeric constant
inline double usersin(double 0.5235987666666666)
^~~~~~
code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp:58:19: error: expected ',' or '...' before numeric constant
_brian_mod(T1 0.5235987666666666, T2 y)
^~~~~~
code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp: In function 'typename {anonymous}::_higher_type<T1, T2>::type {anonymous}::_brian_mod(T1)':
code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp:60:35: error: 'y' was not declared in this scope
return 0.5235987666666666-yfloor(1.00.5235987666666666/y);
^
code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp:60:35: note: suggested alternative: 'yn'
return 0.5235987666666666-yfloor(1.00.5235987666666666/y);
^
yn
code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp: At global scope:
code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp:64:24: error: expected ',' or '...' before numeric constant
_brian_floordiv(T1 0.5235987666666666, T2 y)
^~~~~~
code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp: In function 'typename {anonymous}::_higher_type<T1, T2>::type {anonymous}::_brian_floordiv(T1)':
code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp:66:45: error: 'y' was not declared in this scope
return floor(1.00.5235987666666666/y);
^
code_objects/neurongroup_group_variable_set_conditional_codeobject.cpp:66:45: note: suggested alternative: 'yn'
return floor(1.0
0.5235987666666666/y);
^
yn
make: [make.deps] Error 1
make:
Waiting for unfinished jobs....
make: * [code_objects/neurongroup_group_variable_set_conditional_codeobject.o] Error 1

Marcel Stimberg
@mstimberg
Uhh, you just found an ugly bug in the way we deal with external constants named x (in your case the x = 30/180...). I will work on fixing this later, but for now you can either: directly use the value instead of going via an external constant (i.e. use group.y = 'usersin(30/180.*3.1415926)') or give the external constant a name that is not x(e.g. angle = 30/180.*3.14 ; group.y = 'usersin(angle)').
Marcel Stimberg
@mstimberg
(the name should not be y either :grin: )
wxie2013
@wxie2013
Cool. Thanks for the clarification
wxie2013
@wxie2013
Here is the working version as instructed:
from brian2 import *
set_device('cpp_standalone')

@implementation('cpp','''
                 #include<math.h>
                 inline double usersin(double x)
                 {
                    return sin(x);
                 } 
                 ''')

@check_units(x=1, result=1)

def usersin(x):
    raise NotImplementedError("!!!")


# ... definition of usersin
group = NeuronGroup(1, 'yy : 1')
xx = 30/180.*3.1415926
group.yy = 'usersin(xx)'
run(1*ms)
print(group.yy)
wxie2013
@wxie2013

to check if a synapse has any connect, one can use

 if S.i > 0:
         print('has connection')

is there a cleaner way to do this check?

wxie2013
@wxie2013
Oops. I mean
      if len(S.i) > 0:
             print('has connection')
Marcel Stimberg
@mstimberg
A slightly shorter variant is to use len(S) which also gives the number of connections. But this gives the total number of connections for the whole Synapses object, is that what you wanted to check? I am having a hard time seeing a situation where you don't know whether there are any connections at all.
wxie2013
@wxie2013

Thanks Marcel. It happens when I try to do a spatial connection via Gaussian sampling and when the sigma is too small, for example:

 import numpy as np
 from brian2 import *

 N = 9
 col = sqrt(N)
 G = NeuronGroup(N, '''x : 1
                       y : 1''')
 G.x = '(i // col)*10'
 G.y = '(i % col)*10'
 S = Synapses(G, G)
 sig_val = 1
 S.connect(condition='i!=j', p='exp(-((x_pre-x_post)**2 + (y_pre-y_post)**2)/(2*(sigma)**2))', skip_if_invalid=True, namespace={'sigma':sig_val})
 run(100*ms)
 print(len(S))

The probability for any connection of i!=j is close to zero and all formed connection are i=j.

Marcel Stimberg
@mstimberg
I see, that makes sense. If you don't use standalone mode, you could check the numbers of synapses before running the simulation, though :)
wxie2013
@wxie2013
I see. Will do accordingly
wxie2013
@wxie2013

I'm trying to normalize the weight of all synapses connecting to a certain number of neurons, i.e.

    for j in range(N):
           tot_weight = np.sum(S.w[:,j]) [I 18:18:48.502 NotebookApp] Saving file at /run_Spike.ipynb
           self.S.w[:,j]/=tot_weight

The speed somehow is very slow. Could there be a faster way of doing the same thing?

Marcel Stimberg
@mstimberg
Yes indeed, this kind of loop can be very slow... There are two issues here: 1) The [:, j] syntax requires Brian to search through all the synapses (stored in a flat array) and 2) this search is done twice, once for getting the values and once for setting them
Issue number 2 is quite easy to fix, you can do something like:
for j in range(N):
    indices = S.indices[:, j]
    tot_weight = np.sum(S.w[indices])
    S.w[indices] /= tot_weight
Marcel Stimberg
@mstimberg
For issue number 1, it depends on how your synapses are connected.
If you have a fixed number of neurons per target neuron, you can avoid a loop completely and do normalization very fast using a matrix operation. E.g. if your neurons are all-to-all connected, something like the following should work:
reshaped = np.reshape(S.w[:], (len(source_group), len(target_group))
tot_weight = np.sum(reshaped, axis=0)
S.w[:] = (reshaped / tot_weight).flatten()
wxie2013
@wxie2013
Thanks Marcel. In my case, the number of neuron per target varies (I used Gaussian sampling). Any further suggestion to speed it up? One possibility is to store the index range for each target neuron at the beginning to avoid searching.
wxie2013
@wxie2013
The idea of storing range won't work because the index of the source neurons for each target neuron is not continous. I will use the fully connected network instead and with matrix operation to proceed
Marcel Stimberg
@mstimberg

You could also convert your connections into a matrix, do the normalization and then convert it back to a flat representation again. It's a bit trickier if it is not fully connected, but it is doable. Getting a matrix from Brian's connection structure is quite straightforward: https://brian2.readthedocs.io/en/stable/user/synapses.html#synaptic-connection-weight-matrices Then, you can normalize it and use

flattened = matrix.flatten()
S.w[:] = flattened[~np.isnan(flattened)]

to put it back into Brian's structure

wxie2013
@wxie2013
Thanks Marcel. That solves the problem in general
wxie2013
@wxie2013
I'm running a code by setting defaultclock.dt = 0.5ms and 0.1ms, the total amount of time is similar. I was expecting the code with dt= 0.5ms to run much faster. Is this somewhat expected? By the way, is dt= 0.5ms too large for solving neuron equations?
VigneswaranC
@Vigneswaran-Chandrasekaran
Hi, changing defaultclock.dt as 0.5ms does reduce the running time than that of 0.1ms. I think maybe your overall simulation time is small to show any significant difference
wxie2013
@wxie2013
Thanks. I run about 10K samples for 0.5s each. The total running time is ~10 hours and the saving is not much. It might be due to other overhead in my code. Does Brian has a function to monitor the timing for each step?
VigneswaranC
@Vigneswaran-Chandrasekaran

Does Brian has a function to monitor the timing for each step?

I think you can use progress reporting to see the percentage of simulation time completed and corresponding time elapsed

yerimayohanna
@yerimayohanna:matrix.org
[m]
Hi everyone, I'm new to brian but have learnt relatively some few things over the weekend. I need assistance on how to simulate my EMG data with .npy extension on brian
VigneswaranC
@Vigneswaran-Chandrasekaran
Hi, I am not sure whether you're looking for Brian's model-fitting tool? You shall also post your questions in the new Brian discourse group, where more advanced users can see and help
wxie2013
@wxie2013

Does Brian has a function to monitor the timing for each step?

I think you can use progress reporting to see the percentage of simulation time completed and corresponding time elapsed

Thanks. That's very helpful.

VigneswaranC
@Vigneswaran-Chandrasekaran
Glad it helped
asselSergazina
@asselSergazina
Good day, Dear Brian2 users, Could you give me one full example to use @network_operation, I looked at Brian2 documentation, but couldn't find a suitable approach in my case. In my situation my external input won't give every dt=10*ms(or any other time step), my input must change "10ms after simulating the input layer, the output neurons are given an external simulation" between t=15.5 s to 25 s, Thank you in advance! I wrote the shortest implementation here https://brian.discourse.group/t/pattern-recognition-in-spiking-neural-nets-using-brian2/141/14 , but this is not giving correct result. Could you give any guide, please?
wxie2013
@wxie2013
Sometime it took really long to import Brian2, i.e. "from brian2 import *". Are there possible places I can look into when this happens?
wxie2013
@wxie2013
quick update: after remove .cythan/brian_extensions, the import become normal. Not sure if they are related.
Marcel Stimberg
@mstimberg
Hmm, we check the total size of .cython/brian_extensions to give a warning to the user when this directory is very big. This shouldn't take much time, though. In general, importing brian can be a bit slow because we also import numpy, scipy, etc.
wxie2013
@wxie2013
Thanks Marcel. I did not clean the brian_extensions after seeing the message and it has accumulated a large number of files these days. The import actually froze yesterday until I cleaned up the brian_extensions. It could be an coincidence.
wxie2013
@wxie2013

Does brian2 limit the precision of, e.g. spiking threshold, to 8 digit after decimal? For example, I saved a threshold "-0.05195001" using savez. Then I load it via "a = np.load('file.npz')" and print it out in two ways

  1. print(a['vt']): -0.05195001

  2. print(a['vt'])*volt: -51.95001227

it keep the 8 digit after the decimal and the number after the 6th digit in the 2nd scenario seems random. Just wondering if this is a brian2 feature or my code issue. Thanks

Marcel Stimberg
@mstimberg
I think this is just a display issue. Brian does not limit values in any way (except that they are stored as 64bit floating point values), but numpy's default settings only print 8 decimals. So the actual value is probably closer to the one displayed after converting it to a quantity. You can change the display settings by using something like np.set_printoptions(precision=16).
wxie2013
@wxie2013
This is indeed the case. Thanks!
A. Ziaeemehr
@Ziaeemehr
Hi,
I have a problem with applying delay to continues updating synapse:
'''
I_syn = g_syn * s_in * (-v) :  amp
s_in: 1
ds/dt = 0.5 * (1 + tanh(0.1*v/mV)) * (1-s)/tau_r - s/tau_d : 1
'''
S = b2.Synapses(neurons,
                    neurons,
                    '''
                    w : 1
                    s_in_post = w*s_pre:1 (summed)
                    ''')
S.connect(i=0, j=1)
S.w[0, 1] = weight
S.delay = delay
Traceback (most recent call last):
  File "/home/ziaee/.local/lib/python3.8/site-packages/brian2/groups/group.py", line 355, in state
    var = self.variables[name]
  File "/home/ziaee/.local/lib/python3.8/site-packages/brian2/core/variables.py", line 1448, in __getitem__
    return self._variables[item]
KeyError: 'post'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ziaee/.local/lib/python3.8/site-packages/brian2/groups/group.py", line 391, in __getattr__
    return self.state(name, use_units)
  File "/home/ziaee/.local/lib/python3.8/site-packages/brian2/groups/group.py", line 357, in state
    raise KeyError("State variable "+name+" not found.") from exc
KeyError: 'State variable post not found.'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tt.py", line 75, in <module>
    state_monitor = simulate_bursting_neurons(7.0 * b2.uA, 101 * b2.ms)
  File "tt.py", line 64, in simulate_bursting_neurons
    S.post.delay = delay
  File "/home/ziaee/.local/lib/python3.8/site-packages/brian2/groups/group.py", line 394, in __getattr__
    raise AttributeError('No attribute with name ' + name)
AttributeError: No attribute with name post
1 reply
Marcel Stimberg
@mstimberg
Delays apply to the on_pre/on_post events, not to continuous interactions. The only workaround at the moment is to fake this via an event-based mechanism that sends "spikes" at every time step. You'd need to add something along the lines of:
neurons.run_regularly('s_in = 0', when='start')
S = b2.Synapses(..., on_pre='s_in_post += w*s_pre')
S.delay = ...
JawDrin
@JawDrin
image.png
Hi, I have a problems with brian2.test.
Could you help me?
Marcel Stimberg
@mstimberg
Hi @JawDrin . Your screenshot does not show the actual error that made one of the tests fail. Since there's only one test that failed, could you try to run it without running the rest of the test suite and post the error you get here? Execute the following lines in the Python console or in a script:
from brian2 import prefs
prefs.codegen.target = 'cython'
from brian2.tests.test_functions import test_external_function_cython
test_external_function_cython()
Could you also check the Brian version, e.g. with:
import brian2
print(brian2.__version__)
JawDrin
@JawDrin

import brian2

print(brian2.version)
2.4.2

from brian2 import prefs

prefs.codegen.target = 'cython'

from brian2.tests.test_functions import test_external_function_cython

test_external_function_cython()
Traceback (most recent call last):

File "<ipython-input-7-3a74ea836b1d>", line 1, in <module>
test_external_function_cython()

File "D:\anaconda3\envs\mybrian\lib\site-packages\brian2\tests\test_functions.py", line 528, in test_external_function_cython
net.run(defaultclock.dt)

File "D:\anaconda3\envs\mybrian\lib\site-packages\brian2\core\base.py", line 278, in device_override_decorated_function
return func(args, *kwds)

File "D:\anaconda3\envs\mybrian\lib\site-packages\brian2\units\fundamentalunits.py", line 2434, in new_f
result = f(args, *kwds)

File "D:\anaconda3\envs\mybrian\lib\site-packages\brian2\core\network.py", line 1008, in run
self.before_run(namespace)

File "D:\anaconda3\envs\mybrian\lib\site-packages\brian2\core\base.py", line 278, in device_override_decorated_function
return func(args, *kwds)

File "D:\anaconda3\envs\mybrian\lib\site-packages\brian2\core\network.py", line 899, in before_run
raise BrianObjectException("An error occurred when preparing an object.", obj) from ex

BrianObjectException: Error encountered with object named "statemonitor".
Object was created here (most recent call only, full details in debug log):
File "<ipython-input-7-3a74ea836b1d>", line 1, in <module>
test_external_function_cython()

An error occurred when preparing an object. (See above for original error message and traceback.)

thank you!
@mstimberg thank you
Marcel Stimberg
@mstimberg
Thanks for the full error message in the direct message. I have to say that I've never encountered this error before, so I don't have an easy fix right now. But please also note that if this is the only test that is failing (as indicated by your initial screenshot), then there is nothing to worry about. This test is only for a very specific, advanced feature (enhancing Brian's functionality with user-written code in Cython). You will very likely never encounter this situation in your use of Brian. But if you are willing to aid in debugging this further, could you also answer these questions: how did you install Brian (with pip I guess?), and what Python version are you using? From your error messages I see you are on Windows which unfortunately makes it harder to debug for me since I am on Linux.
JawDrin
@JawDrin
@mstimberg Thanks for your guidance and suggestions! I run the 'brian2.test' just for testing if I installed brian2 successfully with anaconda under Pythion 3.6.13 environment. For now, you're right that I will not encounter this situation in my use of Brian2. I thought I didn't install Brian2 successfully and it wouldn't work, so I came here for some help.
Marcel Stimberg
@mstimberg
Ok, I'll try to investigate a bit further, but I think the bug will be problem will be hard to reproduce. Let us know if you run into any other issue!