def save_page(rst_text, prob_name, file_path): """ Helper function that saves the rst page into text and html after converting it to html. @param rst_text :: page to be converted/saved in rst @param prob_name :: name of the problem @param file_path :: path to where the file is going to be saved @returns :: html/txt visual display page saved at file_path """ html = publish_string(rst_text, writer_name='html') with open(file_path + '.' + FILENAME_EXT_TXT, 'w') as visual_rst: print(rst_text, file=visual_rst) logger.info( 'Saved {prob_name}.{extension} to {working_directory}'.format( prob_name=prob_name, extension=FILENAME_EXT_TXT, working_directory=file_path[file_path.find('fitbenchmarking' ):])) with open(file_path + '.' + FILENAME_EXT_HTML, 'w') as visual_html: print(html, file=visual_html) logger.info( 'Saved {prob_name}.{extension} to {working_directory}'.format( prob_name=prob_name, extension=FILENAME_EXT_HTML, working_directory=file_path[file_path.find('fitbenchmarking' ):]))
def get_problem_files(data_dir): """ Gets all the problem definition files from the specified problem set directory. :param data_dir: directory containing the problems :type data_dir: str :return: array containing of paths to the problems e.g. In NIST we would have [low_difficulty/file1.txt, ..., ...] :rtype: list of str """ test_data = glob.glob(data_dir + '/*.*') if test_data == []: raise NoDataError('"{}" not recognised as a dataset. ' 'Check that it contains problem files ' 'and try again.'.format(data_dir)) problems = [ os.path.join(data_dir, data) for data in test_data if not data.endswith('META.txt') ] problems.sort() for problem in problems: logger.info(problem) return problems
def save_plot(save): """ Save the plot to a .png file or just display it in the console if that option is available. """ if save == "": plt.show() else: output_file = save.replace(",", "") output_file = output_file.replace(" ", "_") logger.info("Saved " + os.path.basename(output_file) + " to " + output_file[output_file.find("fitbenchmarking"):]) plt.savefig(output_file.replace(" ", "_"))
def get_problem_files(data_dir): """ Gets all the problem definition files from the specified problem set directory. @param data_dir :: directory containing the problems @returns :: array containing of paths to the problems e.g. In NIST we would have [low_difficulty/file1.txt, ..., ...] """ test_data = glob.glob(data_dir + '/*.*') if test_data == []: raise ValueError('"{}" not recognised as a dataset. ' 'Check that it contains problem files ' 'and try again.'.format(data_dir)) problems = [os.path.join(data_dir, data) for data in test_data] problems.sort() for problem in problems: logger.info(problem) return problems
def _parse_line_by_line(self): """ Parses the NIST file one line at the time. :returns: the equation, data pattern, and starting values sections of the file :rtype: str, str, list of list of float """ lines = self.file.readlines() idx, ignored_lines = 0, 0 while idx < len(lines): line = lines[idx].strip() idx += 1 if not line: continue if line.startswith('Model:'): equation_text, idx = self._get_nist_model(lines, idx) elif 'Starting values' in line or 'Starting Values' in line: starting_values, idx = self._get_nist_starting_values( lines, idx) elif line.startswith("Data:"): if " x" in line and " y " in line: data_pattern_text, idx = self._get_data_txt(lines, idx) elif line.startswith("Dataset Name:"): name = line.split(':', 1)[1] name = name.split('(', 1)[0] name = name.strip() else: ignored_lines += 1 logger.info("%s lines were ignored in this problem file", ignored_lines) return equation_text, data_pattern_text, starting_values, name