From f815b6720c33d71af4e2207defab7f5d59df781f Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Mon, 10 Feb 2020 23:16:30 +0000 Subject: [PATCH] updated scaling routine. fixed automatic hsotname, changed grid --- binarycpython/utils/grid.py | 98 ++++++++++--------- ...result_david-Lenovo-IdeaPad-S340-14IWL.dat | 2 + .../scaling/comparison_result_test_lapto.dat | 3 + ...pulation_comparing_with_multiprocessing.py | 71 ++++++++------ tests/population/scaling/run_tests_new.sh | 3 + 5 files changed, 98 insertions(+), 79 deletions(-) create mode 100644 tests/population/scaling/comparison_result_david-Lenovo-IdeaPad-S340-14IWL.dat create mode 100644 tests/population/scaling/comparison_result_test_lapto.dat create mode 100755 tests/population/scaling/run_tests_new.sh diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 5f6935e77..e11b31a75 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -452,53 +452,6 @@ class Population(object): else: return out - 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()) - os.remove(file) - 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. - Has two types: - 'single': - - removes the compiled shared library (which name is stored in grid_options['custom_logging_shared_library_file']) - - TODO: unloads/frees the memory allocated to that shared library (which is stored in grid_options['custom_logging_func_memaddr']) - - sets both to None - 'multiple': - - TODO: make this and design this - """ - - if evol_type == "single": - if self.grid_options["verbose"] > 0: - print("Cleaning up the custom logging stuff. type: single") - # TODO: Unset custom logging code - - # TODO: Unset function memory adress - # print(self.grid_options["custom_logging_func_memaddr"]) - - - # remove shared library files - if self.grid_options["custom_logging_shared_library_file"]: - self.remove_file( - self.grid_options["custom_logging_shared_library_file"], - self.grid_options["verbose"], - ) - - if evol_type == "population": - if self.grid_options["verbose"] > 0: - 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 evolve_population(self, parse_function, custom_arg_file=None): """ The function that will evolve the population. This function contains many steps @@ -554,7 +507,7 @@ class Population(object): pass # TODO: add call to function that cleans up the temp customlogging dir, and unloads the loaded libraries. - + ################################################### # Testing functions ################################################### @@ -735,6 +688,55 @@ class Population(object): # Unordered functions ################################################### + 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()) + os.remove(file) + 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. + Has two types: + 'single': + - removes the compiled shared library (which name is stored in grid_options['custom_logging_shared_library_file']) + - TODO: unloads/frees the memory allocated to that shared library (which is stored in grid_options['custom_logging_func_memaddr']) + - sets both to None + 'multiple': + - TODO: make this and design this + """ + + if evol_type == "single": + if self.grid_options["verbose"] > 0: + print("Cleaning up the custom logging stuff. type: single") + # TODO: Unset custom logging code + + # TODO: Unset function memory adress + # print(self.grid_options["custom_logging_func_memaddr"]) + + + # remove shared library files + if self.grid_options["custom_logging_shared_library_file"]: + self.remove_file( + self.grid_options["custom_logging_shared_library_file"], + self.grid_options["verbose"], + ) + + if evol_type == "population": + if self.grid_options["verbose"] > 0: + 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 diff --git a/tests/population/scaling/comparison_result_david-Lenovo-IdeaPad-S340-14IWL.dat b/tests/population/scaling/comparison_result_david-Lenovo-IdeaPad-S340-14IWL.dat new file mode 100644 index 000000000..81ae05378 --- /dev/null +++ b/tests/population/scaling/comparison_result_david-Lenovo-IdeaPad-S340-14IWL.dat @@ -0,0 +1,2 @@ +(2, 225, 23.872895002365112, 17.51114845275879, 1.3632969343369403) +(2, 625, 76.88419461250305, 63.15470623970032, 1.2173945409656914) diff --git a/tests/population/scaling/comparison_result_test_lapto.dat b/tests/population/scaling/comparison_result_test_lapto.dat new file mode 100644 index 000000000..bdb6b72f9 --- /dev/null +++ b/tests/population/scaling/comparison_result_test_lapto.dat @@ -0,0 +1,3 @@ +(2, 100, 9.662783145904541, 5.593015670776367, 1.7276517204113695) +(2, 225, 22.48796582221985, 17.04386305809021, 1.319417185269245) +(2, 225, 22.703202962875366, 16.048972845077515, 1.4146203113452718) diff --git a/tests/population/scaling/evolve_population_comparing_with_multiprocessing.py b/tests/population/scaling/evolve_population_comparing_with_multiprocessing.py index be0d7d090..2a11d4ce4 100644 --- a/tests/population/scaling/evolve_population_comparing_with_multiprocessing.py +++ b/tests/population/scaling/evolve_population_comparing_with_multiprocessing.py @@ -9,30 +9,36 @@ from binarycpython.utils.grid import Population from binarycpython.utils.functions import get_help_all, get_help, create_hdf5 -# import argparse +import argparse -# parser = argparse.ArgumentParser() -# parser.add_argument( -# "amt_systems", help="the amount of systems", -# ) +parser = argparse.ArgumentParser() -# parser.add_argument( -# "amt_nodes", help="the amount of nodes that are used for the multiprocessing", -# ) +parser.add_argument( + "resolution_M_1", help="Resolution in M_1", +) -# parser.add_argument( -# "name_testcase", help="The name of the testcase (e.g. laptop, cluster etc)", -# ) +parser.add_argument( + "resolution_per", help="Resolution in period", +) +parser.add_argument( + "amt_cores", help="The amount of nodes that are used for the multiprocessing", +) + +parser.add_argument( + "name_testcase", help="The name of the testcase (e.g. laptop, cluster etc)", +) -# args = parser.parse_args() -# amt_systems = args.amt_systems -# amt_nodes = args.amt_nodes -# name_testcase = args.name_testcase +args = parser.parse_args() +res_m_1 = int(args.resolution_M_1) +res_per = int(args.resolution_per) +AMT_CORES = int(args.amt_cores) +name_testcase = args.name_testcase +############################################################################## ## Quick script to get some output about which stars go supernova when. def output_lines(output): """ @@ -72,25 +78,28 @@ def parse_function(self, output): with open(outfilename, "a") as f: f.write(seperator.join(values) + "\n") + +resolution = {'M_1': res_m_1, 'per': res_per} +total_systems = np.prod([el for el in resolution.values()]) +# AMT_CORES = int(amt_cores) + + test_pop = Population() test_pop.set(verbose=1, - amt_cores=4, + amt_cores=AMT_CORES, binary=1, ) - -resolution = {'M_1': 10, 'per': 10} - test_pop.add_grid_variable( name="M_1", longname="log primary mass", - valuerange=[10, 100], + valuerange=[1, 100], resolution="{}".format(resolution['M_1']), - spacingfunc="const(10, 100, {})".format(resolution['M_1']), + spacingfunc="const(1, 100, {})".format(resolution['M_1']), precode="", # precode="M_1=math.exp(lnm1)", - probdist="flat(M_1)", + probdist="Kroupa2001(M_1)", # probdist='self.custom_options["extra_prob_function"](M_1)', dphasevol="dlnm1", parameter_name="M_1", @@ -111,14 +120,6 @@ test_pop.add_grid_variable( condition='self.grid_options["binary"]==1', ) -test_pop.set(verbose=1, - amt_cores=2, - binary=1, -) - -total_systems = np.prod([el for el in resolution.values()]) -AMT_CORES = 2 - # Lin total_lin_start = time.time() @@ -140,4 +141,12 @@ total_mp_stop = time.time() total_mp = total_mp_stop - total_mp_start print("MP ({} nodes) run with {} systems: {} of which {} spent on evolving the systems".format(AMT_CORES, total_systems, total_mp, evolve_mp_time)) -print("The speed up by using MP is: {}".format(total_lin/total_mp)) \ No newline at end of file +speed_up = total_lin/total_mp +print("The speed up by using MP is: {}".format(total_lin/total_mp)) + + +# Write to file: +# amt_cores, amt_systems, total_time_lin, total_time_mp, speedup +with open("comparison_result_{}.dat".format(name_testcase), "a") as f: + res = (AMT_CORES, total_systems, total_lin, total_mp, speed_up) + f.write(str(res) + "\n") \ No newline at end of file diff --git a/tests/population/scaling/run_tests_new.sh b/tests/population/scaling/run_tests_new.sh new file mode 100755 index 000000000..ad5386a13 --- /dev/null +++ b/tests/population/scaling/run_tests_new.sh @@ -0,0 +1,3 @@ +#!/bin/bash +python evolve_population_comparing_with_multiprocessing.py 25 25 2 "${HOSTNAME}" + -- GitLab