Loading binarycpython/utils/grid.py +28 −20 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ from binarycpython.utils.functions import ( verbose_print, binarycDecoder, merge_dicts, BinaryCEncoder ) from binarycpython.utils.hpc_functions import ( get_condor_version, Loading Loading @@ -268,39 +269,40 @@ class Population: Function to add grid variables to the grid_options. TODO: Fix this complex function. TODO: update the description The execution of the grid generation will be through a nested forloop, and will rely heavily on the eval() functionality of python. Which, in terms of safety is very bad, but in terms of flexibility is very good. The execution of the grid generation will be through a nested forloop. Each of the grid variables will get create a deeper for loop. 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 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 example: range = [log($mmin),log($mmax)] 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) example: resolution = $resolution->{m1} 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 example: spacingfunction = "const(log($mmin),log($mmax),$resolution->{m1})" 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: # TODO: think of good description. example: precode = '$m1=exp($lnm1);' 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($m1)*$m1' example: probdist = 'Kroupa2001(M_1)*M_1' dphasevol: part of the parameter space that the total probability is calculated with example: dphasevol = '$dlnm1' 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' example: condition = 'self.grid_options['binary']==1' """ # Add grid_variable Loading Loading @@ -457,17 +459,23 @@ class Population: with open(settings_fullname, "w") as file: file.write( json.dumps( all_info_cleaned, indent=4, default=binaryc_json_serializer all_info_cleaned, indent=4, default=binaryc_json_serializer, ) ) else: verbose_print( "Writing settings to {}".format(outfile), self.grid_options["verbosity"], 1, ) # if not outfile.endswith('json'): if not outfile.endswith('json'): verbose_print( "Error: outfile ({}) must end with .json".format(outfile), self.grid_options["verbosity"], 0, ) raise ValueError with open(outfile, "w") as file: file.write( json.dumps( Loading Loading @@ -1123,7 +1131,7 @@ class Population: code_string += ( indent * (depth + 1) + "{}".format( grid_variable["precode"].replace("\n", "\n" + indent * (depth)) grid_variable["precode"].replace("\n", "\n" + indent * (depth+1)) ) + "\n" ) Loading Loading
binarycpython/utils/grid.py +28 −20 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ from binarycpython.utils.functions import ( verbose_print, binarycDecoder, merge_dicts, BinaryCEncoder ) from binarycpython.utils.hpc_functions import ( get_condor_version, Loading Loading @@ -268,39 +269,40 @@ class Population: Function to add grid variables to the grid_options. TODO: Fix this complex function. TODO: update the description The execution of the grid generation will be through a nested forloop, and will rely heavily on the eval() functionality of python. Which, in terms of safety is very bad, but in terms of flexibility is very good. The execution of the grid generation will be through a nested forloop. Each of the grid variables will get create a deeper for loop. 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 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 example: range = [log($mmin),log($mmax)] 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) example: resolution = $resolution->{m1} 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 example: spacingfunction = "const(log($mmin),log($mmax),$resolution->{m1})" 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: # TODO: think of good description. example: precode = '$m1=exp($lnm1);' 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($m1)*$m1' example: probdist = 'Kroupa2001(M_1)*M_1' dphasevol: part of the parameter space that the total probability is calculated with example: dphasevol = '$dlnm1' 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' example: condition = 'self.grid_options['binary']==1' """ # Add grid_variable Loading Loading @@ -457,17 +459,23 @@ class Population: with open(settings_fullname, "w") as file: file.write( json.dumps( all_info_cleaned, indent=4, default=binaryc_json_serializer all_info_cleaned, indent=4, default=binaryc_json_serializer, ) ) else: verbose_print( "Writing settings to {}".format(outfile), self.grid_options["verbosity"], 1, ) # if not outfile.endswith('json'): if not outfile.endswith('json'): verbose_print( "Error: outfile ({}) must end with .json".format(outfile), self.grid_options["verbosity"], 0, ) raise ValueError with open(outfile, "w") as file: file.write( json.dumps( Loading Loading @@ -1123,7 +1131,7 @@ class Population: code_string += ( indent * (depth + 1) + "{}".format( grid_variable["precode"].replace("\n", "\n" + indent * (depth)) grid_variable["precode"].replace("\n", "\n" + indent * (depth+1)) ) + "\n" ) Loading