def ask(optype): ret = False ans = gen_partition.raw_input_save( \ '\n compute ' + optype + '? Y/N (default: No) : ') if len(ans) > 0: if ans[0] == 'Y' or ans[0] == 'y': ret = True if ans[0] == 'N' or ans[0] == 'n': ret = False return ret
def main_nuclide(fn_snt): print print print '*************** specify a nuclide ********************' print nf = gen_partition.raw_input_save( '\n number of valence protons and neutrons\n' + ' (ex. 2, 3 <CR>) <CR> to quit : ') nf = nf.replace(',', ' ').split() if len(nf) == 0: return ("", "", None) if len(nf) == 1: nf.append(0) nf = [int(nf[0]), int(nf[1])] fn_base = fn_element(nf, fn_snt) ans = gen_partition.raw_input_save("\n name for script file (default: " + fn_base + " ): ") ans = ans.strip() if ans: fn_base = ans print "\n J, parity, number of lowest states " print " (ex. 10 for 10 +parity, 10 -parity states w/o J-proj. (default)" print " -5 for lowest five -parity states, " print " 0+3, 2+1 for lowest three 0+ states and one 2+ states, " print " 1.5-, 3.5+3 for lowest one 3/2- states and three 7/2+ states) :" ans = gen_partition.raw_input_save() ans = ans.replace(',', ' ').split() if not ans: ans = ['+10', '-10'] if len(ans) == 1 and ans[0].isdigit(): ans = ['+' + ans[0], '-' + ans[0]] list_jpn = [split_jpn(a, nf) for a in ans] for j, p, n, isp in list_jpn: if (j + sum(nf)) % 2 != 0: print "Remove states J,prty,Num=", j, p, n, isp list_jpn = [a for a in list_jpn if (a[0] + sum(nf)) % 2 == 0] list_prty = list(set(jpn[1] for jpn in list_jpn)) fn_ptn_list = {-1: fn_base + "_n.ptn", 1: fn_base + "_p.ptn"} fn_input = fn_base + ".input" for prty in list_prty: fn_ptn = fn_ptn_list[prty] if prty == 1: print "\n truncation for \"+\" parity state in ", fn_ptn else: print "\n truncation for \"-\" parity state in ", fn_ptn gen_partition.main(fn_snt, fn_ptn, nf, prty)
def main(): print "\n" \ + "----------------------------- \n" \ + " KSHELL user interface \n" \ + " to generate job script. \n" \ + "-----------------------------\n " cdef = 'N' global is_mpi if is_mpi: cdef = is_mpi if cdef == True: cdef = 'Y' list_param = [ 'coma', 'abel', 'stallo', 'fram', 'smaug', 'vilje', 'fx10', 'k-computer', 'yes', 'no' ] readline.set_completer(SimpleCompleter(list_param).complete) readline.parse_and_bind("tab: complete") ans = gen_partition.raw_input_save('\n MPI parallel? Y/N (default: ' + cdef + ') : ') readline.parse_and_bind("tab: None") if len(ans) > 0: if ans[0] == 'Y' or ans[0] == 'y': is_mpi = True elif ans[0] == 'N' or ans[0] == 'n': is_mpi = False else: is_mpi = ans if is_mpi == 'coma': print " ... generate shell script for MPI run on COMA/Tsukuba with SLURM " elif is_mpi == 'fram': print " ... generate shell script for MPI run on Fram@UiT with SLURM " elif is_mpi == 'abel': print " ... generate shell script for MPI run on Abel@UiO with SLURM " elif is_mpi == 'k': print " ... generate shell script for MPI run on K-computer micro with PJM" elif is_mpi: print " ... generate shell script for MPI run on K-computer/FX10 with PJM. " else: print " ... generate shell script for a single node." list_snt = os.listdir( bindir+"/../snt/" ) \ + [fn for fn in os.listdir(".") if len(fn)>4 and fn[-4:]==".snt"] readline.parse_and_bind("tab: complete") readline.set_completer(SimpleCompleter(list_snt).complete) if is_mpi != False: n_nodes = int(gen_partition.raw_input_save( \ "\n number of computer nodes (not cores) for MPI: ")) fn_snt = gen_partition.raw_input_save( \ "\n model space and interaction file name (.snt) \n" \ + " (e.g. w or w.snt, TAB key to complete) : " ) readline.parse_and_bind("tab: None") fn_snt = fn_snt.rstrip() if fn_snt[-4:] != '.snt': fn_snt = fn_snt + '.snt' if os.path.isfile(fn_snt): pass elif os.path.isfile(bindir + "/../snt/" + fn_snt): shutil.copy(bindir + "/../snt/" + fn_snt, ".") else: print "\n*** ERROR: .snt file NOT found ***", fn_snt, "\n" return var_dict['fn_int'] = '"' + fn_snt + '"' if check_cm_snt(fn_snt): var_dict['beta_cm'] = 10.0 if is_mpi: var_dict['mode_lv_hdd'] = 0 if fn_snt in ['w', 'w.snt']: var_dict['hw_type'] = 2 if fn_snt[:3] == 'usd' or fn_snt[:4] == 'sdpf' or fn_snt[:5] == 'GCLST': var_dict['hw_type'] = 2 fn_run = '' fn_snt_base = fn_snt[:-4] outsh = '' nuclides = [] fn_base_list = [] while True: fn_base, out, detail = main_nuclide(fn_snt) if not out: break nuclides.append(detail) fn_base_list.append(fn_base) outsh += out if fn_run: if len(fn_run) > len( fn_snt_base) and fn_run[-len(fn_snt_base):] == fn_snt_base: fn_run = fn_run[:-len(fn_snt_base)] else: fn_run += '_' fn_run += fn_base if not fn_run: print "\n*** NO input ***\n" return nflist = [nf for nf, list_jpn, fn_save_list in nuclides] gt_pair, sfac_pair = [], [] for i1, nf1 in enumerate(nflist): for i2, nf2 in enumerate(nflist): if nf1[0] == nf2[0] + 1 and sum(nf1) == sum(nf2): gt_pair.append((i1, i2)) if nf1[0] == nf2[0] + 1 and nf1[1] == nf2[1]: sfac_pair.append((i1, i2)) if nf1[0] == nf2[0] and nf1[1] == nf2[1] + 1: sfac_pair.append((i1, i2)) def ask(optype): ret = False ans = gen_partition.raw_input_save( \ '\n compute ' + optype + '? Y/N (default: No) : ') if len(ans) > 0: if ans[0] == 'Y' or ans[0] == 'y': ret = True if ans[0] == 'N' or ans[0] == 'n': ret = False return ret isnot_asked = True for i1, i2 in gt_pair: fn_base1 = fn_base_list[i1] fn_base2 = fn_base_list[i2] fn_base = fn_base1 if len(fn_base) > len( fn_snt_base) and fn_base[-len(fn_snt_base):] == fn_snt_base: fn_base = fn_base[:-len(fn_snt_base)] else: fn_base += '_' fn_base += fn_base2 fn_input = fn_base + ".input" fn_save_list = nuclides[i1][2] list_jpn1 = nuclides[i1][1] list_jpn2 = nuclides[i2][1] fn_save_list1 = nuclides[i1][2] fn_save_list2 = nuclides[i2][2] for i1, (m1, np1, ne1, isj1) in enumerate(list_jpn1): for i2, (m2, np2, ne2, isj2) in enumerate(list_jpn2): if (isj1 and m1 == 0) and (isj2 and m2 == 0): continue if abs(m1 - m2) > 2: continue if np1 != np2: continue if isnot_asked: isnot_asked = False print '***********************************************' is_gt = ask('GT transition') if not is_gt: break outsh += '# ----------- Gamow Teller transition ' outsh += '------------ \n' outsh += 'echo \n' outsh += 'echo "Gamow Teller transition calc."\n' if not is_gt: break outsh += output_transit(fn_base, fn_input, fn_save_list1, fn_save_list2, (m1, np1, ne1, isj1), (m2, np2, ne2, isj2)) isnot_asked = True for i1, i2 in sfac_pair: fn_base1 = fn_base_list[i1] fn_base2 = fn_base_list[i2] fn_base = fn_base1 if len(fn_base)> len(fn_snt_base) and \ fn_base[-len(fn_snt_base):] == fn_snt_base: fn_base = fn_base[:-len(fn_snt_base)] else: fn_base += '_' fn_base += fn_base2 fn_input = fn_base + ".input" fn_save_list = nuclides[i1][2] list_jpn1 = nuclides[i1][1] list_jpn2 = nuclides[i2][1] fn_save_list1 = nuclides[i1][2] fn_save_list2 = nuclides[i2][2] for i1, (m1, np1, ne1, isj1) in enumerate(list_jpn1): for i2, (m2, np2, ne2, isj2) in enumerate(list_jpn2): if (isj1 and m1 == 0) and (isj2 and m2 == 0): continue if isnot_asked: isnot_asked = False is_sf = ask('one-particle spectroscopic factor') if not is_sf: break outsh += '# ----------- spectroscocpic factor ------------ \n' outsh += 'echo \n' outsh += 'echo "spectroscopic factor calc."\n' if not is_sf: break outsh += output_transit(fn_base, fn_input, fn_save_list1, fn_save_list2, (m1, np1, ne1, isj1), (m2, np2, ne2, isj2)) fn_run += ".sh" def check_copy(*fns): for fn in fns: binfn = bindir + '/' + fn if not os.path.exists(binfn): print "\n*** WARNING: NOT found " + bindir + '/' + fn, " ***" else: try: shutil.copy(binfn, '.') except IOError: print "\n*** WARNING: copy " + binfn \ + " to current dir. failed ***" # header if is_mpi: check_copy('kshell_mpi', 'transit_mpi', 'collect_logs.py') if is_mpi == 'coma': outsh = '#!/bin/sh \n' \ + '#SBATCH -J ' + fn_run[:-3] + '\n' \ + '#SBATCH -p normal\n' \ + '#SBATCH -N ' + str(n_nodes) + '\n' \ + '#SBATCH -n ' + str(n_nodes) + '\n' \ + '# #SBATCH -t 01:00:00\n' \ + '#SBATCH --cpus-per-task=16\n' \ + '#SBATCH -o stdout\n' \ + '#SBATCH -e stderr\n\n' \ + 'export OMP_NUM_THREADS=16\n\n' \ + 'module load mkl intel intelmpi/4.1.3 \n' \ + 'cd ' + os.getcwd() +'\n\n' \ + outsh # cd $SLURM_SUBMIT_DIR # export OMP_NUM_THREADS=16 print "\n Finish. edit and sbatch " + fn_run + "\n" elif is_mpi == 'fram': # This option added by JEM. Slightly modified 'coma' option above. outsh = '#!/bin/bash \n' \ + '#SBATCH --job-name=' + fn_run[:-3] + ' \n' \ + '#SBATCH --account=<insert account> \n' \ + '#SBATCH --time=02-00:00:00 \n' \ + '#SBATCH --nodes='+ str(n_nodes) + '\n' \ + '#SBATCH --ntasks-per-node=1 \n' \ + '#SBATCH --cpus-per-task=32 \n' \ + 'module purge \n' \ + 'module load intel/2017b \n' \ + 'set -o errexit \n' \ + 'set -o nounset \n' \ + outsh elif is_mpi == 'abel': # This option added by JEM. Slightly modified 'coma' option above. outsh = '#!/bin/bash \n' \ + '#SBATCH --job-name=' + fn_run[:-3] + '\n' \ + '#SBATCH --account=uio\n' \ + '#SBATCH --time=02-00:00:00\n' \ + '#SBATCH --mem-per-cpu=3800\n' \ + '#SBATCH -N ' + str(n_nodes) + '\n' \ + '#SBATCH -n ' + str(n_nodes) + '\n' \ + '#SBATCH --cpus-per-task=16\n\n' \ + 'source /cluster/bin/jobsetup \n' \ + 'module purge \n' \ + 'module load intel/2018.1 \n' \ + 'set -o errexit \n' \ + 'export OMP_NUM_THREADS=16\n' \ + 'ulimit -s unlimited\n' \ + outsh elif is_mpi == 'k': outsh = '#!/bin/sh \n' \ + '#PJM -L "rscgrp=micro"\n' \ + '#PJM -L "node=' + str(n_nodes) + '"\n' \ + '# #PJM -L "elapse=00:30:00"\n\n' \ + '. /work/system/Env_base\n\n' \ + 'cd ' + os.getcwd() +'\n\n' \ + outsh else: outsh = '#!/bin/sh \n' \ + '#PJM -L "rscgrp=debug"\n' \ + '#PJM -L "node=' + str(n_nodes) + '"\n' \ + '# #PJM -L "elapse=24:00:00"\n\n' \ + 'cd ' + os.getcwd() +'\n\n' \ + outsh print "\n Finish. edit and pjsub ./" + fn_run + "\n" else: check_copy('kshell', 'transit', 'collect_logs.py') outsh = '#!/bin/sh \n' \ + '# export OMP_STACKSIZE=1g\n' \ + 'export GFORTRAN_UNBUFFERED_PRECONNECTED=y\n' \ + '# ulimit -s unlimited\n\n' \ + outsh print "\n Finish. Execute ./" + fn_run + "\n" fp_run = open(fn_run, 'w') fp_run.write(outsh) fp_run.close() if not is_mpi: os.chmod(fn_run, 0755) fp = open('save_input_ui.txt', 'w') fp.write(gen_partition.output_ans) fp.close()
gen_partition.main(fn_snt, fn_ptn, nf, prty) #----------------------------------------------------- while True: print "\n --- input parameter --- " print print_var_dict(var_dict, skip=('fn_int', 'fn_save_wave', 'n_eigen')) ask = "modify parameter? \n" \ + " (e.g. maxiter = 300 for parameter change\n" \ + " <CR> for no more modification ) :\n" list_param = [k + " = " for k in var_dict.keys()] readline.set_completer(SimpleCompleter(list_param).complete) readline.parse_and_bind("tab: complete") ans = gen_partition.raw_input_save(ask) readline.parse_and_bind("tab: None") ans = ans.strip() if not ans: break elif '=' in ans: arr = ans.split('=') arr = [a.strip() for a in arr] if len(arr[1]) != 0: var_dict[arr[0]] = arr[1] else: del var_dict[arr[0]] else: print "ILLEGAL INPUT"