def run_job(cfg_file, log_level, log_file, exports='', hazard_calculation_id=None): """ Run a job using the specified config file and other options. :param str cfg_file: Path to calculation config (INI-style) files. :param str log_level: 'debug', 'info', 'warn', 'error', or 'critical' :param str log_file: Path to log file. :param exports: A comma-separated string of export types requested by the user. :param hazard_calculation_id: ID of the previous calculation or None """ # if the master dies, automatically kill the workers concurrent_futures_process_monkeypatch() job_ini = os.path.abspath(cfg_file) job_id, oqparam = eng.job_from_file( job_ini, getpass.getuser(), hazard_calculation_id) calc = eng.run_calc(job_id, oqparam, log_level, log_file, exports, hazard_calculation_id=hazard_calculation_id) calc.monitor.flush() for line in logs.dbcmd('list_outputs', job_id, False): print(line) return job_id
def run_job(cfg_file, log_level, log_file, exports='', hazard_calculation_id=None): """ Run a job using the specified config file and other options. :param str cfg_file: Path to calculation config (INI-style) files. :param str log_level: 'debug', 'info', 'warn', 'error', or 'critical' :param str log_file: Path to log file. :param exports: A comma-separated string of export types requested by the user. Currently only 'xml' is supported. :param hazard_calculation_id: ID of the previous calculation or None """ # if the master dies, automatically kill the workers concurrent_futures_process_monkeypatch() job_id, oqparam = dbcmd( 'job_from_file', cfg_file, getpass.getuser(), hazard_calculation_id) calc = engine.run_calc(job_id, oqparam, log_level, log_file, exports, hazard_calculation_id=hazard_calculation_id) duration = calc.monitor.duration # set this before monitor.flush() calc.monitor.flush() dbcmd('print_results', job_id, duration) return job_id
def run(job_ini, slowest, hc, param, concurrent_tasks=CT, exports='', loglevel='info', pdb=None): """ Run a calculation. """ concurrent_futures_process_monkeypatch() params = oqvalidation.OqParam.check( dict(p.split('=', 1) for p in param or ())) if slowest: prof = cProfile.Profile() stmt = ('_run(job_ini, concurrent_tasks, pdb, loglevel, hc, ' 'exports, params)') prof.runctx(stmt, globals(), locals()) pstat = calc_path + '.pstat' prof.dump_stats(pstat) print('Saved profiling info in %s' % pstat) print(get_pstats(pstat, slowest)) else: _run(job_ini, concurrent_tasks, pdb, loglevel, hc, exports, params)
def run(job_ini, slowest, hc, param, concurrent_tasks=CT, exports='', loglevel='info', pdb=None): """ Run a calculation. :param job_ini: the configuration file (or filew, comma-separated) :param slowest: enable Python cProfile functionality :param hc: ID of the previous calculation (or None) :param param: override a configuration parameter :param concurrent_tasks: the number of concurrent tasks (0 to disable the parallelization) :param loglevel: the logging level (default 'info') :param exports: export type, can be '', 'csv', 'xml', 'geojson' or combinations :param pdb: flag to enable pdb debugging on failing calculations """ concurrent_futures_process_monkeypatch() params = oqvalidation.OqParam.check( dict(p.split('=', 1) for p in param or ())) if slowest: prof = cProfile.Profile() stmt = ('_run(job_ini, concurrent_tasks, pdb, loglevel, hc, ' 'exports, params)') prof.runctx(stmt, globals(), locals()) pstat = calc_path + '.pstat' prof.dump_stats(pstat) print('Saved profiling info in %s' % pstat) print(get_pstats(pstat, slowest)) else: _run(job_ini, concurrent_tasks, pdb, loglevel, hc, exports, params)