예제 #1
0
def nb_frameprod_upper_delta_multithread(**kargs):
    Nenv1, nA, nL = kargs['vals1'].shape
    Nenv2, nB, nL = kargs['vals2'].shape
    result = np.zeros((Nenv1, Nenv2), dtype=np.float64)

    keys1, keys2, vals1, vals2, chemicalKernelmat = [kargs['keys1'], kargs['keys2'], kargs['vals1'], kargs['vals2'], \
                                                     kargs['chemicalKernelmat']]

    numthreadsTot2nthreads = {2: (2, 1), 4: (2, 2), 6: (3, 2), 9: (3, 3),
                              12: (4, 3), 16: (4, 4), 25: (5, 5), 36: (6, 6),
                              48: (7, 7), 64: (8,8), 81: (9,9), 100: (10,10)}
    numthreads1, numthreads2 = numthreadsTot2nthreads[4]

    chunks1, slices1 = chunk_list(vals1, numthreads1)
    chunks2, slices2 = chunk_list(vals2, numthreads2)

    chunks = []
    for it in range(numthreads1):
        for jt in range(numthreads2):
            chunks3 = result[slices1[it][0]:slices1[it][-1] + 1, slices2[jt][0]:slices2[jt][-1] + 1]
            a = {'result': chunks3, 'chemicalKernelmat': chemicalKernelmat.copy(), 'keys1': keys1.copy(), 'keys2': keys2.copy()}
            a.update(**{'vals1': chunks1[it]})
            a.update(**{'vals2': chunks2[jt]})

            chunks.append(a)

    threads = [threading.Thread(target=nb_frameprod_upper_delta, kwargs=chunk) for chunk in chunks]

    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
    return result
예제 #2
0
def get_environmentalKernels_mt_mp_chunks(atoms,
                                          nocenters=None,
                                          chem_channels=True,
                                          centerweight=1.0,
                                          gaussian_width=0.5,
                                          cutoff=3.5,
                                          cutoff_transition_width=0.5,
                                          nmax=8,
                                          lmax=6,
                                          chemicalKernelmat=None,
                                          chemicalKernel=None,
                                          chemicalProjection=None,
                                          nthreads=4,
                                          nprocess=2,
                                          nchunks=2,
                                          islow_memory=False,
                                          isDeltaKernel=True,
                                          dispbar=False,
                                          is_fast_average=False):
    if nocenters is None:
        nocenters = []

    # Builds the kernel matrix from the species present in the frames and a specified chemical
    # kernel function

    if chemicalKernelmat is not None:
        pass
    elif chemicalProjection is not None:
        pass
    elif (chemicalKernelmat is None) and (chemicalKernel is not None):
        chemicalKernelmat = Atoms2ChemicalKernelmat(
            atoms, chemicalKernel=chemicalKernel)
    else:
        raise ValueError('wrong chemicalKernelmat and/or chemicalKernel input')

    Natoms = len(atoms)
    NenvKernels = Natoms * (Natoms + 1) / 2.

    # fpointers = [frame._fpointer.copy() for frame in atoms]
    # chunks1d, slices = chunk_list(fpointers, nchunks=nchunks)
    # cut atomsList in chunks
    if islow_memory:
        frames = get_Soaps(atoms,
                           nocenters=nocenters,
                           chem_channels=chem_channels,
                           centerweight=centerweight,
                           gaussian_width=gaussian_width,
                           cutoff=cutoff,
                           is_fast_average=is_fast_average,
                           chemicalProjection=chemicalProjection,
                           cutoff_transition_width=cutoff_transition_width,
                           nmax=nmax,
                           lmax=lmax,
                           nprocess=nprocess)
        chunks1d, slices = chunk_list(frames, nchunks=nchunks)

    else:
        chunks1d, slices = chunk_list(atoms, nchunks=nchunks)

    soap_params = {
        'centerweight': centerweight,
        'gaussian_width': gaussian_width,
        'cutoff': cutoff,
        'cutoff_transition_width': cutoff_transition_width,
        'nmax': nmax,
        'lmax': lmax,
        'chemicalKernelmat': chemicalKernelmat,
        'chemicalProjection': chemicalProjection,
        'chem_channels': chem_channels,
        'nocenters': nocenters,
        'is_fast_average': is_fast_average,
    }

    # create inputs for each block of the global kernel matrix
    chunks = chunks1d_2_chuncks2d(chunks1d, **soap_params)

    # new_atoms1 = {}
    # new_atoms2 = {}
    # for it,chunk in enumerate(chunks):
    #     atoms1 = chunk.pop('atoms1')
    #     atoms2 = chunk.pop('atoms2')
    #     # new_atoms1[it] = [qp.Atoms().copy_from(frame) for frame in atoms1]
    #     new_atoms1[it] = [frame.copy() for frame in atoms1]
    #     fpointers1 = [frame._fpointer.copy() for frame in new_atoms1[it]]
    #     if atoms2 is not None:
    #         # new_atoms2[it] = [qp.Atoms().copy_from(frame) for frame in atoms2]
    #         new_atoms2[it] = [frame.copy() for frame in atoms2]
    #         fpointers2 = [frame._fpointer.copy() for frame in new_atoms2[it]]
    #     else:
    #         fpointers2 = None
    #
    #     chunk.update(**{'fpointers1':fpointers1,'fpointers2':fpointers2})

    # get a list of environemental kernels
    pool = mp_framesprod(chunks,
                         nprocess,
                         nthreads,
                         NenvKernels,
                         isDeltaKernel=isDeltaKernel,
                         dispbar=dispbar)
    results = pool.run()
    # reorder the list of environemental kernels into a dictionary which keys are the (i,j) of the global kernel matrix
    environmentalKernels = join_envKernel(results, slices)

    return environmentalKernels