def genbash(self, name, num_partitions, num_reinsurance_iterations=0, fifo_tmp_dir=False, mem_limit=False): input_filename = os.path.join(KPARSE_INPUT_FOLDER, "{}.json".format(name)) if num_reinsurance_iterations <= 0: output_filename = os.path.join( KPARSE_OUTPUT_FOLDER, "{}_{}_partition.sh".format(name, num_partitions)) else: output_filename = os.path.join( KPARSE_OUTPUT_FOLDER, "{}_{}_reins_layer_{}_partition.sh".format( name, num_reinsurance_iterations, num_partitions)) with io.open(input_filename, encoding='utf-8') as file: analysis_settings = json.load(file)['analysis_settings'] genbash(num_partitions, analysis_settings, filename=output_filename, num_reinsurance_iterations=num_reinsurance_iterations, fifo_tmp_dir=fifo_tmp_dir, mem_limit=mem_limit)
def genbash(self, name, num_partitions, num_reinsurance_iterations=None, fifo_tmp_dir=None, stderr_guard=None, gul_alloc_rule=None, il_alloc_rule=None, ri_alloc_rule=None, bash_trace=None): input_filename = os.path.join(self.KPARSE_INPUT_FOLDER, "{}.json".format(name)) if not num_reinsurance_iterations: output_filename = os.path.join(self.KPARSE_OUTPUT_FOLDER, "{}_{}_partition.sh".format(name, num_partitions)) else: output_filename = os.path.join( self.KPARSE_OUTPUT_FOLDER, "{}_{}_reins_layer_{}_partition.sh".format(name, num_reinsurance_iterations, num_partitions)) with io.open(input_filename, encoding='utf-8') as file: analysis_settings = json.load(file)['analysis_settings'] genbash( num_partitions, analysis_settings, filename=output_filename, num_reinsurance_iterations=(num_reinsurance_iterations or self.ri_iterations), fifo_tmp_dir=(fifo_tmp_dir or self.fifo_tmp_dir), stderr_guard=(stderr_guard or self.stderr_guard), gul_alloc_rule=(gul_alloc_rule or self.gul_alloc_rule), il_alloc_rule=(il_alloc_rule or self.il_alloc_rule), ri_alloc_rule=(ri_alloc_rule or self.ri_alloc_rule), bash_trace=(bash_trace or self.bash_trace), )
def genbash(self, name, num_partitions): input_filename = os.path.join(KPARSE_INPUT_FOLDER, "{}.json".format(name)) output_filename = os.path.join( KPARSE_OUTPUT_FOLDER, "{}_{}_partition.sh".format(name, num_partitions)) with io.open(input_filename, encoding='utf-8') as file: analysis_settings = json.load(file)['analysis_settings'] genbash(num_partitions, analysis_settings, output_filename)
def run(analysis_settings, number_of_processes=-1, num_reinsurance_iterations=0, ktools_mem_limit=False, set_alloc_rule=ALLOCATE_TO_ITEMS_BY_PREVIOUS_LEVEL_ALLOC_ID, fifo_tmp_dir=True, run_debug=None, filename='run_ktools.sh'): if os.name == 'nt': filename = 'run_ktools.bat' if number_of_processes == -1: number_of_processes = multiprocessing.cpu_count() custom_gulcalc_cmd = "EarthquakeDamage" # Check for custom gulcalc if shutil.which(custom_gulcalc_cmd): def custom_get_getmodel_cmd(number_of_samples, gul_threshold, use_random_number_file, coverage_output, item_output, process_id, max_process_id, **kwargs): cmd = "{} -m {} -n {} -a {} -p {} -S{}".format( custom_gulcalc_cmd, process_id, max_process_id, os.path.abspath("analysis_settings.json"), ".", number_of_samples) if coverage_output != '': cmd = '{} -c {}'.format(cmd, coverage_output) if item_output != '': cmd = '{} -i {}'.format(cmd, item_output) return cmd if os.name == 'nt': run_batch( number_of_processes, analysis_settings, num_reinsurance_iterations=num_reinsurance_iterations, fifo_tmp_dir=fifo_tmp_dir, mem_limit=ktools_mem_limit, alloc_rule=set_alloc_rule, filename=filename, _get_getmodel_cmd=custom_get_getmodel_cmd, ) else: genbash( number_of_processes, analysis_settings, num_reinsurance_iterations=num_reinsurance_iterations, fifo_tmp_dir=fifo_tmp_dir, mem_limit=ktools_mem_limit, alloc_rule=set_alloc_rule, filename=filename, _get_getmodel_cmd=custom_get_getmodel_cmd, ) else: genbash(number_of_processes, analysis_settings, num_reinsurance_iterations=num_reinsurance_iterations, fifo_tmp_dir=fifo_tmp_dir, mem_limit=ktools_mem_limit, alloc_rule=set_alloc_rule, filename=filename) try: if os.name != 'nt': subprocess.check_call(['bash', filename]) else: subprocess.check_call([filename]) except subprocess.CalledProcessError as e: raise OasisException('Error running ktools: {}'.format(str(e)))