Esempio n. 1
0
 def serialize(self, data, fileName=None, useCompression=False):
     buffArrObjName = (str (type (data)).split ()[1].split ('>')[0] + "()").replace ("'", '')
     dataArch = InputDataArchive ()
     data.serialize (dataArch)
     length = dataArch.getSizeOfArchive ()
     bufferArray = np.zeros (length, dtype=np.ubyte)
     dataArch.copyArchiveToArray (bufferArray)
     if useCompression == True:
         if fileName != None:
             if len(fileName.rsplit (".", 1))==2:
                 fileName = fileName.rsplit (".", 1)[0]
             compressedData = LinearRegression.compress (self,bufferArray)
             np.save (fileName, compressedData)
         else:
             comBufferArray = LinearRegression.compress (self,bufferArray)
             serialObjectDict = {"Array Object": comBufferArray,
                                 "Object Information": buffArrObjName}
             return serialObjectDict
     else:
         if fileName != None:
             if len (fileName.rsplit (".", 1)) == 2:
                 fileName = fileName.rsplit (".", 1)[0]
             np.save (fileName, bufferArray)
         else:
             serialObjectDict = {"Array Object": bufferArray,
                                 "Object Information": buffArrObjName}
             return serialObjectDict
     infoFile = open (fileName + ".txt", "w")
     infoFile.write (buffArrObjName)
     infoFile.close ()
def gatherPartialResultsFromNodes(partialResult, partialResults,
                                  partialResultArchLength,
                                  partialResultLocalBuffer,
                                  partialResultMasterBuffer):

    dataArch = InputDataArchive()
    partialResult.serialize(dataArch)
    if partialResultArchLength == 0:
        partialResultArchLength = dataArch.getSizeOfArchive()

    # Serialized data is of equal size on each node
    if rankId == MPI_ROOT and len(partialResultMasterBuffer) == 0:
        partialResultMasterBuffer = np.zeros(partialResultArchLength * nNodes,
                                             dtype=np.uint8)

    if len(partialResultLocalBuffer) == 0:
        partialResultLocalBuffer = np.zeros(partialResultArchLength,
                                            dtype=np.uint8)

    dataArch.copyArchiveToArray(partialResultLocalBuffer)

    # Transfer partial results to step 2 on the root node
    partialResultMasterBuffer = comm.gather(partialResultLocalBuffer)

    if rankId == MPI_ROOT:
        for node in range(nNodes):
            # Deserialize partial results from step 1
            dataArch = OutputDataArchive(partialResultMasterBuffer[node])

            partialResults[node] = training.PartialResult()
            partialResults[node].deserialize(dataArch)
def serializeDAALObject(data):
    # Create a data archive to serialize the numeric table
    dataArch = InputDataArchive()

    # Serialize the numeric table into the data archive
    data.serialize(dataArch)

    length = dataArch.getSizeOfArchive()
    buffer = np.zeros(length, dtype=np.uint8)
    dataArch.copyArchiveToArray(buffer)
    return buffer
Esempio n. 4
0
    def serializeTrainingResult(self):
        #  Create a data archive to serialize the numeric table
        dataArch = InputDataArchive()
        #  Serialize the numeric table into the data archive
        self.trainingResult.serialize(dataArch)
        #  Get the length of the serialized data in bytes
        length = dataArch.getSizeOfArchive()
        #  Store the serialized data in an array
        buffer = np.zeros(length, dtype=np.ubyte)
        dataArch.copyArchiveToArray(buffer)

        return buffer
Esempio n. 5
0
File: Kmeans.py Progetto: ravi9/csp
 def serialize(
     self,
     data,
     fileName=None,
     useCompression=False,
 ):
     buffArrObjName = (str(type(data)).split()[1].split('>')[0] +
                       '()').replace("'", '')
     dataArch = InputDataArchive()
     data.serialize(dataArch)
     length = dataArch.getSizeOfArchive()
     bufferArray = np.zeros(length, dtype=np.ubyte)
     dataArch.copyArchiveToArray(bufferArray)
     if useCompression == True:
         if fileName != None:
             if len(fileName.rsplit('.', 1)) == 2:
                 fileName = fileName.rsplit('.', 1)[0]
             compressedData = Kmeans.compress(self, bufferArray)
             np.save(fileName, compressedData)
         else:
             comBufferArray = Kmeans.compress(self, bufferArray)
             serialObjectDict = {
                 'Array Object': comBufferArray,
                 'Object Information': buffArrObjName
             }
             return serialObjectDict
     else:
         if fileName != None:
             if len(fileName.rsplit('.', 1)) == 2:
                 fileName = fileName.rsplit('.', 1)[0]
             np.save(fileName, bufferArray)
         else:
             serialObjectDict = {
                 'Array Object': bufferArray,
                 'Object Information': buffArrObjName
             }
             return serialObjectDict
     infoFile = open(fileName + '.txt', 'w')
     infoFile.write(buffArrObjName)
     infoFile.close()
def broadcastWeightsAndBiasesToNodes(wb):

    wbBuffer = None
    # Serialize weights and biases on the root node
    if rankId == MPI_ROOT:
        if not wb:
            # Weights and biases table should be valid and not NULL on master
            return HomogenNumericTable()

        wbDataArch = InputDataArchive()
        wb.serialize(wbDataArch)
        wbBuffer = np.zeros(wbDataArch.getSizeOfArchive(), dtype=np.uint8)
        wbDataArch.copyArchiveToArray(wbBuffer)

    # Broadcast the serialized weights and biases
    wbBuffer = comm.bcast(wbBuffer)

    # Deserialize weights and biases
    wbDataArchLocal = OutputDataArchive(wbBuffer)

    wbLocal = HomogenNumericTable(ntype=np.float32)
    wbLocal.deserialize(wbDataArchLocal)

    return wbLocal