Exemple #1
0
 def test_connect_with_valid_list(self):
     connection_list = [
         (0, 0, 0.1, 0.1),
         (3, 0, 0.2, 0.11),
         (2, 3, 0.3, 0.12),  # local
         (2, 2, 0.4, 0.13),
         (0, 1, 0.5, 0.14),  # local
     ]
     C = connectors.FromListConnector(connection_list)
     syn = sim.StaticSynapse()
     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, 0.5, 0.14), (2, 3, 0.3, 0.12)])
Exemple #2
0
 def test_connect_with_random_weights_parallel_safe(self):
     rd_w = random.RandomDistribution(rng=MockRNG(delta=1.0, parallel_safe=True))
     rd_d = random.RandomDistribution(rng=MockRNG(start=1.0, delta=0.1, parallel_safe=True))
     syn = sim.StaticSynapse(weight=rd_w, delay=rd_d)
     connections = numpy.array([
             [0, 1, 1, 0],
             [1, 1, 0, 1],
             [0, 0, 1, 0],
         ])
     C = connectors.ArrayConnector(connections, 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
                      [(1, 0, 0.0, 1.0),
                       (0, 2, 3.0, 1.3),
                       (2, 2, 4.0, 1.4000000000000001)])  # better to do an "almost-equal" check
 def test_get_weights_as_list(self, sim=sim):
     prj = sim.Projection(self.p1,
                          self.p2,
                          connector=self.all2all,
                          synapse_type=self.syn2)
     weights = prj.get("weight", format="list")
     weights = _sort_by_column(weights, 1)[:5]
     target = np.array([
         (0, 0, 0.007),
         (1, 0, 0.007),
         (2, 0, 0.007),
         (3, 0, 0.007),
         (4, 0, 0.007),
     ])
     assert_array_equal(weights, target)
Exemple #4
0
 def test_with_n_smaller_than_population_size(self):
     C = connectors.FixedNumberPreConnector(n=3, rng=MockRNG(delta=1))
     syn = sim.StaticSynapse(weight="0.1*d")
     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
         [
             (3, 1, 0.2, 0.123),
             (2, 1, 0.1, 0.123),
             (1, 1, 0.0, 0.123),
             (3, 3, 0.0, 0.123),
             (2, 3, 0.1, 0.123),
             (1, 3, 0.2, 0.123),
         ])
 def test_get_weights_as_array_with_multapses_min(self, sim=sim):
     C = sim.FixedNumberPreConnector(n=7, rng=MockRNG(delta=1))
     prj = sim.Projection(self.p2, self.p3, C, synapse_type=self.syn1)
     target = np.array([
         [0.006, 0.006, 0.006, 0.006, 0.006],
         [0.006, 0.006, 0.006, 0.006, 0.006],
         [0.006, 0.006, 0.006, 0.006, 0.006],
         [0.006, 0.006, 0.006, 0.006, 0.006],
     ])
     # use gather False because we are faking the MPI
     weights = prj.get("weight",
                       format="array",
                       gather=False,
                       multiple_synapses='min')
     assert_array_equal(weights, target)
 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', 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)])
     nan = np.nan
     assert_array_equal(
         prj.get('weight', format='array', gather=False),
         np.array([[nan, 5.0, nan, 5.0, nan], [nan, 5.0, nan, 5.0, nan],
                   [nan, 5.0, nan, 5.0, nan], [nan, 5.0, nan, 5.0, nan]]))
 def test_with_replacement(self, sim=sim):
     C = connectors.FixedNumberPostConnector(n=3,
                                             with_replacement=True,
                                             rng=MockRNG(delta=1))
     syn = sim.StaticSynapse()
     prj = sim.Projection(self.p1, self.p2, C, syn)
     # 0 - 0 1 2
     # 1 - 3 4 0
     # 2 - 1 2 3
     # 3 - 4 0 1
     self.assertEqual(
         prj.get(["weight", "delay"], format='list', gather=False
                 ),  # use gather False because we are faking the MPI
         [(0, 1, 0.0, 0.123), (2, 1, 0.0, 0.123), (3, 1, 0.0, 0.123),
          (1, 3, 0.0, 0.123), (2, 3, 0.0, 0.123)])
Exemple #8
0
 def test_with_plastic_synapse(self, sim=sim):
     connection_list = [
         (0, 0, 0.1, 0.1, 100, 400),
         (3, 0, 0.2, 0.11, 101, 500),
         (2, 3, 0.3, 0.12, 102, 600),  # local
         (2, 2, 0.4, 0.13, 103, 700),
         (0, 1, 0.5, 0.14, 104, 800),  # local
     ]
     C = connectors.FromListConnector(connection_list, column_names=[
                                      "weight", "delay", "U", "tau_rec"])
     syn = sim.TsodyksMarkramSynapse(U=99, tau_facil=88.8)
     prj = sim.Projection(self.p1, self.p2, C, syn)
     self.assertEqual(prj.get(["weight", "delay", "tau_facil", "tau_rec", "U"], format='list', gather=False),  # use gather False because we are faking the MPI
                      [(0, 1, 0.5, 0.14, 88.8, 800.0, 104.0),
                       (2, 3, 0.3, 0.12, 88.8, 600.0, 102.0)])
 def setUp(self, sim=sim, **extra):
     self.MIN_DELAY = 0.123
     sim.setup(num_processes=2, rank=1, min_delay=self.MIN_DELAY, **extra)
     self.p1 = sim.Population(7, sim.IF_cond_exp())
     self.p2 = sim.Population(4, sim.IF_cond_exp())
     self.p3 = sim.Population(5, sim.IF_curr_alpha())
     self.projections = {"cond": {}, "curr": {}}
     for psr, post in (("cond", self.p2), ("curr", self.p3)):
         for rt in ("excitatory", "inhibitory"):
             self.projections[psr][rt] = sim.Projection(
                 self.p1,
                 post,
                 sim.AllToAllConnector(safe=True),
                 sim.StaticSynapse(),
                 receptor_type=rt)
Exemple #10
0
    def test_connect_with_default_args(self):
        C = connectors.FixedProbabilityConnector(p_connect=0.85,
                                                 rng=MockRNG(
                                                     delta=0.1,
                                                     parallel_safe=True))
        syn = sim.StaticSynapse()
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 possible connections. Due to the mock RNG, only the
        # first 9 are created (0,0), (1,0), (2,0), (3,0), (0,1), (1,1), (2,1), (3,1), (0,2)
        # of these, (0,1), (1,1), (2,1), (3,1) are created on this node
        self.assertEqual(
            prj.get(["weight", "delay"], format='list', gather=False
                    ),  # use gather False because we are faking the MPI
            [(0, 1, 0.0, 0.123), (1, 1, 0.0, 0.123), (2, 1, 0.0, 0.123),
             (3, 1, 0.0, 0.123)])
    def test_connect_with_probability_1(self, sim=sim):
        # see https://github.com/NeuralEnsemble/PyNN/issues/309
        C = connectors.FixedProbabilityConnector(p_connect=1,
                                                 rng=MockRNG(
                                                     delta=0.01,
                                                     parallel_safe=True))
        syn = sim.StaticSynapse()
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 connections, only some of which are created on this node
        self.assertEqual(
            prj.get(["weight", "delay"], format='list', gather=False
                    ),  # use gather False because we are faking the MPI
            [(0, 1, 0.0, 0.123), (1, 1, 0.0, 0.123), (2, 1, 0.0, 0.123),
             (3, 1, 0.0, 0.123), (0, 3, 0.0, 0.123), (1, 3, 0.0, 0.123),
             (2, 3, 0.0, 0.123), (3, 3, 0.0, 0.123)])
Exemple #12
0
 def test_with_plastic_synapses_not_distributed(self, sim=sim):
     connection_list = [
         (0, 0, 0.1, 0.1,  100, 100),
         (3, 0, 0.2, 0.11, 110, 99),
         (2, 3, 0.3, 0.12, 120, 98),  # local
         (2, 2, 0.4, 0.13, 130, 97),
         (0, 1, 0.5, 0.14, 140, 96),  # local
     ]
     file = recording.files.StandardTextFile("test.connections.2", mode='wb')
     file.write(connection_list, {"columns": ["i", "j", "weight", "delay", "U", "tau_rec"]})
     C = connectors.FromFileConnector("test.connections.2", distributed=False)
     syn = sim.TsodyksMarkramSynapse(tau_facil=88.8)
     prj = sim.Projection(self.p1, self.p2, C, syn)
     self.assertEqual(prj.get(["weight", "delay", "U", "tau_rec", "tau_facil"], format='list', gather=False),  # use gather False because we are faking the MPI
                      [(0, 1, 0.5, 0.14, 140.0, 96.0, 88.8),
                       (2, 3, 0.3, 0.12, 120.0, 98.0, 88.8)])
Exemple #13
0
 def test_with_replacement_with_variable_n(self):
     n = random.RandomDistribution('binomial', (5, 0.5),
                                   rng=MockRNG(start=1, delta=2))
     # should give (1, 3, 0, 2, 4)
     C = connectors.FixedNumberPreConnector(n=n,
                                            with_replacement=True,
                                            rng=MockRNG(delta=1))
     syn = sim.StaticSynapse()
     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, 0, 0.0, 0.123),
             (1, 1, 0.0, 0.123), (2, 1, 0.0, 0.123), (3, 1, 0.0, 0.123),
             (0, 3, 0.0, 0.123), (1, 3, 0.0, 0.123)
         ])
Exemple #14
0
 def test_with_replacement_no_self_connections(self, sim=sim):
     C = connectors.FixedNumberPostConnector(n=3, with_replacement=True,
                                             allow_self_connections=False, rng=MockRNG(start=2, delta=1))
     syn = sim.StaticSynapse()
     prj = sim.Projection(self.p2, self.p2, C, syn)
     # 0 - 2 3 4
     # 1 - 0 2 3
     # 2 - 4 0 1
     # 3 - 2 4 0
     # 4 - 1 2 3
     self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False),  # use gather False because we are faking the MPI
                      [(2, 1, 0.0, 0.123),
                       (4, 1, 0.0, 0.123),
                       (0, 3, 0.0, 0.123),
                       (1, 3, 0.0, 0.123),
                       (4, 3, 0.0, 0.123)])
 def test_connect_with_scalar_weights_and_delays(self, sim=sim):
     connections = np.array([
         [0, 1, 1, 0],
         [1, 1, 0, 1],
         [0, 0, 1, 0],
     ], dtype=bool)
     C = connectors.ArrayConnector(connections, 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'),
                      [(1, 0, 5.0, 0.5),
                       (0, 1, 5.0, 0.5),
                       (1, 1, 5.0, 0.5),
                       (0, 2, 5.0, 0.5),
                       (2, 2, 5.0, 0.5),
                       (1, 3, 5.0, 0.5)])
 def test_connect_with_valid_list(self, sim=sim):
     connection_list = [
         (0, 0, 0.1, 0.18),
         (3, 0, 0.2, 0.17),
         (2, 3, 0.3, 0.16),  # local
         (2, 2, 0.4, 0.15),
         (0, 1, 0.5, 0.14),  # local
     ]
     C = connectors.FromListConnector(connection_list)
     syn = sim.StaticSynapse()
     prj = sim.Projection(self.p1, self.p2, C, syn)
     self.assertEqual(prj.get(["weight", "delay"], format='list'),
                      [(0, 0, 0.1, 0.18),
                       (3, 0, 0.2, 0.17),
                       (0, 1, 0.5, 0.14),
                       (2, 2, 0.4, 0.15),
                       (2, 3, 0.3, 0.16)])
 def test_connect_weight_function_and_one_post_synaptic_neuron_not_connected(self, sim=sim):
     C = connectors.FixedProbabilityConnector(p_connect=0.8,
                                              rng=MockRNG(delta=0.05))
     syn = sim.StaticSynapse(weight=lambda d: 0.1 * d)
     prj = sim.Projection(self.p1, self.p2, C, syn)
     assert_array_almost_equal(prj.get(["weight", "delay"], format='array'),
                               np.array([
                                   [[0., 0.1, 0.2, 0.3, nan],
                                    [0.1,  0., 0.1, 0.2, nan],
                                       [0.2, 0.1, 0.0, 0.1, nan],
                                       [0.3, 0.2, 0.1, 0.0, nan]],
                                   [[0.123, 0.123, 0.123, 0.123, nan],
                                    [0.123, 0.123,   0.123, 0.123, nan],
                                    [0.123, 0.123,   0.123, 0.123, nan],
                                    [0.123, 0.123,   0.123, 0.123, nan]]
                               ]),
                               9)
Exemple #18
0
 def test_with_replacement(self):
     C = connectors.FixedNumberPreConnector(n=3, with_replacement=True, rng=MockRNG(delta=1))
     syn = sim.StaticSynapse()
     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, 0, 0.0, 0.123),
                       #(1, 0, 0.0, 0.123),
                       #(2, 0, 0.0, 0.123),
                       (3, 1, 0.0, 0.123),
                       (0, 1, 0.0, 0.123),
                       (1, 1, 0.0, 0.123),
                       #(2, 2, 0.0, 0.123),
                       #(3, 2, 0.0, 0.123),
                       #(0, 2, 0.0, 0.123),
                       (1, 3, 0.0, 0.123),
                       (2, 3, 0.0, 0.123),
                       (3, 3, 0.0, 0.123),])
Exemple #19
0
 def test_with_stdp_synapse(self, sim=sim):
     connection_list = [
         (0, 0, 0.1, 0.1, 10.0, 0.4),
         (3, 0, 0.2, 0.11, 10.1, 0.5),
         (2, 3, 0.3, 0.12, 10.2, 0.6),  # local
         (2, 2, 0.4, 0.13, 10.3, 0.7),
         (0, 1, 0.5, 0.14, 10.4, 0.8),  # local
     ]
     C = connectors.FromListConnector(connection_list, column_names=[
                                      "weight", "delay", "tau_plus", "w_max"])
     syn = sim.STDPMechanism(timing_dependence=sim.SpikePairRule(tau_plus=12.3, tau_minus=33.3),
                             weight_dependence=sim.MultiplicativeWeightDependence(w_max=1.11),
                             weight=0.321, delay=0.2)
     prj = sim.Projection(self.p1, self.p2, C, syn)
     self.assertEqual(prj.get(["weight", "delay", "tau_plus", "tau_minus", "w_max"], format='list', gather=False),  # use gather False because we are faking the MPI
                      [(0, 1, 0.5, 0.14, 10.4, 33.3, 0.8),
                       (2, 3, 0.3, 0.12, 10.2, 33.3, 0.6)])
 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)
Exemple #21
0
 def test_connect_with_random_delays_parallel_safe(self):
     rd = random.RandomDistribution('uniform', low=0.1, high=1.1, rng=MockRNG(start=1.0, delta=0.2, parallel_safe=True))
     syn = sim.StaticSynapse(delay=rd)
     C = connectors.FixedProbabilityConnector(p_connect=0.5,
                                              rng=MockRNG2(1 - numpy.array([1, 0, 0, 1,
                                                                            0, 0, 0, 1,
                                                                            1, 1, 0, 0,
                                                                            1, 0, 1, 0,
                                                                            1, 1, 0, 1]),
                                                           parallel_safe=True))
     prj = sim.Projection(self.p1, self.p2, C, syn)
     nan = numpy.nan
     assert_array_almost_equal(prj.get('delay', format='array', gather=False),
                               numpy.array([[nan, nan, nan, 2.0, nan],
                                            [nan, nan, nan, nan, nan],
                                            [nan, nan, nan, 2.2, nan],
                                            [nan, 1.4, nan, nan, nan]]),
                               9)
Exemple #22
0
 def test_with_n_larger_than_population_size(self, sim=sim):
     C = connectors.FixedNumberPostConnector(n=7, rng=MockRNG(delta=1))
     syn = sim.StaticSynapse()
     prj = sim.Projection(self.p1, self.p2, C, syn)
     # each pre neuron will connect to all post neurons (population size 5 is less than n), then to 4, 3 (MockRNG.permutation)
     self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False),  # use gather False because we are faking the MPI
                      [(0, 1, 0.0, 0.123),
                       (1, 1, 0.0, 0.123),
                       (2, 1, 0.0, 0.123),
                       (3, 1, 0.0, 0.123),
                       (0, 3, 0.0, 0.123),
                       (0, 3, 0.0, 0.123),
                       (1, 3, 0.0, 0.123),
                       (1, 3, 0.0, 0.123),
                       (2, 3, 0.0, 0.123),
                       (2, 3, 0.0, 0.123),
                       (3, 3, 0.0, 0.123),
                       (3, 3, 0.0, 0.123)])
 def test_connect_with_default_args(self, sim=sim):
     C = connectors.DistanceDependentProbabilityConnector(d_expression="d<1.5",
                                                          rng=MockRNG(delta=0.01))
     syn = sim.StaticSynapse()
     prj = sim.Projection(self.p1, self.p2, C, syn)
     # 20 possible connections. Only those with a sufficiently small distance
     # are created
     self.assertEqual(prj.get(["weight", "delay"], format='list'),
                      [(0, 0, 0.0, 0.123),
                       (1, 0, 0.0, 0.123),
                       (0, 1, 0.0, 0.123),
                       (1, 1, 0.0, 0.123),
                       (2, 1, 0.0, 0.123),
                       (1, 2, 0.0, 0.123),
                       (2, 2, 0.0, 0.123),
                       (3, 2, 0.0, 0.123),
                       (2, 3, 0.0, 0.123),
                       (3, 3, 0.0, 0.123),
                       (3, 4, 0.0, 0.123)])
Exemple #24
0
 def test_no_replacement_no_self_connections(self):
     C = connectors.FixedNumberPreConnector(n=3,
                                            with_replacement=False,
                                            allow_self_connections=False,
                                            rng=MockRNG(start=2, delta=1))
     syn = sim.StaticSynapse()
     prj = sim.Projection(self.p2, self.p2, C, syn)
     self.assertEqual(
         prj.get(["weight", "delay"], format='list', gather=False
                 ),  # use gather False because we are faking the MPI
         [
             (4, 1, 0.0, 0.123),
             (3, 1, 0.0, 0.123),
             (2, 1, 0.0, 0.123),
             (4, 3, 0.0, 0.123),
             #(3, 3, 0.0, 0.123),
             (2, 3, 0.0, 0.123),
             (1, 3, 0.0, 0.123),
         ])
Exemple #25
0
 def test_with_n_larger_than_population_size_no_self_connections(self):
     C = connectors.FixedNumberPreConnector(n=7, allow_self_connections=False, rng=MockRNG(delta=1))
     syn = sim.StaticSynapse()
     prj = sim.Projection(self.p2, 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, 0.0, 0.123),
                       (2, 1, 0.0, 0.123),
                       (3, 1, 0.0, 0.123),
                       (4, 1, 0.0, 0.123),
                       (4, 1, 0.0, 0.123),
                       (3, 1, 0.0, 0.123),
                       (2, 1, 0.0, 0.123),
                       (0, 3, 0.0, 0.123),
                       (1, 3, 0.0, 0.123),
                       (2, 3, 0.0, 0.123),
                       (4, 3, 0.0, 0.123),
                       (4, 3, 0.0, 0.123),
                       (2, 3, 0.0, 0.123),
                       (1, 3, 0.0, 0.123),])
    def test_connect_with_default_args(self, sim=sim):
        C = connectors.FixedProbabilityConnector(p_connect=0.85,
                                                 rng=MockRNG(delta=0.1, parallel_safe=True))
        syn = sim.StaticSynapse()
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 possible connections. Due to the mock RNG, only the
        # first 9 are created (0,0), (1,0), (2,0), (3,0), (0,1), (1,1), (2,1), (3,1), (0,2)
        self.assertEqual(prj.get(["weight", "delay"], format='list'),
                         [(0, 0, 0.0, 0.123),
                          (1, 0, 0.0, 0.123),
                          (2, 0, 0.0, 0.123),
                          (3, 0, 0.0, 0.123),
                          (0, 1, 0.0, 0.123),
                          (1, 1, 0.0, 0.123),
                          (2, 1, 0.0, 0.123),
                          (3, 1, 0.0, 0.123),
                          (0, 2, 0.0, 0.123)
                          ])
 def test_no_replacement_parallel_unsafe(self, sim=sim):
     C = connectors.FixedNumberPreConnector(n=3,
                                            with_replacement=False,
                                            rng=MockRNG(
                                                delta=1,
                                                parallel_safe=False))
     syn = sim.StaticSynapse()
     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
         [
             (3, 1, 0.0, 0.123),
             (2, 1, 0.0, 0.123),
             (1, 1, 0.0, 0.123),
             (3, 3, 0.0, 0.123),
             (2, 3, 0.0, 0.123),
             (1, 3, 0.0, 0.123),
         ])
 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_weight_function(self, sim=sim):
        C = connectors.FixedProbabilityConnector(p_connect=0.85,
                                                 rng=MockRNG(delta=0.1))
        syn = sim.StaticSynapse(weight=lambda d: 0.1 * d)
        prj = sim.Projection(self.p1, self.p2, C, syn)

        # 20 possible connections. Due to the mock RNG, only the
        # first 9 are created (0,0), (1,0), (2,0), (3,0), (0,1), (1,1), (2,1), (3,1), (0,2)
        assert_array_almost_equal(prj.get(["weight", "delay"], format='array'),
                                  np.array([
                                      [[0., 0.1, 0.2, nan, nan],
                                       [0.1,  0., nan, nan, nan],
                                          [0.2, 0.1, nan, nan, nan],
                                          [0.3, 0.2, nan, nan, nan]],
                                      [[0.123, 0.123, 0.123, nan, nan],
                                       [0.123, 0.123,   nan, nan, nan],
                                       [0.123, 0.123,   nan, nan, nan],
                                       [0.123, 0.123,   nan, nan, nan]]
                                  ]),
                                  9)
 def test_with_replacement(self, sim=sim):
     C = connectors.FixedNumberPreConnector(n=3, with_replacement=True, rng=MockRNG(delta=1))
     syn = sim.StaticSynapse()
     prj = sim.Projection(self.p1, self.p2, C, syn)
     self.assertEqual(prj.get(["weight", "delay"], format='list'),
                      [(0, 0, 0.0, 0.123),
                       (1, 0, 0.0, 0.123),
                       (2, 0, 0.0, 0.123),
                       (3, 1, 0.0, 0.123),
                       (0, 1, 0.0, 0.123),
                       (1, 1, 0.0, 0.123),
                       (2, 2, 0.0, 0.123),
                       (3, 2, 0.0, 0.123),
                       (0, 2, 0.0, 0.123),
                       (1, 3, 0.0, 0.123),
                       (2, 3, 0.0, 0.123),
                       (3, 3, 0.0, 0.123),
                       (0, 4, 0.0, 0.123),
                       (1, 4, 0.0, 0.123),
                       (2, 4, 0.0, 0.123), ])