Пример #1
0
def recived_mission(update, context):
    global mode
    global link
    global target
    target = update.effective_message.text
    if "/cancel" == target.strip()[:7]:
        return cancel(update, context)

    # extract lid,tid from Link(shared & Target)
    lid = "".join(re.findall(regex, link))
    tid = "".join(re.findall(regex, target))

    # extract Shared_Link folderName
    if len(lid) == 28 or len(lid) == 33:
        foldername = folder_name(settings.Remote, lid, lid)
    elif len(lid) != 28 and len(lid) != 33:
        d_id = lid
        foldername = drive_get(d_id)['name']

    # get Target_folderName under quick mode
    if "quick" == mode:
        # tid = Pre_Dst_id under quick mode
        tid = settings.Pre_Dst_id
        if len(tid) == 28 or len(tid) == 33:
            target_folder = folder_name(settings.Remote, tid, tid)
        elif len(tid) != 28 and len(tid) != 33:
            d_id = tid
            target_folder = drive_get(d_id)['name']

    # get Target_folderName under copy mode
    elif "copy" == mode:
        if len(tid) == 28 or len(tid) == 33:
            target_folder = folder_name(settings.Remote, tid, tid)
        elif len(tid) != 28 and len(tid) != 33:
            d_id = tid
            target_folder = drive_get(d_id)['name']

    # sendmsg Mission.INFO
    update.effective_message.reply_text(task_message().format(
        foldername, lid, target_folder, foldername))

    # Build Mission Command
    commandstr = """{}' JSUSPLIT 'copy' JSUSPLIT '{}:{{{}}}' JSUSPLIT '{}:{{{}}}/{}' JSUSPLIT '{}' JSUSPLIT '{}' JSUSPLIT '{}""".format(
        settings.Clone,
        settings.Remote,
        lid,
        settings.Remote,
        tid,
        foldername,
        settings.Run_Mode,
        settings.TRANSFER,
        settings.CHECKERS,
    )

    command = commandstr.split("' JSUSPLIT '")
    #print(command)

    return ConversationHandler.END, copyprocess(update, context, command)
Пример #2
0
def recived_mission(update, context):
    global mode
    global link
    global target
    target = update.effective_message.text

    # extract lid,tid from Link(shared & Target)
    lid = "".join(re.findall(regex, link))
    tid = "".join(re.findall(regex, target))

    # extract Shared_Link folderName
    if len(lid) == 28 or len(lid) == 33:
        foldername = folder_name(settings.Remote, lid, lid)
    elif len(lid) != 28 and len(lid) != 33:
        d_id = lid
        foldername = drive_get(d_id)

    # get Target_folderName under quick mode
    if "quick" == mode:
        # tid = Pre_Dst_id under quick mode
        tid = settings.Pre_Dst_id
        if len(tid) == 28 or len(tid) == 33:
            target_folder = folder_name(settings.Remote, tid, tid)
        elif len(tid) != 28 and len(tid) != 33:
            d_id = tid
            target_folder = drive_get(d_id)

    # get Target_folderName under copy mode
    elif "copy" == mode:
        if len(tid) == 28 or len(tid) == 33:
            target_folder = folder_name(settings.Remote, tid, tid)
        elif len(tid) != 28 and len(tid) != 33:
            d_id = tid
            target_folder = drive_get(d_id)

    # sendmsg Mission.INFO
    update.effective_message.reply_text(task_message().format(
        foldername, lid, target_folder, foldername))

    # Build Mission Command
    command = """gclone copy {}:{{{}}} {}:{{{}}}/"{}" {} {}""".format(
        settings.Remote,
        lid,
        settings.Remote,
        tid,
        foldername,
        settings.Run_Mode,
        settings.TRANSFER,
    )
    copyprocess(update, context, command)

    return ConversationHandler.END
Пример #3
0
def print_folders(dis_weight):
    folders = dict()
    for T1, T2 in dis_weight:
        for i_dis, i_weight in dis_weight[T1, T2].items():
            folders[utils.folder_name(T1, T2, i_dis)] = i_weight
    with open("folders", "w") as file:
        print(json.dumps(folders, indent=4), file=file)
Пример #4
0
def cal_ABACUS(T1, T2, i_dis):
    folder = pathlib.Path(utils.folder_name(T1, T2, i_dis)).resolve()
    folder.mkdir(parents=True, exist_ok=False)

    with open(folder / "INPUT", "w") as file:
        info = utils.read_info()
        input_dict = read_stru.get_input_dict()
        input_dict["ntype"] = 1 if T1 == T2 else 2
        input_dict["exx_hybrid_type"] = 'opt_orb'
        input_dict["nbands"] = (read_stru.get_nw()[T1] if abs(i_dis) < 1E-10
                                else read_stru.get_nw()[T1] +
                                read_stru.get_nw()[T2])
        input_dict["nspin"] = 1
        input_dict["gamma_only"] = 1
        input_dict["pseudo_dir"] = os.path.abspath(
            input_dict.get("pseudo_dir", r"./"))
        input_dict["exx_opt_orb_lmax"] = len(info["Nu"]) - 1
        read_stru.print_input(file, input_dict)

    with open(folder / "STRU", "w") as file:
        Ts = (T1, ) if T1 == T2 else (T1, T2)
        file.write("ATOMIC_SPECIES\n")
        pseudo_path = read_stru.get_pseudo_path()
        for T in Ts:
            file.write(f"{T}	1	{pseudo_path[T]}\n")
        file.write("\nNUMERICAL_ORBITAL\n")
        lcao_path = read_stru.get_lcao_path()
        for T in Ts:
            file.write(f"{lcao_path[T]}\n")
        file.write(
            textwrap.dedent(f"""
			LATTICE_CONSTANT
			1\n
			LATTICE_VECTORS
			30 0 0
			0 30 0
			0 0 30\n
			ATOMIC_POSITIONS
			Cartesian
			"""))
        if T1 == T2:
            if abs(i_dis) < 1E-10:
                file.write(
                    textwrap.dedent(f"""
					{T1}
					0
					1
					0 0 0 0 0 0
					"""))
            else:
                file.write(
                    textwrap.dedent(f"""
					{T1}
					0
					2
					0 0 0 0 0 0
					{i_dis} 0 0 0 0 0
					"""))
        else:
            file.write(
                textwrap.dedent(f"""
				{T1}
				0
				1
				0 0 0 0 0 0\n
				{T2}
				0
				1
				{i_dis} 0 0 0 0 0
				"""))

    with open(folder / "KPT", "w") as file:
        file.write(
            textwrap.dedent(f"""\
			K_POINTS
			0
			Gamma
			1 1 1 0 0 0
			"""))

    info = utils.read_info()
    if utils.sub == "qsub":
        with open(folder / "sub.sh", "w") as file:
            file.write(
                textwrap.dedent(f"""\
				#!/bin/bash
				#PBS -q gold5120
				#PBS -l nodes=1:ppn=1
				#PBS -l walltime=1:00:00
				#PBS -o job.log
				#PBS -e job.err
				ulimit -s unlimited
				cd $PBS_O_WORKDIR
				EXEC={info["ABACUS"]}
				mpirun -n 1 -env OMP_NUM_THREADS=1 $EXEC
				"""))
    elif utils.sub == "bsub":
        with open(folder / "sub.sh", "w") as file:
            file.write(
                textwrap.dedent(f"""\
				#!/bin/sh
				#BSUB -q renxg
				#BSUB -o job.log -e job.err
				#BSUB -n 1
				EXEC={info["ABACUS"]}
				mpirun -n 1 -env OMP_NUM_THREADS=1 $EXEC
				"""))

    os.chdir(folder)
    if utils.sub == "qsub":
        os.system("qsub sub.sh")
    elif utils.sub == "bsub":
        os.system("bsub < sub.sh")
    elif utils.sub == "tianh2":
        os.system(f'yhrun -n 1 -c 1 {info["ABACUS"]} >Log.txt')
    os.chdir("../")
Пример #5
0
 # trials to updated the network weights
 up_net = 400
 # network units
 net = 'ugru'
 # instance
 inst = 0
 # folder where data will be saved
 main_folder = '/home/molano/priors_project/priors/'
 # num trials file
 num_tr = 280000
 # worker
 worker = 0
 test = ''  # '/test'
 exp = ut.folder_name(gamma=gamma, up_net=up_net, trial_dur=trial_dur,
                      rep_prob=rep_prob, exp_dur=exp_dur, rewards=rewards,
                      block_dur=block_dur, num_units=num_units,
                      stim_ev=stim_ev, network=net, learning_rate=lr,
                      instance=inst, main_folder=main_folder) +\
     test + '/trains/train_' + str(worker) + '/trials_stats_0_' +\
     str(num_tr) + '.npz'
 data = np.load(exp)
 start_per = 20000
 ev = np.reshape(data['evidence'], (1, data['evidence'].shape[0])).copy()
 perf = np.reshape(data['performance'],
                   (1, data['performance'].shape[0])).copy()
 action = np.reshape(data['action'], (1, data['action'].shape[0])).copy()
 stim_pos = np.reshape(data['stims_position'],
                       (1, data['stims_position'].shape[0])).copy()
 plt.figure(figsize=(8, 8), dpi=100)
 plot_psychometric_curves(ev[:, start_per:],
                          perf[:, start_per:],
Пример #6
0
def main_priors(load_model=False, train=True, gamma=.8, up_net=5,
                trial_dur=10, rep_prob=(0.2, 0.8), exp_dur=1000,
                rewards=(-0.1, 0.0, 1.0, -1.0), block_dur=200,
                num_units=32, stim_ev=.3, network='ugru',
                learning_rate=1e-3, instance=0, main_folder='',
               **kwargs):
    a_size = 3  # number of actions
    state_size = a_size  # number of inputs

    data_path = utils.folder_name(gamma=gamma, up_net=up_net,
                                  trial_dur=trial_dur, rep_prob=rep_prob,
                                  exp_dur=exp_dur, rewards=rewards,
                                  block_dur=block_dur, num_units=num_units,
                                  stim_ev=stim_ev, network=network,
                                  learning_rate=learning_rate,
                                  instance=instance, main_folder=main_folder)

    data = {'trial_dur': trial_dur, 'rep_prob': rep_prob, 'learning_rate':learning_rate,
            'rewards': rewards, 'stim_ev': stim_ev, 'exp_dur': exp_dur,
            'block_dur': block_dur, 'gamma': gamma, 'num_units': num_units,
            'up_net': up_net, 'network': network}

    # create folder from which to load the model
    model_load_path = data_path + '/model_meta_context'
    
    if not train:
        data_path += '/test/'
        for ind in kwargs.keys():
            old_param = ind[1:]
            data[old_param] = kwargs[ind]
            data_path += '_' + old_param + '_' + utils.list_str((kwargs[ind]))
        data_path += '/'

    # create folder to save the data
    if not os.path.exists(data_path):
        os.makedirs(data_path)

    # create folder to save the model
    model_path = data_path + '/model_meta_context'

    if not os.path.exists(model_path):
        os.makedirs(model_path)
    
    # save experiment setup
    np.savez(data_path + '/experiment_setup.npz', **data)
    print(data_path)
    tf.reset_default_graph()
    with tf.device("/cpu:0"):
        global_episodes = tf.Variable(0, dtype=tf.int32,
                                      name='global_episodes',
                                      trainable=False)
        trainer = tf.train.AdamOptimizer(learning_rate=data['learning_rate'])
        ag.AC_Network(a_size, state_size, 'global',
                      None, data['num_units'], data['network'])  # Generate global net
        # Set workers to number of available CPU threads
        num_workers = multiprocessing.cpu_count()
        workers = []
        # Create worker classes
        for i in range(num_workers):
            saving_path = data_path + '/trains/train_' + str(i)
            if not os.path.exists(saving_path):
                os.makedirs(saving_path)
            workers.append(ag.Worker(task.PriorsEnv(upd_net=data['up_net'],
                                                    trial_dur=data['trial_dur'],
                                                    rep_prob=data['rep_prob'],
                                                    rewards=data['rewards'],
                                                    block_dur=data['block_dur'],
                                                    stim_ev=data['stim_ev'],
                                                    folder=saving_path,
                                                    plot=(i == 0)),
                                     i, a_size, state_size,
                                     trainer, model_path, global_episodes,
                                     data_path, data['num_units'], data['network']))
        saver = tf.train.Saver(max_to_keep=5)

    with tf.Session() as sess:
        coord = tf.train.Coordinator()
        if load_model:
            print('Loading Model...')
            ckpt = tf.train.get_checkpoint_state(model_load_path)
            saver.restore(sess, ckpt.model_checkpoint_path)
        else:
            sess.run(tf.global_variables_initializer())

        worker_threads = []
        for worker in workers:
            worker_work = lambda: worker.work(data['gamma'], sess, coord,
                                              saver, train, data['exp_dur'])
            thread = threading.Thread(target=(worker_work))
            thread.start()
            worker_threads.append(thread)
        coord.join(worker_threads)