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

fixed small bugs

parent d3f5b316
No related branches found
No related tags found
No related merge requests found
...@@ -696,7 +696,11 @@ class Population: ...@@ -696,7 +696,11 @@ class Population:
# Log and print some information # Log and print some information
verbose_print( verbose_print(
"Population-{} finished!".format(self.grid_options["_population_id"]), "Population-{} finished! It took a total of {}s to run {} systems on {} cores".format(
self.grid_options["_population_id"],
self.grid_options['_end_time_evolution']-self.grid_options['_start_time_evolution'],
self.grid_options['_total_starcount'],
self.grid_options['amt_cores']),
self.grid_options["verbosity"], self.grid_options["verbosity"],
0, 0,
) )
...@@ -723,6 +727,8 @@ class Population: ...@@ -723,6 +727,8 @@ class Population:
self.grid_options["verbosity"], self.grid_options["verbosity"],
0, 0,
) )
else:
verbose_print("There were no errors found in this run.", self.grid_options["verbosity"], 0)
## ##
# Clean up code: remove files, unset values. # Clean up code: remove files, unset values.
...@@ -745,11 +751,13 @@ class Population: ...@@ -745,11 +751,13 @@ class Population:
self._load_grid_function() self._load_grid_function()
# Set up generator # Set up generator
generator = self.grid_options["_system_generator"](self) generator = self.grid_options["_system_generator"](self, print_results=False)
# Set up local variables # Set up local variables
running = True running = True
localcounter = 0 localcounter = 0 # global counter for the whole loop. (need to be ticked every loop)
probability_of_systems_run = 0 # counter for the probability of the actual systems this tread ran
number_of_systems_run = 0 # counter for the actual amt of systems this thread ran
verbose_print( verbose_print(
"Process {} started".format(ID), self.grid_options["verbosity"], 0 "Process {} started".format(ID), self.grid_options["verbosity"], 0
...@@ -778,16 +786,18 @@ class Population: ...@@ -778,16 +786,18 @@ class Population:
# Evolve the system # Evolve the system
self._evolve_system_mp(full_system_dict) self._evolve_system_mp(full_system_dict)
# TODO: fix the 'repeat' and 'weight' tracking here
# Keep track of systems:
probability_of_systems_run += full_system_dict['probability']
number_of_systems_run += 1
except StopIteration: except StopIteration:
verbose_print(
"Process {}: generator done".format(ID),
self.grid_options["verbosity"],
0,
)
running = False running = False
# Has to be here because this one is used for the (localcounter+ID) % (self..)
localcounter += 1 localcounter += 1
# Return a set of results and errors # Return a set of results and errors
output_dict = { output_dict = {
"results": self.grid_options["results"], "results": self.grid_options["results"],
...@@ -800,6 +810,12 @@ class Population: ...@@ -800,6 +810,12 @@ class Population:
"_errors_found": self.grid_options["_errors_found"], "_errors_found": self.grid_options["_errors_found"],
} }
verbose_print(
"Process {}: generator done. Ran {} systems with a total probability of {}. This thread had {} failing systems with a total probability of {}".format(ID, number_of_systems_run, probability_of_systems_run, self.grid_options["_failed_count"], self.grid_options["_failed_prob"]),
self.grid_options["verbosity"],
0,
)
return output_dict return output_dict
def _evolve_population_mp(self): def _evolve_population_mp(self):
...@@ -1132,7 +1148,8 @@ class Population: ...@@ -1132,7 +1148,8 @@ class Population:
# TODO: add centering center left right for the spacing. # TODO: add centering center left right for the spacing.
# TODO: add sensible description to this function. # TODO: add sensible description to this function.
# TODO: Check whether all the probability and phasevol values are correct. # TODO: Check whether all the probability and phasevol values are correct.
# TODO: import only the necessary packages/functions
Results in a generated file that contains a system_generator function. Results in a generated file that contains a system_generator function.
""" """
...@@ -1153,7 +1170,7 @@ class Population: ...@@ -1153,7 +1170,7 @@ class Population:
code_string += "\n\n" code_string += "\n\n"
# Make the function # Make the function
code_string += "def grid_code(self):\n" code_string += "def grid_code(self, print_results=True):\n"
# Increase depth # Increase depth
depth += 1 depth += 1
...@@ -1191,8 +1208,8 @@ class Population: ...@@ -1191,8 +1208,8 @@ class Population:
code_string += indent * depth + "phasevol = 1\n" code_string += indent * depth + "phasevol = 1\n"
code_string += indent * depth + "\n" code_string += indent * depth + "\n"
code_string += indent * depth + "# setting probability lists\n"
# Prepare the probability # Prepare the probability
code_string += indent * depth + "# setting probability lists\n"
for grid_variable_el in sorted( for grid_variable_el in sorted(
self.grid_options["_grid_variables"].items(), self.grid_options["_grid_variables"].items(),
key=lambda x: x[1]["grid_variable_number"], key=lambda x: x[1]["grid_variable_number"],
...@@ -1400,26 +1417,36 @@ class Population: ...@@ -1400,26 +1417,36 @@ class Population:
# Calculate value # Calculate value
code_string += ( code_string += (
indent * (depth + 1) indent * (depth + 1)
+ 'probability = self.grid_options["_weight"] * probabilities_list[{}]'.format( + 'probability = self.grid_options["weight"] * probabilities_list[{}]'.format(
grid_variable["grid_variable_number"] grid_variable["grid_variable_number"]
) )
+ "\n" + "\n"
) )
# TODO: ask rob if just replacing this with probability is enough
code_string += ( code_string += (
indent * (depth + 1) indent * (depth + 1)
+ 'repeat_probability = probability / self.grid_options["_repeat"]' # + 'repeat_probability = probability / self.grid_options["repeat"]'
+ 'probability = probability / self.grid_options["repeat"]'
+ "\n" + "\n"
) )
code_string += indent * (depth + 1) + "_total_starcount += 1\n"
# set probability and phasevol values # For each repeat of the system this has to be done yes.
code_string += ( code_string += (
indent * (depth + 1) indent * (depth + 1)
+ 'for _ in range(self.grid_options["repeat"]):'
+ "\n"
)
code_string += indent * (depth + 2) + "_total_starcount += 1\n"
# set probability and phasevol values
code_string += (
indent * (depth + 2)
+ 'parameter_dict["{}"] = {}'.format("probability", "probability") + 'parameter_dict["{}"] = {}'.format("probability", "probability")
+ "\n" + "\n"
) )
code_string += ( code_string += (
indent * (depth + 1) indent * (depth + 2)
+ 'parameter_dict["{}"] = {}'.format("phasevol", "phasevol") + 'parameter_dict["{}"] = {}'.format("phasevol", "phasevol")
+ "\n" + "\n"
) )
...@@ -1434,13 +1461,13 @@ class Population: ...@@ -1434,13 +1461,13 @@ class Population:
# Increment total probability # Increment total probability
code_string += ( code_string += (
indent * (depth + 1) + "self._increment_probtot(probability)\n" indent * (depth + 2) + "self._increment_probtot(probability)\n"
) )
if not dry_run: if not dry_run:
# Handling of what is returned, or what is not. # Handling of what is returned, or what is not.
# TODO: think of whether this is a good method # TODO: think of whether this is a good method
code_string += indent * (depth + 1) + "yield(parameter_dict)\n" code_string += indent * (depth + 2) + "yield(parameter_dict)\n"
# The below solution might be a good one to add things to specific queues # The below solution might be a good one to add things to specific queues
# $self->queue_evolution_code_run($self->{_flexigrid}->{thread_q}, # $self->queue_evolution_code_run($self->{_flexigrid}->{thread_q},
...@@ -1448,7 +1475,7 @@ class Population: ...@@ -1448,7 +1475,7 @@ class Population:
# If its a dry run, dont do anything with it # If its a dry run, dont do anything with it
else: else:
code_string += indent * (depth + 1) + "pass\n" code_string += indent * (depth + 2) + "pass\n"
code_string += indent * (depth + 1) + "#" * 40 + "\n" code_string += indent * (depth + 1) + "#" * 40 + "\n"
...@@ -1490,13 +1517,20 @@ class Population: ...@@ -1490,13 +1517,20 @@ class Population:
code_string += indent * (depth + 1) + "#" * 40 + "\n" code_string += indent * (depth + 1) + "#" * 40 + "\n"
code_string += ( code_string += (
indent * (depth + 1) indent * (depth + 1)
+ "if print_results:\n"
)
code_string += (
indent * (depth + 2)
+ "print('Grid has handled {} stars'.format(_total_starcount))\n" + "print('Grid has handled {} stars'.format(_total_starcount))\n"
) )
code_string += ( code_string += (
indent * (depth + 1) indent * (depth + 2)
+ "print('with a total probability of {}'.format(self.grid_options['_probtot']))\n" + "print('with a total probability of {}'.format(self.grid_options['_probtot']))\n"
) )
################
# Finalising return statement for dry run.
#
if dry_run: if dry_run:
code_string += indent * (depth + 1) + "return _total_starcount\n" code_string += indent * (depth + 1) + "return _total_starcount\n"
......
...@@ -88,8 +88,8 @@ grid_options_defaults_dict = { ...@@ -88,8 +88,8 @@ grid_options_defaults_dict = {
"_count": 0, # count of systems "_count": 0, # count of systems
"_total_starcount": 0, # Total count of systems in this generator "_total_starcount": 0, # Total count of systems in this generator
"_probtot": 0, # total probability "_probtot": 0, # total 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, # number of times to repeat each system (probability is adjusted to be 1/repeat)
"results": {}, # dict to store the results. Every process fills this on its own and then it will be joined later "results": {}, # dict to store the results. Every process fills this on its own and then it will be joined later
"_start_time_evolution": 0, # Start time of the grid "_start_time_evolution": 0, # Start time of the grid
"_end_time_evolution": 0, # end time of the grid "_end_time_evolution": 0, # end time of the grid
...@@ -466,8 +466,8 @@ grid_options_descriptions = { ...@@ -466,8 +466,8 @@ grid_options_descriptions = {
"slurm": "Int flag whether to use a slurm type population evolution.", # TODO: describe this in more detail "slurm": "Int flag whether to use a slurm type population evolution.", # TODO: describe this in more detail
"population_type": "variable storing what kind of population type should be evolved. See population_type_options for the options.", # TODO: make this functionality work properly "population_type": "variable storing what kind of population type should be evolved. See population_type_options for the options.", # TODO: make this functionality work properly
"_population_type_options": "List storing the population_type options.", "_population_type_options": "List storing the population_type options.",
"_weight": "Weight factor for each system. The calculated probability is mulitplied by this. If the user wants each system to be repeated several times, then this variable should not be changed, rather change the _repeat variable instead, as that handles the reduction in probability per system. This is useful for systems that have a process with some random element in it.", # TODO: add more info here, regarding the evolution splitting. "weight": "Weight factor for each system. The calculated probability is mulitplied by this. If the user wants each system to be repeated several times, then this variable should not be changed, rather change the _repeat variable instead, as that handles the reduction in probability per system. This is useful for systems that have a process with some random element in it.", # TODO: add more info here, regarding the evolution splitting.
"_repeat": "Factor of how many times a system should be repeated. Consider the evolution splitting binary_c argument for supernovae kick repeating.", # TODO: make sure this is used. "repeat": "Factor of how many times a system should be repeated. Consider the evolution splitting binary_c argument for supernovae kick repeating.", # TODO: make sure this is used.
"evolution_type": "Variable containing the type of evolution used of the grid. Multiprocessing or linear processing", "evolution_type": "Variable containing the type of evolution used of the grid. Multiprocessing or linear processing",
} }
......
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