GSoC 2020 project idea 9: Realtime simulations

Hi, thank you for your interest in the project. The exercises from the book are a great way to learn about computational neuroscience, but be aware that their code hides away a lot of how Brian works. To get more familiar with Brian itself I’d recommend having a look at the tutorials: https://brian2.readthedocs.io/en/stable/resources/tutorials/index.html

For the project, it will be important to understand how Brian’s code generation mechanism works. Have a look at section 3 in our 2014 paper or e.g. at section 2.1 in the code generation review paper that we co-authored. Finally, to really get a detailed understanding of what is happening behind the scenes you can run a simple example with Brian’s standalone mode and have a look at the generated code.

I have gone through the above mentioned sites.Now can you please give me a concrete example of this: “currently the simulation time advances in fixed time step, completely independent from the real time”.i.e., in what format is the real time input ,say from a sensor, is fed into the simulation model and in what way mechanism slowing the simulation is to be applied i.e, a c++ function is to be written or changes in source code of Brian is to be made?

I want to start analysing the solution for the problem,can someone please help me with the query?

Hi. There is no general mechanism to feed real time input into Brian, but you can use its function extension system for that task. The only actual “real time” example we have is an example from our recent 2019 paper where we feed audio input from a microphone into a model. You can find a notebook with the example here: https://github.com/brian-team/brian2_paper_examples/blob/master/example_4_microphone.ipynb (the C++ file responsible for getting the microphone input is here: https://github.com/brian-team/brian2_paper_examples/blob/master/example_4_microphone.ipynb). We have a similar example for video input, although in the example it comes from a file (but it could use the same framework to get the input from a camera): https://brian2.readthedocs.io/en/stable/examples/advanced.opencv_movie.html These examples use quite naive blocking operations and might actually not be real time after all.

The “slow down” mechanism should be quite straightforward to implement. Inside the C++ code we’d need to keep track of the real time in addition to the simulated time, and use a sleep operation if necessary. On the Brian side, it would only need some minor changes to expose some syntax triggering the mechanism. The second mechanism (adaptive time step) would be more involved on the Brian side, since many parts of the code assume that the time step cannot change during a simulation and therefore do some pre-calculations with a fixed time step.

Now I get a much clear idea .I will work on it and keep you updated
.

Dear students interested in this project. Please see my comment on project 8 for a task (https://github.com/brian-team/brian2/issues/1162) that I’d like all prospective applicants to do as part of the application process.

Dear students. As you all know, the application period for this year’s GSoC has started. I hope you are all doing well and are able to cope with the issues around the ongoing pandemic. Since GSoC is an online-only program it is obviously much less affected than other activities; at the moment no changes to the schedule (e.g. deadline extension) are planned. For some of you it might be difficult to get the necessary proof of enrolment from your university at a time of lockdowns and office closures. Google has updated their guidelines, hopefully you can find a solution that works for you. From the GSoC program lead: “We know some of you may need to get creative to show us forms and that’s okay. Submit what you have before the March 31 deadline and if there is a problem with the form you will be emailed the first week of April and can submit a different proof at that point.”

Regarding your applications for this specific project:

  • please include a link to any Brian contribution you made (e.g. to the Brian issue I linked earlier)
  • the most important thing about the application is not so much the detailed timeline (it’s always hard to plan these things in advance), but rather that you show that you understand the task and its potential problems. You can refer to the existing examples I mentioned earlier and discuss what would change in a realtime setting. For example, where in the generated code would be the best place to slow down a simulation if it advances too fast? In the opposite case, what solutions are possible if a complex simulation is running too slow to cope with incoming video/audio input? Whenever you can, try to show concrete examples. These can be something like an “imagined” generated code snippet. I.e., try show the outcome of what your code should do in the end.

Hopefully this makes things a bit clearer, let me know if you have any further questions.

Hello Everyone!
My name is Osama and I am in my final year, pursuing a bachelor’s degree in Computer Science from University of Karachi, Karachi, Pakistan. I have been working on web related technologies for the past one year (Node, React, Django). I like to use C++ in my course projects as I think it’s a great language to learn core programming concepts. I have been studying different research papers related to BCI, EEG and neuroscience but I haven’t worked with a brain simulator before and have started watching tutorials on TVB. I would be interested in this project. I hope I’m not too late. Thanks!

Hi Osama. Thank you for your interest in the project. Please have a look at the linked documents in the comments above, and at the Brian simulator in general (https://briansimulator.org) to see whether this is something you’d be interested to work on. There are also a number of projects for TVB, and several related to web technologies – maybe these would be a better fit? However, it will be difficult to discuss any type of project in detail in the short remaining time, so this certainly puts you at a disadvantage with respect to students that had back-and-forth discussion with their mentors for some time.

Thank you for the suggestions. I have already gone through most of the project ideas here. Most of them have requirements that don’t match with my skills set. Those which match don’t perfectly align with my interests. I have gone through some of the links and documentation for the project. I am known to be a fast learner. I hope that I can catch up.

I have also gone through the code. Can you clarify what variant of cpp is used in the standalone module? I have very basic knowledge of cython but it seems a bit different.

Hi Osama. The standalone mode uses standard C++ (C99). Cython is used for the runtime mode. Is this what you were asking? I’m not 100% sure I understood your question correctly.

Sorry for the confusing question.
I was referring to the following syntax which closely resembles django ( python based web framework). I haven’t seen this syntax used in C++ before.Capture

Ah ok, sorry now I get it. This is not the final C++ code but the template that is used for code generation. This will be filled with the information from the actual model defined by the user to get the final C++ code. The templating language we use is Jinja2, which is indeed quite often used in web frameworks.

Thank you for the clarification!

Hello @mstimberg. I have made some changes in the project to solve the issue you posted earlier. Can you guide how can I test the changes if they worked or not?

Hi Osama, are you referring to github issue #1162? If yes, to test it you can run one of the standalone examples, e.g. https://brian2.readthedocs.io/en/stable/examples/standalone.STDP_standalone.html . If needed, you can increase the runtime a bit so that the displayed elapsed/estimated remaining time is big enough to go into minutes/hours.

Yes I was referring to #1162. Thanks. But I am encountering an error while running the command “pip install -e .

Well, I’m afraid I can’t help you without further information… What error do you get?

I get the following error:

It seems as if there’s a problem with the Cython/C++ compilation. For the runtime mode this is not necessarily a problem – like the message says, it can use a pure Python version. For the standalone mode, you’ll necessarily need a working Visual Studio installation, though. You don’t need to install everything, the “Build Tools for Visual Studio” with the C++ compiler should be enough (see the Python wiki for details).