def set_run_stage(self, stage, present=False): """ Specify the given stage in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_no_value(separate_args(line), ('--' + stage, ), present) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_nprocs(self, parameters): """ Set the nprocs option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value(separate_args(line), ('--nprocs', '--nprocs=', '-n'), enquote_arg(parameters)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_coupling(self, coupling): """ Set the coupling option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value(separate_args(line), ('--coupling',), enquote_arg(coupling)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_compute_build(self, parameters): """ Set the compute-build option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value( separate_args(line), ('--compute-build', '--compute-build='), enquote_arg(parameters)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_nthreads(self, parameters): """ Set the nthreads option in the run command """ line = self.lines[self.run_cmd_line_id] args = update_command_single_value( separate_args(line), ('--threads-per-task', '--threads-per-task=', '-nt'), enquote_arg(parameters)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def set_run_id(self, run_id=None, run_id_prefix=None, run_id_suffix=None): """ Set the run id, id_prefix, and id_suffix options in the run command """ line = self.lines[self.run_cmd_line_id] args = separate_args(line) if run_id != None: args = update_command_single_value(args, ('--id', '--id='), enquote_arg(run_id)) if run_id_prefix != None: args = update_command_single_value(args, ('--id-prefix', '--id-prefix='), enquote_arg(run_id_prefix)) if run_id_suffix != None: args = update_command_single_value(args, ('--id-suffix', '--id-suffix='), enquote_arg(run_id_suffix)) self.lines[self.run_cmd_line_id] = assemble_args(args)
def getRestartInfo(package, results_dir=None, restart_path='*'): """ Return a tuple (path, number of time steps, time value) or None describing the current restart selection. """ restart_input = None from code_saturne.cs_exec_environment import get_command_output, assemble_args nt_names = ('nbre_pas_de_temps', 'ntcabs') t_names = ('instant_precedent', 'ttcabs') results = [] if results_dir and restart_path == '*': results = os.listdir(results_dir) results.sort(reverse=True) elif restart_path: results = [ restart_path, ] io_dump = package.get_io_dump() for r in results: if restart_path == '*': m = os.path.join(results_dir, r, 'checkpoint', 'main') else: m = os.path.join(r, 'main') if os.path.isfile(m): if True: # try: nt = -1 for name in nt_names: cmd = [io_dump, '-e', '--section'] cmd.append(name) cmd.append(m) cmd_str = assemble_args(cmd) res = get_command_output(cmd_str) if res: nt = -1 try: nt = int(res.strip()) break except Exception: pass t = -1 for name in t_names: cmd = [io_dump, '-e', '--section'] cmd.append(name) cmd.append(m) cmd_str = assemble_args(cmd) res = get_command_output(cmd_str) if res: t = -1 try: t = float(res.strip()) break except Exception: pass return (os.path.split(m)[0], nt, t) elif False: # except Exception: d = os.path.split(m)[0] print('checkpoint: ' + d + ' does not seem usable') continue restart_input = os.path.join(results_dir, r, 'checkpoint') break return None
def run(argv=[], pkg=None, run_args=None, submit_args=None): """ Run calculation; returns return code, run id, and results directory path when created. """ if not pkg: from code_saturne.cs_package import package pkg = package() if run_args == None: options = parse_cmd_line(argv, pkg) else: options = run_args i_c = cs_run_conf.get_install_config_info(pkg) r_c, s_c, run_conf = process_options(options, pkg) if not r_c['casedir'] and not r_c['staging_dir']: return 1, None, None # Read run configuration read_run_config_file(i_c, r_c, s_c, pkg, run_conf=run_conf) # Determine compute stages update_run_steps(s_c, None, final=True) stages = {'prepare_data': s_c['stage'], 'initialize': s_c['initialize'], 'run_solver': s_c['compute'], 'save_results': s_c['finalize']} # Use alternate compute (back-end) package if defined pkg_compute = None if not r_c['compute_build']: if i_c['compute_builds']: r_c['compute_build'] = i_c['compute_builds'][0] if r_c['compute_build']: pkg_compute = pkg.get_alternate_version(r_c['compute_build']) # Specific case for coupling if r_c['coupled_domains'] != []: from code_saturne import cs_case_coupling domains = r_c['coupled_domains'] verbose = True if r_c['suggest_id']: verbose = False c = cs_case_coupling.coupling(pkg, domains, r_c['casedir'], r_c['dest_dir'], staging_dir=r_c['staging_dir'], verbose=verbose, package_compute=pkg_compute) else: # Values in case and associated domain set from parameters d = cs_case_domain.domain(pkg, package_compute=pkg_compute, param=r_c['param']) # Now handle case for the corresponding calculation domain(s). c = cs_case.case(pkg, package_compute=pkg_compute, case_dir=r_c['casedir'], dest_dir=r_c['dest_dir'], staging_dir=r_c['staging_dir'], domains=d) # Determine run id if not forced if not r_c['run_id']: r_c['run_id'] = c.suggest_id(r_c['id_prefix'], r_c['id_suffix']) if r_c['suggest_id']: print(r_c['run_id']) return 0, r_c['run_id'], None if submit_args != None: submit_stages = {'prepare_data': False} for s in ('initialize', 'run_solver', 'save_results'): submit_stages[s] = stages[s] stages[s] = False c.run_prologue = r_c['run_prologue'] c.run_epilogue = r_c['run_epilogue'] c.compute_prologue = r_c['compute_prologue'] c.compute_epilogue = r_c['compute_epilogue'] # Now run case retval = c.run(n_procs=r_c['n_procs'], n_threads=r_c['n_threads'], time_limit=r_c['time_limit'], run_id=r_c['run_id'], force_id=r_c['force_id'], stages=stages) if submit_args != None: resource_name = cs_run_conf.get_resource_name(i_c) run_cfg_path = os.path.join(c.result_dir, 'run.cfg') if len(submit_args) > 1: job_parameters = cs_exec_environment.assemble_args(submit_args) r_c['job_parameters'] = job_parameters generate_run_config_file(run_cfg_path, resource_name, r_c, submit_stages, pkg) return retval, c.result_dir, r_c
def set_run_args(self, args): """ Set the run command and arguments from a list """ self.lines[self.run_cmd_line_id] = assemble_args(args)