def test_connect_with_array_weights(self, sim=sim): C = connectors.AllToAllConnector(safe=False) syn = sim.StaticSynapse(weight=np.arange(0.0, 2.0, 0.1).reshape(4, 5), delay=0.5) prj = sim.Projection(self.p1, self.p2, C, syn) assert_array_almost_equal( np.array(prj.get(["weight", "delay"], format='list')), np.array([ (0, 0, 0.0, 0.5), (1, 0, 0.5, 0.5), (2, 0, 1.0, 0.5), (3, 0, 1.5, 0.5), (0, 1, 0.1, 0.5), (1, 1, 0.6, 0.5), (2, 1, 1.1, 0.5), (3, 1, 1.6, 0.5), (0, 2, 0.2, 0.5), (1, 2, 0.7, 0.5), (2, 2, 1.2, 0.5), (3, 2, 1.7, 0.5), (0, 3, 0.3, 0.5), (1, 3, 0.8, 0.5), (2, 3, 1.3, 0.5), (3, 3, 1.8, 0.5), (0, 4, 0.4, 0.5), (1, 4, 0.9, 0.5), (2, 4, 1.4, 0.5), (3, 4, 1.9, 0.5)] ) ) assert_array_almost_equal(prj.get('weight', format='array'), np.array([[0., 0.1, 0.2, 0.3, 0.4], [0.5, 0.6, 0.7, 0.8, 0.9], [1., 1.1, 1.2, 1.3, 1.4], [1.5, 1.6, 1.7, 1.8, 1.9]]), 9)
def test_connect_with_random_weights_parallel_safe(self, sim=sim): rd = random.RandomDistribution( 'uniform', (0, 1), rng=MockRNG(delta=1.0, parallel_safe=True)) syn = sim.StaticSynapse(weight=rd, delay=0.5) C = connectors.AllToAllConnector(safe=False) prj = sim.Projection(self.p1, self.p2, C, syn) # note that the outer loop is over the post-synaptic cells, the inner loop over the pre-synaptic self.assertEqual(prj.get(["weight", "delay"], format='list'), [(0, 0, 0.0, 0.5), (1, 0, 1.0, 0.5), (2, 0, 2.0, 0.5), (3, 0, 3.0, 0.5), (0, 1, 4.0, 0.5), (1, 1, 5.0, 0.5), (2, 1, 6.0, 0.5), (3, 1, 7.0, 0.5), (0, 2, 8.0, 0.5), (1, 2, 9.0, 0.5), (2, 2, 10.0, 0.5), (3, 2, 11.0, 0.5), (0, 3, 12.0, 0.5), (1, 3, 13.0, 0.5), (2, 3, 14.0, 0.5), (3, 3, 15.0, 0.5), (0, 4, 16.0, 0.5), (1, 4, 17.0, 0.5), (2, 4, 18.0, 0.5), (3, 4, 19.0, 0.5)]) assert_array_almost_equal(prj.get('weight', format='array'), np.array([[0., 4., 8., 12., 16.], [1., 5., 9., 13., 17.], [2., 6., 10., 14., 18.], [3., 7., 11., 15., 19.]]), 9)
def test_connect_with_delays_None(self): syn = sim.StaticSynapse(weight=0.1, delay=None) C = connectors.AllToAllConnector() assert C.safe assert C.allow_self_connections prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False)[0][3], prj._simulator.state.min_delay)
def test_connect_with_list_delays_too_small(self): delays = numpy.ones((self.p1.size, self.p2.size), float) delays[2, 3] = sim.Projection._simulator.state.min_delay - 0.01 syn = sim.StaticSynapse(weight=0.1, delay=delays) C = connectors.AllToAllConnector() self.assertRaises(errors.ConnectionError, sim.Projection, self.p1, self.p2, C, syn)
def test_connect_with_scalar_weights_and_delays(self, sim=sim): C = connectors.AllToAllConnector(safe=False) syn = sim.StaticSynapse(weight=5.0, delay=0.5) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list'), [(0, 0, 5.0, 0.5), (1, 0, 5.0, 0.5), (2, 0, 5.0, 0.5), (3, 0, 5.0, 0.5), (0, 1, 5.0, 0.5), (1, 1, 5.0, 0.5), (2, 1, 5.0, 0.5), (3, 1, 5.0, 0.5), (0, 2, 5.0, 0.5), (1, 2, 5.0, 0.5), (2, 2, 5.0, 0.5), (3, 2, 5.0, 0.5), (0, 3, 5.0, 0.5), (1, 3, 5.0, 0.5), (2, 3, 5.0, 0.5), (3, 3, 5.0, 0.5), (0, 4, 5.0, 0.5), (1, 4, 5.0, 0.5), (2, 4, 5.0, 0.5), (3, 4, 5.0, 0.5)]) assert_array_equal(prj.get('weight', format='array'), np.array([[5.0, 5.0, 5.0, 5.0, 5.0], [5.0, 5.0, 5.0, 5.0, 5.0], [5.0, 5.0, 5.0, 5.0, 5.0], [5.0, 5.0, 5.0, 5.0, 5.0]]))
def test_connect_with_distance_dependent_weights_and_delays(self, sim=sim): syn = sim.StaticSynapse(weight="d+100", delay="0.2+2*d") C = connectors.AllToAllConnector(safe=False) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list'), [(0, 0, 100.0, 0.2), (1, 0, 101.0, 2.2), (2, 0, 102.0, 4.2), (3, 0, 103.0, 6.2), (0, 1, 101.0, 2.2), (1, 1, 100.0, 0.2), (2, 1, 101.0, 2.2), (3, 1, 102.0, 4.2), (0, 2, 102.0, 4.2), (1, 2, 101.0, 2.2), (2, 2, 100.0, 0.2), (3, 2, 101.0, 2.2), (0, 3, 103.0, 6.2), (1, 3, 102.0, 4.2), (2, 3, 101.0, 2.2), (3, 3, 100.0, 0.2), (0, 4, 104.0, 8.2), (1, 4, 103.0, 6.2), (2, 4, 102.0, 4.2), (3, 4, 101.0, 2.2)])
def test_connect_with_delays_None(self): C = connectors.AllToAllConnector(weights=0.1, delays=None) assert_equal(C.weights, 0.1) assert_equal(C.delays, None) assert C.safe assert C.allow_self_connections C.connect(self.prj) assert_equal(self.prj.connections[0][3], self.prj._simulator.state.min_delay)
def test_connect_with_distance_dependent_weights_and_delays(self): syn = sim.StaticSynapse(weight="d+100", delay="0.2+2*d") C = connectors.AllToAllConnector(safe=False) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual( prj.get(["weight", "delay"], format='list', gather=False ), # use gather False because we are faking the MPI [(0, 1, 101.0, 2.2), (1, 1, 100.0, 0.2), (2, 1, 101.0, 2.2), (3, 1, 102.0, 4.2), (0, 3, 103.0, 6.2), (1, 3, 102.0, 4.2), (2, 3, 101.0, 2.2), (3, 3, 100.0, 0.2)])
def test_connect_with_scalar_weights_and_delays(self): C = connectors.AllToAllConnector(weights=5.0, delays=0.5, safe=False) C.progressbar = Mock() C.progression = Mock() C.connect(self.prj) assert_equal( set(self.prj.connections), set([(17, 80, 5.0, 0.5), (17, 82, 5.0, 0.5), (18, 80, 5.0, 0.5), (18, 82, 5.0, 0.5), (19, 80, 5.0, 0.5), (19, 82, 5.0, 0.5), (20, 80, 5.0, 0.5), (20, 82, 5.0, 0.5)]))
def test_connect_with_scalar_weights_and_delays(self): C = connectors.AllToAllConnector(safe=False) syn = sim.StaticSynapse(weight=5.0, delay=0.5) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual( prj.get(["weight", "delay"], format='list', gather=False ), # use gather False because we are faking the MPI [(0, 1, 5.0, 0.5), (1, 1, 5.0, 0.5), (2, 1, 5.0, 0.5), (3, 1, 5.0, 0.5), (0, 3, 5.0, 0.5), (1, 3, 5.0, 0.5), (2, 3, 5.0, 0.5), (3, 3, 5.0, 0.5)])
def test_connect_with_distance_dependent_weights(self, sim=sim): d_expr = "d+100" syn = sim.StaticSynapse(weight=d_expr, delay=0.5) C = connectors.AllToAllConnector(safe=False) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual( prj.get(["weight", "delay"], format='list', gather=False ), # use gather False because we are faking the MPI [(0, 1, 101.0, 0.5), (1, 1, 100.0, 0.5), (2, 1, 101.0, 0.5), (3, 1, 102.0, 0.5), (0, 3, 103.0, 0.5), (1, 3, 102.0, 0.5), (2, 3, 101.0, 0.5), (3, 3, 100.0, 0.5)])
def test_connect_with_random_weights_parallel_safe(self): rd = random.RandomDistribution( rng=MockRNG(delta=1.0, parallel_safe=True)) syn = sim.StaticSynapse(weight=rd, delay=0.5) C = connectors.AllToAllConnector(safe=False) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual( prj.get(["weight", "delay"], format='list', gather=False ), # use gather False because we are faking the MPI [(0, 1, 4.0, 0.5), (1, 1, 5.0, 0.5), (2, 1, 6.0, 0.5), (3, 1, 7.0, 0.5), (0, 3, 12.0, 0.5), (1, 3, 13.0, 0.5), (2, 3, 14.0, 0.5), (3, 3, 15.0, 0.5)])
def test_connect_with_random_weights_parallel_safe(self): rd = random.RandomDistribution(rng=MockRNG(num_processes=2, delta=1.0)) C = connectors.AllToAllConnector(weights=rd, delays=0.5, safe=False) C.progressbar = Mock() C.progression = Mock() C.connect(self.prj) assert_equal(self.prj.connections, [(17, 80, 1.0, 0.5), (17, 82, 3.0, 0.5), (18, 80, 6.0, 0.5), (18, 82, 8.0, 0.5), (19, 80, 11.0, 0.5), (19, 82, 13.0, 0.5), (20, 80, 16.0, 0.5), (20, 82, 18.0, 0.5)])
def test_connect_with_array_weights(self, sim=sim): C = connectors.AllToAllConnector(safe=False) syn = sim.StaticSynapse(weight=np.arange(0.0, 2.0, 0.1).reshape(4, 5), delay=0.5) prj = sim.Projection(self.p1, self.p2, C, syn) assert_array_almost_equal( # use gather False because we are faking the MPI np.array(prj.get(["weight", "delay"], format='list', gather=False)), np.array([(0, 1, 0.1, 0.5), (1, 1, 0.6, 0.5), (2, 1, 1.1, 0.5), (3, 1, 1.6, 0.5), (0, 3, 0.3, 0.5), (1, 3, 0.8, 0.5), (2, 3, 1.3, 0.5), (3, 3, 1.8, 0.5)])) nan = np.nan assert_array_almost_equal( prj.get('weight', format='array', gather=False), np.array([[nan, 0.1, nan, 0.3, nan], [nan, 0.6, nan, 0.8, nan], [nan, 1.1, nan, 1.3, nan], [nan, 1.6, nan, 1.8, nan]]), 9)
def test_connect_with_distance_dependent_weights_parallel_safe(self): d_expr = "d+100" C = connectors.AllToAllConnector(weights=d_expr, delays=0.5, safe=False) C.progressbar = Mock() C.progression = Mock() C.connect(self.prj) assert_equal( self.prj.connections, [ (17, 80, 163.0, 0.5), # 100+|17-80| (17, 82, 165.0, 0.5), # 100+|17-82| (18, 80, 162.0, 0.5), # etc. (18, 82, 164.0, 0.5), (19, 80, 161.0, 0.5), (19, 82, 163.0, 0.5), (20, 80, 160.0, 0.5), (20, 82, 162.0, 0.5) ])
def test_connect_with_random_weights_parallel_safe(self, sim=sim): rd = random.RandomDistribution('uniform', (0, 1), rng=MockRNG(delta=1.0, parallel_safe=True)) syn = sim.StaticSynapse(weight=rd, delay=0.5) C = connectors.AllToAllConnector(safe=False) prj = sim.Projection(self.p1, self.p2, C, syn) # note that the outer loop is over the post-synaptic cells, the inner loop over the pre-synaptic self.assertEqual( prj.get(["weight", "delay"], format='list', gather=False ), # use gather False because we are faking the MPI [(0, 1, 4.0, 0.5), (1, 1, 5.0, 0.5), (2, 1, 6.0, 0.5), (3, 1, 7.0, 0.5), (0, 3, 12.0, 0.5), (1, 3, 13.0, 0.5), (2, 3, 14.0, 0.5), (3, 3, 15.0, 0.5)]) nan = np.nan assert_array_almost_equal( prj.get('weight', format='array', gather=False), np.array([[nan, 4.0, nan, 12.0, nan], [nan, 5.0, nan, 13.0, nan], [nan, 6.0, nan, 14.0, nan], [nan, 7.0, nan, 15.0, nan]]), 9)
def test_connect_with_delays_too_small(self): C = connectors.AllToAllConnector(weights=0.1, delays=0.0) assert_raises(errors.ConnectionError, C.connect, self.prj)
def test_connect_with_delays_too_small(self): C = connectors.AllToAllConnector() syn = sim.StaticSynapse(weight=0.1, delay=0.0) self.assertRaises(errors.ConnectionError, sim.Projection, self.p1, self.p2, C, syn)
def test_connect_with_list_delays_too_small(self): C = connectors.AllToAllConnector( weights=0.1, delays=[1.0, 1.0, 0.0, 0.0, 3.0, 1.5, 2.3, 0.9]) assert_raises(errors.ConnectionError, C.connect, self.prj)