From d1c1ee8ae689cb7f83795359c6584f73ec1151db Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Thu, 27 Feb 2020 00:37:36 +0000 Subject: [PATCH] updated stuff --- binarycpython/utils/grid.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 7f9b6754a..3c3a9c416 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -351,6 +351,16 @@ class Population(object): include_binary_c_help_all=include_binary_c_help_all, ) + # Copy dict + all_info_cleaned = copy.deepcopy(all_info) + + + # Clean the all_info_dict: (i.e. transform the function objects to strings) + if all_info_cleaned.get('population_settings', None): + if all_info_cleaned['population_settings']['grid_options']['parse_function']: + all_info_cleaned['population_settings']['grid_options']['parse_function'] = str(all_info_cleaned['population_settings']['grid_options']['parse_function']) + + if use_datadir: base_name = os.path.splitext(self.custom_options["base_filename"])[0] settings_name = base_name + "_settings.json" @@ -366,14 +376,14 @@ class Population(object): print("Writing settings to {}".format(settings_fullname)) # if not outfile.endswith('json'): with open(settings_fullname, "w") as f: - f.write(json.dumps(all_info, indent=4)) + f.write(json.dumps(all_info_cleaned, indent=4)) else: if self.grid_options["verbose"] > 0: print("Writing settings to {}".format(outfile)) # if not outfile.endswith('json'): with open(outfile, "w") as f: - f.write(json.dumps(all_info, indent=4)) + f.write(json.dumps(all_info_cleaned, indent=4)) def set_custom_logging(self): """ @@ -978,6 +988,7 @@ class Population(object): code_string += "import numpy as np\n" code_string += "from binarycpython.utils.distribution_functions import *\n" code_string += "from binarycpython.utils.spacing_functions import *\n" + code_string += "from binarycpython.utils.useful_funcs import *\n" code_string += "\n\n" # Make the function @@ -1123,7 +1134,7 @@ class Population(object): code_string += ( indent * (depth + 1) + "{}".format( - grid_variable["precode"].replace("\n", "\n" + indent * (depth + 1)) + grid_variable["precode"].replace("\n", "\n" + indent * (depth)) ) + "\n" ) @@ -1440,9 +1451,9 @@ class Population(object): # Define frequency if self.grid_options['verbose'] == 1: - print_freq = 10 - else: print_freq = 1 + else: + print_freq = 10 # Calculate amount of time left -- GitLab