Example #1
0
    def run(self, func, X_L, X_H, X_N, Y_L, Y_H, Y_N, X_Name="", Y_Name=""):
        self.T_start = datetime.now()
        print("Start Calculation at ", str(self.T_start))
        self.func = func
        X = np.linspace(X_L, X_H, num=X_N, endpoint=True)
        Y = np.linspace(Y_L, Y_H, num=Y_N, endpoint=True)

        m = Manager()
        p = m.Pool()
        Phase = m.list([m.list([0] * Y_N) for i in range(X_N)])

        for i, j in product(list(range(X_N)), list(range(Y_N))):
            _X, _Y = X[i], Y[j]
            p.apply_async(self.func, args=(_X, _Y, i, j, Phase))

        p.close()
        p.join()

        self.data = [list(x) for x in list(Phase)]
        self.info = dict(X_L=X_L,
                         X_H=X_H,
                         X_N=X_N,
                         Y_L=Y_L,
                         Y_H=Y_H,
                         Y_N=Y_N,
                         X_Name=X_Name,
                         Y_Name=Y_Name)

        self.T_end = datetime.now()
        print("End Calculation at ", str(self.T_end))
        print("Total time:", str(self.T_end - self.T_start))

        return self
Example #2
0
def PhaseDiag(func, title="Phase Diagram of Theta & J"):
    T_start = datetime.now()
    print("Start Calculation at ", str(T_start))

    J_min, J_max, N_J = 0.00, 0.03, 31
    Theta_min, Theta_max, N_Theta = 0, np.pi, 31
    J = np.linspace(J_min, J_max, N_J, endpoint=True)
    T = np.linspace(Theta_min, Theta_max, N_Theta, endpoint=True)

    # Run Calculation in Multi Process
    m = Manager()
    p = m.Pool()
    Phase = m.list([m.list([0 for j in range(N_J)]) for i in range(N_Theta)])

    for i, j in product(list(range(N_Theta)), list(range(N_J))):
        T_, J_ = T[i], J[j]
        p.apply_async(func, args=(T_, J_, i, j, Phase,))

    p.close()
    p.join()

    P = [list(x) for x in list(Phase)]
    stime = nt()
    with open("PD_Data_"+stime+".txt", "w") as f:
        d = dict(Theta_min=Theta_min, Theta_max=Theta_max, N_Theta=N_Theta, J_min=J_min,
                 J_max=J_max, N_J=N_J, Phase=P)
        f.write(dumps(d))

    Draw(T, J, P, title=title,
         filename="PhaseDiag_"+stime)
    T_end = datetime.now()
    print("End Calculation at ", str(T_end))
    print("Total time:", str(T_end-T_start))
Example #3
0
 def get_list():
     if (MultiProcessing._pList == None):
         print("MultiProcessing Manager init!")
         mgr = Manager()
         #maxLength = 50
         #MultiProcessing._pList  =Array('d', maxLength, lock=False)
         MultiProcessing._pList = mgr.list()
         #MultiProcessing._pList = []
         mgr.Pool()
     return MultiProcessing._pList
    # templates
    T1 = Image.open('./red_light_single.jpg')
    T2 = Image.open('./red_light_double.jpg')
    T1 = T1.resize((int(T1.width / 2), int(T1.height / 2)))
    T2 = T2.resize((int(T2.width / 2), int(T2.height / 2)))

    file_names_train = np.load(os.path.join(split_path,
                                            'file_names_train.npy'))
    file_names_test = np.load(os.path.join(split_path, 'file_names_test.npy'))

    manager = Manager()

    # Make predictions on the training set.
    preds_train = manager.dict()
    with manager.Pool(processes=8) as pool:
        pool.map(partial(detect_worker, preds_train, [T1, T2], 0.9),
                 file_names_train)
    with open(os.path.join(preds_path, 'preds_train.json'), 'w') as f:
        json.dump(dict(preds_train), f)

    # Make predictions on the test set
    if done_tweaking:
        preds_test = manager.dict()
        with manager.Pool(processes=8) as pool:
            pool.map(partial(detect_worker, preds_test, [T1, T2], 0.9),
                     file_names_test)

        with open(os.path.join(preds_path, 'preds_test.json'), 'w') as f:
            json.dump(dict(preds_test), f)