def scan_nested_simulation(root_simulation,nest_simulation): a=tree_gen_flat_list(root_simulation,level=1) print(a) return program_list=tree_load_program(nest_simulation) names=tree_load_flat_list(root_simulation) commands=[] flat_simulation_list=[] #tree_save_flat_list(self.sim_dir,flat_simulation_list) for i in range(0,len(names)): dest_name=os.path.join(root_simulation,names[i]) tree_gen(flat_simulation_list,program_list,dest_name,dest_name) files = os.listdir(dest_name) for file in files: if file.endswith(".inp") or file.endswith(".gpvdm") or file.endswith(".dat") : os.remove(os.path.join(dest_name,file)) print(names[i],flat_simulation_list) tree_save_flat_list(root_simulation,flat_simulation_list) return
def run(self, run_simulation=True, generate_simulations=True, args=""): f = inp() f.load(os.path.join(self.scan_dir, "scan_config.inp")) args = f.get_token("#scan_config_args") if args == False: args = "" args = args + " --mindbustx" if self.scan_dir == "": error_dlg(self.parent_window, _("No sim dir name")) return self.make_dir() if generate_simulations == True: self.build_scan() if run_simulation == True: commands = tree_load_flat_list(self.scan_dir) if commands == False: error_dlg( self.parent_window, _("I can't load flat_list.inp. This usually means there is a problem with how you have set up your scan." )) return for i in range(0, len(commands)): self.myserver.add_job(commands[i], args) #print("Adding job"+commands[i]) self.myserver.start() gc.collect()
def scan_list_unconverged_simulations(dir_to_search): found_dirs=[] sim_dirs=tree_load_flat_list(dir_to_search) for i in range(0,len(sim_dirs)): add=True fit_log=os.path.join(sim_dirs[i],'fitlog.dat') if os.path.isfile(fit_log): f = open(fit_log, "r") lines = f.readlines() f.close() for l in range(0, len(lines)): lines[l]=lines[l].rstrip() if len(lines)>4: error=float(lines[len(lines)-2].split()[1]) if error<0.1: print(fit_log,error) add=False if add==True: found_dirs.append(sim_dirs[i]) return found_dirs
def scan_gen_report(path): tokens = [] tokens.append(report_token("dos0.inp", "#Etrape")) tokens.append(report_token("dos0.inp", "#mueffe")) tokens.append(report_token("dos0.inp", "#Ntrape")) tokens.append(report_token("dos0.inp", "#srhsigman_e")) tokens.append(report_token("dos0.inp", "#srhsigmap_e")) tokens.append(report_token("dos0.inp", "#srhsigman_h")) tokens.append(report_token("dos0.inp", "#srhsigmap_h")) tokens.append(report_token("sim/thick_light/sim_info.dat", "#jv_pmax_tau")) tokens.append(report_token("sim/thick_light/sim_info.dat", "#jv_pmax_mue")) tokens.append(report_token("sim/thick_light/sim_info.dat", "#jv_pmax_muh")) tokens.append(report_token("jv1.inp", "#jv_Rcontact")) tokens.append(report_token("jv1.inp", "#jv_Rshunt")) simulation_dirs = tree_load_flat_list(path) for i in range(0, len(simulation_dirs)): for ii in range(0, len(tokens)): value = inp_get_token_value( os.path.join(simulation_dirs[i], tokens[ii].file_name), tokens[ii].token) #print(os.path.join(simulation_dirs[i],tokens[ii].file_name), tokens[ii].token,value) if value != None: tokens[ii].values.append(float(value)) for ii in range(0, len(tokens)): print(tokens[ii].token, tokens[ii].values, sum(tokens[ii].values) / len(tokens[ii].values), std(tokens[ii].values)) for ii in range(0, len(tokens)): print(tokens[ii].token, sum(tokens[ii].values) / len(tokens[ii].values), std(tokens[ii].values))
def scan_run(self, args=""): commands = tree_load_flat_list(self.sim_dir) if commands == False: error_dlg( self, _("I can't load flat_list.inp. This usually means there is a problem with how you have set up your scan." )) return self.send_commands_to_server(commands, args)
def scan_plot_fits(dir_to_search): sim_dirs=tree_load_flat_list(dir_to_search) for i in range(0,len(sim_dirs)): os.chdir(sim_dirs[i]) name=sim_dirs[i].replace("/","_") os.system("gnuplot fit.plot >plot.eps") os.system("gs -dNOPAUSE -r600 -dEPSCrop -sDEVICE=jpeg -sOutputFile="+os.path.join(dir_to_search,name+".jpg")+" plot.eps -c quit") os.chdir(dir_to_search)
def clean_simulation(dir_to_clean,simulation_dirs): files_to_delete=[] sims_we_should_have=tree_load_flat_list(dir_to_clean) for i in range(0,len(simulation_dirs)): if sims_we_should_have.count(simulation_dirs[i])==0: files_to_delete.append(simulation_dirs[i]) else: listing=os.listdir(simulation_dirs[i]) for ii in range(0,len(listing)): delete=True path=os.path.join(simulation_dirs[i],listing[ii]) if path.endswith(".inp"): delete=False if path.endswith("exp"): delete=False if path.endswith("materials"): delete=False if path.endswith(".opvdm"): delete=False elif path.endswith(".opvdm"): delete=False elif path.endswith("fitlog_time_error.dat"): delete=False elif path.endswith("fitlog_time_speed.dat"): delete=False elif path.endswith("fitlog_time_odes.dat"): delete=False elif path.endswith("fitlog.dat"): delete=False elif path.endswith("fitlog_speed.dat"): delete=False elif path.endswith("fiterror.dat"): delete=False if delete==True: print "delete",path files_to_delete.append(path) scan_ask_to_delete(files_to_delete)
def scan_plot_fits(dir_to_search): files=os.listdir(dir_to_search) for i in range(0,len(files)): if files[i].endswith(".jpg"): os.remove(os.path.join(dir_to_search,files[i])) #print("remove",os.path.join(dir_to_search,files[i])) sim_dirs=tree_load_flat_list(dir_to_search) for i in range(0,len(sim_dirs)): os.chdir(sim_dirs[i]) name=sim_dirs[i].replace("/","_") os.system("gnuplot fit.plot >plot.eps") os.system("gs -dNOPAUSE -r600 -dEPSCrop -sDEVICE=jpeg -sOutputFile="+os.path.join(dir_to_search,name+".jpg")+" plot.eps -c quit") os.chdir(dir_to_search)
def scan_nested_simulation(root_simulation,nest_simulation): names=tree_load_flat_list(root_simulation) commands=[] for i in range(0,len(names)): dest_name=os.path.join(names[i],os.path.basename(nest_simulation)) copy_scan_dir(dest_name,nest_simulation) program_list=[] flat_list=[] tree_load_program(program_list,dest_name) print("call=",names[i],dest_name) tree_gen(flat_list,program_list,names[i],dest_name) server_find_simulations_to_run(commands,dest_name) return commands
def scan_list_unconverged_simulations(dir_to_search): found_dirs = [] sim_dirs = tree_load_flat_list(dir_to_search) for i in range(0, len(sim_dirs)): add = False fit_log = os.path.join(sim_dirs[i], 'fitlog.dat') error = scan_get_converged_status(fit_log) if error == False: add = True elif error > 0.1: add = True if add == True: found_dirs.append(sim_dirs[i]) return found_dirs
def simulate(self,run_simulation,generate_simulations,args): base_dir=os.getcwd() run=True if self.tab.rowCount() == 0: error_dlg(self,_("You have not selected any parameters to scan through. Use the add button.")) return if self.sim_name=="": error_dlg(self,_("No sim dir name")) return self.make_sim_dir() if generate_simulations==True: scan_clean_dir(self,self.sim_dir) print("Running") program_list=[] for i in range(0,self.tab.rowCount()): program_list.append([tab_get_value(self.tab,i,0),tab_get_value(self.tab,i,1),tab_get_value(self.tab,i,3),tab_get_value(self.tab,i,4)]) print(program_list) tree_load_config(self.sim_dir) if generate_simulations==True: flat_simulation_list=[] if tree_gen(flat_simulation_list,program_list,base_dir,self.sim_dir)==False: error_dlg(self,_("Problem generating tree.")) return print("flat list",flat_simulation_list) tree_save_flat_list(self.sim_dir,flat_simulation_list) commands=tree_load_flat_list(self.sim_dir) print("loaded commands",commands) if run_simulation==True: self.send_commands_to_server(commands,args) self.save_combo() os.chdir(base_dir) gc.collect()
def add_jobs(self, scan_dir_path): exe_command = get_exe_command() scans = scans_io(os.getcwd()) scan_config_file = scans.find_path_by_name( os.path.basename(scan_dir_path)) s = scan_io() s.load(scan_config_file) program_list = s.program_list watch_dir = os.path.join(os.getcwd(), scan_dir_path) commands = [] #server_find_simulations_to_run(commands,scan_dir_path) commands = tree_load_flat_list(scan_dir_path) print(commands) self.server.base_server_init(watch_dir) for i in range(0, len(commands)): self.server.add_job(commands[i], "") print("Adding job" + commands[i])
def scan_list_unconverged_simulations(dir_to_search): found_dirs = [] sim_dirs = tree_load_flat_list(dir_to_search) for i in range(0, len(sim_dirs)): add = True fit_log = os.path.join(sim_dirs[i], 'fitlog.dat') if os.path.isfile(fit_log): f = open(fit_log, "r") lines = f.readlines() f.close() for l in range(0, len(lines)): lines[l] = lines[l].rstrip() if len(lines) > 4: error = float(lines[len(lines) - 2].split()[1]) if error < 0.1: add = False if add == True: found_dirs.append(sim_dirs[i]) return found_dirs
def command_args(argc, argv): if test_arg_for_sim_file() != False: return if argc >= 2: if args.version: print(version()) sys.exit(0) elif args.ver: print(ver()) sys.exit(0) elif args.syncver: ver_sync_ver() sys.exit(0) elif args.importscandirs: import_scan_dirs(os.getcwd(), args.importscandirs[0]) exit(0) elif args.replace: device_lib_replace(args.replace[0], dir_name=args.replace[1]) exit(0) elif args.delete: device_lib_delete(args.delete[0], dir_name=args.delete[1]) exit(0) elif args.clean: clean_sim_dir() sys.exit(0) elif args.export: export_as(args.export[0]) sys.exit(0) elif args.makeman: make_man() sys.exit(0) elif args.cleanscandirs: clean_scan_dirs(os.getcwd()) sys.exit(0) elif args.importfile: import_archive(args.importfile[0], os.path.join(os.getcwd(), "sim.gpvdm"), False) sys.exit(0) elif args.dumptab: export_as(args.dumptab[0]) sys.exit(0) elif args.patch: import_archive(args.patch[0], args.patch[1], True) sys.exit(0) elif args.patchfile: patch_file(args.patchfile[0], args.patchfile[1], args.patchfile[2]) sys.exit(0) elif args.clone: gpvdm_clone(os.getcwd(), copy_dirs=True) sys.exit(0) elif args.matcompress: archive_materials(os.path.join(os.getcwd(), "materials")) sys.exit(0) elif args.clonesrc: gpvdm_copy_src(clone - src[0]) sys.exit(0) elif args.editvalue: inp_update_token_value(args.editvalue[0], args.editvalue[1], args.editvalue[2]) sys.exit(0) elif args.load: set_sim_path(os.path.dirname(args.load[0])) #print("a") elif args.encrypt: inp_encrypt(args.encrypt[0]) sys.exit(0) elif args.extract: archive_decompress("sim.gpvdm") sys.exit(0) elif args.scanplot: plot_token = dat_file() oplot_file = args.scan - plot[0] if plot_load_info(plot_token, oplot_file) == True: print("file0=", plot_token.file0, "<") plot_files, plot_labels, save_file = scan_gen_plot_data( plot_token, os.path.dirname(oplot_file)) print("written data to", save_file) else: print("Problem loading oplot file") sys.exit(0) if args.unpack: archive_unpack(args.unpack[0]) sys.exit() if args.runscan: set_gui(False) scan_dir_path = args.runscan[0] #program file exe_command = get_exe_command() program_list = tree_load_program(scan_dir_path) watch_dir = os.path.join(os.getcwd(), scan_dir_path) commands = [] #server_find_simulations_to_run(commands,scan_dir_path) commands = tree_load_flat_list(scan_dir_path) print(commands) myserver = base_server() myserver.base_server_init(watch_dir) for i in range(0, len(commands)): myserver.base_server_add_job(commands[i], "") print("Adding job" + commands[i]) myserver.print_jobs() myserver.simple_run() #simple_run(exe_command) sys.exit(0) if args.scanarchive: set_gui(False) scan_archive(args.scanarchive[0]) sys.exit(0) if args.buildscan: set_gui(False) scan_items_clear() scan_items_populate_from_known_tokens() scan_items_populate_from_files() scan_dir_path = args.buildscan[0] #program file base_dir = args.buildscan[1] #base dir build_scan(scan_dir_path, base_dir) sys.exit(0) if args.scanbuildvectors: set_gui(False) scan_ml_build_vector(args.scanbuildvectors[0]) sys.exit(0) if args.buildnestedscan: set_gui(False) scan_items_clear() scan_items_populate_from_known_tokens() scan_items_populate_from_files() scan_dir_path = os.path.abspath( args.buildnestedscan[0]) #program file sim_to_nest = os.path.abspath( args.buildnestedscan[1]) #program file scan_build_nested_simulation( scan_dir_path, os.path.join(os.getcwd(), sim_to_nest)) sys.exit(0)