From 9cbbbb0b6e4d7d07ddced4e1913e75debd1eb7ca Mon Sep 17 00:00:00 2001 From: Yngve Levinsen <yngve.levinsen@ess.eu> Date: Wed, 4 Mar 2020 13:55:08 +0100 Subject: [PATCH] fixing tracewin_errorstudy script for python3 --- ess/__queue_templates__.py | 4 ++-- scripts/tracewin_errorstudy | 39 +++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/ess/__queue_templates__.py b/ess/__queue_templates__.py index b5b37dc..9f2dfbb 100644 --- a/ess/__queue_templates__.py +++ b/ess/__queue_templates__.py @@ -8,7 +8,7 @@ initialdir = {args.calc_dir}/Local_TraceWin_$(Process) transfer_input_files = {input_files} requirements = ( OpSys == "LINUX" || OpSys == "OSX" ) log = condor.log -executable = TraceWin_exe/tracewin.$$(OpSys).$$(Arch) +executable = TraceWin/exe/tracewin.$$(OpSys).$$(Arch) """ HEAD_MULTI_TEMPLATE = """ universe = Vanilla @@ -16,7 +16,7 @@ universe = Vanilla should_transfer_files = yes requirements = ( OpSys == "LINUX" || OpSys == "OSX" ) log = condor.log -executable = TraceWin_exe/tracewin.$$(OpSys).$$(Arch) +executable = TraceWin/exe/tracewin.$$(OpSys).$$(Arch) """ QUEUE_TEMPLATE = """ diff --git a/scripts/tracewin_errorstudy b/scripts/tracewin_errorstudy index 0a9a871..b950aa8 100644 --- a/scripts/tracewin_errorstudy +++ b/scripts/tracewin_errorstudy @@ -20,10 +20,10 @@ def define_and_handle_args(): def setup_exec_folder(): import os,shutil - orig_path=os.path.join(os.environ.get("HOME"),"TraceWin_exe") + orig_path=os.path.join(os.environ.get("HOME"),"TraceWin/exe") if not os.path.isdir(orig_path): raise ValueError("Cannot find tracewin executables in "+orig_path+" yet") - os.makedirs("TraceWin_exe") + os.makedirs("TraceWin/exe") o=dict(LINUX="lx",OSX="mac") a=dict(INTEL="",X86_64="64") @@ -31,7 +31,7 @@ def setup_exec_folder(): for OpSys in ["LINUX", "OSX"]: for Arch in ["INTEL", "X86_64"]: shutil.copy(os.path.join(orig_path,"trace"+o[OpSys]+a[Arch]), - os.path.join("TraceWin_exe","tracewin.%s.%s" % (OpSys,Arch))) + os.path.join("TraceWin/exe","tracewin.%s.%s" % (OpSys,Arch))) def create_and_copy_lattice(args, calc_dir, commented=[], extra_line=''): ''' @@ -45,20 +45,21 @@ def create_and_copy_lattice(args, calc_dir, commented=[], extra_line=''): if os.path.exists(args.settings): # Create the lattice file from template: - lattice_settings=yaml.load(file(args.settings,'r').read()) + lattice_settings=yaml.load(open(args.settings,'r').read()) lattice_settings['extra_line']=extra_line - lattice_template=file(args.lattice+'.tmp','r').read() + lattice_template=open(args.lattice+'.tmp','r').read() for cmd in commented: lattice_template=lattice_template.replace(cmd.lower(),';'+cmd) lattice_template=lattice_template.replace(cmd.upper(),';'+cmd) - file(os.path.join(calc_dir,args.lattice),'w').write(lattice_template.format(**lattice_settings)) + open(os.path.join(calc_dir,args.lattice),'w').write(lattice_template.format(**lattice_settings)) shutil.copy(args.settings, calc_dir) else: - shutil.copy(args.lattice,os.path.join(calc_dir,args.lattice)) + if calc_dir != '.': + shutil.copy(args.lattice, os.path.join(calc_dir, args.lattice)) for folder in os.listdir(calc_dir): if folder[0:15]=="Local_TraceWin_": @@ -113,10 +114,10 @@ def setup_multi(args): num_jobs=0 new_folders=[] - for njob in xrange(args.num_jobs): + for njob in range(args.num_jobs): folder='Local_TraceWin_{}'.format(njob) - if os.path.isfile(os.path.join(args.calc_dir,folder,'Error_Datas.txt')): - for mjob in xrange(args.multi): + if os.path.isfile( os.path.join(args.calc_dir, folder, 'Error_Datas.txt')): + for mjob in range(args.multi): num_jobs+=1 if mjob==int(folder.split('_')[-1]): continue @@ -126,19 +127,19 @@ def setup_multi(args): delete_output_files(args,newfolder) create_and_copy_lattice(args, os.path.join(args.calc_dir,newfolder), commented=['ERROR_CAV_CPL_DYN', 'ERROR_CAV_NCPL_DYN'], extra_line='ERROR_DYN_FILE Error_Datas.txt') - if not os.path.isdir("TraceWin_exe"): + if not os.path.isdir("TraceWin/exe"): setup_exec_folder() # Get random seeds from previously run jobs: seeds=[] - for l in file(os.path.join(args.calc_dir,'submit.job')): + for l in open(os.path.join(args.calc_dir,'submit.job'), 'r'): if len(l.strip()) and l.split()[0]=='arguments': seeds.append(l.split()[-1]) head_template=__queue_templates__.get_head_multi_template() queue_template=__queue_templates__.get_queue_multi_template() - with file(args.calc_dir+"/multi.job","w") as out: + with open(args.calc_dir+"/multi.job","w") as out: out.write(head_template.format(**locals())) for job_folder in new_folders: @@ -176,7 +177,7 @@ def setup(args): # Create extra folders if needed.. if args.num_jobs>num_jobs: - for n in xrange(num_jobs,args.num_jobs): + for n in range(num_jobs,args.num_jobs): folder_name='Local_TraceWin_{n}'.format(**locals()) create_extra_folder(args.calc_dir,'Local_TraceWin_0',folder_name) num_jobs=args.num_jobs @@ -186,12 +187,12 @@ def setup(args): create_and_copy_lattice(args, args.calc_dir) - if not os.path.isdir("TraceWin_exe"): + if not os.path.isdir("TraceWin/exe"): setup_exec_folder() if args.seed!=None: random.seed(args.seed) - rand_lst=[random.randint(1e5,1e9) for i in xrange(num_jobs)] + rand_lst=[random.randint(1e5,1e9) for i in range(num_jobs)] #rand_lst=file('rand.dat','r').read().split() # Get file list: @@ -203,10 +204,10 @@ def setup(args): head_template=__queue_templates__.get_head_template() queue_template=__queue_templates__.get_queue_template() - with file(args.calc_dir+"/submit.job","w") as out: + with open(args.calc_dir + "/submit.job", "w") as out: out.write(head_template.format(**locals())) - for i in xrange(num_jobs): + for i in range(num_jobs): q_priority=max(-5,args.priority-i/100) rand=rand_lst[i] out.write(queue_template.format(**locals())) @@ -215,7 +216,7 @@ def ask(args): print("You have now set up an error study running {} jobs in folder {}".format(args.num_jobs,args.calc_dir)) if args.multi>1: print("This is a multi-error study") - answer=raw_input("Do you want to submit the jobs immediately? (yes/no) ") + answer = input("Do you want to submit the jobs immediately? (yes/no) ") if answer=='yes': return 0 -- GitLab