Skip to content
Snippets Groups Projects
Commit 22049a49 authored by David Hendriks's avatar David Hendriks
Browse files

updated grid code to have a dedicated status printing function

parent 1bafaf58
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ from binarycpython.utils.functions import get_defaults, parse_binary_c_version_i ...@@ -39,6 +39,7 @@ from binarycpython.utils.functions import get_defaults, parse_binary_c_version_i
# TODO: add functionality to return the nuclear_mass_list # TODO: add functionality to return the nuclear_mass_list
# TODO: add functionality to return the source_list # TODO: add functionality to return the source_list
# TODO: add functionality to return the ensemble_list # TODO: add functionality to return the ensemble_list
# TODO: change the grid_options dict structure so that there is room for descriptions
# DONE: add verbosity options # DONE: add verbosity options
# DONE: add functionality to return the evcode_version_string # DONE: add functionality to return the evcode_version_string
...@@ -778,6 +779,8 @@ class Population(object): ...@@ -778,6 +779,8 @@ class Population(object):
####################### #######################
# MP run # MP run
self.grid_options['probtot'] = 0 # To make sure that the values are reset. TODO: fix this in a cleaner way self.grid_options['probtot'] = 0 # To make sure that the values are reset. TODO: fix this in a cleaner way
self.grid_options['start_time_grid'] = time.time() # Setting start time of grid
start_mp = time.time() start_mp = time.time()
...@@ -785,6 +788,7 @@ class Population(object): ...@@ -785,6 +788,7 @@ class Population(object):
self.load_grid_function() self.load_grid_function()
# def evolve_system(binary_cmdline_string):
def evolve_system(binary_cmdline_string): def evolve_system(binary_cmdline_string):
out = binary_c_python_api.run_population( out = binary_c_python_api.run_population(
binary_cmdline_string, binary_cmdline_string,
...@@ -800,9 +804,11 @@ class Population(object): ...@@ -800,9 +804,11 @@ class Population(object):
full_system_dict.update(system) full_system_dict.update(system)
binary_cmdline_string = self.return_argline(full_system_dict) binary_cmdline_string = self.return_argline(full_system_dict)
print("{}/{}".format(i+1, total_starcount_run), binary_cmdline_string)
self.print_info(i+1, total_starcount_run, full_system_dict)
# print("{}/{}".format(i+1, total_starcount_run), binary_cmdline_string)
yield binary_cmdline_string yield binary_cmdline_string
# yield i
print("generator done") print("generator done")
# Create pool # Create pool
...@@ -817,6 +823,8 @@ class Population(object): ...@@ -817,6 +823,8 @@ class Population(object):
p.join() p.join()
stop_mp = time.time() stop_mp = time.time()
self.grid_options['start_time_grid'] = 0
# Give feedback # Give feedback
print( print(
...@@ -1422,4 +1430,39 @@ class Population(object): ...@@ -1422,4 +1430,39 @@ class Population(object):
raise KeyError raise KeyError
def print_info(self, run_number, total_systems, full_system_dict):
"""
Function to print info about the current system and the progress of the grid.
# color info tricks from https://ozzmaker.com/add-colour-to-text-in-python/
https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python
"""
# Define frequency
if self.grid_options['verbose'] == 1:
print_freq = 10
else:
print_freq = 1
# Calculate amount of time left
# calculate amount of time passed
time_passed = time.time() - self.grid_options['start_time_grid']
if run_number%print_freq==0:
binary_cmdline_string = self.return_argline(full_system_dict)
info_string = "{color_part_1} {text_part_1}{end_part_1}{color_part_2} {text_part_2}{end_part_2}".format(
color_part_1="\033[1;32;41m",
text_part_1="{}/{}".format(run_number, total_systems),
end_part_1="\033[0m",
color_part_2="\033[1;32;42m",
text_part_2="{}".format(binary_cmdline_string),
end_part_2="\033[0m",
)
print(info_string)
################################################################################################ ################################################################################################
...@@ -40,12 +40,12 @@ grid_options_defaults_dict = { ...@@ -40,12 +40,12 @@ grid_options_defaults_dict = {
# binary # binary
"binary": 0, "binary": 0,
# Locations: # Locations:
"tmp_dir": temp_dir(), "tmp_dir": temp_dir(), # Setting the temp dir of the program
# Probability: # Probability:
"weight": 1.0, # weighting for the 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) "repeat": 1.0, # number of times to repeat each system (probability is adjusted to be 1/repeat)
"parse_function": None, "parse_function": None, #
"start_time_grid": 0, # Start time of the grid
## ##
# return_array_refs=>1, # quicker data parsing mode # return_array_refs=>1, # quicker data parsing mode
# sort_args=>1, # sort_args=>1,
......
...@@ -294,19 +294,21 @@ test_pop.set(verbose=1, ...@@ -294,19 +294,21 @@ test_pop.set(verbose=1,
binary=0, binary=0,
) )
resolution = {'M_1': 10, 'per': 10}
test_pop.add_grid_variable( test_pop.add_grid_variable(
name="M_1", name="M_1",
longname="log primary mass", longname="log primary mass",
valuerange=[10, 100], valuerange=[10, 100],
resolution="20", resolution="{}".format(resolution['M_1']),
spacingfunc="const(10, 100, 20)", spacingfunc="const(10, 100, {})".format(resolution['M_1']),
precode="",
# precode="M_1=math.exp(lnm1)", # precode="M_1=math.exp(lnm1)",
probdist="flat(M_1)", probdist="flat(M_1)",
# probdist='self.custom_options["extra_prob_function"](M_1)', # probdist='self.custom_options["extra_prob_function"](M_1)',
dphasevol="dM_1", dphasevol="dM_1",
parameter_name="M_1", parameter_name="M_1",
condition="",
) )
### Grid generating test. ### Grid generating test.
...@@ -314,8 +316,8 @@ test_pop.add_grid_variable( ...@@ -314,8 +316,8 @@ test_pop.add_grid_variable(
name="period", name="period",
longname="period", longname="period",
valuerange=["M_1", 20], valuerange=["M_1", 20],
resolution="20", resolution="{}".format(resolution['per']),
spacingfunc="np.linspace(1, 10, 20)", spacingfunc="np.linspace(1, 10, {})".format(resolution['per']),
precode="orbital_period = period**2", precode="orbital_period = period**2",
probdist="flat(orbital_period)", probdist="flat(orbital_period)",
parameter_name="orbital_period", parameter_name="orbital_period",
...@@ -324,12 +326,10 @@ test_pop.add_grid_variable( ...@@ -324,12 +326,10 @@ test_pop.add_grid_variable(
) )
test_pop.set(verbose=1, test_pop.set(verbose=1,
amt_cores=4, amt_cores=1,
binary=0, binary=0,
) )
test_pop.test_evolve_population_mp() # test_pop.test_evolve_population_mp()
test_pop.evolve_population_mp_chunks()
# print(test_pop.grid_options["probtot"])
# print(test_pop.grid_options["count"])
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment