def test_set(self): p = sim.Population(4, IF_cond_exp, {'tau_m': 14.0, 'v_reset': -50., 'tau_syn_E': 1.0}) rng = MockRNG(start=12.31, delta=0.01, parallel_safe=True) p.set(tau_m=random.RandomDistribution('uniform', (0.5, 1.5), rng=rng), v_reset=-60) tau_m, v_reset, tau_syn_E = p.get(('tau_m', 'v_reset', 'tau_syn_E'), gather=True) assert_array_equal(tau_m, numpy.array([12.31, 12.32, 12.33, 12.34])) assert_array_equal(v_reset, -60.0**numpy.ones((4,))) assert_array_equal(tau_syn_E, 1.0 * numpy.ones((4,)))
def test_set_random_distribution_parallel_safe(self): orig_rcfg = random.get_mpi_config random.get_mpi_config = lambda: (1, 2) sim.simulator.state.num_processes = 2 sim.simulator.state.mpi_rank = 1 p = sim.Population(4, IF_cond_exp(tau_syn_E=1.0)) rng = MockRNG(start=2.0, delta=0.01, parallel_safe=True) p.set(tau_syn_E=random.RandomDistribution('uniform', (0.1, 3.0), rng=rng)) tau_syn_E = p.get('tau_syn_E', gather=False) assert_array_equal(tau_syn_E, numpy.array([2.01, 2.03])) random.get_mpi_config = orig_rcfg sim.simulator.state.num_processes = 1 sim.simulator.state.mpi_rank = 0