def run_pricm(folder, RANGE=(0, 5), QUEUE=None, WALLTIME="1-00:00:00", sample_domain=1000): ''' Submit a number of miso jobs for HOIP optimization. **Parameters** folder: *str* The name for the output folder. **Returns** None ''' script = ''' import sys from run_pricm import run run( int(sys.argv[-1]), "$MODEL$", folder="$FOLDER$", hp_opt="$HP_OPT$", sample_domain=$SAMPLE_DOMAIN$ ) '''.strip() systems = [ # Model , HP_Opt ("pricm", "is0" ), ("icm" , "is0" ), ("miso" , "is0" ), ("pricm", "full" ), ("icm" , "full" ), ("miso" , "full" ), ("pricm", "overlap"), ("icm" , "overlap"), ("miso" , "overlap"), ] for model, hp_opt in systems: local = fullreplace(script, "$MODEL$", model) local = fullreplace(local, "$FOLDER$", folder) local = fullreplace(local, "$HP_OPT$", hp_opt) local = fullreplace(local, "$SAMPLE_DOMAIN$", sample_domain) fname = "%s_%s_%d.py" % (model, hp_opt, sample_domain) fptr = open(fname, 'w') fptr.write(local) fptr.close() pysub( fname, queue=QUEUE, nprocs=NPROCS, use_mpi=False, walltime=WALLTIME, modules=["pal"], unique_name=False, jobarray=RANGE ) print("Submitting %s" % fname) time.sleep(0.2)
def run_ei(folder, RANGE=(0, 5), QUEUE=None, WALLTIME="1-00:00:00", sample_domain=1000): ''' Submit a number of EI jobs for HOIP optimization. **Parameters** folder: *str* The name for the output folder. cost: *bool* The cost of the information source. Mainly, True if the true cost was used in the corresponding run_ei file, and False if it is an approximation. This will only change the naming of files so we keep track of this. **Returns** None ''' script = ''' import sys from run_ei import run run(int(sys.argv[-1]), folder="$FOLDER$", sample_domain=$SAMPLE_DOMAIN$) ''' model = "ei" local = fullreplace(script, "$FOLDER$", folder) local = fullreplace(local, "$SAMPLE_DOMAIN$", sample_domain) fname = "%s.py" % (model) fptr = open(fname, 'w') fptr.write(local) fptr.close() pysub(fname, queue=QUEUE, nprocs="4", use_mpi=False, walltime=WALLTIME, priority=20, modules=["pal"], jobarray=RANGE) print("Submitting %s" % fname) time.sleep(0.1)
def run_ei(nsample=1000): script = ''' from run_ei import run_ei run_ei( $INDEX$, SAMPLE_DOMAIN=$NSAMPLE$ ) '''.strip() script = script.replace("$NSAMPLE$", str(nsample)) for i in njobs: fptr = open("%d_%d_ei.py" % (i, nsample), 'w') fptr.write(script.replace("$INDEX$", str(i))) fptr.close() jobs.pysub( "%d_%d_ei" % (i, nsample), nprocs=2, queue="long", priority=10 )
def run(name, sffx, scaled=False, loose=False, very_loose=False, use_MAP=False, upper=1.0, run_standard_misokg=False, run_unitary=False, use_miso=False): # Run misoKG Benchmarks script = ''' from run_misokg import run_misokg run_misokg( $INDEX$, sffx="$SFFX$", scaled=$SCALED$, loose=$LOOSE$, very_loose=$VERY_LOOSE$, use_MAP=$USE_MAP$, upper=$UPPER$, run_unitary=$RUN_UNITARY$, use_miso=$RSM$ ) '''.strip() script = script.replace("$SFFX$", sffx) script = script.replace("$SCALED$", str(scaled)) script = script.replace("$LOOSE$", str(loose)) script = script.replace("$VERY_LOOSE$", str(very_loose)) script = script.replace("$USE_MAP$", str(use_MAP)) script = script.replace("$UPPER$", str(upper)) script = script.replace("$RSM$", str(use_miso)) script = script.replace("$RUN_UNITARY$", str(run_unitary)) for i in njobs: fptr = open("%d_%s.py" % (i, name), 'w') fptr.write(script.replace("$INDEX$", str(i))) fptr.close() jobs.pysub("%d_%s" % (i, name), nprocs=2, queue="long", priority=10)
def run(sffx, nsample=1000): # Run misoKG Benchmarks script = ''' from run_misokg import run_misokg run_misokg( $INDEX$, sffx="$SFFX$", SAMPLE_DOMAIN=$NSAMPLE$ ) '''.strip() script = script.replace("$SFFX$", sffx) script = script.replace("$NSAMPLE$", str(nsample)) for i in njobs: fptr = open("%d_%d_%s.py" % (i, nsample, sffx), 'w') fptr.write(script.replace("$INDEX$", str(i))) fptr.close() jobs.pysub( "%d_%d_%s" % (i, nsample, sffx), nprocs=2, queue="long", priority=10 )
def fullreplace(book, word, newword): while word in book: book = book.replace(str(word), str(newword)) return book script = ''' from run_simple_$SIM import run_$SIM run_$SIM($INDEX) ''' UPPER = 100 RANGE = range(UPPER) for sim in ["misokg"]: #for sim in ["ei"]:for sim in ["kg"]: #for sim in ["kg"]: #for sim in ["misokg", "ei", "kg"]: for i in RANGE: local = fullreplace(script, "$SIM", sim) local = fullreplace(local, "$INDEX", i) fname = "%d_%s.py" % (i, sim) fptr = open(fname, 'w') fptr.write(local) fptr.close() pysub(fname, queue="long", nprocs="4", use_mpi=False) time.sleep(0.1)
rss = False if "-mo" in argv[2:]: mo = True use_these_mods = [] if "-mods" in argv[2:]: use_these_mods = use_these_mods + argv[argv.index("-mods") + 1:] elif "-m" in argv[2:]: use_these_mods = use_these_mods + argv[argv.index("-m") + 1:] if "-py3" in argv[2:]: py3 = True if "-t" in argv[2:]: walltime = argv[argv.index('-t') + 1] if "-walltime" in argv[2:]: walltime = argv[argv.index('-walltime') + 1] pysub(job_name, nprocs=nprocs, ntasks=tasks, omp=omp, queue=queue, xhost=xhost, path=getcwd(), remove_sub_script=rss, priority=priority, walltime=walltime, unique_name=unique, py3=py3, use_mpi=use_mpi, modules=use_these_mods, slurm_allocation=slurm_allocation)
def run_pricm(infosources, folder, cost, RANGE=range(5), QUEUE=None, WALLTIME="1-00:00:00", N_History=10): ''' Submit a number of miso jobs for HOIP optimization. **Parameters** infosources: *int* The information source to use: 0 - IS_N1R3 vs IS_N1R2 1 - IS_N3R2 vs IS_N1R2 2 - IS_N5R2 vs IS_N3R2 3 - IS_N5R2 vs IS_N3R2 vs IS_N1R2 folder: *str* The name for the output folder. cost: *bool* The cost of the information source. Mainly, True if the true cost was used in the corresponding run_ei file, and False if it is an approximation. This will only change the naming of files so we keep track of this. **Returns** None ''' script = ''' import sys from run_pricm import run run( int(sys.argv[-1]), "$MODEL$", $IS$, folder="$FOLDER$", exact_cost=$COST$, hp_opt="$HP_OPT$", generate_new_historical=$GNH$, N_historical=$N_HISTORY$ ) '''.strip() systems = [ # Model , HP_Opt , generate_new_historical # ("pricm", "is0" , True ), # ("icm" , "is0" , False ), # ("pricm", "full" , False ), # ("icm" , "full" , False ), ############ # ("pricm", "overlap", True ), ("icm", "overlap", False), ("pricm", "full", False), ] for model, hp_opt, gen_new_hist in systems: local = fullreplace(script, "$MODEL$", model) local = fullreplace(local, "$IS$", infosources) local = fullreplace(local, "$FOLDER$", folder) local = fullreplace(local, "$COST$", cost) local = fullreplace(local, "$HP_OPT$", hp_opt) local = fullreplace(local, "$GNH$", gen_new_hist) local = fullreplace(local, "$N_HISTORY$", N_History) if cost: fname = "%d_%s_%s_TC.py" % (infosources, model, hp_opt) else: fname = "%d_%s_%s.py" % (infosources, model, hp_opt) fptr = open(fname, 'w') fptr.write(local) fptr.close() pysub(fname, queue=QUEUE, nprocs="4", use_mpi=False, walltime=WALLTIME, modules=["pal"], unique_name=False, jobarray=RANGE) print("Submitting %s" % fname) time.sleep(0.2)
def run_ei(infosources, folder, cost, RANGE=(0, 5), QUEUE=None, WALLTIME="1-00:00:00"): ''' Submit a number of EI jobs for HOIP optimization. **Parameters** infosources: *int* The information source to use. In the case of EI, this is only the 0th, as there is no need to look at the cheaper alternatives (being that this is not a miso approach). 0 - IS_N1R3 vs IS_N1R2 1 - IS_N3R2 vs IS_N1R2 2 - IS_N5R2 vs IS_N3R2 3 - IS_N5R2 vs IS_N3R2 vs IS_N1R2 folder: *str* The name for the output folder. cost: *bool* The cost of the information source. Mainly, True if the true cost was used in the corresponding run_ei file, and False if it is an approximation. This will only change the naming of files so we keep track of this. **Returns** None ''' # Recall that infosources 2 and 3 are the same for EI if infosources == 3: return None script = ''' import sys from run_ei import run run(int(sys.argv[-1]), folder="$FOLDER$", infosources=$IS$, exact_cost=$ECOST$) ''' model = "ei" if cost: fname = "%d_%s_TC.py" % (infosources, model) else: fname = "%d_%s.py" % (infosources, model) local = fullreplace(script, "$FOLDER$", folder) local = fullreplace(local, "$IS$", infosources) local = fullreplace(local, "$ECOST$", cost) fptr = open(fname, 'w') fptr.write(local) fptr.close() pysub(fname, queue=QUEUE, nprocs="4", use_mpi=False, walltime=WALLTIME, priority=20, modules=["pal"], jobarray=RANGE) print("Submitting %s" % fname) time.sleep(0.1)
def pysub(): # Default Documentation help_info = ''' pysub --------- A command line tool to submit jobs to the queue. pysub [script.py] [Options] Flag Default Description -help, -h : : Print this help menu -n : 1 : Number of processors to use -nt, -tasks : 1 : Number of tasks this job will run -o, -omp : : Manually specify what OMP_NUM_THREADS should be. -mpi : : Whether to run python with mpirun or not. -q : : Which queue to submit to -walltime, -t : 00:30:00 : The walltime to use -priority, -p : : Manually specify job priority -unique, -u : False : Whether to require a unique simulation name. -jobarray, -ja : None : Whether to run a job array. If this flag is specified, it MUST be followed by two values to indicate the lower and upper bounds of the indexing. -xhost, -x : : If needed, specify computer -args, -a : : A list of arguments for the python code -mods, -m : : Specify the modules you wish to use here. -mo : False : Whether to override the default modules. -keep, -k : : Whether to keep the submission file -py3 : : Whether to use python 3, or 2 (2 is default). -alloc, -A : None : Whether to specify a SLURM Allocation. -gpu : None : The number of desired GPUs you want. -hts : : If specified, we allow openMPI to use hyperthreads. Default behaviour is to generate a job with the same name as the python script and to generate a .log file with the same name as well. When using -mpi, it will only be effective if nprocs > 1. NOTE! If using xhost or args, make sure it is the last flag as we assume all remaining inputs are the desired strings. This means that only xhost or args can be used at a time (both would lead to errors). ''' # Parse Arguments if '-h' in argv or '-help' in argv or len(argv) < 2: print(help_info) exit() # Parse Arguments nprocs = '1' queue = None xhost = None rss = True walltime = '00:30:00' job_name = argv[1] args = None priority = None unique = False omp = None py3 = False use_mpi = False tasks = 1 allocation = None jobarray = None gpu = None hts = False use_these_mods = [] if ".py" in job_name: job_name = job_name.split(".py")[0] if "-n" in argv[2:]: nprocs = argv[argv.index('-n') + 1] if "-tasks" in argv[2:]: tasks = int(argv[argv.index('-tasks') + 1]) elif "-nt" in argv[2:]: tasks = int(argv[argv.index('-nt') + 1]) if "-o" in argv[2:]: omp = argv[argv.index('-o') + 1] elif "-omp" in argv[2:]: omp = argv[argv.index('-omp') + 1] if "-q" in argv[2:]: queue = argv[argv.index('-q') + 1] if "-A" in argv[2:]: allocation = argv[argv.index('-A') + 1] elif "-alloc" in argv[2:]: allocation = argv[argv.index('-alloc') + 1] if "-x" in argv[2:]: xhost = argv[argv.index('-x') + 1:] elif "-xhost" in argv[2:]: xhost = argv[argv.index('-xhost') + 1:] if "-p" in argv[2:]: priority = int(argv[argv.index('-p') + 1]) elif "-priority" in argv[2:]: priority = int(argv[argv.index('-priority') + 1]) if "-unique" in argv[2:]: unique = True elif "-u" in argv[2:]: unique = True if "-a" in argv[2:]: args = argv[argv.index('-a') + 1:] elif "-args" in argv[2:]: args = argv[argv.index('-argv') + 1:] if "-mpi" in argv[2:]: use_mpi = True if "-k" in argv[2:]: rss = False elif "-keep" in argv[2:]: rss = False if "-mods" in argv[2:]: use_these_mods = use_these_mods + argv[argv.index("-mods") + 1:] elif "-m" in argv[2:]: use_these_mods = use_these_mods + argv[argv.index("-m") + 1:] if "-py3" in argv[2:]: py3 = True if "-t" in argv[2:]: walltime = argv[argv.index('-t') + 1] if "-walltime" in argv[2:]: walltime = argv[argv.index('-walltime') + 1] if "-gpu" in argv[2:]: gpu = int(argv[argv.index('-gpu') + 1]) if "-jobarray" in argv[2:]: i = argv.index("-jobarray") jobarray = map(int, [argv[i + 1], argv[i + 2]]) elif "-ja" in argv[2:]: i = argv.index("-ja") jobarray = map(int, [argv[i + 1], argv[i + 2]]) if "-hts" in argv[2:]: hts = True jobs.pysub(job_name, ntasks=tasks, nprocs=nprocs, ompi_threads=omp, queue=queue, xhosts=xhost, args=args, path=getcwd(), priority=priority, walltime=walltime, unique_name=unique, py3=py3, preface_mpi=use_mpi, modules=use_these_mods, allocation=allocation, jobarray=jobarray, gpu=gpu, use_hyperthreads=hts)
for index, unitary in enumerate([None, 1.0 - 1E-6, 0.83]): for i in RANGE: sffx = ["bl", "bu", "bpc"][index] local = fullreplace(script, "$SIM", sim) local = fullreplace(local, "$INDEX", i) local = fullreplace(local, "$UNITARY$", unitary) local = fullreplace(local, "$SFFX$", sffx) fname = "%d_%s_%s.py" % (i, sim, sffx) fptr = open(fname, 'w') fptr.write(local) fptr.close() pysub(fname, queue=QUEUE, nprocs="4", use_mpi=False, walltime=WALLTIME) time.sleep(0.1) script = ''' from run_simple_$SIM import run_$SIM run_$SIM($INDEX) ''' if not os.path.exists("data_dumps"): os.mkdir("data_dumps") for sim in ["ei", "kg"]: for i in RANGE: local = fullreplace(script, "$SIM", sim) local = fullreplace(local, "$INDEX", i)