def test_split_stochastic(): tau = 5 * ms expr = Expression('(-v + I) / tau') # No stochastic part assert expr.split_stochastic() == (expr, None) # No non-stochastic part -- note that it should return 0 and not None expr = Expression('sigma*xi/tau**.5') non_stochastic, stochastic = expr.split_stochastic() assert sympy_equals(non_stochastic, 0) assert 'xi' in stochastic assert len(stochastic) == 1 assert sympy_equals(stochastic['xi'].code, 'sigma/tau**.5') expr = Expression('(-v + I) / tau + sigma*xi/tau**.5') non_stochastic, stochastic = expr.split_stochastic() assert 'xi' in stochastic assert len(stochastic) == 1 assert sympy_equals(non_stochastic.code, '(-v + I) / tau') assert sympy_equals(stochastic['xi'].code, 'sigma/tau**.5') expr = Expression('(-v + I) / tau + sigma*xi_1/tau**.5 + xi_2*sigma2/sqrt(tau_2)') non_stochastic, stochastic = expr.split_stochastic() assert set(stochastic.keys()) == {'xi_1', 'xi_2'} assert sympy_equals(non_stochastic.code, '(-v + I) / tau') assert sympy_equals(stochastic['xi_1'].code, 'sigma/tau**.5') assert sympy_equals(stochastic['xi_2'].code, 'sigma2/tau_2**.5') expr = Expression('-v / tau + 1 / xi') assert_raises(ValueError, expr.split_stochastic)
def test_split_stochastic(): tau = 5 * ms expr = Expression('(-v + I) / tau') expr.resolve(['v', 'I']) # No stochastic part assert expr.split_stochastic() == (expr, None) expr = Expression('(-v + I) / tau + sigma*xi/tau**.5') expr.resolve(['v', 'I', 'sigma']) non_stochastic, stochastic = expr.split_stochastic() assert 'xi' in stochastic.identifiers assert sympy_equals(non_stochastic.code, '(-v + I) / tau') assert sympy_equals(stochastic.code, 'sigma*xi/tau**.5') expr = Expression('-v / tau + 1 / xi') assert_raises(ValueError, expr.split_stochastic)