查看官方文档:https://brian2.readthedocs.io/en/2.0rc/user/running.html
对于构建的SNN,Brian有多种运行方法,在大多数简单的模拟中,您不必显式地创建Network对象(参考官方手册intro3-simulator有用到Network的例子),而是可以简单地调用run()来运行模拟。这就是所谓的'Magic'系统,因为brain会自动知道你想做什么。
然而多次运行后往往会得到报错:
MagicError: The magic network contains a mix of objects that has been run before and new objects, Brian does not know whether you want to start a new simulation or continue an old one. Consider explicitly creating a Network object. Also note that you can find out which objects will be included in a magic network with the collect() function.
翻译:magic network包含以前运行过的对象和新对象的组合,Brian不知道是要开始一个新的仿真还是继续一个旧的仿真。考虑显式地创建网络对象。(这是一种解决方法,但对代码改动较大)
第二种方法是在代码段前面加上start_scope()
start_scope()
'''
Starts a new scope for magic functions
All objects created before this call will no longer be automatically
included by the magic functions such as `run`.
'''
这个方法的作用是使仿真器忽略前面的仿真。
第三种方法是直接在spyder的Python console中选择清除所有变量,这个方法比较简单粗暴。