1
1
from __future__ import division
2
2
from __future__ import absolute_import
3
3
import uuid
4
-
4
+ import sys
5
5
import sympy
6
6
import numpy as np
7
7
from numpy .testing .utils import assert_raises , assert_equal
22
22
from brian2 .units .fundamentalunits import (DimensionMismatchError ,
23
23
have_same_dimensions )
24
24
from brian2 .units .unitsafefunctions import linspace
25
- from brian2 .units .allunits import second , volt
26
- from brian2 .units .stdunits import ms , mV , Hz
25
+ from brian2 .units .allunits import second , volt , umetre , siemens , ufarad
26
+ from brian2 .units .stdunits import ms , mV , Hz , cm
27
27
from brian2 .utils .logger import catch_logs
28
28
29
29
from brian2 .tests .utils import assert_allclose
@@ -1639,6 +1639,36 @@ def test_semantics_mod():
1639
1639
assert_allclose (G .x [:], float_values % 3 )
1640
1640
assert_allclose (G .y [:], float_values % 3 )
1641
1641
1642
+ def test_resting_value ():
1643
+ """
1644
+ Test the resting state values of the system
1645
+ """
1646
+ # simple model with single dependent variable, here it is not necessary
1647
+ # to run the model as the resting value is certain
1648
+ epsilon = sys .float_info .epsilon
1649
+ El = - 100
1650
+ tau = 1 * ms
1651
+ eqs = '''
1652
+ dv/dt = (El - v)/tau : 1
1653
+ '''
1654
+ grp = NeuronGroup (1 , eqs , method = 'exact' )
1655
+ resting_state = grp .resting_state ()
1656
+ assert abs (resting_state ['v' ] - El ) < epsilon * max (abs (resting_state ['v' ]), abs (El ))
1657
+
1658
+ # one more example
1659
+ area = 100 * umetre ** 2
1660
+ g_L = 1e-2 * siemens * cm ** - 2 * area
1661
+ E_L = 1000
1662
+ Cm = 1 * ufarad * cm ** - 2 * area
1663
+ grp = NeuronGroup (10 , '''dv/dt = I_leak / Cm : volt
1664
+ I_leak = g_L*(E_L - v) : amp''' )
1665
+ resting_state = grp .resting_state ({'v' : float (10000 )})
1666
+ assert abs (resting_state ['v' ] - E_L ) < epsilon * max (abs (resting_state ['v' ]), abs (E_L ))
1667
+
1668
+ # check unsupported models are identified
1669
+ tau = 10 * ms
1670
+ grp = NeuronGroup (1 , 'dv/dt = -v/tau : volt' , threshold = 'v > -50*mV' , reset = 'v = -70*mV' )
1671
+ assert_raises (NotImplementedError , lambda : grp .resting_state ())
1642
1672
1643
1673
if __name__ == '__main__' :
1644
1674
test_set_states ()
@@ -1714,3 +1744,4 @@ def test_semantics_mod():
1714
1744
test_semantics_floor_division ()
1715
1745
test_semantics_floating_point_division ()
1716
1746
test_semantics_mod ()
1747
+ test_resting_value ()
0 commit comments