def run_HEJFOG(args): gf.print_flush("TODO HEJFOG not implemented yet") command = "HEJ/bin/HEJFOG" gf.do_shell("chmod +x {0}".format(command)) # TODO: # parse runcard # run HEJ-FOG (with chmod) return 1
def bring_nnlojet(input_grid, runcard, runname): # Todo: this is not very general, is it? tmp_tar = "nnlojet.tar.gz" input_name = "{0}/{1}{2}.tar.gz".format(input_grid, runcard, runname) stat = gf.copy_from_grid(input_name, tmp_tar, args) stat += gf.untar_file(tmp_tar) stat += gf.do_shell("rm {0}".format(tmp_tar)) stat += gf.do_shell("ls") return stat
def download_program(source): tar_name = os.path.basename(source) if not tar_name.endswith("tar.gz"): gf.print_flush("{0} is not a valid path to download".format(source)) return 1 stat = gf.copy_from_grid(source, tar_name, args) stat += gf.untar_file(tar_name) stat += gf.do_shell("rm {0}".format(tar_name)) if gf.DEBUG_LEVEL > 2: gf.do_shell("ls -l") return stat
def print_copy_status(args, status_copy): if status_copy == 0: gf.print_flush("Copied over to grid storage!") elif args.Sockets: gf.print_flush( "This was a socketed run so we are copying the grid to stderr just " "in case") gf.do_shell("cat $(ls *.y* | grep -v .txt) 1>&2") status_copy = 0 elif args.Warmup: gf.print_flush("Failure! Outputing vegas warmup to stdout") gf.do_shell("cat $(ls *.y* | grep -v .txt)")
def bring_files(args): bring_status = 0 if not args.use_cvmfs_lhapdf: gf.print_flush("Using own version of LHAPDF") bring_status += bring_lhapdf(args.lhapdf_grid) bring_status += bring_nnlojet(args.input_folder, args.runcard, args.runname) gf.do_shell("chmod +x {0}".format(args.executable)) if bring_status != 0: gf.print_flush("Not able to bring data from storage. Exiting now.") sys.exit(-95) return bring_status
def run_HEJ(args): config = config_name(args.runname) seed = args.seed status = gf.do_shell( 'sed -i -e "s/seed:.1/seed: {0}/g" {1}'.format(seed, config)) status += gf.do_shell( 'sed -i -e "s/output:.HEJ/output: {0}/g" {1}'.format( yoda_name(seed), config)) status += gf.do_shell("chmod +x {0}".format(args.executable)) if status == 0: status += gf.run_command( "{0} {1} {2}".format(args.executable, config, LHE_FILE)) return status
def download_runcard(input_folder, runcard, runname): tar = warmup_name(runcard, runname) gf.print_flush("downloading " + input_folder + "/" + tar) stat = gf.copy_from_grid(input_folder + "/" + tar, tar, args) gf.print_flush("finished copying from grid storage... untarring now") stat += gf.untar_file(tar) return gf.do_shell("rm {0}".format(tar)) + stat
def run_example(args): status = gf.do_shell("chmod +x {0}".format(args.executable)) if status == 0: status += gf.run_command("./{executable} {runcard} {outfile}".format( executable=args.executable, runcard=args.runname, outfile="{0}.out".format(args.seed))) return status
def download_runcard(input_folder, runcard, runname): tar = warmup_name(runcard, runname) gf.print_flush("downloading "+input_folder+"/"+tar) stat = gf.copy_from_grid(input_folder+"/"+tar, tar, args) stat += gf.untar_file(tar) # TODO download: # Scale setters return gf.do_shell("rm {0}".format(tar))+stat
def download_rivet(rivet_folder): tar = os.path.basename(rivet_folder) gf.print_flush("downloading "+rivet_folder) stat = gf.copy_from_grid(rivet_folder, "", args) stat += gf.untar_file(tar) rivet_dir = os.path.basename(os.path.splitext(rivet_folder)[0]) os.environ['RIVET_ANALYSIS_PATH'] = os.getcwd()+"/"+rivet_dir return gf.do_shell("rm {0}".format(tar))+stat
def run_executable(nnlojet_command): # TODO replace by gf.run_command gf.print_flush(" > Executing command: {0}".format(nnlojet_command)) # Run command status_nnlojet = gf.do_shell(nnlojet_command) if status_nnlojet == 0: gf.print_flush("Command successfully executed") else: gf.print_flush("Something went wrong") gf.DEBUG_LEVEL = 9999 return status_nnlojet
def run_example(args): status = gf.do_shell("chmod +x {0}".format(args.executable)) if status == 0: activate_environment() os.system("echo Attempting to activate venv and run simulation...") status += gf.run_command( "source JUNE_env/bin/activate && export PYTHONPATH=$PYTHONPATH:`pwd`/JUNE/ && ./{executable} --idx={idx} --world={world} --latin_hypercube={latin_hypercube} {runcard} {outfile}" .format(executable=args.executable, idx=args.seed, world=args.world, latin_hypercube=args.latin_hypercube, runcard=args.runname, outfile="{0}.out".format(args.seed))) return status
def store_output(args, socketed=False, socket_config=""): # Copy stuff to grid storage, remove executable and lhapdf folder # Core files can be upwards of 6G - make sure they're deleted! os.system("rm core*") if not args.use_cvmfs_lhapdf: gf.do_shell("rm -rf {0} {1}".format(args.executable, args.lhapdf_local)) if args.Production: local_out = output_name(args.runcard, args.runname, args.seed) output_file = os.path.join(args.output_folder, args.runname, local_out) elif args.Warmup: local_out = warmup_name(args.runcard, args.runname) output_file = os.path.join(args.warmup_folder, local_out) tar_status = gf.tar_this(local_out, "*") if gf.DEBUG_LEVEL > 1: gf.do_shell("ls") if socketed: # Avoid conflicting simultaneous copies and resulting error messages: # - first node attempts copy to warmup_name(...); # - other nodes attempt copy to warmup_name_ns(...) as backup. # Still results in large redundancy. socket_no = int(socket_config.split()[-1].strip()) if socket_no == 1: status_copy = gf.copy_to_grid(local_out, output_file, args) else: subfolder = os.path.splitext(os.path.basename(output_file))[ 0].replace(".tar", "") backup_name = warmup_name_ns(args.runcard, args.runname, socket_no) backup_fullpath = os.path.join( args.warmup_folder, subfolder, backup_name) status_copy = gf.copy_to_grid(local_out, backup_fullpath, args) else: status_copy = gf.copy_to_grid(local_out, output_file, args) return status_copy, tar_status
def setup(): start_time = datetime.datetime.now() gf.print_flush("Start time: {0}".format( start_time.strftime("%d-%m-%Y %H:%M:%S"))) args = gf.parse_arguments() setup_environment(args, args.lhapdf_local) socket_config = None if gf.DEBUG_LEVEL > 1: # Architecture info gf.print_flush("Python version: {0}".format(sys.version)) gf.print_node_info("node_info.log") os.system("lsb_release -a") gf.do_shell("env") gf.do_shell("voms-proxy-info --all") if args.copy_log: # initialise with node name gf.do_shell("hostname >> {0}".format(gf.COPY_LOG)) return args, socket_config
args = gf.parse_arguments() lhapdf_local = "" if args.use_cvmfs_lhapdf: lhapdf_local = args.cvmfs_lhapdf_location set_environment(args, lhapdf_local) if gf.DEBUG_LEVEL > -1: # Architecture info gf.print_flush("Python version: {0}".format(sys.version)) gf.print_node_info("node_info.log") if args.copy_log: # initialise with node name gf.do_shell("hostname >> {0}".format(gf.COPY_LOG)) # Debug info if gf.DEBUG_LEVEL > 16: gf.do_shell("env") gf.do_shell("voms-proxy-info --all") setup_time = datetime.datetime.now() # Download components status = download_program() # uncomment for downloaded exe # gf.do_shell("chmod +x {0}".format(args.executable)) # uncomment for downloaded exe # if gf.DEBUG_LEVEL > 8:
# ------------------------- MAIN ------------------------- if __name__ == "__main__": args, socket_config = setup() bring_status = bring_files(args) nnlojet_command = RUN_CMD.format( args.threads, args.executable, args.runcard) if args.Sockets: nnlojet_command, socket_config = setup_sockets( args, nnlojet_command, bring_status) if args.Production: # Assume sockets does not work with production nnlojet_command += " -iseed {0}".format(args.seed) if gf.DEBUG_LEVEL > 1: gf.do_shell("ls") gf.do_shell("ldd -v {0}".format(args.executable)) # Run executable status_nnlojet = run_executable(nnlojet_command) # Store output status_copy, status_tar = store_output( args, socketed=args.Sockets, socket_config=socket_config) print_copy_status(args, status_copy) if args.Sockets: try: # only the first one arriving will go through! gf.print_flush("Close Socket connection") _ = socket_sync_str(args.Host, args.port, "bye!") # Be polite except socket.error:
def bring_lhapdf(lhapdf_grid): tmp_tar = "lhapdf.tar.gz" stat = gf.copy_from_grid(lhapdf_grid, tmp_tar, args) gf.print_flush("LHAPDF copy from GRID status: {0}".format(stat)) stat += gf.untar_file(tmp_tar) return gf.do_shell("rm {0}".format(tmp_tar))+stat
args = gf.parse_arguments() lhapdf_local = "" if args.use_cvmfs_lhapdf: lhapdf_local = args.cvmfs_lhapdf_location set_environment(args, lhapdf_local) if gf.DEBUG_LEVEL > -1: # Architecture info gf.print_flush("Python version: {0}".format(sys.version)) gf.print_node_info("node_info.log") if args.copy_log: # initialise with node name gf.do_shell("hostname >> {0}".format(gf.COPY_LOG)) # Debug info if gf.DEBUG_LEVEL > 16: gf.do_shell("env") gf.do_shell("voms-proxy-info --all") setup_time = datetime.datetime.now() # Download components # we are abusing "args.warmup_folder", which is otherwise not needed for HEJ status = download_program(args.warmup_folder) gf.do_shell("chmod +x {0}".format(args.executable)) if gf.DEBUG_LEVEL > 8: gf.do_shell("ldd {0}".format(args.executable))