diff --git a/binarycpython/utils/custom_logging_functions.py b/binarycpython/utils/custom_logging_functions.py index efad8c2bc17294a23619f6fabcebaa788f4d899b..763b4f143732ab161643c0d6b5a012d596d3513b 100644 --- a/binarycpython/utils/custom_logging_functions.py +++ b/binarycpython/utils/custom_logging_functions.py @@ -240,7 +240,7 @@ def return_compilation_dict(verbose=0): def compile_shared_lib(code, sourcefile_name, outfile_name, verbose=0): """ Function to write the custom logging code to a file and then compile it. - + TODO: nicely put in the -fPIC """ @@ -289,7 +289,8 @@ def compile_shared_lib(code, sourcefile_name, outfile_name, verbose=0): def create_and_load_logging_function(custom_logging_code, verbose=0): """ - Function to automatically compile the shared library with the given custom logging code and load it with ctypes + Function to automatically compile the shared library with the given + custom logging code and load it with ctypes returns: memory adress of the custom logging function in a int type. @@ -312,9 +313,10 @@ def create_and_load_logging_function(custom_logging_code, verbose=0): print("loading shared library for custom logging") # Loading library - dll1 = ctypes.CDLL("libgslcblas.so", mode=ctypes.RTLD_GLOBAL) - dll2 = ctypes.CDLL("libgsl.so", mode=ctypes.RTLD_GLOBAL) - dll3 = ctypes.CDLL("libbinary_c.so", mode=ctypes.RTLD_GLOBAL) + _ = ctypes.CDLL("libgslcblas.so", mode=ctypes.RTLD_GLOBAL) + _ = ctypes.CDLL("libgsl.so", mode=ctypes.RTLD_GLOBAL) + _ = ctypes.CDLL("libbinary_c.so", mode=ctypes.RTLD_GLOBAL) + libcustom_logging = ctypes.CDLL( library_name, mode=ctypes.RTLD_GLOBAL, ) # loads the shared library diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index 5e401986f9c7f810d1e944dbbbc208e7efd47425..516235312a79cffe5d4a9255af09056a2214c230 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -9,6 +9,7 @@ from collections import defaultdict import numpy as np import binary_c_python_api + def remove_file(file, verbose=0): """ Function to remove files but with verbosity @@ -363,6 +364,7 @@ def get_help_all(print_help=True, return_dict=False): else: return None + def filter_arg_dict(arg_dict): """ Function to filter out keys that contain values included in ['NULL', 'Function', ''] @@ -370,7 +372,7 @@ def filter_arg_dict(arg_dict): old_dict = arg_dict.copy() new_dict = {} - + for key in old_dict.keys(): if not old_dict[key] in ["NULL", "Function"]: if not old_dict[key] == "": @@ -379,7 +381,6 @@ def filter_arg_dict(arg_dict): return new_dict - def create_arg_string(arg_dict, sort=False, filter_values=False): """ Function that creates the arg string diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 311e740354350ab5c9303d887bc34987116c87de..a7c75e57a655bacff09d0e59631911e3fa2a37af 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -371,8 +371,10 @@ class Population(object): ) if use_datadir: - if not self.custom_options.get('base_filename', None): - base_name = 'simulation_{}'.format(datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d_%H%M%S')) + if not self.custom_options.get("base_filename", None): + base_name = "simulation_{}".format( + datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d_%H%M%S") + ) else: base_name = os.path.splitext(self.custom_options["base_filename"])[0] @@ -466,7 +468,7 @@ class Population(object): # Dry run and getting starcount self.grid_options["probtot"] = 0 - # Put in check + # Put in check if len(self.grid_options["grid_variables"]) == 0: print("Error: you havent defined any grid variables! Aborting") raise ValueError @@ -1216,11 +1218,6 @@ class Population(object): # warning; dont use yet. not fully tested. """ - - - - - if self.grid_options["system_generator"]: # Check if there is an output dir configured if self.custom_options.get("data_dir", None): diff --git a/binarycpython/utils/plot_functions.py b/binarycpython/utils/plot_functions.py index 0529702932f4fc1c82f853d24bcafc3fe42a9b56..4d7a88b03db7d0f74eb7b218c1acd909cc7c286f 100644 --- a/binarycpython/utils/plot_functions.py +++ b/binarycpython/utils/plot_functions.py @@ -11,13 +11,17 @@ import pandas as pd import numpy as np import matplotlib.pyplot as plt -from david_phd_functions.plotting.plot_functions import plot_orbit, plot_masses, plot_HR_diagram +from david_phd_functions.plotting.plot_functions import ( + plot_orbit, + plot_masses, + plot_HR_diagram, +) from binarycpython.utils.functions import get_arg_keys, output_lines from binarycpython.utils.run_system_wrapper import run_system from binarycpython.utils.custom_logging_functions import binary_c_log_code -# Define the custom_logging_strings. These are kept to the minimum necessary for each plotting routine. +# Define the custom_logging_strings. These are kept to the minimum necessary for each plotting routine. custom_logging_string_masses = "" custom_logging_string_orbit = "" @@ -44,18 +48,11 @@ Printf("HR_PLOTTING %30.12e %d %d %g %g %g %g %g %g\\n", """ - - - - - - # Define the parse functions for the plotting routines def dummy(): pass - def parse_function_hr_diagram(output): """ Parsing function for the HR plotting routine @@ -65,30 +62,37 @@ def parse_function_hr_diagram(output): values_list = [] - parameters = ['time', - 'stellar_type_1', 'stellar_type_2', - 'luminosity_1', 'luminosity_2', - 'radius_1', 'radius_2', 'pms_mass_1', 'pms_mass_2'] + parameters = [ + "time", + "stellar_type_1", + "stellar_type_2", + "luminosity_1", + "luminosity_2", + "radius_1", + "radius_2", + "pms_mass_1", + "pms_mass_2", + ] # Go over the output. for el in output_lines(output): headerline = el.split()[0] # Check the header and act accordingly - if (headerline=='HR_PLOTTING'): + if headerline == "HR_PLOTTING": values = el.split()[1:] values_list.append(values) df = pd.DataFrame(values_list) df.columns = parameters - df = df.astype(np.float64) - df['stellar_type_1'] = df['stellar_type_1'].astype(np.int64) - df['stellar_type_2'] = df['stellar_type_2'].astype(np.int64) + df["stellar_type_1"] = df["stellar_type_1"].astype(np.int64) + df["stellar_type_2"] = df["stellar_type_2"].astype(np.int64) return df + def plot_system(plot_type, **kwargs): """ TODO: Complex Function! @@ -119,24 +123,40 @@ def plot_system(plot_type, **kwargs): show_stellar_types = False plot_types_dict = { - 'mass_evolution': {'plot_function': plot_masses, 'custom_logging_string': custom_logging_string_masses, 'parse_function': dummy}, - 'orbit_evolution': {'plot_function': plot_orbit, 'custom_logging_string': custom_logging_string_orbit, 'parse_function': dummy}, - 'hr_diagram': {'plot_function': plot_HR_diagram, 'custom_logging_string': custom_logging_string_HR_diagram, 'parse_function': parse_function_hr_diagram}, - } - plot_system_specific_keywords = ['plot_type', 'show_plot', 'show_stellar_types'] + "mass_evolution": { + "plot_function": plot_masses, + "custom_logging_string": custom_logging_string_masses, + "parse_function": dummy, + }, + "orbit_evolution": { + "plot_function": plot_orbit, + "custom_logging_string": custom_logging_string_orbit, + "parse_function": dummy, + }, + "hr_diagram": { + "plot_function": plot_HR_diagram, + "custom_logging_string": custom_logging_string_HR_diagram, + "parse_function": parse_function_hr_diagram, + }, + } + plot_system_specific_keywords = ["plot_type", "show_plot", "show_stellar_types"] # First check on the plot_type input if not plot_type in plot_types_dict.keys(): - print("Warning, the provided plot type is not known. Please choose one from the following:\n\t{}".format(plot_types_dict.keys())) + print( + "Warning, the provided plot type is not known. Please choose one from the following:\n\t{}".format( + plot_types_dict.keys() + ) + ) raise ValueError # First: check all the arguments. Chosen to not check all the keywords for run_system and binary_c specifically, but just to pick out the ones needed for this routine. run_system will handle the rest run_system_arg_dict = {} for key in kwargs.keys(): - if key == 'show_plot': + if key == "show_plot": show_plot = kwargs[key] - elif key == 'show_stellar_types': + elif key == "show_stellar_types": show_stellar_types = kwargs[key] # The rest will be passed to run_system @@ -144,19 +164,29 @@ def plot_system(plot_type, **kwargs): run_system_arg_dict[key] = kwargs[key] # TODO: When a list of plot_types is passed, make it so that the strings are chained, and that the output of the binary_c call is handled by multiple parsers - custom_logging_code = binary_c_log_code(plot_types_dict[plot_type]['custom_logging_string']) - run_system_arg_dict['custom_logging_code'] = custom_logging_code + custom_logging_code = binary_c_log_code( + plot_types_dict[plot_type]["custom_logging_string"] + ) + run_system_arg_dict["custom_logging_code"] = custom_logging_code - run_system_arg_dict['parse_function'] = plot_types_dict[plot_type]['parse_function'] + run_system_arg_dict["parse_function"] = plot_types_dict[plot_type]["parse_function"] # Run and get the output of the parse function binary_c_output_df = run_system(**run_system_arg_dict) - - fig = plot_types_dict[plot_type]['plot_function'](binary_c_output_df, show_plot=show_plot, show_stellar_types=show_stellar_types) + fig = plot_types_dict[plot_type]["plot_function"]( + binary_c_output_df, show_plot=show_plot, show_stellar_types=show_stellar_types + ) if not show_plot: return fig -plot_system(plot_type='hr_diagram', M_1=10, M_2=5, orbital_period=100000, max_evolution_time=15000, show_plot=True) \ No newline at end of file +plot_system( + plot_type="hr_diagram", + M_1=10, + M_2=5, + orbital_period=100000, + max_evolution_time=15000, + show_plot=True, +) diff --git a/binarycpython/utils/run_system_wrapper.py b/binarycpython/utils/run_system_wrapper.py index 0a247f1f0074c7568445dad536bacbefa3a63bdf..4237548dc3cb232d461a189074144508e5ca55c4 100644 --- a/binarycpython/utils/run_system_wrapper.py +++ b/binarycpython/utils/run_system_wrapper.py @@ -38,7 +38,7 @@ def run_system(**kwargs): # Load available arg keywords available_binary_c_arg_keywords = get_arg_keys() - other_keywords = ['custom_logging_code', 'log_filename', 'parse_function'] + other_keywords = ["custom_logging_code", "log_filename", "parse_function"] # Set default values func_memaddr = -1 @@ -55,8 +55,11 @@ def run_system(**kwargs): # Notify user when this key wont be used else: if not key in other_keywords: - print("The following keyword was not recognized and wont be used:\n\t{}".format(key)) - + print( + "The following keyword was not recognized and wont be used:\n\t{}".format( + key + ) + ) # Check if custom logging is required if "custom_logging_code" in kwargs: diff --git a/docs/source/conf.py b/docs/source/conf.py index e9df5d4be59ee15b89a4eae8f408b62d022fe1ad..85556cc802d9f72698a56799987c0ff568f8e3e9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -26,8 +26,8 @@ cautodoc_root = os.path.abspath("../../") # -- Project information ----------------------------------------------------- project = "binary_c-python" -copyright = "2019, Jeff Andrews, Robert Izzard, David Hendriks" -author = "Jeff Andrews, Robert Izzard, David Hendriks" +copyright = "2020, David Hendriks, Robert Izzard, Jeff Andrews" +author = "David Hendriks, Robert Izzard, Jeff Andrews" # -- General configuration --------------------------------------------------- diff --git a/test_systems/README.md b/examples/example_systems/README.md similarity index 100% rename from test_systems/README.md rename to examples/example_systems/README.md diff --git a/pathos_worker_objects.py b/pathos_worker_objects.py deleted file mode 100644 index 26e4e0017145d52ebf0b765e69c57289b7b8e217..0000000000000000000000000000000000000000 --- a/pathos_worker_objects.py +++ /dev/null @@ -1,17 +0,0 @@ -import multiprocessing as mp - -from pathos.multiprocessing import ProcessingPool as Pool - - -# Create pool -p = Pool(processes=1, ncpus=3) - - -print(dir(p)) -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))