From a4a758a67f72e54d4807a7fe3af1ef0651644823 Mon Sep 17 00:00:00 2001 From: dh00601 <dh00601@surrey.ac.uk> Date: Mon, 1 Nov 2021 17:35:47 +0000 Subject: [PATCH] reformatted code --- binarycpython/tests/test_c_bindings.py | 1 - binarycpython/tests/test_functions.py | 20 +++++---------- binarycpython/utils/ensemble.py | 5 ++-- binarycpython/utils/functions.py | 7 +----- binarycpython/utils/grid.py | 26 +++++++++++++------- binarycpython/utils/grid_options_defaults.py | 12 ++++----- setup.py | 2 ++ 7 files changed, 34 insertions(+), 39 deletions(-) diff --git a/binarycpython/tests/test_c_bindings.py b/binarycpython/tests/test_c_bindings.py index b231189ae..2fc163d87 100644 --- a/binarycpython/tests/test_c_bindings.py +++ b/binarycpython/tests/test_c_bindings.py @@ -29,7 +29,6 @@ from binarycpython.utils.dicts import ( ) - TMP_DIR = temp_dir("tests", "test_c_bindings") #### some useful functions diff --git a/binarycpython/tests/test_functions.py b/binarycpython/tests/test_functions.py index e75861045..d4ad330ec 100644 --- a/binarycpython/tests/test_functions.py +++ b/binarycpython/tests/test_functions.py @@ -9,12 +9,8 @@ import tempfile import json import h5py -from binarycpython.utils.custom_logging_functions import ( - binary_c_log_code -) -from binarycpython.utils.run_system_wrapper import ( - run_system -) +from binarycpython.utils.custom_logging_functions import binary_c_log_code +from binarycpython.utils.run_system_wrapper import run_system from binarycpython.utils.functions import ( temp_dir, Capturing, @@ -34,17 +30,12 @@ from binarycpython.utils.functions import ( get_help_all, get_help_super, write_binary_c_parameter_descriptions_to_rst_file, - make_build_text -) -from binarycpython.utils.dicts import ( - AutoVivificationDict, - inspect_dict, - merge_dicts + make_build_text, ) +from binarycpython.utils.dicts import AutoVivificationDict, inspect_dict, merge_dicts from binarycpython.utils.ensemble import ( binaryc_json_serializer, - handle_ensemble_string_to_json - + handle_ensemble_string_to_json, ) TMP_DIR = temp_dir("tests", "test_functions") @@ -161,6 +152,7 @@ class test_temp_dir(unittest.TestCase): os.path.join(general_temp_dir, "binary_c_python-{}".format(username)) ) == binary_c_temp_dir + class test_create_hdf5(unittest.TestCase): """ Unittests for create_hdf5 diff --git a/binarycpython/utils/ensemble.py b/binarycpython/utils/ensemble.py index 24e812ba3..72a0ced7d 100644 --- a/binarycpython/utils/ensemble.py +++ b/binarycpython/utils/ensemble.py @@ -28,9 +28,8 @@ from binarycpython.utils.dicts import ( custom_sort_dict, recursive_change_key_to_string, ) -from binarycpython.utils.functions import ( - verbose_print -) +from binarycpython.utils.functions import verbose_print + def ensemble_setting(ensemble, parameter_name): """ diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index 906dd9f32..1480a418e 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -9,7 +9,6 @@ Tasks: """ - import bz2 import collections from colorama import Fore, Back, Style @@ -45,11 +44,7 @@ import astropy.units as u import binarycpython.utils.moe_di_stefano_2017_data as moe_di_stefano_2017_data from binarycpython import _binary_c_bindings -from binarycpython.utils.dicts import ( - filter_dict, - filter_dict_through_values -) - +from binarycpython.utils.dicts import filter_dict, filter_dict_through_values ######################################################## diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 1891df1eb..11aae0493 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -46,7 +46,7 @@ from typing import Union, Any from collections import ( OrderedDict, ) -from collections.abc import Iterable # drop `.abc` with Python 2.7 or lower +from collections.abc import Iterable # drop `.abc` with Python 2.7 or lower import setproctitle import py_rinterpolate @@ -1203,13 +1203,15 @@ class Population: # Setup of the generator # Check again if we use custom generator or not: if self.grid_options["evolution_type"] == "custom_generator": - generator = self.grid_options['custom_generator'] + generator = self.grid_options["custom_generator"] else: self._generate_grid_code(dry_run=False) self._load_grid_function() - generator = self.grid_options["_system_generator"](self, print_results=False) + generator = self.grid_options["_system_generator"]( + self, print_results=False + ) # TODO: build in method to handle with the HPC. # Continuously fill the queue @@ -1657,7 +1659,7 @@ class Population: # Check option to ignore 0 probability systems if not self.grid_options["run_zero_probability_system"]: - if full_system_dict.get('probability', 1) == 0: + if full_system_dict.get("probability", 1) == 0: run_system = False zero_prob_stars_skipped += 1 @@ -1775,7 +1777,7 @@ class Population: self.grid_options["verbosity"], 1, ) - + ensemble_output = extract_ensemble_json_from_string(ensemble_raw_output) ensemble_output = extract_ensemble_json_from_string(ensemble_raw_output) @@ -2110,8 +2112,12 @@ class Population: # user-provided custom generator if self.grid_options["evolution_type"] == "custom_generator": - if not isinstance(self.grid_options['custom_generator'], Iterable): - print("Error. provided no or wrong custom value for the system generator (custom_generator: {})".format(self.grid_options['custom_generator'])) + if not isinstance(self.grid_options["custom_generator"], Iterable): + print( + "Error. provided no or wrong custom value for the system generator (custom_generator: {})".format( + self.grid_options["custom_generator"] + ) + ) raise ValueError # NOTE: In the part above i apparently have moved the load grid function call to another part. Now i wonder if that was useful, because it would be best if that is handled in this function @@ -4723,7 +4729,7 @@ eccentricity3=0 Makes use of the self.bse_options['multiplicity'] value. If its not set, it will raise an error grid_options['multiplicity_fraction_function'] will be checked for the choice - + TODO: add option to put a manual binary fraction in here (solve via negative numbers being the functions) """ @@ -4822,7 +4828,9 @@ eccentricity3=0 raise ValueError(msg) # To make sure we normalize the dictionary - multiplicity_fraction_dict = normalize_dict(multiplicity_fraction_dict, verbosity=self.grid_options["verbosity"]) + multiplicity_fraction_dict = normalize_dict( + multiplicity_fraction_dict, verbosity=self.grid_options["verbosity"] + ) verbose_print( "Multiplicity: {} multiplicity_fraction: {}".format( diff --git a/binarycpython/utils/grid_options_defaults.py b/binarycpython/utils/grid_options_defaults.py index e8f7a5108..bfe7a48b0 100644 --- a/binarycpython/utils/grid_options_defaults.py +++ b/binarycpython/utils/grid_options_defaults.py @@ -42,9 +42,9 @@ grid_options_defaults_dict = { "max_queue_size": 1000, # Maximum size of the system call queue. "run_zero_probability_system": True, # Whether to run the zero probability systems "_zero_prob_stars_skipped": 0, - "ensemble_factor_in_probability_weighted_mass": False, # Whether to multiply the ensemble results by 1/probability_weighted_mass - "do_dry_run": True, # Whether to do a dry run to calculate the total probability for this run - "custom_generator": None, # Place for the custom system generator + "ensemble_factor_in_probability_weighted_mass": False, # Whether to multiply the ensemble results by 1/probability_weighted_mass + "do_dry_run": True, # Whether to do a dry run to calculate the total probability for this run + "custom_generator": None, # Place for the custom system generator "exit_after_dry_run": False, # Exit after dry run? ########################## # Execution log: @@ -74,7 +74,7 @@ grid_options_defaults_dict = { "_loaded_Moe2017_data": False, # Holds flag whether the Moe and di Stefano (2017) data is loaded into memory "_set_Moe2017_grid": False, # Whether the Moe and di Stefano (2017) grid has been loaded "Moe2017_options": None, # Holds the Moe and di Stefano (2017) options. - "_Moe2017_JSON_data": None, # Stores the data + "_Moe2017_JSON_data": None, # Stores the data ########################## # Custom logging ########################## @@ -100,7 +100,7 @@ grid_options_defaults_dict = { ## General "evolution_type": "grid", # Flag for type of population evolution "_evolution_type_options": [ - "grid", + "grid", "custom_generator", ], # available choices for type of population evolution. # TODO: fill later with Monte Carlo, source file "_system_generator": None, # value that holds the function that generates the system @@ -504,7 +504,7 @@ grid_options_descriptions = { "m&s_options": "Internal variable that holds the Moe and di Stefano (2017) options. Don't write to this your self", "_loaded_Moe2017_data": "Internal variable storing whether the Moe and di Stefano (2017) data has been loaded into memory", "do_dry_run": "Whether to do a dry run to calculate the total probability for this run", - "_Moe2017_JSON_data": "Location to store the loaded Moe&diStefano2017 dataset", # Stores the data + "_Moe2017_JSON_data": "Location to store the loaded Moe&diStefano2017 dataset", # Stores the data } ### diff --git a/setup.py b/setup.py index 670225cc0..593b49d51 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ import distutils.command.build # TODO: replace the tasks that call binary_c-config with a single function that handles the return status a bit better. + def version(): """ opens VERSION and returns version number @@ -21,6 +22,7 @@ def version(): with open("VERSION") as file: return file.read().strip() + VERSION_NUMBER = version() # Functions -- GitLab