def dev__write_kde_file(): kde_data_fn = 'pyposmat.kde.test.out' try: os.remove(kde_data_fn) except FileNotFoundError as e: pass testing_set = get_testing_set() o = PyposmatDataAnalyzer() o.initialize_configuration(config_fn=testing_set['config_fn']) o.initialize_results_data(results_data_fn=testing_set['results_data_fn']) is_survive_idx, filter_info = o.analyze_results( i_iteration=testing_set['i_iteration']) o.write_kde_file(filename=kde_data_fn) print(o.kde_data.df['sim_id'])
def analyze_results(self, i_iteration, data_fn=None, config_fn=None, kde_fn=None, analysis_fn=None): """ analyze the results of the simulation this method analyzes the results of the simulation, and does post simulation tasks, such as filtering by qoi performance, pareto optimization, etc. Args: data_fn(str): the path of the data file. By default this is set to none where the the file will be determine by i_iteration and internal attributes config_fn(str): the path of the data file. By default this is set to none where the the file will be determine by i_iteration and internal attributes kde_fn(str): the path of the data file. By default this is set to none where the the file will be determine by i_iteration and internal attributes """ if data_fn is None: data_fn = os.path.join(\ self.root_directory, self.data_directory, 'pyposmat.results.{}.out'.format(i_iteration)) if config_fn is None: config_fn = os.path.join(\ self.root_directory, self.configuration_filename) if kde_fn is None: kde_fn = os.path.join(\ self.root_directory, self.data_directory, 'pyposmat.kde.{}.out'.format(i_iteration+1)) if analysis_fn is None: analysis_fn = os.path.join(self.root_directory, self.data_directory, 'pyposmat.analysis.out') data_analyzer = PyposmatDataAnalyzer() data_analyzer.initialize_configuration(config_fn=config_fn) data_analyzer.analyze_results_data(i_iteration, filename=data_fn) assert isinstance(data_analyzer.results_statistics, OrderedDict) if os.path.isfile(analysis_fn): data_analyzer.read_analysis_file(filename=analysis_fn) self.log( data_analyzer.str__results_descriptive_statistics( statistics=data_analyzer.results_statistics)) self.log(data_analyzer.str__qoi_filtering_summary()) data_analyzer.write_kde_file(filename=kde_fn) data_analyzer.analyze_kde_data(i_iteration, filename=kde_fn) assert isinstance(data_analyzer.kde_statistics, OrderedDict) self.log( data_analyzer.str__kde_descriptive_statistics( statistics=data_analyzer.kde_statistics)) data_analyzer.update_analysis(i_iteration) data_analyzer.write_analysis_file(filename=analysis_fn)
import pypospack.utils from pypospack.io.filesystem import OrderedDictYAMLLoader from pypospack.pyposmat.data import PyposmatConfigurationFile from pypospack.pyposmat.data import PyposmatDataFile from pypospack.pyposmat.data import PyposmatDataAnalyzer data_directory = os.path.join(pypospack.utils.get_pypospack_root_directory(), 'data', 'Si__sw__data', 'pareto_optimization_1') config_fn = os.path.join(data_directory, 'pyposmat.config.in') analysis_fn = 'pyposmat.analysis.out' assert os.path.isdir(data_directory) assert os.path.isfile(config_fn) o = PyposmatDataAnalyzer() o.initialize_configuration(config_fn=config_fn) n_iterations = o.configuration.n_iterations print("n_iterations:{}".format(n_iterations)) # read analysis results to file system if os.path.isfile(analysis_fn): with open(analysis_fn, 'r') as f: analysis_results = yaml.load(f, OrderedDictYAMLLoader) else: analysis_results = OrderedDict() for i in range(n_iterations): if i not in analysis_results: print('i_iteration:{}'.format(i)) analysis_results[i] = OrderedDict()