diff --git a/binarycpython/utils/Moe_di_Stefano_2017.py b/binarycpython/utils/Moe_di_Stefano_2017.py index 0cfb636041eddcb0666836250ec94ca19879e533..31de51a4e9af0873971be34465ef59c9bcb1037f 100644 --- a/binarycpython/utils/Moe_di_Stefano_2017.py +++ b/binarycpython/utils/Moe_di_Stefano_2017.py @@ -813,6 +813,7 @@ eccentricity3=0 "clean load flag": False, "clean all": False, } + if not options: options = {} options = update_dicts(default_options, options) diff --git a/binarycpython/utils/dataIO.py b/binarycpython/utils/dataIO.py index f6e8990bcb38170cb182d2cbfbd72b717874e320..9f62f748ccdecb42b841b72b3bdcda5461310128 100644 --- a/binarycpython/utils/dataIO.py +++ b/binarycpython/utils/dataIO.py @@ -672,16 +672,19 @@ class dataIO(): else: return None - def open(self,file, mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, compression=None, compresslevel=None): + def open(self,file, mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, compression=None, compresslevel=None, vb=False): """ Wrapper for open() with automatic compression based on the file extension. """ if compression is None: compression = self.compression_type(file) - print("open() with mode = {mode}, compression {compression}".format( - compression=compression, - mode=mode)) + if vb: + print("open() file at \"{file}\" with mode = {mode}, compression {compression}, compresslevel {compresslevel}".format( + file=file, + compression=compression, + compresslevel=compresslevel, + mode=mode)) if compression: if compresslevel is None: compresslevel = 9 @@ -690,10 +693,14 @@ class dataIO(): # defaults to binary, which isn't compatible with JSON, # so default to text if not specified otherwise mode += 't' + if vb: + print("open() adding text mode") else: encoding = None errors = None newline = None + if vb: + print("open() setting encoding=errors=newline=None") if compression is "bzip2": file_object = bz2.open(file, mode=mode, @@ -719,4 +726,7 @@ class dataIO(): newline=newline, closefd=closefd, opener=opener) + + if vb: + print("open() return file_object =",file_object) return file_object diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index 75ff3df4ddd30e9bcc7d436c692d253b5d3f89c6..875398fe9231be171ac4c288c94ac3388e663ef1 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -370,7 +370,10 @@ def call_binary_c_config(argument): ######################################################## -def verbose_print(message: str, verbosity: int, minimal_verbosity: int) -> None: +def verbose_print(message: str, + verbosity: int, + minimal_verbosity: int, + newline = "\n") -> None: """ Function that decides whether to print a message based on the current verbosity and its minimum verbosity @@ -384,7 +387,10 @@ def verbose_print(message: str, verbosity: int, minimal_verbosity: int) -> None: """ if verbosity >= minimal_verbosity: - print(message) + if newline is "\n": + print(message) + else: + print(message,newline,sep="",end="") sys.stdout.flush() diff --git a/binarycpython/utils/grid_logging.py b/binarycpython/utils/grid_logging.py index b695da1497a4b08661ad406067d44881076c7418..e843e0744981a2fa876007398583470fe59ba8d0 100644 --- a/binarycpython/utils/grid_logging.py +++ b/binarycpython/utils/grid_logging.py @@ -281,7 +281,7 @@ class grid_logging(): ) else: self.verbose_print( - "{opening_colour}{system_number}{modulo} {time_colour}{hours:02d}:{minutes:02d}:{seconds:02d} tpr={tpr:2.2e} {mem_use_colour}mem:{mem_use:.1f}MB {system_string_colour}{system_string}{closing_colour}".format( + "{opening_colour}{system_number}{modulo} {time_colour}{hours:02d}:{minutes:02d}:{seconds:02d} tpr={tpr:2.2e} {mem_use_colour}mem:{mem_use:.1f}MB {system_string_colour}{system_string}{closing_colour}{newline}".format( opening_colour=self.ANSI_colours["reset"] + self.ANSI_colours["yellow on black"], system_number=system_number, @@ -296,6 +296,7 @@ class grid_logging(): system_string_colour=self.ANSI_colours["yellow"], system_string=system_string, closing_colour=self.ANSI_colours["reset"], + newline=self.grid_options["log_newline"] ), self.grid_options["verbosity"], 1, diff --git a/binarycpython/utils/grid_options_defaults.py b/binarycpython/utils/grid_options_defaults.py index 742c2037ce1af9cf0f5db4453525731fc6074243..1d1538ff99061551373aa36188576fedfe377f94 100644 --- a/binarycpython/utils/grid_options_defaults.py +++ b/binarycpython/utils/grid_options_defaults.py @@ -76,11 +76,12 @@ class grid_options_defaults(): # Execution log: ########################## "verbosity": 0, # Level of verbosity of the simulation - "log_file": os.path.join( + "log_file": os.path.join( # not used (yet?) temp_dir(), "binary_c_python.log" ), # Set to None to not log to file. The directory will be created "log_dt": 5, # time between vb=1 logging outputs "n_logging_stats": 50, # number of logging stats used to calculate time remaining (etc.) default = 50 + "log_newline" : "\n", # newline character in logs ("\n" for newlines, "\x0d" for carriage return) ########################## # binary_c files ########################## @@ -200,7 +201,7 @@ class grid_options_defaults(): ######################################## "HPC_force_join" : 0, # if True, and the HPC variable ("slurm" or "condor") is 3, skip checking our own job and force the join "HPC_rebuild_joinlist": 0, # if True, ignore the joinlist we would usually use and rebuild it automatically - + ######################################## # Slurm stuff ######################################## @@ -278,6 +279,9 @@ class grid_options_defaults(): "_binary_c_executable": "Full path to the binary_c executable. This options is not used in the population object.", "_binary_c_shared_library": "Full path to the libbinary_c file. This options is not used in the population object", "verbosity": "Verbosity of the population code. Default is 0, by which only errors will be printed. Higher values will show more output, which is good for debugging.", + "log_dt" : "Time between verbose logging output.", + "log_newline" : "Newline character used at the end of verbose logging statements. This is \\n (newline) by default, but \\x0d (carriage return) might also be what you want.", + "n_logging_stats" : "Number of logging statistics used to calculate time remaining (etc.). E.g., if you set this to 10 the previous 10 calls to the verbose log will be used to construct an estimate of the time remaining.", # deprecated: "binary": "Set this to 1 if the population contains binaries. Input: int", # TODO: write what effect this has. "num_cores": "The number of cores that the population grid will use. You can set this manually by entering an integer great than 0. When 0 uses all logical cores. When -1 uses all physical cores. Input: int", "num_processes" : "Number of processes launched by multiprocessing. This should be set automatically by binary_c-python, not by the user.",