diff --git a/binarycpython/utils/custom_logging_functions.py b/binarycpython/utils/custom_logging_functions.py index 4d8ee5f7595ebf972c53f0dd01f9726ccfa64548..efad8c2bc17294a23619f6fabcebaa788f4d899b 100644 --- a/binarycpython/utils/custom_logging_functions.py +++ b/binarycpython/utils/custom_logging_functions.py @@ -6,7 +6,8 @@ import ctypes import random import uuid -from binarycpython.utils.functions import temp_dir +from binarycpython.utils.functions import temp_dir, remove_file + def autogen_C_logging_code(logging_dict, verbose=0): """ @@ -109,16 +110,15 @@ def binary_c_write_log_code(code, filename, verbose=0): """ cwd = os.getcwd() - filePath = os.path.join(cwd, filename) - if os.path.exists(filePath): - try: - os.remove(filePath) - except: - print("Error while deleting file {}".format(filePath)) + + # Remove if it exists + remove_file(filePath, verbose) if verbose > 0: print("Writing the custom logging code to {}".format(filePath)) + + # Write again with open(filePath, "w") as f: f.write(code) @@ -248,12 +248,7 @@ def compile_shared_lib(code, sourcefile_name, outfile_name, verbose=0): binary_c_write_log_code(code, sourcefile_name, verbose) # Remove the library if present: - if os.path.exists(outfile_name): - try: - print("removing", outfile_name) - os.remove(outfile_name) - except: - print("Error while deleting file {}".format(outfile_name)) + remove_file(outfile_name, verbose) # create compilation command compilation_dict = return_compilation_dict(verbose) diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index dcdc4ffe796a7628cdd5381cb48008712e44e27d..2fb54fc6986480fb90dd6d6c9b1d8cea20f144d0 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -13,6 +13,24 @@ import binary_c_python_api # create_and_load_logging_function, # ) + +def remove_file(file, verbose=0): + """ + Function to remove files but with verbosity + """ + + if os.path.exists(file): + try: + if verbose > 0: + print("Removed {}".format(file)) + os.remove(file) + + # TODO: Put correct exception here. + except: + print("Error while deleting file {}".format(file)) + raise FileNotFoundError + + def temp_dir(): """ Function to return the path the custom logging library shared object and script will be written to. @@ -496,6 +514,7 @@ def get_help(param_name="", print_help=True, return_dict=False, fail_silently=Fa ) return None + def parse_output(output, selected_header): """ Function that parses output of binary_c: diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 0706050710e07aa99c93215d88a9f59d5cf1b551..41e77311dcd2e352b942db779edd492f7fcd5a84 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -26,6 +26,7 @@ from binarycpython.utils.functions import ( get_defaults, parse_binary_c_version_info, output_lines, + remove_file, ) @@ -64,7 +65,7 @@ class Population(object): self.argline_dict = {} # Set main process id - self.grid_options['main_pid'] = os.getpid() + self.grid_options["main_pid"] = os.getpid() ################################################### # Argument functions @@ -512,7 +513,9 @@ class Population(object): out = binary_c_python_api.run_system( argstring=binary_cmdline_string, - custom_logging_func_memaddr=self.grid_options["custom_logging_func_memaddr"], + custom_logging_func_memaddr=self.grid_options[ + "custom_logging_func_memaddr" + ], store_memaddr=self.grid_options["store_memaddr"], population=1, ) @@ -546,7 +549,7 @@ class Population(object): """ ### Custom logging code: - self.set_custom_logging() + self.set_custom_logging() # Get argument line argline = self.return_argline(self.bse_options) @@ -554,10 +557,12 @@ class Population(object): # Run system out = binary_c_python_api.run_system( argstring=argline, - custom_logging_func_memaddr=self.grid_options["custom_logging_func_memaddr"], + custom_logging_func_memaddr=self.grid_options[ + "custom_logging_func_memaddr" + ], store_memaddr=self.grid_options["store_memaddr"], population=0, - ) + ) # TODO: add call to function that cleans up the temp customlogging dir, and unloads the loaded libraries. # TODO: make a switch to turn this off @@ -585,7 +590,7 @@ class Population(object): # https://python-forum.io/Thread-Dynamic-updating-of-a-nested-dictionary-in-multiprocessing-pool # https://stackoverflow.com/questions/28740955/working-with-pathos-multiprocessing-tool-in-python-and manager = pathos_multiprocess.Manager() - self.grid_options['result_dict'] = manager.dict() + self.grid_options["result_dict"] = manager.dict() # Create pool p = Pool(processes=self.grid_options["amt_cores"]) @@ -614,7 +619,9 @@ class Population(object): binary_cmdline_string = self.return_argline(full_system_dict) out = binary_c_python_api.run_system( argstring=binary_cmdline_string, - custom_logging_func_memaddr=self.grid_options["custom_logging_func_memaddr"], + custom_logging_func_memaddr=self.grid_options[ + "custom_logging_func_memaddr" + ], store_memaddr=self.grid_options["store_memaddr"], population=1, ) @@ -689,8 +696,8 @@ class Population(object): ################################################### # Gridcode functions - # - # Function below are used to run populations with + # + # Function below are used to run populations with # a variable grid ################################################### @@ -1163,26 +1170,27 @@ class Population(object): ################################################### # Montecarlo functions - # + # # Functions below are used to run populations with # Monte carlo ################################################### ################################################### # Population from file functions - # + # # Functions below are used to run populations from # a file containing binary_c calls ################################################### - ################################################### # Unordered functions - # + # # Functions that arent ordered yet ################################################### - def write_binary_c_calls_to_file(self, output_dir=None, output_filename=None, include_defaults=False): + def write_binary_c_calls_to_file( + self, output_dir=None, output_filename=None, include_defaults=False + ): """ Function that loops over the gridcode and writes the generated parameters to a file. In the form of a commandline call @@ -1216,14 +1224,14 @@ class Population(object): else: binary_c_calls_filename = "binary_c_calls.txt" - binary_c_calls_full_filename = os.path.join(binary_c_calls_output_dir, binary_c_calls_filename) + binary_c_calls_full_filename = os.path.join( + binary_c_calls_output_dir, binary_c_calls_filename + ) print("Writing binary_c calls to {}".format(binary_c_calls_full_filename)) # Write to file - with open( - binary_c_calls_full_filename, "w" - ) as f: - # Get defaults and clean them, then overwrite them with the set values. + with open(binary_c_calls_full_filename, "w") as f: + # Get defaults and clean them, then overwrite them with the set values. if include_defaults: # TODO: make sure that the defaults here are cleaned up properly cleaned_up_defaults = self.cleaned_up_defaults() @@ -1242,7 +1250,6 @@ class Population(object): print("Error. No grid function found!") raise KeyError - def cleanup_defaults(self): """ Function to clean up the default values: @@ -1257,28 +1264,11 @@ class Population(object): cleaned_dict = {} binary_c_defaults = self.return_binary_c_defaults().copy() for key in binary_c_defaults: - if not binary_c_defaults[key] in ['NULL', '', 'Function']: + if not binary_c_defaults[key] in ["NULL", "", "Function"]: cleaned_dict[key] = binary_c_defaults[key] return cleaned_dict - - def remove_file(self, file, verbose): - """ - Function to remove files but with verbosity - """ - - if os.path.exists(file): - try: - if verbose > 0: - print("Removed {}".format(file)) - os.remove(file) - # TODO: Put correct exception here. - except: - print("Error while deleting file {}".format(file)) - raise FileNotFoundError - - def clean_up_custom_logging(self, evol_type): """ Function to clean up the custom logging. @@ -1301,7 +1291,7 @@ class Population(object): # remove shared library files if self.grid_options["custom_logging_shared_library_file"]: - self.remove_file( + remove_file( self.grid_options["custom_logging_shared_library_file"], self.grid_options["verbose"], ) @@ -1311,7 +1301,6 @@ class Population(object): print("Cleaning up the custom logging stuffs. type: population") # TODO: make sure that these also work. not fully sure if necessary tho. whether its a single file, or a dict of files/memaddresses - def increment_probtot(self, prob): """ Function to add to the total probability @@ -1331,6 +1320,4 @@ class Population(object): # """ - - -################################################################################################ \ No newline at end of file +################################################################################################ diff --git a/binarycpython/utils/grid_options_defaults.py b/binarycpython/utils/grid_options_defaults.py index 429c86657a04f61ad01715b2ebe62d9837fe1dbc..6e212d3997a377f0626a63a78363c1190c45b3d3 100644 --- a/binarycpython/utils/grid_options_defaults.py +++ b/binarycpython/utils/grid_options_defaults.py @@ -12,8 +12,7 @@ grid_options_defaults_dict = { "binary": 0, # FLag on whether the systems are binary systems or single systems. "parse_function": None, # FUnction to parse the output with. "tmp_dir": temp_dir(), # Setting the temp dir of the program - "main_pid": -1, # Placeholder for the main process id of the run. - + "main_pid": -1, # Placeholder for the main process id of the run. # "output_dir": ########################## # binary_c files @@ -62,17 +61,14 @@ grid_options_defaults_dict = { "probtot": 0, # total probability "weight": 1.0, # weighting for the probability "repeat": 1.0, # number of times to repeat each system (probability is adjusted to be 1/repeat) - "results_per_worker": {}, # dict which can store info per worker. meh. doesnt work properly - - + "results_per_worker": {}, # dict which can store info per worker. meh. doesnt work properly "start_time_evolution": 0, # Start time of the grid - "end_time_evolution": 0, # end time of the grid - "error": 0, # error? - "failed_count": 0, # amt of failed systems - "failed_prob": 0, # Summed probability of failed systems - "id": 0, # Random id of this grid/population run, - "modulo": 1, # run modulo n of the grid. - + "end_time_evolution": 0, # end time of the grid + "error": 0, # error? + "failed_count": 0, # amt of failed systems + "failed_prob": 0, # Summed probability of failed systems + "id": 0, # Random id of this grid/population run, + "modulo": 1, # run modulo n of the grid. ## Grid type evolution "grid_variables": {}, # grid variables "grid_code": None, # literal grid code @@ -81,9 +77,7 @@ grid_options_defaults_dict = { # TODO: make MC options ## Evolution from source file # TODO: make run from sourcefile options. - - ## Other no yet implemented parts for the population evolution part - + ## Other no yet implemented parts for the population evolution part # # start at this model number: handy during debugging # # to skip large parts of the grid # start_at => 0 @@ -106,29 +100,12 @@ grid_options_defaults_dict = { # _lock => undef, # _evcode_pids => [], # }; - - - - - - - - - - - - - ######################################## # Slurm stuff ######################################## - "slurm": 0, # dont use the slurm by default - "slurm_command": "", # Command that slurm runs (e.g. run_flexigrid or join_datafiles) - "slurm_dir": "", #working directory containin scripts output logs etc. - - - - + "slurm": 0, # dont use the slurm by default + "slurm_command": "", # Command that slurm runs (e.g. run_flexigrid or join_datafiles) + "slurm_dir": "", # working directory containin scripts output logs etc. # slurm_njobs=>'', # number of scripts # slurm_jobid=>'', # slurm job id (%A) # slurm_jobarrayindex=>'', # slurm job array index (%a) @@ -147,8 +124,6 @@ grid_options_defaults_dict = { # # which means it allocates all the CPUs in a node to the job # slurm_control_CPUs=>0, # if so, leave this many for Perl control (0) # slurm_array=>undef,# override for --array, useful for rerunning jobs - - # ######################################## # # Condor stuff # ######################################## @@ -182,20 +157,6 @@ grid_options_defaults_dict = { # condor_resubmit_submitted=>0, # condor_resubmit_running=>0, # condor_resubmit_crashed=>0, - - - - - - - - - - - - - - ########################## # Unordered. Need to go through this. Copied from the perl implementation. ########################## @@ -207,7 +168,6 @@ grid_options_defaults_dict = { # timeout=>15, # seconds until timeout # log_filename=>"/scratch/davidh/results_simulations/tmp/log.txt", # # current_log_filename=>"/scratch/davidh/results_simulations/tmp/grid_errors.log", - ############################################################ # Set default grid properties (in %self->{_grid_options}} # and %{$self->{_bse_options}}) @@ -227,7 +187,6 @@ grid_options_defaults_dict = { # suspend_files=>[$tmp.'/force_binary_c_suspend', # './force_binary_c_suspend'], # snapshot_file=>$tmp.'/binary_c-snapshot', - # ######################################## # # infomration about the running grid script # ######################################## @@ -316,7 +275,6 @@ grid_options_defaults_dict = { # results_hash_dumpfile => '', # # compress files with bzip2 by default # compress_results_hash => 1, - # ######################################## # # CPU # ######################################## @@ -356,16 +314,6 @@ grid_options_defaults_dict = { # 'run_flexigrid_thread', # 'thread_vb' # ], - - - - - - - - - - # ######################################## # # INPUT/OUTPUT # ######################################## @@ -438,5 +386,4 @@ grid_options_defaults_dict = { # # than a normal initiation: this enables you to # # stop and start a grid # starting_snapshot_file=>undef, - } diff --git a/binarycpython/utils/run_system_wrapper.py b/binarycpython/utils/run_system_wrapper.py index 6c2f0fef5e0b9739585c0a96b408224c58a92cb9..b6f471baf8ad867dd33774213843a03f59e945d9 100644 --- a/binarycpython/utils/run_system_wrapper.py +++ b/binarycpython/utils/run_system_wrapper.py @@ -1,15 +1,17 @@ import binary_c_python_api from binarycpython.utils.functions import ( - get_defaults, - create_arg_string, - get_arg_keys, - ) + get_defaults, + create_arg_string, + get_arg_keys, + remove_file, +) from binarycpython.utils.custom_logging_functions import ( - create_and_load_logging_function + create_and_load_logging_function, ) + def run_system(**kwargs): """ Function that runs a system. Mostly as a useful utility function that handles all the setup of argument lists etc. @@ -50,22 +52,30 @@ def run_system(**kwargs): # Check if custom logging is required if "custom_logging_code" in kwargs: - func_memaddr, shared_lib_filename = create_and_load_logging_function(kwargs["custom_logging_code"]) + func_memaddr, shared_lib_filename = create_and_load_logging_function( + kwargs["custom_logging_code"] + ) # Check if writing logfile is required: if "log_filename" in kwargs: write_logfile = 1 - - # Construct arguments string and final execution string arg_string = create_arg_string(binary_c_args) binary_c_command = "binary_c {}".format(arg_string) - output = binary_c_python_api.run_system(binary_c_command, custom_logging_func_memaddr=func_memaddr, write_logfile=write_logfile) + # Call binary_c + output = binary_c_python_api.run_system( + binary_c_command, + custom_logging_func_memaddr=func_memaddr, + write_logfile=write_logfile, + ) + # Remove and unload files. . + if "custom_logging_code" in kwargs: + remove_file(shared_lib_filename) if "parse_function" in kwargs: return kwargs["parse_function"](output) else: - return output \ No newline at end of file + return output diff --git a/examples/examples.py b/examples/examples.py index f11bee8ef45fe4aa999b7f44a65bde873a0cf3ef..7d306e3a18ae12f8645765574beb320275ac8b59 100644 --- a/examples/examples.py +++ b/examples/examples.py @@ -50,6 +50,7 @@ def run_example_binary(): run_example_binary() + def run_example_binary_with_run_system(): """ This function serves as an example on the function run_system and parse_output. @@ -123,7 +124,9 @@ def run_example_custom_logging_autogenerated(): custom_logging_code = binary_c_log_code(logging_line) # Generate library and get memaddr - func_memaddr, shared_lib_filename = create_and_load_logging_function(custom_logging_code) + func_memaddr, shared_lib_filename = create_and_load_logging_function( + custom_logging_code + ) # m1 = 15.0 # Msun @@ -142,7 +145,9 @@ def run_example_custom_logging_autogenerated(): metallicity, max_evolution_time, ) - output = binary_c_python_api.run_system(argstring, custom_logging_func_memaddr=func_memaddr) + output = binary_c_python_api.run_system( + argstring, custom_logging_func_memaddr=func_memaddr + ) print(output) diff --git a/pathos_worker_objects.py b/pathos_worker_objects.py index b9d4fa11be73ea848f961f0a00c7fa4a2b43783a..26e4e0017145d52ebf0b765e69c57289b7b8e217 100644 --- a/pathos_worker_objects.py +++ b/pathos_worker_objects.py @@ -14,8 +14,4 @@ print(p) quit() # Execute # TODO: calculate the chunksize value based on: total starcount and cores used. -r = list( - p.imap_unordered( - self.evolve_system_mp, self.yield_system_mp(), chunksize=20 - ) -) +r = list(p.imap_unordered(self.evolve_system_mp, self.yield_system_mp(), chunksize=20)) diff --git a/tests/population/grid_tests.py b/tests/population/grid_tests.py index 858e809c7ec3ea6f0cb313a3a183156acc520134..b1874816134afc09dbf43b6dd6af52150bc3d2ed 100644 --- a/tests/population/grid_tests.py +++ b/tests/population/grid_tests.py @@ -332,10 +332,8 @@ test_pop.add_grid_variable( test_pop.set(verbose=1, amt_cores=2, binary=0, evolution_type="linear") - - # test_pop.evolve_population() # test_pop.generate_grid_code() # test_pop.load_grid_function() # print(test_pop.grid_options['system_generator']) -# test_pop.grid_options['system_generator'](test_pop) \ No newline at end of file +# test_pop.grid_options['system_generator'](test_pop) diff --git a/tests/population/test_population.py b/tests/population/test_population.py index 6393d239af3fc85144d9607796bc31056249387a..56aea16d49b7acbda8315da8df482c00cc392c57 100644 --- a/tests/population/test_population.py +++ b/tests/population/test_population.py @@ -7,9 +7,14 @@ import sys import matplotlib.pyplot as plt from binarycpython.utils.grid import Population -from binarycpython.utils.functions import get_help_all, get_help, create_hdf5, output_lines +from binarycpython.utils.functions import ( + get_help_all, + get_help, + create_hdf5, + output_lines, +) -### +### # Script to generate BH MS systems. @@ -19,24 +24,42 @@ def parse_function(self, output): #################################################### # Get some information from the grid - data_dir = self.custom_options['data_dir'] - base_filename = self.custom_options['base_filename'] + data_dir = self.custom_options["data_dir"] + base_filename = self.custom_options["base_filename"] # Check directory, make if necessary os.makedirs(data_dir, exist_ok=True) #################################################### # - seperator = ' ' - + seperator = " " + # Create filename outfilename = os.path.join(data_dir, base_filename) - result_header = ['zams_mass', 'st_0', 'st_1', 'st_2', 'st_3', 'st_4', 'st_5', 'st_6', 'st_7', 'st_8', 'st_9', 'st_10', 'st_11', 'st_12', 'st_13', 'st_14', 'st_15'] + result_header = [ + "zams_mass", + "st_0", + "st_1", + "st_2", + "st_3", + "st_4", + "st_5", + "st_6", + "st_7", + "st_8", + "st_9", + "st_10", + "st_11", + "st_12", + "st_13", + "st_14", + "st_15", + ] mass_lost_dict = {} for i in range(16): - mass_lost_dict['{}'.format(i)] = 0 + mass_lost_dict["{}".format(i)] = 0 total_mass_lost = 0 @@ -45,12 +68,19 @@ def parse_function(self, output): headerline = el.split()[0] # Check the header and act accordingly - if (headerline=='DAVID_MASSLOSS_SN'): - parameters = ['time', 'mass_1', 'prev_mass_1', 'zams_mass_1', 'stellar_type', 'probability'] + if headerline == "DAVID_MASSLOSS_SN": + parameters = [ + "time", + "mass_1", + "prev_mass_1", + "zams_mass_1", + "stellar_type", + "probability", + ] values = el.split()[1:] - if not float(values[0])==0.0: - mass_lost = float(values[2])-float(values[1]) + if not float(values[0]) == 0.0: + mass_lost = float(values[2]) - float(values[1]) mass_lost_dict[values[4]] += mass_lost initial_mass = values[3] @@ -61,17 +91,17 @@ def parse_function(self, output): for key in mass_lost_dict.keys(): result_list.append(str(mass_lost_dict[key])) - result_dict = self.grid_options['result_dict'] + result_dict = self.grid_options["result_dict"] # This trick is necessary # Make the mass dict and set values - result_dict['mass'] = result_dict.get('mass', {}) - mass_result = result_dict['mass'] + result_dict["mass"] = result_dict.get("mass", {}) + mass_result = result_dict["mass"] mass_result[initial_mass] = mass_result.get(initial_mass, 0) + total_mass_lost - result_dict['mass'] = mass_result + result_dict["mass"] = mass_result + result_dict["probability"] = result_dict.get("probability", 0) + 0.00002123 - result_dict['probability'] = result_dict.get('probability', 0) + 0.00002123 ## Set values test_pop = Population() @@ -86,11 +116,12 @@ Printf("DAVID_MASSLOSS_SN %30.12e %g %g %g %d %g\\n", stardata->star[0].stellar_type, //5 stardata->model.probability //6 ); -""") +""" +) # Set grid variables -resolution = {'M_1': 5, 'q': 5, 'per': 5} +resolution = {"M_1": 5, "q": 5, "per": 5} test_pop.add_grid_variable( name="lnm1", @@ -109,13 +140,13 @@ test_pop.add_grid_variable( name="q", longname="Mass ratio", valuerange=["0.1/M_1", 1], - resolution="{}".format(resolution['q']), - spacingfunc="const(0.1/M_1, 1, {})".format(resolution['q']), + resolution="{}".format(resolution["q"]), + spacingfunc="const(0.1/M_1, 1, {})".format(resolution["q"]), probdist="flatsections(q, [{'min': 0.1/M_1, 'max': 0.8, 'height': 1}, {'min': 0.8, 'max': 1.0, 'height': 1.0}])", dphasevol="dq", precode="M_2 = q * M_1", parameter_name="M_2", - condition="", # Impose a condition on this grid variable. Mostly for a check for yourself + condition="", # Impose a condition on this grid variable. Mostly for a check for yourself ) test_pop.add_grid_variable( @@ -124,7 +155,7 @@ test_pop.add_grid_variable( valuerange=[-2, 12], resolution="{}".format(resolution["per"]), spacingfunc="np.linspace(-2, 12, {})".format(resolution["per"]), - precode="orbital_period = 10** logper\n", # TODO: + precode="orbital_period = 10** logper\n", # TODO: probdist="gaussian(logper,4.8, 2.3, -2.0, 12.0)", parameter_name="orbital_period", dphasevol="dln10per", @@ -133,18 +164,17 @@ test_pop.add_grid_variable( ########################################################################## metallicity = 0.002 test_pop.set( - separation=1000000000, - orbital_period=400000000, - metallicity=metallicity, + separation=1000000000, + orbital_period=400000000, + metallicity=metallicity, M_1=100, M_2=5, - verbose=1, - data_dir=os.path.join(os.environ['BINARYC_DATA_ROOT'], 'testing_python', 'BHMS'), + data_dir=os.path.join(os.environ["BINARYC_DATA_ROOT"], "testing_python", "BHMS"), base_filename="BH_MS_z{}.dat".format(metallicity), parse_function=parse_function, amt_cores=2, - ) +) # out = test_pop.evolve_single() # print(out) @@ -153,15 +183,18 @@ test_pop.set( # quit() test_pop.evolve_population() + def handle_output(test_pop): # $results is a hash reference containing # the results that were added up in parse_data() - results = test_pop.grid_options['result_dict'] + results = test_pop.grid_options["result_dict"] print(results) # output the mass distribution + + handle_output(test_pop) @@ -170,4 +203,4 @@ handle_output(test_pop) # test_pop.export_all_info(use_datadir=True) # # hdf5 -# create_hdf5(test_pop.custom_options['data_dir'], name="BH_MS_z{}.hdf5".format(metallicity)) \ No newline at end of file +# create_hdf5(test_pop.custom_options['data_dir'], name="BH_MS_z{}.hdf5".format(metallicity)) diff --git a/tests/python_API_test.py b/tests/python_API_test.py index e70f0ed8fe50bef66dcf995e5366eea8d58bbd25..6975051523341ee57feea5810136d7b4a4275483 100755 --- a/tests/python_API_test.py +++ b/tests/python_API_test.py @@ -7,21 +7,20 @@ from binarycpython.utils.custom_logging_functions import ( binary_c_log_code, create_and_load_logging_function, ) -from binarycpython.utils.functions import ( - temp_dir, -) +from binarycpython.utils.functions import temp_dir import tempfile ############################################################ # Test script for the api functions -# TODO: Add asserts to these functions and use em as +# TODO: Add asserts to these functions and use em as # unittests ############################################################ # Evolution functionality + def test_run_system(): m1 = 15.0 # Msun m2 = 14.0 # Msun @@ -45,6 +44,7 @@ def test_run_system(): print("\n\nBinary_c output:") print(output) + def test_run_system_with_log(): m1 = 15.0 # Msun m2 = 14.0 # Msun @@ -74,6 +74,7 @@ def test_run_system_with_log(): print("\n\nBinary_c output:") print(output) + def test_run_system_with_custom_logging(): """ """ @@ -88,7 +89,9 @@ def test_run_system_with_custom_logging(): custom_logging_code = binary_c_log_code(logging_line) # Load memory adress - func_memaddr, shared_lib_filename = create_and_load_logging_function(custom_logging_code) + func_memaddr, shared_lib_filename = create_and_load_logging_function( + custom_logging_code + ) # Some values m1 = 15.0 # Msun @@ -111,11 +114,15 @@ def test_run_system_with_custom_logging(): print(func_memaddr) - out = binary_c_python_api.run_system(argstring, custom_logging_func_memaddr=func_memaddr) + out = binary_c_python_api.run_system( + argstring, custom_logging_func_memaddr=func_memaddr + ) print(out) + # Testing other utility functions + def test_return_help(): out = binary_c_python_api.return_help("M_1") print(out) @@ -125,6 +132,7 @@ def test_return_arglines(): out = binary_c_python_api.return_arglines() print(out) + def test_return_help_all(): out = binary_c_python_api.return_help_all("M_1") print(out) @@ -134,12 +142,15 @@ def test_return_version_info(): out = binary_c_python_api.return_version_info() print(out) + # Testing other functions + def test_return_store(): out = binary_c_python_api.return_store("") print(out) + #### if __name__ == "__main__": test_run_system() @@ -157,4 +168,3 @@ if __name__ == "__main__": test_return_version_info() test_return_store() -