def testDestroySegment(self): """ Creates a segment, destroys it, and makes sure it got destroyed along with all of its synapses. """ connections = Connections(1024) connections.createSegment(10) segment2 = connections.createSegment(20) connections.createSegment(30) connections.createSegment(40) connections.createSynapse(segment2, 80, 0.85) connections.createSynapse(segment2, 81, 0.85) connections.createSynapse(segment2, 82, 0.15) self.assertEqual(4, connections.numSegments()) self.assertEqual(3, connections.numSynapses()) connections.destroySegment(segment2) self.assertEqual(3, connections.numSegments()) self.assertEqual(0, connections.numSynapses()) (numActiveConnected, numActivePotential) = connections.computeActivity([80, 81, 82], 0.5) self.assertEqual(0, numActiveConnected[segment2.flatIdx]) self.assertEqual(0, numActivePotential[segment2.flatIdx])
def testPathsNotInvalidatedByOtherDestroys(self): """ Creates segments and synapses, then destroys segments and synapses on either side of them and verifies that existing Segment and Synapse instances still point to the same segment / synapse as before. """ connections = Connections(1024) segment1 = connections.createSegment(11) connections.createSegment(12) segment3 = connections.createSegment(13) connections.createSegment(14) segment5 = connections.createSegment(15) synapse1 = connections.createSynapse(segment3, 201, .85) synapse2 = connections.createSynapse(segment3, 202, .85) synapse3 = connections.createSynapse(segment3, 203, .85) synapse4 = connections.createSynapse(segment3, 204, .85) synapse5 = connections.createSynapse(segment3, 205, .85) self.assertEqual(203, synapse3.presynapticCell) connections.destroySynapse(synapse1) self.assertEqual(203, synapse3.presynapticCell) connections.destroySynapse(synapse5) self.assertEqual(203, synapse3.presynapticCell) connections.destroySegment(segment1) self.assertEqual(set([synapse2, synapse3, synapse4]), connections.synapsesForSegment(segment3)) connections.destroySegment(segment5) self.assertEqual(set([synapse2, synapse3, synapse4]), connections.synapsesForSegment(segment3)) self.assertEqual(203, synapse3.presynapticCell)
def testWriteRead(self): c1 = Connections(1024) # Add data before serializing s1 = c1.createSegment(0) c1.createSynapse(s1, 254, 0.1173) s2 = c1.createSegment(100) c1.createSynapse(s2, 20, 0.3) c1.createSynapse(s1, 40, 0.3) s3 = c1.createSegment(0) c1.createSynapse(s3, 0, 0.5) c1.createSynapse(s3, 1, 0.5) s4 = c1.createSegment(10) c1.createSynapse(s4, 0, 0.5) c1.createSynapse(s4, 1, 0.5) c1.destroySegment(s4) proto1 = ConnectionsProto_capnp.ConnectionsProto.new_message() c1.write(proto1) # Write the proto to a temp file and read it back into a new proto with tempfile.TemporaryFile() as f: proto1.write(f) f.seek(0) proto2 = ConnectionsProto_capnp.ConnectionsProto.read(f) # Load the deserialized proto c2 = Connections.read(proto2) # Check that the two connections objects are functionally equal self.assertEqual(c1, c2)
def testDestroySegmentsThenReachLimit(self): """ Destroy some segments then verify that the maxSegmentsPerCell is still correctly applied. """ connections = Connections(1024, 2, 2) segment1 = connections.createSegment(11) segment2 = connections.createSegment(11) self.assertEqual(2, connections.numSegments()) connections.destroySegment(segment1) connections.destroySegment(segment2) self.assertEqual(0, connections.numSegments()) connections.createSegment(11) self.assertEqual(1, connections.numSegments()) connections.createSegment(11) self.assertEqual(2, connections.numSegments()) segment3 = connections.createSegment(11) self.assertEqual(2, connections.numSegments(11)) self.assertEqual(2, connections.numSegments())
def testReuseSegmentWithDestroyedSynapses(self): """ Destroy a segment that has a destroyed synapse and a non-destroyed synapse. Create a new segment in the same place. Make sure its synapse count is correct. """ connections = Connections(1024) segment = connections.createSegment(11) synapse1 = connections.createSynapse(segment, 201, .85) connections.createSynapse(segment, 202, .85) connections.destroySynapse(synapse1) self.assertEqual(1, connections.numSynapses(segment)) connections.destroySegment(segment) reincarnated = connections.createSegment(11) self.assertEqual(0, connections.numSynapses(reincarnated)) self.assertEqual(0, len(connections.synapsesForSegment(reincarnated)))
def testDestroySegmentWithDestroyedSynapses(self): """ Destroy a segment that has a destroyed synapse and a non-destroyed synapse. Make sure nothing gets double-destroyed. """ connections = Connections(1024) segment1 = connections.createSegment(11) segment2 = connections.createSegment(12) connections.createSynapse(segment1, 101, .85) synapse2a = connections.createSynapse(segment2, 201, .85) connections.createSynapse(segment2, 202, .85) self.assertEqual(3, connections.numSynapses()) connections.destroySynapse(synapse2a) self.assertEqual(2, connections.numSegments()) self.assertEqual(2, connections.numSynapses()) connections.destroySegment(segment2) self.assertEqual(1, connections.numSegments()) self.assertEqual(1, connections.numSynapses())