示例#1
0
 def test_add(self):
     pl = Placement()
     pl.add(BioNeuron(42, 0), LogicalNeuron.external(13))
     pl.add(BioNeuron(123, 0), (LogicalNeuron.on(NeuronBlockOnWafer()).add(
         NeuronOnNeuronBlock(X(2), Y(0)), 4).add(
             NeuronOnNeuronBlock(X(3), Y(1)), 2).done()))
     return pl
示例#2
0
    def test_denmems(self):
        # |  XXXX
        # |   XX
        nrn = (LogicalNeuron.on(NeuronBlockOnWafer()).add(
            NeuronOnNeuronBlock(X(2), Y(0)),
            4).add(NeuronOnNeuronBlock(X(3), Y(1)), 2).done())
        reference_denmems = [
            NeuronOnWafer(NeuronOnHICANN(X(2), Y(0))),
            NeuronOnWafer(NeuronOnHICANN(X(3), Y(0))),
            NeuronOnWafer(NeuronOnHICANN(X(4), Y(0))),
            NeuronOnWafer(NeuronOnHICANN(X(5), Y(0))),
            NeuronOnWafer(NeuronOnHICANN(X(3), Y(1))),
            NeuronOnWafer(NeuronOnHICANN(X(4), Y(1))),
        ]

        self.assertFalse(nrn.is_external())
        self.assertEqual(6, nrn.size())
        self.assertEqual(reference_denmems[0], nrn.denmem(0))
        self.assertEqual(reference_denmems[1], nrn.denmem(1))
        self.assertEqual(reference_denmems[2], nrn.denmem(2))
        self.assertEqual(reference_denmems[3], nrn.denmem(3))
        self.assertEqual(reference_denmems[4], nrn.denmem(4))
        self.assertEqual(reference_denmems[5], nrn.denmem(5))
        with self.assertRaises(IndexError):
            nrn.denmem(6)
        self.assertSequenceEqual(reference_denmems, list(nrn))
        self.assertNotEqual(LogicalNeuron.external(12), nrn)
        self.assertEqual(nrn, nrn)
示例#3
0
    def test_rectangular(self):
        nrn = LogicalNeuron.rectangular(
            NeuronOnWafer(NeuronOnHICANN(X(3), Y(0))), 4)
        reference_denmems = [
            NeuronOnWafer(NeuronOnHICANN(X(3), Y(0))),
            NeuronOnWafer(NeuronOnHICANN(X(4), Y(0))),
            NeuronOnWafer(NeuronOnHICANN(X(3), Y(1))),
            NeuronOnWafer(NeuronOnHICANN(X(4), Y(1))),
        ]
        self.assertFalse(nrn.is_external())
        self.assertEqual(4, nrn.size())
        self.assertSequenceEqual(reference_denmems, list(nrn))
        self.assertTrue(str(nrn).startswith('LogicalNeuron::on('))
        with self.assertRaises(RuntimeError):
            nrn.external_identifier()
        with self.assertRaises(RuntimeError):
            nrn.external_index()

        with self.assertRaises(ValueError):
            wrong_size = LogicalNeuron.rectangular(
                NeuronOnWafer(NeuronOnHICANN(X(3), Y(0))), 5)

        with self.assertRaises(ValueError):
            wrong_row = LogicalNeuron.rectangular(
                NeuronOnWafer(NeuronOnHICANN(X(3), Y(1))), 4)
示例#4
0
    def test_builder(self):
        nrn = (LogicalNeuron.on(NeuronBlockOnWafer()).add(
            NeuronOnNeuronBlock(), 5).done())
        self.assertFalse(nrn.is_external())
        self.assertTrue(str(nrn).startswith('LogicalNeuron::on('))
        with self.assertRaises(RuntimeError):
            nrn.external_identifier()
        with self.assertRaises(RuntimeError):
            nrn.external_index()

        with self.assertRaises(ValueError):
            no_chunks_specified = (LogicalNeuron.on(
                NeuronBlockOnWafer()).done())
示例#5
0
    def test_set_address(self):
        pl = self.test_add()
        nrn = LogicalNeuron.external(13)

        items = list(pl.find(nrn))
        self.assertEqual(1, len(items))
        self.assertIsNone(items[0].address())

        address = L1AddressOnWafer(DNCMergerOnWafer(DNCMergerOnHICANN(3)),
                                   L1Address(42))
        pl.set_address(LogicalNeuron.external(13), address)

        items = list(pl.find(nrn))
        self.assertEqual(1, len(items))
        self.assertIsNotNone(items[0].address())
        self.assertEqual(address, items[0].address())

        return pl
示例#6
0
 def test_item(self):
     bio = BioNeuron(42, 5)
     logical = LogicalNeuron.external(13)
     item = Placement.item_type(bio, logical)
     self.assertIsNone(item.neuron_block())
     self.assertIsNone(item.dnc_merger())
     self.assertEqual(bio, item.bio_neuron())
     self.assertEqual(bio.population(), item.population())
     self.assertEqual(bio.neuron_index(), item.neuron_index())
     self.assertEqual(logical, item.logical_neuron())
     self.assertIsNone(item.address())
示例#7
0
    def test_external_node(self):
        nrn = LogicalNeuron.external(15)

        self.assertTrue(nrn.is_external())
        with self.assertRaises(RuntimeError):
            nrn.size()
        self.assertSequenceEqual([], list(nrn))
        with self.assertRaises(RuntimeError):
            nrn.denmem(0)

        self.assertEqual(LogicalNeuron.external(15), nrn)
        self.assertNotEqual(LogicalNeuron.external(12), nrn)
        self.assertEqual(15, nrn.external_identifier())
        self.assertEqual(0, nrn.external_index())

        nrn = LogicalNeuron.external(42, 2)
        self.assertEqual(42, nrn.external_identifier())
        self.assertEqual(2, nrn.external_index())

        self.assertTrue(str(nrn).startswith('LogicalNeuron::external('))
示例#8
0
 def test_find_by_logical_neuron(self):
     pl = self.test_add()
     items = list(pl.find(LogicalNeuron.external(13)))
     self.assertEqual(1, len(items))
     self.assertEqual(42, items[0].population())
示例#9
0
 def test_no_denmems(self):
     with self.assertRaises(ValueError):
         LogicalNeuron.on(NeuronBlockOnWafer()).done()