77import matplotlib .pyplot as plt
88from brainpy ._src .integrators .sde .normal import ExponentialEuler
99
10- block = False
10+ show = False
1111
1212
1313class TestExpEuler (unittest .TestCase ):
@@ -33,16 +33,18 @@ def lorenz_g(x, y, z, t, **kwargs):
3333 runner .run (100. )
3434
3535 plt .plot (runner .mon .x .flatten (), runner .mon .y .flatten ())
36- plt .show (block = block )
36+ if show :
37+ plt .show ()
38+ plt .close ()
3739
3840 def test2 (self ):
3941 p = 0.1
4042 p2 = 0.02
4143
4244 def lorenz_g (x , y , z , t , ** kwargs ):
4345 return bp .math .asarray ([p * x , p2 * x ]), \
44- bp .math .asarray ([p * y , p2 * y ]), \
45- bp .math .asarray ([p * z , p2 * z ])
46+ bp .math .asarray ([p * y , p2 * y ]), \
47+ bp .math .asarray ([p * z , p2 * z ])
4648
4749 dx = lambda x , t , y , sigma = 10 : sigma * (y - x )
4850 dy = lambda y , t , x , z , rho = 28 : x * (rho - z ) - y
@@ -54,8 +56,8 @@ def lorenz_g(x, y, z, t, **kwargs):
5456 wiener_type = bp .integrators .VECTOR_WIENER ,
5557 var_type = bp .integrators .POP_VAR ,
5658 show_code = True )
57- runner = bp .integrators . IntegratorRunner (intg , monitors = ['x' , 'y' , 'z' ],
58- dt = 0.001 , inits = [1. , 1. , 0. ], jit = False )
59+ runner = bp .IntegratorRunner (intg , monitors = ['x' , 'y' , 'z' ],
60+ dt = 0.001 , inits = [1. , 1. , 0. ], jit = False )
5961 with self .assertRaises (ValueError ):
6062 runner .run (100. )
6163
@@ -65,8 +67,8 @@ def test3(self):
6567
6668 def lorenz_g (x , y , z , t , ** kwargs ):
6769 return bp .math .asarray ([p * x , p2 * x ]).T , \
68- bp .math .asarray ([p * y , p2 * y ]).T , \
69- bp .math .asarray ([p * z , p2 * z ]).T
70+ bp .math .asarray ([p * y , p2 * y ]).T , \
71+ bp .math .asarray ([p * z , p2 * z ]).T
7072
7173 dx = lambda x , t , y , sigma = 10 : sigma * (y - x )
7274 dy = lambda y , t , x , z , rho = 28 : x * (rho - z ) - y
@@ -78,15 +80,17 @@ def lorenz_g(x, y, z, t, **kwargs):
7880 wiener_type = bp .integrators .VECTOR_WIENER ,
7981 var_type = bp .integrators .POP_VAR ,
8082 show_code = True )
81- runner = bp .integrators . IntegratorRunner (intg ,
82- monitors = ['x' , 'y' , 'z' ],
83- dt = 0.001 ,
84- inits = [1. , 1. , 0. ],
85- jit = True )
83+ runner = bp .IntegratorRunner (intg ,
84+ monitors = ['x' , 'y' , 'z' ],
85+ dt = 0.001 ,
86+ inits = [1. , 1. , 0. ],
87+ jit = True )
8688 runner .run (100. )
8789
8890 plt .plot (runner .mon .x .flatten (), runner .mon .y .flatten ())
89- plt .show (block = block )
91+ if show :
92+ plt .show ()
93+ plt .close ()
9094
9195
9296class TestMilstein (unittest .TestCase ):
@@ -110,11 +114,14 @@ def test1(self):
110114 wiener_type = bp .integrators .SCALAR_WIENER ,
111115 var_type = bp .integrators .POP_VAR ,
112116 method = 'milstein' )
113- runner = bp .integrators . IntegratorRunner (intg ,
114- monitors = ['x' , 'y' , 'z' ],
115- dt = 0.001 , inits = [1. , 1. , 0. ],
116- jit = True )
117+ runner = bp .IntegratorRunner (intg ,
118+ monitors = ['x' , 'y' , 'z' ],
119+ dt = 0.001 , inits = [1. , 1. , 0. ],
120+ jit = True )
117121 runner .run (100. )
118122
119123 plt .plot (runner .mon .x .flatten (), runner .mon .y .flatten ())
120- plt .show (block = block )
124+ if show :
125+ plt .show ()
126+ plt .close ()
127+
0 commit comments