def test_probe_vector_recorders(self): sim = self.init_sim(cc2_recipe()) ts = [0, 0.1, 0.3, 0.7] h0 = sim.sample((1, 0), A.explicit_schedule(ts), A.sampling_policy.exact) h1 = sim.sample((1, 1), A.explicit_schedule(ts), A.sampling_policy.exact) sim.run(10., 0.01) # probe (1, 0) is the whole cell voltage; expect time + 6 sample values per row in returned data (see test_probe_meta above). s0, meta0 = sim.samples(h0)[0] self.assertEqual(6, len(meta0)) self.assertEqual((len(ts), 7), s0.shape) for i, t in enumerate(s0[:, 0]): self.assertEqual(t, ts[i]) # probe (1, 1) is the 'g' state for all expsyn synapses. # With the default descretization, expect two synapses with multiplicity 2 and two with multiplicity 1. s1, meta1 = sim.samples(h1)[0] self.assertEqual(4, len(meta1)) self.assertEqual((len(ts), 5), s1.shape) for i, t in enumerate(s1[:, 0]): self.assertEqual(t, ts[i]) meta1_mult = {(m.location.branch, m.location.pos): m.multiplicity for m in meta1} self.assertEqual(2, meta1_mult[(0, 0.3)]) self.assertEqual(2, meta1_mult[(0, 0.6)]) self.assertEqual(1, meta1_mult[(1, 0.3)]) self.assertEqual(1, meta1_mult[(2, 0.3)])
def test_probe_multi_scalar_recorders(self): sim = self.init_sim(cc2_recipe()) ts = [0, 0.1, 0.3, 0.7] h0 = sim.sample((0, 0), A.explicit_schedule(ts)) h1 = sim.sample((0, 1), A.explicit_schedule(ts)) h2 = sim.sample((0, 2), A.explicit_schedule(ts)) dt = 0.01 sim.run(10., dt) r0 = sim.samples(h0) self.assertEqual(1, len(r0)) s0, meta0 = r0[0] r1 = sim.samples(h1) self.assertEqual(1, len(r1)) s1, meta1 = r1[0] r2 = sim.samples(h2) self.assertEqual(2, len(r2)) s20, meta20 = r2[0] s21, meta21 = r2[1] # Probe id (0, 2) has probes over the two locations that correspond to probes (0, 0) and (0, 1). # (order is not guaranteed to line up though) if meta20 == meta0: self.assertEqual(meta1, meta21) self.assertTrue((s0[:, 1] == s20[:, 1]).all()) self.assertTrue((s1[:, 1] == s21[:, 1]).all()) else: self.assertEqual(meta1, meta20) self.assertTrue((s1[:, 1] == s20[:, 1]).all()) self.assertEqual(meta0, meta21) self.assertTrue((s0[:, 1] == s21[:, 1]).all())
def event_generators(self, gid): """two stimuli: one that makes the cell spike, the other to monitor STDP """ stimulus_times = numpy.linspace(50, 500, self.n_pairs) # strong enough stimulus spike = arbor.event_generator("synapse", 1., arbor.explicit_schedule(stimulus_times)) # zero weight -> just modify synaptic weight via stdp stdp = arbor.event_generator("stpd_synapse", 0., arbor.explicit_schedule(stimulus_times - self.dT)) return [spike, stdp]
def test_event_generator_explicit_schedule(self): cm = arb.cell_member(0, 42) es = arb.explicit_schedule([0, 1, 2, 3, 4.4]) eg = arb.event_generator(cm, -0.01, es) self.assertEqual(eg.target.gid, 0) self.assertEqual(eg.target.index, 42) self.assertAlmostEqual(eg.weight, -0.01)
def test_event_generator_explicit_schedule(self): cm = arb.cell_local_label("tgt1", arb.selection_policy.round_robin) es = arb.explicit_schedule([0,1,2,3,4.4]) eg = arb.event_generator(cm, -0.01, es) self.assertEqual(eg.target.label, "tgt1") self.assertEqual(eg.target.policy, arb.selection_policy.round_robin) self.assertAlmostEqual(eg.weight, -0.01)
def test_events_explicit_schedule(self): times = [0.1, 0.3, 1.0, 2.2, 1.25, 1.7] expected = [0.1, 0.3, 1.0] es = arb.explicit_schedule(times) for i in range(len(expected)): self.assertAlmostEqual(expected[i], es.events(0., 1.25)[i], places = 2) expected = [0.3, 1.0, 1.25, 1.7] for i in range(len(expected)): self.assertAlmostEqual(expected[i], es.events(0.3, 1.71)[i], places = 2)
def test_exceptions_explicit_schedule(self): with self.assertRaisesRegex( RuntimeError, "explicit time schedule can not contain negative values"): arb.explicit_schedule([-1]) with self.assertRaises(TypeError): arb.explicit_schedule(['times']) with self.assertRaises(TypeError): arb.explicit_schedule([None]) with self.assertRaises(TypeError): arb.explicit_schedule([[1, 2, 3]])
def test_probe_scalar_recorders(self): sim = self.init_sim(cc2_recipe()) ts = [0, 0.1, 0.3, 0.7] h = sim.sample((0, 0), A.explicit_schedule(ts)) dt = 0.01 sim.run(10., dt) s, meta = sim.samples(h)[0] self.assertEqual(A.location(1, 1), meta) for i, t in enumerate(s[:, 0]): self.assertLess(abs(t - ts[i]), dt) sim.remove_sampler(h) sim.reset() h = sim.sample(A.cell_member(0, 0), A.explicit_schedule(ts), A.sampling_policy.exact) sim.run(10., dt) s, meta = sim.samples(h)[0] for i, t in enumerate(s[:, 0]): self.assertEqual(t, ts[i])
def test_exceptions_explicit_schedule(self): with self.assertRaisesRegex(RuntimeError, "explicit time schedule cannot contain negative values"): arb.explicit_schedule([-1]) with self.assertRaises(TypeError): arb.explicit_schedule(['times']) with self.assertRaises(TypeError): arb.explicit_schedule([None]) with self.assertRaises(TypeError): arb.explicit_schedule([[1,2,3]]) with self.assertRaisesRegex(RuntimeError, "t1 must be a non-negative number"): rs = arb.regular_schedule(0.1) rs.events(1., -1.)
def event_generators(self, gid): if gid==0: sched = arbor.explicit_schedule([1]) return [arbor.event_generator(arbor.cell_member(0,0), 0.1, sched)] return []
def cell_description(self, gid): if gid < 3: return arbor.spike_source_cell( "src", arbor.explicit_schedule(self.trains[gid])) else: return self._cable_cell()
def test_event_generator_explicit_schedule(self): es = arb.explicit_schedule([0,1,2,3,4.4]) eg = arb.event_generator(42, -0.01, es) self.assertEqual(eg.target, 42) self.assertAlmostEqual(eg.weight, -0.01)
def event_generators(self, gid): if gid==0: sched = arbor.explicit_schedule([1]) # one event at 1 ms weight = 0.1 # 0.1 μS on expsyn return [arbor.event_generator('syn', weight, sched)] return []
def test_set_times_explicit_schedule(self): es = arb.explicit_schedule() es.times = [42, 43, 44, 55.5, 100] self.assertEqual(es.times, [42, 43, 44, 55.5, 100])
def test_times_contor_explicit_schedule(self): es = arb.explicit_schedule([1, 2, 3, 4.5]) self.assertEqual(es.times, [1, 2, 3, 4.5])
def event_generators(self, gid): if gid==0: sched = arbor.explicit_schedule([1]) weight = 0.1 return [arbor.event_generator('syn', weight, sched)] return []
def event_generators(self, gid): print_v('Getting event_generators for: %s'%(gid)) if gid==0: sched = arbor.explicit_schedule([1]) return [arbor.event_generator((0,0), 0.1, sched)] return []
def cell_description(self, gid): return A.spike_source_cell("src", A.explicit_schedule(self.trains[gid]))