How BrainPy Works¶
The goal of
BrainPy is to provide a highly flexible and efficient neural simulator for Python users. Specifically, several principles are kept in mind during the development of BrainPy.
Easy to learn and use. The aim of BrainPy is to accelerate your reaches on neuronal dynamics modeling. We don’t want BrainPy make you pay much time on the learning of how to code. On the contrary, all you need is to focus on the implementation logic of the network model by using your familiar NumPy APIs. Although you’ve never used NumPy, even you are unfamiliar with Python, using BrainPy is also a easy thing. This is because the Python and NumPy syntax is simple, elegant and human-like.
Flexible and Transparent. Another consideration of BrainPy is the flexibility. Traditional simulators with code generation approach have intrinsic limitations. In order to generate efficient low-level (such as c++) codes, these simulators make assumptions for models to simulate, and require users to provide string descriptions to define models. Such string descriptions greatly reduce the programming capacity. Moreover, there will always be exceptions beyond the framework assumptions, such as the data or logical flows that the framework did not consider before. Once such frameworks are not tailored to the user needs, extensions becomes difficult and even impossible. Furthermore, no framework is immune to errors when dealing with user’s incredible models (even the well-tested framework TensorFlow). Therefore, making the framework transparent to users becomes indispensable. Considering this, BrainPy enables the users to directly modify the final formatted code once some errors are found (see examples comming soon). Actually, BrainPy endows the users with the fully data/logic flow control.
Simulation with the guidance of the analysis. Simulation, although very important in neurodynamics, has to be guided by theory. Blind simulation of nonlinear systems is likely to produce few results or misleading results. A “brute force” simulation approach is hardly effective and accurate in practice. For example, attractors and repellors can be easily obtained through simulation, forward and backward in time, while saddles can be hard to find. Moreover, some complex dynamical equations are hard to analyze by hand, and can only be analyzed by computer optimization. However, current popular neural simulators (including NEURON, NEST, BRIAN, etc.) cannot give any insights for the defined dynamical models. Traditionally, users need define the models twice by two different ways, one for simulation in neural simulators, and one for model analysis in other programming language. There, BrainPy provides an integrated simulation and analysis environment for neuronal dynamics. The same codes defined by users can not only be used for simulation, but also for neurodyanmics analysis.
Running Efficient. The final consideration of BrainPy is to accelerate the running speed of of your coded models. In order to achieve high efficiency, we incorporate several Just-In-Time compilers (such as Numba) into BrainPy.
BrainPy is designed to support general computing backends on multiple devices. The overall architecture is shown in the following figure:
BrainPy is aimed to provide a general operating system for neuronal dynamics programming. At the first step, BrainPy provides general numerical solvers for ordinary differential equations (ODEs), stochastic differential equations (SDEs), delay differential equations (DDEs), fractional differential equations (FDEs). Then, based on the numerical solvers of various DEs, at one hand, BrainPy supports neuronal dynamics simulation, at the other hand, such general coded differential equations can
be used for neuronal dynamics analysis.
Behind the programming interface, BrainPy provides various drivers for different backends. For example, when users run models on NumPy or PyTorch backend (
brainpy.backend.set('pytorch')), the tensor-based drivers will be automatically utilized. Moreover, BrainPy support JIT compilers (such as Numba, JAX) because of the powerful JIT drivers. For the other accessible devices and corresponding backends in the future, BrainPy can have a seamless support
because of the new driver can be defined.
Date: 2020.10.01, updated at 2021.05.29