diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 7f9b6754a0dade92699ce4b78478f2dd6461b88c..3c3a9c4167b88eba3aab5735de55c650f5f74243 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