diff --git a/binarycpython/utils/custom_logging_functions.py b/binarycpython/utils/custom_logging_functions.py index 6a31405d4fd5193a2d141720db6cee294bb6dbf4..4f21aa95f73ed7cf27c934a3022dc2309273c4b6 100644 --- a/binarycpython/utils/custom_logging_functions.py +++ b/binarycpython/utils/custom_logging_functions.py @@ -10,7 +10,7 @@ import socket import ctypes import uuid from typing import Union, Tuple, Optional -from binarycpython.utils.functions import temp_dir, remove_file +from binarycpython.utils.functions import temp_dir, remove_file, verbose_print def autogen_C_logging_code(logging_dict: dict, verbose: int=0) -> Optional[str]: """ @@ -73,6 +73,7 @@ def autogen_C_logging_code(logging_dict: dict, verbose: int=0) -> Optional[str]: print( "Error: please use a list for the list of parameters that you want to have logged" ) + return None code = code.strip() return code @@ -118,8 +119,11 @@ def binary_c_log_code(code: str, verbose: int=0) -> str: """ - if verbose > 0: - print("Creating the code for the shared library for the custom logging") + verbose_print("Creating the code for the shared library for the custom logging", verbose, 0) + + if not "Printf" in code: + print("Error: There has to be at least a printf statement in the provided code. Aborting") + return None # Create code custom_logging_function_string = """\ diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 5fc3fdaff785b7712503d54f366faf78d83bd7cb..e73d9719f887aa67ee6758cda7a9a787de604c93 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -5,6 +5,18 @@ Here all the functionality of a Population object is defined. Useful for the user to understand the functionality, but copying functionality isn't recommended except if you know what you are doing + +Tasks: + - TODO: add functionality to 'on-init' set arguments + - TODO: add functionality to return the initial_abundance_hash + - TODO: add functionality to return the isotope_hash + - TODO: add functionality to return the isotope_list + - TODO: add functionality to return the nuclear_mass_hash + - TODO: add functionality to return the nuclear_mass_list + - TODO: add functionality to return the source_list + - TODO: add functionality to return the ensemble_list + - TODO: consider spreading the functions over more files. + - TODO: type the private functions """ import os @@ -18,7 +30,7 @@ import logging import argparse import subprocess import importlib.util - +from typing import Union, Any from pathos.helpers import mp as pathos_multiprocess from pathos.pools import _ProcessPool as Pool @@ -52,24 +64,6 @@ from binarycpython.utils.hpc_functions import ( from binarycpython import _binary_c_bindings -# Tasks -# TODO: add functionality to 'on-init' set arguments -# TODO: add functionality to return the initial_abundance_hash -# TODO: add functionality to return the isotope_hash -# TODO: add functionality to return the isotope_list -# TODO: add functionality to return the nuclear_mass_hash -# TODO: add functionality to return the nuclear_mass_list -# TODO: add functionality to return the source_list -# TODO: add functionality to return the ensemble_list -# TODO: change the grid_options dict structure so that there is room for descriptions -# TODO: consider spreading the functions over more files. -# TODO: indicate private or pbulic subroutines -# TODO: make explicit comparison to perl - -# Make this function also an API call. Doest seem to get written to a buffer -# that is stored into a python object. rather its just written to stdout - - class Population: """ Population Object. Contains all the necessary functions to set up, run and process a @@ -121,7 +115,7 @@ class Population: # I do however suggest everyone to export the binary_c defaults to a file, so that you know # exactly which values were the defaults. - def set(self, **kwargs): + def set(self, **kwargs) -> None: """ Function to set the values of the population. This is the preferred method to set values of functions, as it provides checks on the input. @@ -133,6 +127,9 @@ class Population: in the self.grid_options If neither of above is met; the key and the value get stored in a custom_options dict. + + Args: + via kwargs all the arguments are either set to binary_c parameters, grid_options or custom_options (see above) """ # Select the params that end with %d @@ -195,11 +192,13 @@ class Population: self.bse_options[key] = arg - def parse_cmdline(self): + def parse_cmdline(self) -> None: """ - Function to handle settings values via the command line: + Function to handle settings values via the command line. + Best to be called after all the .set(..) lines, and just before the .evolve() is called - TODO: remove the need for --cmdline + Tasks: + - TODO: remove the need for --cmdline """ parser = argparse.ArgumentParser() @@ -257,17 +256,17 @@ class Population: def add_grid_variable( self, - name, - longname, - valuerange, - resolution, - spacingfunc, - probdist, - dphasevol, - parameter_name, - precode=None, - condition=None, - ): + name: str, + longname: str, + valuerange: Union[list, str], + resolution: str, + spacingfunc: str, + probdist: str, + dphasevol: str, + parameter_name: str, + precode: Union[str, None]=None, + condition: Union[str, None]=None, + ) -> None: """ Function to add grid variables to the grid_options. @@ -279,33 +278,34 @@ class Population: The real function that generates the numbers will get written to a new file in the TMP_DIR, and then loaded imported and evaluated. beware that if you insert some destructive piece of code, it will be executed anyway. Use at own risk. - name: - name of parameter. This is evaluated as a parameter and you can use it throughout the rest of the function - example: name = 'lnm1' - longname: - Long name of parameter - example: longname = 'Primary mass' - range: - Range of values to take. Does not get used really, the spacingfunction is used to get the values from - example: range = [math.log(m_min), math.log(m_max)] - resolution: - Resolution of the sampled range (amount of samples). TODO: check if this is used anywhere - example: resolution = resolution["M_1"] - spacingfunction: - Function determining how the range is sampled. You can either use a real function, or a string representation of a function call. Will get written to a file and then evaluated. - example: spacingfunction = "const(math.log(m_min), math.log(m_max), {})".format(resolution['M_1']) - precode: - Extra room for some code. This code will be evaluated within the loop of the sampling function (i.e. a value for lnm1 is chosen already) - example: precode = 'M_1=math.exp(lnm1);' - probdist: - FUnction determining the probability that gets asigned to the sampled parameter - example: probdist = 'Kroupa2001(M_1)*M_1' - dphasevol: - part of the parameter space that the total probability is calculated with - example: dphasevol = 'dlnm1' - condition: - condition that has to be met in order for the grid generation to continue - example: condition = 'self.grid_options['binary']==1' + Args: + name: + name of parameter. This is evaluated as a parameter and you can use it throughout the rest of the function + example: name = 'lnm1' + longname: + Long name of parameter + example: longname = 'Primary mass' + range: + Range of values to take. Does not get used really, the spacingfunction is used to get the values from + example: range = [math.log(m_min), math.log(m_max)] + resolution: + Resolution of the sampled range (amount of samples). TODO: check if this is used anywhere + example: resolution = resolution["M_1"] + spacingfunction: + Function determining how the range is sampled. You can either use a real function, or a string representation of a function call. Will get written to a file and then evaluated. + example: spacingfunction = "const(math.log(m_min), math.log(m_max), {})".format(resolution['M_1']) + precode: + Extra room for some code. This code will be evaluated within the loop of the sampling function (i.e. a value for lnm1 is chosen already) + example: precode = 'M_1=math.exp(lnm1);' + probdist: + FUnction determining the probability that gets asigned to the sampled parameter + example: probdist = 'Kroupa2001(M_1)*M_1' + dphasevol: + part of the parameter space that the total probability is calculated with + example: dphasevol = 'dlnm1' + condition: + condition that has to be met in order for the grid generation to continue + example: condition = 'self.grid_options['binary']==1' """ # Add grid_variable @@ -335,11 +335,14 @@ class Population: # Return functions ################################################### - def return_population_settings(self): + def return_population_settings(self) -> dict: """ Function that returns all the options that have been set. Can be combined with json to make a nice file. + + Returns: + dictionary containing "bse_options", "grid_options", "custom_options" """ options = { @@ -371,13 +374,22 @@ class Population: def return_all_info( self, - include_population_settings=True, - include_binary_c_defaults=True, - include_binary_c_version_info=True, - include_binary_c_help_all=True, - ): + include_population_settings: bool=True, + include_binary_c_defaults: bool=True, + include_binary_c_version_info: bool=True, + include_binary_c_help_all: bool=True, + ) -> dict: """ Function that returns all the information about the population and binary_c + + Args: + include_population_settings: whether to include the population_settings (see function return_population_settings) + include_binary_c_defaults: whether to include a dict containing the binary_c parameters and their default values + include_binary_c_version_info: whether to include a dict containing all the binary_c version info (see return_binary_c_version_info) + include_binary_c_help_all: whether to include a dict containing all the information about the binary_c parameters (see get_help_all) + + Return: + dictionary containing all, or part of, the above dictionaries """ # @@ -405,25 +417,31 @@ class Population: def export_all_info( self, - use_datadir=True, - outfile=None, - include_population_settings=True, - include_binary_c_defaults=True, - include_binary_c_version_info=True, - include_binary_c_help_all=True, - ): + use_datadir: bool=True, + outfile: Union[str, None]=None, + include_population_settings: bool=True, + include_binary_c_defaults: bool=True, + include_binary_c_version_info: bool=True, + include_binary_c_help_all: bool=True, + ) -> None: """ Function that exports the all_info to a json file - TODO: if any of the values in the dicts here is of a not-serializable form, then we need - to change that to a string or something so, use a recursive function that goes over the - all_info dict and finds those that fit - - TODO: Fix to write things to the directory. which options do which etc - - TODO: theres flawed logic here. rewrite this part pls - - TODO: consider actually just removing the whole 'output to file' part and let the user do this. + Tasks: + - TODO: if any of the values in the dicts here is of a not-serializable form, then we need + to change that to a string or something so, use a recursive function that goes over the + all_info dict and finds those that fit + - TODO: Fix to write things to the directory. which options do which etc + - TODO: theres flawed logic here. rewrite this part pls + - TODO: consider actually just removing the whole 'output to file' part and let the user do this. + + Args: + include_population_settings: whether to include the population_settings (see function return_population_settings) + include_binary_c_defaults: whether to include a dict containing the binary_c parameters and their default values + include_binary_c_version_info: whether to include a dict containing all the binary_c version info (see return_binary_c_version_info) + include_binary_c_help_all: whether to include a dict containing all the information about the binary_c parameters (see get_help_all) + use_datadir: boolean whether to use the custom_options['data_dir'] to write the file to. If the custom_options["base_filename"] is set, the output file will be called <custom_options["base_filename"]>_settings.json. Otherwise a file called simulation_<date+time>_settings.json will be created + outfile: if use_datadir is false, a custom filename will be used """ all_info = self.return_all_info( @@ -609,11 +627,17 @@ class Population: # Evolution functions ################################################### - def evolve(self): + def evolve(self) -> None: """ Entrypoint function of the whole object. From here, based on the settings, we set up a SLURM or CONDOR grid, or if no setting is given we go straight to evolving the population + + There are no direct arguments to this function, rather it is based on the grid_options settings: + grid_options['slurm']: integer boolean whether to use a slurm_grid evolution + grid_options['condor']: integer boolean whether to use a condor_grid evolution + + If neither of the above is set, we continue without using HPC routines (that doesn't mean this cannot be run on a server with many cores) """ # Check which type: @@ -626,21 +650,21 @@ class Population: self._condor_grid() else: # Execute population evolution subroutines - self._evolve_population() + self.evolve_population() - def _evolve_population(self): + def evolve_population(self): """ Function to evolve populations. This handles the setting up, evolving and cleaning up of a population of stars. Choices here are: - - to evolve a population via multiprocessing or linearly on 1 core. - - to evolve a population via a variable grid, a source file or MC + to evolve a population via multiprocessing or linearly on 1 core. + NOT IMPLEMENTED YET to evolve a population via a variable grid, a source file or MC - TODO: include options for different ways of generating a population here. + Tasks: + - TODO: include options for different ways of generating a population here. (i.e. MC or source file) """ - # TODO: set a unique population_name here self.grid_options["_population_id"] = uuid.uuid4().hex ## @@ -868,11 +892,17 @@ class Population: self.grid_options["parse_function"](self, out) # Single system - def evolve_single(self, clean_up_custom_logging_files=True): + def evolve_single(self, clean_up_custom_logging_files: bool=True) -> Any: """ - Function to run a single system + Function to run a single system, based on the settings in the grid_options The output of the run gets returned, unless a parse function is given to this function. + + Args: + clean_up_custom_logging_files: whether the clean up all the custom_logging files. + + returns: + either returns the raw binary_c output, or whatever the parse_function does """ ### Custom logging code: @@ -912,11 +942,12 @@ class Population: Since we have different methods of running a population, this setup function will do different things depending on different settings - # TODO: Make other kinds of populations possible. i.e, read out type of grid, - and set up accordingly + Tasks: + TODO: Make other kinds of populations possible. i.e, read out type of grid, + and set up accordingly - # TODO: make this function more general. Have it explicitly set the system_generator - function + TODO: make this function more general. Have it explicitly set the system_generator + function """ if not self.grid_options["parse_function"]: @@ -1848,7 +1879,7 @@ class Population: ) # - self._evolve_population() + self.evolve_population() elif self.grid_options["slurm_command"] == "join": # Joining the output. @@ -2095,7 +2126,7 @@ class Population: ) # - self._evolve_population() + self.evolve_population() elif self.grid_options["condor_command"] == "join": # TODO: write this function @@ -2110,19 +2141,9 @@ class Population: # Functions that arent ordered yet ################################################### - def generate_population_arglines_file(self, output_file): - """ - Function to generate a file that contains all the argument lines that would be given to - binary_c if the population had been run - - TODO: Fix this function - """ - - pass - def write_binary_c_calls_to_file( - self, output_dir=None, output_filename=None, include_defaults=False - ): + self, output_dir: Union[str, None]=None, output_filename: Union[str, None]=None, include_defaults: bool=False + ) -> None: """ Function that loops over the gridcode and writes the generated parameters to a file. In the form of a commandline call @@ -2134,7 +2155,15 @@ class Population: On default this will write to the datadir, if it exists - # warning; dont use yet. not fully tested. + WARNING; dont use yet. not fully tested. + + Tasks: + - TODO: test this function + + Args: + output_dir: (optional, default = None) directory where to write the file to. If custom_options['data_dir'] is present, then that one will be used first, and then the output_dir + output_filename: (optional, default = None) filename of the output. If not set it will be called "binary_c_calls.txt" + include_defaults: (optional, default = None) whether to include the defaults of binary_c in the lines that are written. Beware that this will result in very long lines, and it might be better to just export the binary_c defaults and keep them in a seperate file. """ # Check if there is no compiled grid yet. If not, lets try to build it first. @@ -2162,6 +2191,7 @@ class Population: # self._load_grid_function() + # then if the _system_generator is present, we go through it 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/grid_options_defaults.py b/binarycpython/utils/grid_options_defaults.py index 3759ca6696674c72cf389196350e50604f070146..b3fb7e576c4fadd19f96682ab4965cd54881cc95 100644 --- a/binarycpython/utils/grid_options_defaults.py +++ b/binarycpython/utils/grid_options_defaults.py @@ -8,7 +8,7 @@ There are several other functions in this module, mostly to generate help texts - grid_options_description_checker: function that checks that checks which options have a description. - write_grid_options_to_rst_file: function to generate the .rst document for the docs -With this its also possible to automatically generate a pdf file containing all the setting names + descriptions. +With this its also possible to automatically generate a document containing all the setting names + descriptions. All the options starting with _ should not be changed by the user except when you really know what you're doing (which is probably hacking the code :P) """ @@ -475,13 +475,12 @@ grid_options_descriptions = { # Grid options functions # Utility functions -def grid_options_help(option: str) -> str: +def grid_options_help(option: str) -> None: """ Function that prints out the description of a grid option. Useful function for the user. Args: option: which option you want to have the description of - """ option_keys = grid_options_defaults_dict.keys() diff --git a/binarycpython/utils/hpc_functions.py b/binarycpython/utils/hpc_functions.py index 1eae7769ca5a2b52aa1ab91e341c2678256f43e0..bc085032f2081ce97189eaa8d31c5ce65e96670f 100644 --- a/binarycpython/utils/hpc_functions.py +++ b/binarycpython/utils/hpc_functions.py @@ -10,14 +10,18 @@ import os import sys import time import subprocess +from typing import Union import __main__ as main -def get_slurm_version(): +def get_slurm_version() -> Union[str, None]: """ Function that checks whether slurm is installed and returns the version if its installed. Only tested this with slurm v17+ + + Returns: + slurm version, or None """ slurm_version = None @@ -40,13 +44,16 @@ def get_slurm_version(): return slurm_version -def get_condor_version(): +def get_condor_version() -> Union[str, None]: """ Function that checks whether slurm is installed and returns the version if its installed. otherwise returns None Result has to be condor v8 or higher + + Returns: + condor version, or None """ condor_version = None @@ -71,11 +78,14 @@ def get_condor_version(): return condor_version -def create_directories_hpc(working_dir): +def create_directories_hpc(working_dir: str) -> None: """ Function to create a set of directories, given a root directory These directories will contain stuff for the HPC runs + + Args: + working_dir: main working directory of the run. Under this directory all the dirs will be created """ # Check if working_dir exists @@ -114,17 +124,21 @@ def create_directories_hpc(working_dir): print("..Finished! Directories exist.") -def path_of_calling_script(): +def path_of_calling_script() -> str: """ Function to get the name of the script the user executes. + TODO: fix this function. seems not to work properly. """ return main.__file__ -def get_python_details(): +def get_python_details() -> dict: """ Function to get some info about the used python version and virtualenv etc + + Returns: + dictionary with python executable, virtual environment and version information. """ python_info_dict = {} diff --git a/binarycpython/utils/plot_functions.py b/binarycpython/utils/plot_functions.py index 430be90623f3dc48ee1cd2dc6632faec98155313..63c812a0305264ff64fa9ea1d5ef76645b95b23a 100644 --- a/binarycpython/utils/plot_functions.py +++ b/binarycpython/utils/plot_functions.py @@ -1,19 +1,26 @@ """ -Module that contains Functionality to plot different aspect of (binary) systems. +Module that contains functionality to plot some properties of (binary) systems. Different routines are defined here to plot orbits, masses, angular momenta etc. -Its split up into logging string, parsing functions, plotting functions, -and one master function called plot_system that will provide ease of use. +Structure of file: + custom logging strings + parsing functions + plotting functions + master function: plot_system All the loose components here can ofcourse be used in other routines if you want. There is no preloaded matplotlib rc, you should do that yourself -TODO: This module is not finished yet. -TODO: Make modules for single system -TODO: Put all the plotting functions in here +These plotting routines are designed for binary systems, and admittingly they are here mostly for +inspirational purposes, since one would problably want to customize the plots. +Regardless, having some plotting routines in here seemed like a nice idea +Tasks + TODO: This module is not finished yet. + TODO: Make modules for single system + TODO: Put all the plotting functions in here """ import math @@ -84,7 +91,7 @@ def color_by_index(row, column, colors): def plot_HR_diagram( - df, show_stellar_types=False, show_plot=True, use_astropy_values=True + df, show_stellar_types: bool=False, show_plot: bool=True, use_astropy_values: bool=True ): """ Function to plot the HR diagram evolution of the system. Assumes its a binary system. @@ -106,9 +113,20 @@ def plot_HR_diagram( Plots: luminosity_1 vs teff_1 luminosity_2 vs teff_2 + + Tasks: + TODO: add HD limit + TODO: add lines of constant radius + + Args: + df: pandas dataframe with the required columns + show_stellar_types: whether to color code the tracks and show the stellar types + show_plot: whether to actually show the plot. If false: returns the figure object + use_astropy_values: Whether to use astropy values for for Rsun, Lsun and stefan boltzman constant. + + Returns + returns a figure object if show_plot is false - TODO: add HD limit - TODO: add lines of constant radius """ # prefactor = (1/(4 * math.pi * omega_sb))**(1.0/4) @@ -205,7 +223,7 @@ def plot_HR_diagram( return fig -def plot_orbit(df, show_stellar_types=False, show_plot=True): +def plot_orbit(df, show_stellar_types:bool =False, show_plot:bool =True): """ Function to plot the orbital elements of the system @@ -213,6 +231,14 @@ def plot_orbit(df, show_stellar_types=False, show_plot=True): - Orbital period - Separation - eccentricity + + Args: + df: pandas dataframe with the required columns + show_stellar_types: whether to color code the tracks and show the stellar types + show_plot: whether to actually show the plot. If false: returns the figure object + + Returns + returns a figure object if show_plot is false """ if show_stellar_types: @@ -252,7 +278,7 @@ def plot_orbit(df, show_stellar_types=False, show_plot=True): return fig -def plot_masses(df, show_stellar_types=False, show_plot=True): +def plot_masses(df, show_stellar_types: bool=False, show_plot: bool=True): """ Function to plot the masses of the system. @@ -271,6 +297,14 @@ def plot_masses(df, show_stellar_types=False, show_plot=True): - pms mass 2 - pms total mass (maybe?) core and env masses + + Args: + df: pandas dataframe with the required columns + show_stellar_types: whether to color code the tracks and show the stellar types + show_plot: whether to actually show the plot. If false: returns the figure object + + Returns + returns a figure object if show_plot is false """ if show_stellar_types: @@ -337,9 +371,15 @@ def dummy(): pass -def parse_function_hr_diagram(output): +def parse_function_hr_diagram(output: str): """ Parsing function for the HR plotting routine + + Args: + output: raw binary_c output string + + Returns: + pandas dataframe containing the columns for the HR diagram plotting routine """ # extract info from the single evolution @@ -377,9 +417,15 @@ def parse_function_hr_diagram(output): return df -def parse_function_orbit(output): +def parse_function_orbit(output: str): """ Parsing function for the orbit plotting routine + + Args: + output: raw binary_c output string + + Returns: + pandas dataframe containing the columns for the orbit plotting routine """ values_list = [] @@ -408,9 +454,15 @@ def parse_function_orbit(output): return df -def parse_function_masses(output): +def parse_function_masses(output: str): """ Parsing function for the orbit plotting routine + + Args: + output: raw binary_c output string + + Returns: + pandas dataframe containing the columns for the masses plotting routine """ values_list = [] @@ -442,23 +494,28 @@ def parse_function_masses(output): def plot_system(plot_type, **kwargs): """ - TODO: Complex Function! - TODO: make sure this way of passing args works correctly. - TODO: make the plotting specific keywords available via the inspect stuff - Function to plot the evolution of the system. - + Function to plot the different quantities of a system. + This goes (in general) via the following steps: - - a preset custom logging for a specific plotting routine is loaded. + - a preset custom logging for a specific plotting routine is loaded, depending on the choice of plot_type - This is used for the run_system call - The output of this run_system is loaded into a dataframe by parsing it with a corresponding parsing function - The dataframe is passed to the plotting routine - plot is shown or returned. - There are several pre-set plots to choose from + There are several pre-set plots to choose from: + mass_evolution + orbit_evolution + hr_diagram + + Tasks: + TODO: Complex Function! + TODO: make sure this way of passing args works correctly. + TODO: make the plotting specific keywords available via the inspect stuff All keywords are considered kwargs, except for plot_type - input: + Args: plot_type: string input should be one of the following types: ['mass_evolution', 'orbit_evolution', 'hr_diagram']. Input will be matched against this, @@ -469,6 +526,9 @@ def plot_system(plot_type, **kwargs): This is not included in all the plotting routines. Other input: other kwargs that are passed to run_system (inspect the docstring of run_system for more info) + + Returns: + returns a object figure if show_plot = false """ # set defaults and options diff --git a/binarycpython/utils/run_system_wrapper.py b/binarycpython/utils/run_system_wrapper.py index e13535cd470ffc9f7a64614f37468f3731064aea..f43d1eee917b602be6b94a0b582306c662d3440f 100644 --- a/binarycpython/utils/run_system_wrapper.py +++ b/binarycpython/utils/run_system_wrapper.py @@ -3,7 +3,6 @@ Module containing the utility function run_system, which handles a lot of things by analysing the passed kwargs """ - from binarycpython.utils.functions import ( create_arg_string, get_arg_keys, @@ -16,35 +15,38 @@ from binarycpython.utils.custom_logging_functions import ( from binarycpython import _binary_c_bindings - def run_system(**kwargs): """ Function that runs a system. Mostly as a useful utility function that handles all the setup of argument lists etc. + examples: + * run_system(M_1=10): will run a system with ZAMS mass 1 = 10 + * run_system(M_1=10, log_filename="~/example_log.txt"): Will run a system + and write the logfile too + * run_system(M_1=10, parse_function=fancy_parsing_function) + + Tasks: + TODO: Expand functionality. + TODO: Notify user when an unknown keyword is passed. + All~ the arguments known to binary_c can be passed to this function as kwargs. Several extra arguments can be passed through the kwargs: - * custom_logging_code (string): + custom_logging_code (string): Should contain a string containing the c-code for the shared library. If this is provided binary_c will use that custom logging code to output its data - * log_filename (string): + log_filename (string): Should contain name of the binary_c system logfile. Passing this will make sure that the filename gets written for a run (its default behaviour is NOT to write a logfile for a system) - * parse_function (function): + parse_function (function): should contain a function that parses the output. The parse function should take 1 required parameter: the output of the binaryc run Passing this will call the parse_function by passing it the output of the binary_c call and returns what the parse_function returns - examples: - * run_system(M_1=10): will run a system with ZAMS mass 1 = 10 - * run_system(M_1=10, log_filename="~/example_log.txt"): Will run a system - and write the logfile too - * run_system(M_1=10, parse_function=fancy_parsing_function) - - TODO: Expand functionality. - TODO: Notify user when an unknown keyword is passed. + Returns: + Either returns the raw output of binary_c, or the output of a parse_function if parse_function is given """ # Load available arg keywords diff --git a/binarycpython/utils/spacing_functions.py b/binarycpython/utils/spacing_functions.py index 28fe7ebe27b2ff2562941d92d19e82d58a67644b..4dbea809a94e37dbfce80cc0e9d39b7968dc294d 100644 --- a/binarycpython/utils/spacing_functions.py +++ b/binarycpython/utils/spacing_functions.py @@ -1,14 +1,25 @@ """ -Module containing the spacing functions for the binarycpython package -""" +Module containing the spacing functions for the binarycpython package. Very under-populated at the moment, but more are likely to come soon +Tasks: + TODO: add more spacing functions to this module. +""" +from typing import Union import numpy as np -def const(min_bound, max_bound, steps): +def const(min_bound: Union[int, float], max_bound: Union[int, float], steps: int) -> list: """ Samples a range linearly. Uses numpy linspace. + + Args: + min_bound: lower bound of range + max_bound: upper bound of range + steps: amount of segments between min_bound and max_bound + + Returns: + np.linspace(min_bound, max_bound, steps) """ return np.linspace(min_bound, max_bound, steps)