def prepare_for_submission(self, folder): # create calculation info calcinfo = CalcInfo() calcinfo.uuid = self.uuid calcinfo.codes_info = [] calcinfo.retrieve_list = [] for key, params in self.inputs.parameters.get_dict().items(): cube_name = key+".cube" kind_str = params["kind"] npts = params["npts"] # create code info codeinfo = CodeInfo() codeinfo.cmdline_params = [] codeinfo.cmdline_params.append(str(self.inputs.metadata.options.resources['tot_num_mpiprocs'])) codeinfo.cmdline_params.append(kind_str) codeinfo.cmdline_params.append(self._PARENT_FOLDER_NAME + "/" + self._DEFAULT_INPUT_FILE) codeinfo.cmdline_params.append(cube_name) codeinfo.cmdline_params.append(str(npts)) codeinfo.code_uuid = self.inputs.code.uuid codeinfo.withmpi = self.inputs.metadata.options.withmpi calcinfo.codes_info.append(codeinfo) if self.inputs.retrieve_cubes.value: calcinfo.retrieve_list.append(cube_name) extra_prepend = "\nexport GAUSS_MEMDEF=%dMB\n" % self.inputs.gauss_memdef if not hasattr(calcinfo, 'prepend_text') or not calcinfo.prepend_text: calcinfo.prepend_text = extra_prepend else: calcinfo.prepend_text += extra_prepend # symlink or copy to parent calculation calcinfo.remote_symlink_list = [] calcinfo.remote_copy_list = [] comp_uuid = self.inputs.parent_calc_folder.computer.uuid remote_path = self.inputs.parent_calc_folder.get_remote_path() copy_info = (comp_uuid, remote_path, self._PARENT_FOLDER_NAME) if self.inputs.code.computer.uuid == comp_uuid: # if running on the same computer - make a symlink # if not - copy the folder calcinfo.remote_symlink_list.append(copy_info) else: calcinfo.remote_copy_list.append(copy_info) return calcinfo
def prepare_for_submission(self, tempfolder): # Setup template with open(self.inputs.template, 'r') as tempfile: temp_contents = tempfile.read() lmp_template = Template(temp_contents) # # check variables # for variable in self.inputs.variables.values(): # if not isinstance(variable, list): # raise TypeError('Values in variables must be list') # check kinds if 'kinds' in self.inputs: kind_var = { kind: kind_index + 1 for kind_index, kind in enumerate(self.inputs.kinds) } lmp_template = Template(lmp_template.safe_substitute(**kind_var)) for i, case in enumerate(self.inputs.cases): structure = case.pop('structure') if isinstance(structure, StructureData): structure_txt, struct_transform = generate_lammps_structure( structure, kinds=self.inputs.kinds) elif isinstance(structure, SinglefileData): structure_txt = structure.get_content() else: raise TypeError( 'Input structure must be StructureData or SinglefileData') input_txt = lmp_template.safe_substitute(**case) # ========================= dump to file =========================== tempfolder.get_subfolder(i, create=True) input_filename = tempfolder.get_abs_path( f'{i}/{self._INPUT_FILE_NAME}') with open(input_filename, 'w') as infile: infile.write(input_txt) structure_filename = tempfolder.get_abs_path( f'{i}/{self._INPUT_STRUCTURE}') with open(structure_filename, 'w') as infile: infile.write(structure_txt) case_filename = tempfolder.get_abs_path(f'{i}/case.json') case.update({'structure pk': structure.pk}) with open(case_filename, 'w') as infile: json.dump(case, infile, sort_keys=True, indent=2) # ============================ calcinfo ================================ settings = self.inputs.settings.get_dict() \ if 'settings' in self.inputs else {} codeinfo = CodeInfo() codeinfo.cmdline_params = self._cmdline_params codeinfo.code_uuid = self.inputs.code.uuid codeinfo.stdout_name = self._stdout_name codeinfo.join_files = True calcinfo = CalcInfo() calcinfo.uuid = self.uuid calcinfo.prepend_text = (f'for i in $(seq 0 {i})\n' 'do\n' 'cd "${i}" || exit') calcinfo.append_text = ('cd ..\n' 'done') calcinfo.cmdline_params = codeinfo.cmdline_params calcinfo.stdin_name = self._INPUT_FILE_NAME calcinfo.stdout_name = self._stdout_name calcinfo.retrieve_list = self._retrieve_list + [ self.options.output_filename ] calcinfo.retrieve_list += settings.pop('additional_retrieve_list', []) calcinfo.retrieve_temporary_list = self._retrieve_temporary_list calcinfo.codes_info = [codeinfo] # =========================== local_copy_list ========================== if 'file' in self.inputs: calcinfo.local_copy_list = [] for name, obj in self.inputs.file.items(): calcinfo.local_copy_list.append( (obj.uuid, obj.filename, f'{name}.pb')) return calcinfo
def prepare_for_submission(self, folder): # create calculation info calcinfo = CalcInfo() calcinfo.uuid = self.uuid calcinfo.codes_info = [] calcinfo.retrieve_list = [] calcinfo.retrieve_temporary_list = [] calcinfo.prepend_text = "export GAUSS_MEMDEF=%dMB\n" % self.inputs.gauss_memdef calcinfo.local_copy_list = [] if "stencil" in self.inputs: calcinfo.local_copy_list.append( (self.inputs.stencil.uuid, self.inputs.stencil.filename, 'stencil.txt')) for key, params in self.inputs.parameters.get_dict().items(): cube_name = key + ".cube" kind_str = params["kind"] npts = params["npts"] # create code info codeinfo = CodeInfo() codeinfo.cmdline_params = [] codeinfo.cmdline_params.append( str(self.inputs.metadata.options.resources['tot_num_mpiprocs']) ) codeinfo.cmdline_params.append(kind_str) codeinfo.cmdline_params.append(self.PARENT_FOLDER_NAME + "/" + self.DEFAULT_INPUT_FILE) codeinfo.cmdline_params.append(cube_name) if npts == -1: if 'stencil' not in self.inputs: self.report( "Warning: npts: -1 set but no stencil provided, using -2" ) codeinfo.cmdline_params.append("-2") else: codeinfo.cmdline_params.append(str(npts)) codeinfo.stdin_name = "stencil.txt" else: codeinfo.cmdline_params.append(str(npts)) codeinfo.code_uuid = self.inputs.code.uuid codeinfo.withmpi = self.inputs.metadata.options.withmpi calcinfo.codes_info.append(codeinfo) if self.inputs.retrieve_cubes.value: calcinfo.retrieve_list.append(cube_name) else: calcinfo.retrieve_temporary_list.append(cube_name) # symlink or copy to parent calculation calcinfo.remote_symlink_list = [] calcinfo.remote_copy_list = [] comp_uuid = self.inputs.parent_calc_folder.computer.uuid remote_path = self.inputs.parent_calc_folder.get_remote_path() copy_info = (comp_uuid, remote_path, self.PARENT_FOLDER_NAME) if self.inputs.code.computer.uuid == comp_uuid: # if running on the same computer - make a symlink # if not - copy the folder calcinfo.remote_symlink_list.append(copy_info) else: calcinfo.remote_copy_list.append(copy_info) return calcinfo