From a8c1fa27b09ae32173d9841a464f43038cb52edd Mon Sep 17 00:00:00 2001
From: David Hendriks <davidhendriks93@gmail.com>
Date: Tue, 12 Jan 2021 15:36:49 +0000
Subject: [PATCH] removed some functions for the persistent data cause that
 wasnt persistent when passed through threads

---
 binarycpython/utils/grid.py | 87 ++-----------------------------------
 1 file changed, 4 insertions(+), 83 deletions(-)

diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py
index c6c7635bc..36f3833b9 100644
--- a/binarycpython/utils/grid.py
+++ b/binarycpython/utils/grid.py
@@ -607,75 +607,8 @@ class Population:
     # Ensemble functions
     ###################################################
 
-    def _load_persistent_data_memory_dict(self):
-        """
-        Function that loads a set amount (amt_cores) of persistent data memory adresses to
-        pass to binary_c.
-        """
-
-        for thread_id in range(self.grid_options["amt_cores"]):
-            persistent_data_memaddr = (
-                _binary_c_bindings.return_persistent_data_memaddr()
-            )
-            self.persistent_data_memory_dict[thread_id] = persistent_data_memaddr
-        verbose_print(
-            "Created the following dict with persistent memaddresses: {}".format(
-                self.persistent_data_memory_dict
-            ),
-            self.grid_options["verbosity"],
-            1,
-        )
-
-    def _free_persistent_data_memory_and_combine_results_and_output(self):
-        """
-        Function that loads a set amount of persisten data memory adresses to
-        pass to binary_c.
-
-        TODO: fix the function
-        TODO: remove this function probably.
-        TODO: add option to delay combining all the ensemble outputs.
-        """
-
-        combined_ensemble_json = {}
-
-        for thread_id in self.persistent_data_memory_dict:
-            persistent_data_memaddr = self.persistent_data_memory_dict[thread_id]
-
-            verbose_print(
-                "Freeing {} (thread {})and merging output to combined dict".format(
-                    persistent_data_memaddr, thread_id
-                ),
-                self.grid_options["verbosity"],
-                1,
-            )
-
-            # Get the output and decode it correctly to get the numbers correct
-            ensemble_raw_output = _binary_c_bindings.free_persistent_data_memaddr_and_return_json_output(
-                persistent_data_memaddr
-            )
-
-            print("ensemble_raw_output: ", ensemble_raw_output)
-
-            # Readout the raw string and get the ensemble_json str:
-            parsed_json = extract_ensemble_json_from_string(ensemble_raw_output)
-
-            # Combine the output with the main output
-            combined_ensemble_json = merge_dicts(combined_ensemble_json, parsed_json)
-
-        # Write results to file.
-        # TODO: Make sure everything is checked beforehand
-        full_output_filename = os.path.join(
-            self.custom_options["data_dir"], self.custom_options["ensemble_output_name"]
-        )
-        verbose_print(
-            "Writing ensemble output to {}".format(full_output_filename),
-            self.grid_options["verbosity"],
-            1,
-        )
-
-        # Output to dir:
-        with open(full_output_filename, "w") as output_file:
-            output_file.write(json.dumps(combined_ensemble_json, indent=4))
+    # Now they are stored in the _process_run_population thing. 
+    # Needed less code since they all 
 
     ###################################################
     # Evolution functions
@@ -882,15 +815,9 @@ class Population:
         for output_dict in result:
             combined_output_dict = merge_dicts(combined_output_dict, output_dict)
 
-        # handle the ensemble if necessary
-        if self.bse_options.get("ensemble", None):
-            self._free_persistent_data_memory_and_combine_results_and_output()
-
-        print(combined_output_dict)
-
         # Put the values back as object properties
         self.grid_options["results"] = combined_output_dict["results"]
-        self.grid_options["ensemble_results"] = combined_output_dict["ensemble_results"]
+        self.grid_options["ensemble_results"] = combined_output_dict["ensemble_results"] # Ensemble results are also passed as output from that dictionary
         self.grid_options["_failed_count"] = combined_output_dict["_failed_count"]
         self.grid_options["_failed_prob"] = combined_output_dict["_failed_prob"]
         self.grid_options["_failed_systems_error_codes"] = list(
@@ -913,7 +840,7 @@ class Population:
         persistent_data_memaddr = -1
         if self.bse_options.get("ensemble", 0) == 1:
             persistent_data_memaddr = self.persistent_data_memory_dict[self.process_ID]
-            print("thread {}: persistent_data_memaddr: ".format(self.process_ID), persistent_data_memaddr)
+            # print("thread {}: persistent_data_memaddr: ".format(self.process_ID), persistent_data_memaddr)
 
         # Get results binary_c
         out = _binary_c_bindings.run_system(
@@ -929,12 +856,6 @@ class Population:
         # Check for errors
         _ = self._check_binary_c_error(out, full_system_dict)
 
-        # print("custom output:")
-        # ensemble_raw_output = _binary_c_bindings.free_persistent_data_memaddr_and_return_json_output(
-        #     persistent_data_memaddr
-        # )
-        # print("ensemble_raw_output custom: ", ensemble_raw_output)
-
         # Have some user-defined function do stuff with the data.
         if self.grid_options["parse_function"]:
             self.grid_options["parse_function"](self, out)
-- 
GitLab