Ejemplo n.º 1
0
    def run(self, out):
        Nit = len(self.chunks)
        pbar = tqdm_cs(total=Nit,
                       desc='SOAP vectors',
                       disable=self.disable_pbar)

        results = out
        ids_list = self.ids_list

        if self.nprocess > 1:
            pool = mp.Pool(self.nprocess,
                           initializer=self.worker_init,
                           maxtasksperchild=10)

            for idx, res in pool.imap_unordered(self.func_wrap, self.chunks):
                results[ids_list[idx], :] = res
                pbar.update()

            pool.close()
            pool.join()

        elif self.nprocess == 1:
            for chunk in self.chunks:
                idx, res = self.func_wrap(chunk)
                results[ids_list[idx], :] = res

                pbar.update()
        else:
            print 'Nproces: ', self.nprocess
            raise NotImplementedError('need at least 1 process')

        pbar.close()
Ejemplo n.º 2
0
Archivo: soap.py Proyecto: rzk1/glosim2
    def run(self):
        Nit = len(self.chunks)
        pbar = tqdm_cs(total=Nit,desc='SOAP vectors',disable=self.dispbar)
        results = {}
        if self.nprocess > 1:
            pool = mp.Pool(self.nprocess, initializer=self.worker_init,
                                maxtasksperchild=10)

            for idx, res in pool.imap_unordered(self.func_wrap, self.chunks):
                results[idx] = res
                pbar.update()

            pool.close()
            pool.join()

        elif self.nprocess == 1:
            for chunk in self.chunks:
                idx,res = self.func_wrap(chunk)
                results[idx] = res

                pbar.update()
        else:
            print('Nproces: ',self.nprocess)
            raise NotImplementedError('need at least 1 process')

        pbar.close()

        Frames = [results[it] for it in range(Nit)]

        return Frames
Ejemplo n.º 3
0
Archivo: LC.py Proyecto: rzk1/glosim2
    def run(self):
        Nit = len(self.chunks)
        pbar = tqdm_cs(total=Nit, desc='LearningCurve', disable=self.dispbar)
        scores_test = []
        scores_train = []
        scores_test_err = []
        scores_train_err = []

        Ntrains = []
        if self.nprocess > 1:
            pool = Pool(self.nprocess,
                        initializer=self.worker_init,
                        maxtasksperchild=1)

            for Ntrain, res_test, res_train in pool.imap_unordered(
                    self.func_wrap, self.chunks):
                scores_test.append(np.mean(res_test, axis=0))
                scores_train.append(np.mean(res_train, axis=0))
                scores_test_err.append(np.std(res_test, axis=0))
                scores_train_err.append(np.std(res_train, axis=0))
                Ntrains.append(Ntrain)
                pbar.update()

            pool.close()
            pool.join()

        elif self.nprocess == 1:
            for chunk in self.chunks:
                Ntrain, res_test, res_train = self.func_wrap(chunk)
                scores_test.append(np.mean(res_test, axis=0))
                scores_train.append(np.mean(res_train, axis=0))
                scores_test_err.append(np.std(res_test, axis=0))
                scores_train_err.append(np.std(res_train, axis=0))
                Ntrains.append(Ntrain)

                pbar.update()
        else:
            print 'Nproces: ', self.nprocess
            raise NotImplementedError('need at least 1 process')

        pbar.close()

        scores_test = np.asarray(scores_test)
        scores_train = np.asarray(scores_train)
        scores_test_err = np.asarray(scores_test_err)
        scores_train_err = np.asarray(scores_train_err)

        return Ntrains, scores_test, scores_test_err, scores_train, scores_train_err
Ejemplo n.º 4
0
    def run(self):
        Nit = len(self.chunks)
        pbar = tqdm_cs(total=Nit, desc='GridSearch', disable=self.dispbar)
        scores = []
        gs_params = []
        if self.nprocess > 1:
            pool = Pool(self.nprocess,
                        initializer=self.worker_init,
                        maxtasksperchild=1)

            for param, res in pool.imap_unordered(self.func_wrap, self.chunks):
                scores.append(res)
                gs_params.append(param)
                pbar.update()

            pool.close()
            pool.join()

        elif self.nprocess == 1:
            for chunk in self.chunks:
                param, res = self.func_wrap(chunk)
                scores.append(res)
                gs_params.append(param)

                pbar.update()
        else:
            print 'Nproces: ', self.nprocess
            raise NotImplementedError('need at least 1 process')

        pbar.close()

        scores = np.asarray(scores)

        ii = np.argmin(scores[:, 0])
        bestParams = gs_params[ii]
        bestParams.pop('memory_eff')
        return bestParams, scores, gs_params
Ejemplo n.º 5
0
 def __init__(self, Niter, name, dispbar):
     # super(dummy_queue,self).__init__()
     self.tbar = tqdm_cs(total=int(Niter), desc=name, disable=dispbar)
Ejemplo n.º 6
0
def simulateur_NVT_efficace(positions,
                            velocities,
                            masse,
                            temperature,
                            r_m,
                            epsilon,
                            k_spring,
                            Nstep,
                            dt,
                            enregistrement_stride=10):
    mass = masse
    Nparticule, _ = positions.shape
    accelerations = np.zeros(positions.shape)
    pos = []
    vel = []
    masses = np.ones((Nparticule)) * mass
    thermostat_frequency = np.sqrt(2) * np.sqrt(2 * k_spring)
    Nrecord = Nstep // enregistrement_stride
    diagnostic = dict(E_variation=np.zeros((Nrecord, )),
                      Temperature=np.zeros((Nrecord, )),
                      E_system=np.zeros((Nrecord, )),
                      E_potentiel=np.zeros((Nrecord, )),
                      E_cinetique=np.zeros((Nrecord, )),
                      time=np.zeros((Nrecord, )))
    dt_half = 0.5 * dt
    #th_en = 0.5*mass*np.power(velocities,2).sum()
    sys_en = 0
    econs = 0.0
    # Calculates the initial potential energy
    forces, ljpot, sppot = get_forces(positions, r_m, epsilon, k_spring)
    Ekin_tot = 0.5 * mass * np.power(velocities, 2).sum()
    sys_en += ljpot + sppot + Ekin_tot
    econs += sys_en
    ii = 0
    for it in tqdm_cs(range(Nstep)):

        #Apply thermostat
        econs += 0.5 * mass * np.power(velocities, 2).sum()
        velocities = andersen_thermostat(velocities, temperature,
                                         thermostat_frequency, dt)
        #CoM = np.average(velocities,weights=masses,axis=0).reshape((1,3))
        #velocities = velocities - CoM
        econs -= 0.5 * mass * np.power(velocities, 2).sum()

        # half update of velocities
        velocities = velocities + dt_half * accelerations
        # update of positions
        positions = positions + dt * velocities
        # update forces from new posittions
        forces, ljpot, sppot = get_forces(positions, r_m, epsilon, k_spring)
        # update acceleration
        accelerations = forces / mass
        # half update of velocities
        velocities = velocities + dt_half * accelerations

        Ekin_tot = 0.5 * mass * np.power(velocities, 2).sum()
        econs += ljpot + sppot + Ekin_tot - sys_en
        sys_en = ljpot + sppot + Ekin_tot

        if it % enregistrement_stride == 0:
            diagnostic['E_variation'][ii] = econs
            diagnostic['E_system'][ii] = sys_en
            diagnostic['E_cinetique'][ii] = Ekin_tot
            diagnostic['time'][ii] = it * dt
            diagnostic['Temperature'][ii] = Ekin_tot / 1.5 / len(positions)
            diagnostic['E_potentiel'][ii] = ljpot + sppot
            ii += 1

            vel.append(velocities)
            pos.append(positions)

    return pos, vel, diagnostic
Ejemplo n.º 7
0
 def listener(queue, Niter, dispbar):
     print 'listener ', dispbar
     tbar = tqdm_cs(total=int(Niter), desc='Env kernels', disable=dispbar)
     for ii in iter(queue.get, None):
         tbar.update(ii)
     tbar.close()