Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoming0625 committed Apr 18, 2022
1 parent 23c4ae9 commit 71e0874
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 27 deletions.
5 changes: 4 additions & 1 deletion brainpy/analysis/lowdim/tests/test_phase_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import unittest

import brainpy as bp
import matplotlib.pyplot as plt

block = False


class TestPhasePlane(unittest.TestCase):
def test_1d(self):
import matplotlib.pyplot as plt
bp.math.enable_x64()

@bp.odeint
def int_x(x, t, Iext):
dx = x ** 3 - x + Iext
Expand All @@ -28,6 +29,8 @@ def int_x(x, t, Iext):
bp.math.disable_x64()

def test_2d_decision_making_model(self):
import matplotlib.pyplot as plt

bp.math.enable_x64()
gamma = 0.641 # Saturation factor for gating variable
tau = 0.06 # Synaptic time constant [sec]
Expand Down
9 changes: 7 additions & 2 deletions brainpy/initialize/tests/test_decay_inits.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import unittest

import matplotlib.pyplot as plt
import numpy as np

import brainpy as bp
Expand All @@ -10,7 +9,11 @@


# visualization
def mat_visualize(matrix, cmap=plt.cm.get_cmap('coolwarm')):
def mat_visualize(matrix, cmap=None):
import matplotlib.pyplot as plt
if cmap is None:
cmap = plt.cm.get_cmap('coolwarm')
plt.cm.get_cmap('coolwarm')
im = plt.matshow(matrix, cmap=cmap)
plt.colorbar(mappable=im, shrink=0.8, aspect=15)
plt.show()
Expand Down Expand Up @@ -71,6 +74,8 @@ def test_dog_decay_init2(self):
assert isinstance(weights, bp.math.ndarray)

def test_dog_decay3(self):
import matplotlib.pyplot as plt

size = (10, 12)
dog_init = bp.init.DOGDecay(sigmas=(1., 3.),
max_ws=(10., 5.),
Expand Down
6 changes: 5 additions & 1 deletion brainpy/inputs/tests/test_currents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@

from unittest import TestCase

import matplotlib.pyplot as plt

import numpy as np

import brainpy as bp

plt = None
block = False


def show(current, duration, title=''):
global plt
if plt is None:
import matplotlib.pyplot as plt
ts = np.arange(0, duration, bp.math.get_dt())
plt.plot(ts, current)
plt.title(title)
Expand Down
8 changes: 7 additions & 1 deletion brainpy/integrators/fde/tests/test_GL.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@


import unittest
import matplotlib.pyplot as plt

import brainpy as bp

plt = None


class TestGLShortMemory(unittest.TestCase):
def test_lorenz(self):
global plt
if plt is None:
import matplotlib.pyplot as plt

a, b, c = 10, 28, 8 / 3

def lorenz(x, y, z, t):
Expand Down
8 changes: 7 additions & 1 deletion brainpy/integrators/ode/tests/test_ode_method_adaptive_rk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import unittest

import matplotlib.pyplot as plt
import numpy as np

import brainpy.math as bm
from brainpy.integrators.ode import adaptive_rk

plt = None


sigma = 10
beta = 8 / 3
rho = 28
Expand All @@ -23,6 +25,10 @@ def f_lorenz(x, y, z, t):


def run_integrator(method, show=False, tol=0.001, adaptive=True):
global plt
if plt is None:
import matplotlib.pyplot as plt

f_integral = method(f_lorenz, adaptive=adaptive, tol=tol, show_code=True)
x, y, z = bm.ones(1), bm.ones(1), bm.ones(1)
dt = bm.ones(1) * 0.01
Expand Down
8 changes: 6 additions & 2 deletions brainpy/integrators/ode/tests/test_ode_method_exp_euler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-

import unittest
import numpy as np
import matplotlib.pyplot as plt
import pytest

import brainpy as bp
import brainpy.math as bm
from brainpy.integrators.ode.exponential import ExponentialEuler

plt = None


class TestExpnentialEuler(unittest.TestCase):
def test_hh_model(self):
Expand Down Expand Up @@ -227,6 +227,10 @@ def dev(x, t):

class TestExpEulerAuto(unittest.TestCase):
def test_hh_model(self):
global plt
if plt is None:
import matplotlib.pyplot as plt

class HH(bp.dyn.NeuGroup):
def __init__(self, size, ENa=55., EK=-90., EL=-65, C=1.0, gNa=35., gK=9.,
gL=0.1, V_th=20., phi=5.0, name=None, method='exponential_euler'):
Expand Down
6 changes: 5 additions & 1 deletion brainpy/integrators/ode/tests/test_ode_method_rk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import unittest

import matplotlib.pyplot as plt
import numpy as np

import brainpy.math as bm
from brainpy.integrators.ode import explicit_rk
plt = None

sigma = 10
beta = 8 / 3
Expand All @@ -23,6 +23,10 @@ def f_lorenz(x, y, z, t):


def run_integrator(method, show=False):
global plt
if plt is None:
import matplotlib.pyplot as plt

f_integral = bm.jit(method(f_lorenz, dt=dt), auto_infer=False)
x, y, z = bm.ones(1), bm.ones(1), bm.ones(1)

Expand Down
28 changes: 17 additions & 11 deletions brainpy/integrators/sde/tests/test_sde_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import brainpy as bp
from brainpy.integrators import sde

plt = None

sigma = 10
beta = 8 / 3
rho = 28
Expand Down Expand Up @@ -42,17 +44,21 @@ def lorenz_system(method, **kwargs):
mon1.append(x)
mon2.append(y)
mon3.append(z)
mon1 = bp.math.array(mon1)
mon2 = bp.math.array(mon2)
mon3 = bp.math.array(mon3)

# fig = plt.figure()
# ax = fig.gca(projection='3d')
# plt.plot(mon1, mon2, mon3)
# ax.set_xlabel('x')
# ax.set_xlabel('y')
# ax.set_xlabel('z')
# plt.show()
mon1 = bp.math.array(mon1).to_numpy()
mon2 = bp.math.array(mon2).to_numpy()
mon3 = bp.math.array(mon3).to_numpy()

global plt
if plt is None:
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.gca(projection='3d')
plt.plot(mon1, mon2, mon3)
ax.set_xlabel('x')
ax.set_xlabel('y')
ax.set_xlabel('z')
plt.show()


class TestScalarWienerIntegral(unittest.TestCase):
Expand Down
7 changes: 5 additions & 2 deletions brainpy/integrators/tests/test_integ_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

from unittest import TestCase

import matplotlib.pyplot as plt

import brainpy as bp

plt = None


class TestIntegratorRunnerForODEs(TestCase):
def test_ode(self):
global plt
if plt is None:
import matplotlib.pyplot as plt
sigma = 10
beta = 8 / 3
rho = 28
Expand Down
1 change: 0 additions & 1 deletion brainpy/nn/nodes/ANN/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jax.numpy as jnp

import brainpy.math as bm
import brainpy
from brainpy.initialize import ZeroInit, OneInit, Initializer
from brainpy.nn.base import Node

Expand Down
1 change: 0 additions & 1 deletion brainpy/nn/nodes/ANN/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import jax.lax
import brainpy.math as bm
from brainpy.initialize import XavierNormal, ZeroInit, init_param
from brainpy.nn.base import Node

__all__ = [
Expand Down
1 change: 0 additions & 1 deletion brainpy/nn/nodes/ANN/tests/test_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import brainpy as bp
import jax.numpy as jnp
import numpy as np
import matplotlib.pyplot as plt

class TestConv(TestCase):
def test_Conv2D_img(self):
Expand Down
1 change: 0 additions & 1 deletion brainpy/nn/nodes/ANN/tests/test_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import jax.numpy as jnp
import jax
import numpy as np
import matplotlib.pyplot as plt


class TestPool(TestCase):
Expand Down
1 change: 0 additions & 1 deletion brainpy/nn/tests/test_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import unittest
import brainpy as bp
import brainpy.math as bm


class TestVisualize(unittest.TestCase):
Expand Down

0 comments on commit 71e0874

Please sign in to comment.