From 02430d2b3bb6d9ce2c9196fc371a68c77e4c0d05 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Tue, 29 Jun 2021 22:03:48 +0100 Subject: [PATCH] Updated thing for grid --- binarycpython/utils/grid.py | 49 ++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index bd592001f..577b7ba5c 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -913,6 +913,34 @@ class Population: for _ in range(amt_cores): job_queue.put("STOP") + def format_ensemble_results(self, ensemble_dictionary): + """ + Function to handle all the steps of formatting the ensemble output again. + + Input: + ensemble_dictionary: dictionary containing all the ensemble results + """ + + original_ensemble_results = ensemble_dictionary + + float_format_ensemble_results = recursive_change_key_to_float(original_ensemble_results) + del original_ensemble_results + gc.collect() + + # Then sort the dictionary + sorted_ensemble_results = custom_sort_dict(float_format_ensemble_results) + del float_format_ensemble_results + gc.collect() + + # Then Change the keys back to a string but with a %g format. + reformatted_ensemble_results = recursive_change_key_to_string(sorted_ensemble_results) + del sorted_ensemble_results + gc.collect() + + # Put back in the dictionary + return reformatted_ensemble_results + + def _evolve_population_grid(self): """ Function to evolve the population with multiprocessing approach. @@ -990,27 +1018,14 @@ class Population: # Extra ensemble result manipulation: # We need to reformat and multiply by a factor - original_ensemble_results = combined_output_dict['ensemble_results'] - - float_format_ensemble_results = recursive_change_key_to_float(original_ensemble_results) - del original_ensemble_results - gc.collect() - # Then sort the dictionary - sorted_ensemble_results = custom_sort_dict(float_format_ensemble_results) - del float_format_ensemble_results - gc.collect() - - # Then Change the keys back to a string but with a %g format. - reformatted_ensemble_results = recursive_change_key_to_string(sorted_ensemble_results) - del sorted_ensemble_results - gc.collect() - - # Put back in the dictionary - combined_output_dict['ensemble_results'] = reformatted_ensemble_results + combined_output_dict['ensemble_results']['ensemble'] = self.format_ensemble_results(combined_output_dict['ensemble_results']['ensemble']) gc.collect() # Multiply the value by a factor: + # if self.grid_options['ensemble_factor_in_probability_weighted_mass']: + + # Put the values back as object properties self.grid_results = combined_output_dict["results"] -- GitLab