Skip to content

Commit 98a3af8

Browse files
authored
Merge pull request #675 from jeffriley/minor-updates
Minor fixes
2 parents 871e636 + 6620502 commit 98a3af8

File tree

11 files changed

+412
-78
lines changed

11 files changed

+412
-78
lines changed

examples/methods_paper_plots/chirpmass_distribution/pythonSubmit.py

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,47 @@ class pythonProgramOptions:
2626
# docker container (src, obj, bin), and the COMPAS executable resides
2727
# in the bin directory (rather than the src directory)
2828
compas_executable_override = os.environ.get('COMPAS_EXECUTABLE_PATH')
29-
print('compas_executable_override', compas_executable_override)
3029

3130
if (compas_executable_override is None):
32-
git_directory = os.environ.get('COMPAS_ROOT_DIR')
33-
compas_executable = os.path.join(git_directory, 'src/COMPAS')
31+
32+
# we should fix this one day - we should not assume that the COMPAS executable
33+
# is in the 'src' directory. The standard is to put the object files created
34+
# by the compile into the 'obj' directory, and the executable files created by
35+
# the link in the 'bin' directory.
36+
#
37+
# for now though, because this is how everybody expects it to be, we'll just check
38+
# that the path to the root directory (the parent directory of the directory in
39+
# which we expect the executable to reside - for now, 'src') is set to something.
40+
41+
compas_root_dir = os.environ.get('COMPAS_ROOT_DIR')
42+
assert compas_root_dir is not None, "Unable to locate the COMPAS executable: check that the environment variable COMPAS_ROOT_DIR is set correctly, and the COMPAS executable exists."
43+
44+
# construct path to executable
45+
#
46+
# ideally we wouldn't have the 'src' directory name (or any other directory name)
47+
# prepended to the executable name - if we just execute the executable name on its
48+
# own, as long as the user navigates to the directory in which the executable resides
49+
# they don't need to set the COMPAS_ROOT_DIR environment variable
50+
51+
compas_executable = os.path.join(compas_root_dir, 'src/COMPAS')
3452
else:
3553
compas_executable = compas_executable_override
3654

55+
# check that a file with the correct name exists where we expect it to
56+
assert os.path.isfile(compas_executable), "Unable to locate the COMPAS executable: check that the environment variable COMPAS_ROOT_DIR is set correctly, and the COMPAS executable exists."
57+
58+
3759
enable_warnings = False # option to enable/disable warning messages
3860

39-
number_of_systems = int(1e2) #number of systems per batch
61+
number_of_systems = int(1e2) # number of systems per batch
4062

4163
populationPrinting = False
4264

4365
randomSeedFileName = 'randomSeed.txt'
4466
if os.path.isfile(randomSeedFileName):
4567
random_seed = int(np.loadtxt(randomSeedFileName))
4668
else:
47-
random_seed = 0 # If you want a random seed, use: np.random.randint(2,2**63-1)
69+
random_seed = 0 # If you want a random seed, use: np.random.randint(2,2**63-1)
4870

4971
# environment variable COMPAS_LOGS_OUTPUT_DIR_PATH is used primarily for docker runs
5072
# if COMPAS_LOGS_OUTPUT_DIR_PATH is set (!= None) it is used as the value for the
@@ -55,7 +77,7 @@ class pythonProgramOptions:
5577

5678
if (compas_logs_output_override is None):
5779
output = os.getcwd()
58-
output_container = None # names the directory to be created and in which log files are created. Default in COMPAS is "COMPAS_Output"
80+
output_container = None # names the directory to be created and in which log files are created. Default in COMPAS is "COMPAS_Output"
5981
else:
6082
output = compas_logs_output_override
6183
output_container = None
@@ -76,6 +98,9 @@ class pythonProgramOptions:
7698
hyperparameterList = False
7799
shareSeeds = False
78100

101+
notes_hdrs = None # no annotations header strings (no annotations)
102+
notes = None # no annotations
103+
79104
mode = 'BSE' # evolving single stars (SSE) or binaries (BSE)?
80105

81106
grid_filename = None # grid file name (e.g. 'mygrid.txt')
@@ -86,7 +111,7 @@ class pythonProgramOptions:
86111
else:
87112
grid_filename = compas_input_path_override + '/' + grid_filename
88113

89-
logfile_definitions = "COMPAS_Output_Definitions.txt" # logfile record definitions file name (e.g. 'logdefs.txt')
114+
logfile_definitions = "COMPAS_Output_Definitions.txt" # logfile record definitions file name (e.g. 'logdefs.txt')
90115

91116
if logfile_definitions != None:
92117
if compas_input_path_override == None:
@@ -136,6 +161,8 @@ class pythonProgramOptions:
136161
common_envelope_mass_accretion_min = 0.04 # For 'MACLEOD+2014' [Msol]
137162
common_envelope_mass_accretion_max = 0.10 # For 'MACLEOD+2014' [Msol]
138163
envelope_state_prescription = 'LEGACY'
164+
common_envelope_allow_radiative_envelope_surive = False
165+
common_envelope_allow_immediate_RLOF_post_CE_survive = False
139166

140167
mass_loss_prescription = 'VINK'
141168
luminous_blue_variable_prescription = 'HURLEY_ADD'
@@ -259,6 +286,8 @@ class pythonProgramOptions:
259286

260287
maximum_neutron_star_mass = 2.5 # [Msol]
261288

289+
add_options_to_sysparms = 'GRID' # should all option values be added to system parameters files? options are 'ALWAYS', 'GRID', and 'NEVER'
290+
262291
log_level = 0
263292
log_classes = []
264293

@@ -317,6 +346,8 @@ def booleanChoices(self):
317346
self.pulsation_pair_instability,
318347
self.quiet,
319348
self.common_envelope_allow_main_sequence_survive,
349+
self.common_envelope_allow_radiative_envelope_surive,
350+
self.common_envelope_allow_immediate_RLOF_post_CE_survive,
320351
self.evolvePulsars,
321352
self.debug_to_file,
322353
self.errors_to_file,
@@ -343,6 +374,8 @@ def booleanCommands(self):
343374
'--pulsational-pair-instability',
344375
'--quiet',
345376
'--common-envelope-allow-main-sequence-survive',
377+
'--common-envelope-allow-radiative-envelope-surive',
378+
'--common-envelope-allow-immediate-rlof-post-ce-survive',
346379
'--evolve-pulsars',
347380
'--debug-to-file',
348381
'--errors-to-file',
@@ -538,6 +571,8 @@ def numericalCommands(self):
538571

539572
def stringChoices(self):
540573
stringChoices = [
574+
self.notes_hdrs,
575+
self.notes,
541576
self.mode,
542577
self.case_BB_stability_prescription,
543578
self.chemically_homogeneous_evolution,
@@ -581,13 +616,16 @@ def stringChoices(self):
581616
self.logfile_supernovae,
582617
self.logfile_switch_log,
583618
self.logfile_system_parameters,
584-
self.neutrino_mass_loss_BH_formation
619+
self.neutrino_mass_loss_BH_formation,
620+
self.add_options_to_sysparms
585621
]
586622

587623
return stringChoices
588624

589625
def stringCommands(self):
590626
stringCommands = [
627+
'--notes-hdrs',
628+
'--notes',
591629
'--mode',
592630
'--case-BB-stability-prescription',
593631
'--chemically-homogeneous-evolution',
@@ -631,7 +669,8 @@ def stringCommands(self):
631669
'--logfile-supernovae',
632670
'--logfile-switch-log',
633671
'--logfile-system-parameters',
634-
'--neutrino-mass-loss-BH-formation'
672+
'--neutrino-mass-loss-BH-formation',
673+
'--add-options-to-sysparms'
635674
]
636675

637676
return stringCommands
@@ -698,14 +737,16 @@ def generateCommandLineOptionsDict(self):
698737
for i in range(nBoolean):
699738
if booleanChoices[i] == True:
700739
command.update({booleanCommands[i] : ''})
740+
elif booleanChoices[i] == False:
741+
command.update({booleanCommands[i] : 'False'})
701742

702743
for i in range(nNumerical):
703744
if not numericalChoices[i] == None:
704745
command.update({numericalCommands[i] : str(numericalChoices[i])})
705746

706747
for i in range(nString):
707748
if not stringChoices[i] == None:
708-
command.update({stringCommands[i] : stringChoices[i]})
749+
command.update({stringCommands[i] : cleanStringParameter(stringChoices[i])})
709750

710751
for i in range(nList):
711752
if listChoices[i]:
@@ -729,6 +770,19 @@ def combineCommandLineOptionsDictIntoShellCommand(commandOptions):
729770
return shellCommand
730771

731772

773+
def cleanStringParameter(str_param):
774+
""" clean up string parameters to avoid confusing Boost """
775+
if str_param is not None:
776+
# strip any quotes from the ends of the string
777+
str_param = str_param.strip("'\"")
778+
779+
# escape any unescaped spaces or quotes within the string
780+
escapes = [" ", "'", "\""]
781+
for escape in escapes:
782+
str_param = re.sub(r"(?<!\\){}".format(escape), r"\{}".format(escape), str_param)
783+
return str_param
784+
785+
732786
if __name__ == "__main__":
733787

734788
#-- Get the program options
30 Bytes
Loading

examples/methods_paper_plots/detailed_evolution/pythonSubmitDemo.py

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,45 @@ class pythonProgramOptions:
3535
print('compas_executable_override', compas_executable_override)
3636

3737
if (compas_executable_override is None):
38-
git_directory = os.environ.get('COMPAS_ROOT_DIR')
39-
compas_executable = os.path.join(git_directory, 'src/COMPAS')
38+
39+
# we should fix this one day - we should not assume that the COMPAS executable
40+
# is in the 'src' directory. The standard is to put the object files created
41+
# by the compile into the 'obj' directory, and the executable files created by
42+
# the link in the 'bin' directory.
43+
#
44+
# for now though, because this is how everybody expects it to be, we'll just check
45+
# that the path to the root directory (the parent directory of the directory in
46+
# which we expect the executable to reside - for now, 'src') is set to something.
47+
48+
compas_root_dir = os.environ.get('COMPAS_ROOT_DIR')
49+
assert compas_root_dir is not None, "Unable to locate the COMPAS executable: check that the environment variable COMPAS_ROOT_DIR is set correctly, and the COMPAS executable exists."
50+
51+
# construct path to executable
52+
#
53+
# ideally we wouldn't have the 'src' directory name (or any other directory name)
54+
# prepended to the executable name - if we just execute the executable name on its
55+
# own, as long as the user navigates to the directory in which the executable resides
56+
# they don't need to set the COMPAS_ROOT_DIR environment variable
57+
58+
compas_executable = os.path.join(compas_root_dir, 'src/COMPAS')
4059
else:
4160
compas_executable = compas_executable_override
4261

62+
# check that a file with the correct name exists where we expect it to
63+
assert os.path.isfile(compas_executable), "Unable to locate the COMPAS executable: check that the environment variable COMPAS_ROOT_DIR is set correctly, and the COMPAS executable exists."
64+
65+
4366
enable_warnings = False # option to enable/disable warning messages
4467

45-
number_of_systems = 10 #number of systems per batch
68+
number_of_systems = 10 # number of systems per batch
4669

4770
populationPrinting = False
4871

4972
randomSeedFileName = 'randomSeed.txt'
5073
if os.path.isfile(randomSeedFileName):
5174
random_seed = int(np.loadtxt(randomSeedFileName))
5275
else:
53-
random_seed = 0 # If you want a random seed, use: np.random.randint(2,2**63-1)
76+
random_seed = 0 # If you want a random seed, use: np.random.randint(2,2**63-1)
5477

5578
# environment variable COMPAS_LOGS_OUTPUT_DIR_PATH is used primarily for docker runs
5679
# if COMPAS_LOGS_OUTPUT_DIR_PATH is set (!= None) it is used as the value for the
@@ -61,7 +84,7 @@ class pythonProgramOptions:
6184

6285
if (compas_logs_output_override is None):
6386
output = os.getcwd()
64-
output_container = None # names the directory to be created and in which log files are created. Default in COMPAS is "COMPAS_Output"
87+
output_container = None # names the directory to be created and in which log files are created. Default in COMPAS is "COMPAS_Output"
6588
else:
6689
output = compas_logs_output_override
6790
output_container = None
@@ -82,9 +105,12 @@ class pythonProgramOptions:
82105
hyperparameterList = False
83106
shareSeeds = False
84107

108+
notes_hdrs = None # no annotations header strings (no annotations)
109+
notes = None # no annotations
110+
85111
mode = 'BSE' # evolving single stars (SSE) or binaries (BSE)?
86112

87-
grid_filename = 'Grid_demo.txt' # grid file name (e.g. 'mygrid.txt')
113+
grid_filename = 'Grid_demo.txt' # grid file name (e.g. 'mygrid.txt')
88114

89115
if grid_filename != None:
90116
if compas_input_path_override == None:
@@ -142,6 +168,8 @@ class pythonProgramOptions:
142168
common_envelope_mass_accretion_min = 0.04 # For 'MACLEOD+2014' [Msol]
143169
common_envelope_mass_accretion_max = 0.10 # For 'MACLEOD+2014' [Msol]
144170
envelope_state_prescription = 'LEGACY'
171+
common_envelope_allow_radiative_envelope_surive = False
172+
common_envelope_allow_immediate_RLOF_post_CE_survive = False
145173

146174
mass_loss_prescription = 'VINK'
147175
luminous_blue_variable_prescription = 'HURLEY_ADD'
@@ -265,6 +293,8 @@ class pythonProgramOptions:
265293

266294
maximum_neutron_star_mass = 2.5 # [Msol]
267295

296+
add_options_to_sysparms = 'GRID' # should all option values be added to system parameters files? options are 'ALWAYS', 'GRID', and 'NEVER'
297+
268298
log_level = 0
269299
log_classes = []
270300

@@ -323,6 +353,8 @@ def booleanChoices(self):
323353
self.pulsation_pair_instability,
324354
self.quiet,
325355
self.common_envelope_allow_main_sequence_survive,
356+
self.common_envelope_allow_radiative_envelope_surive,
357+
self.common_envelope_allow_immediate_RLOF_post_CE_survive,
326358
self.evolvePulsars,
327359
self.debug_to_file,
328360
self.errors_to_file,
@@ -349,6 +381,8 @@ def booleanCommands(self):
349381
'--pulsational-pair-instability',
350382
'--quiet',
351383
'--common-envelope-allow-main-sequence-survive',
384+
'--common-envelope-allow-radiative-envelope-surive',
385+
'--common-envelope-allow-immediate-rlof-post-ce-survive',
352386
'--evolve-pulsars',
353387
'--debug-to-file',
354388
'--errors-to-file',
@@ -544,6 +578,8 @@ def numericalCommands(self):
544578

545579
def stringChoices(self):
546580
stringChoices = [
581+
self.notes_hdrs,
582+
self.notes,
547583
self.mode,
548584
self.case_BB_stability_prescription,
549585
self.chemically_homogeneous_evolution,
@@ -587,13 +623,16 @@ def stringChoices(self):
587623
self.logfile_supernovae,
588624
self.logfile_switch_log,
589625
self.logfile_system_parameters,
590-
self.neutrino_mass_loss_BH_formation
626+
self.neutrino_mass_loss_BH_formation,
627+
self.add_options_to_sysparms
591628
]
592629

593630
return stringChoices
594631

595632
def stringCommands(self):
596633
stringCommands = [
634+
'--notes-hdrs',
635+
'--notes',
597636
'--mode',
598637
'--case-BB-stability-prescription',
599638
'--chemically-homogeneous-evolution',
@@ -637,7 +676,8 @@ def stringCommands(self):
637676
'--logfile-supernovae',
638677
'--logfile-switch-log',
639678
'--logfile-system-parameters',
640-
'--neutrino-mass-loss-BH-formation'
679+
'--neutrino-mass-loss-BH-formation',
680+
'--add-options-to-sysparms'
641681
]
642682

643683
return stringCommands
@@ -704,14 +744,16 @@ def generateCommandLineOptionsDict(self):
704744
for i in range(nBoolean):
705745
if booleanChoices[i] == True:
706746
command.update({booleanCommands[i] : ''})
747+
elif booleanChoices[i] == False:
748+
command.update({booleanCommands[i] : 'False'})
707749

708750
for i in range(nNumerical):
709751
if not numericalChoices[i] == None:
710752
command.update({numericalCommands[i] : str(numericalChoices[i])})
711753

712754
for i in range(nString):
713755
if not stringChoices[i] == None:
714-
command.update({stringCommands[i] : stringChoices[i]})
756+
command.update({stringCommands[i] : cleanStringParameter(stringChoices[i])})
715757

716758
for i in range(nList):
717759
if listChoices[i]:
@@ -735,6 +777,19 @@ def combineCommandLineOptionsDictIntoShellCommand(commandOptions):
735777
return shellCommand
736778

737779

780+
def cleanStringParameter(str_param):
781+
""" clean up string parameters to avoid confusing Boost """
782+
if str_param is not None:
783+
# strip any quotes from the ends of the string
784+
str_param = str_param.strip("'\"")
785+
786+
# escape any unescaped spaces or quotes within the string
787+
escapes = [" ", "'", "\""]
788+
for escape in escapes:
789+
str_param = re.sub(r"(?<!\\){}".format(escape), r"\{}".format(escape), str_param)
790+
return str_param
791+
792+
738793
if __name__ == "__main__":
739794

740795
#-- Get the program options

0 commit comments

Comments
 (0)