Skip to content

Commit c61a6db

Browse files
authored
Copy input files (grid, logfile-definitions) to output container + defect repairs (#603)
* Enhancement and Defect Repairs: - Added code to copy any grid file and/or logfile-definitions file specified to output container. - Copying a large grid file could take time, and take up much space, so added new program option '--store-input-files' which is TRUE by default. If FALSE, neither the grid file (if specified) nor the logfile-definitions file (if specified) will be copied to the output container (if TRUE, both will be copied (if specified)). - Fixed issue #600: changed pythonSubmit.py to treat fully-qualified grid filenames and fully-qualified logfile-definitions filenames correctly (i.e. don't add CWD if the filename is already fully-qualified). - Fixed issue #601: changed pythonSubmit.py to put all boolean parameters on the commandline, with True or False value. * Update Log.h Removed extraneous include
1 parent dacc060 commit c61a6db

File tree

7 files changed

+94
-13
lines changed

7 files changed

+94
-13
lines changed

docs/COMPAS_LaTeX/sections/Appendices/ProgramOptions.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ \section{Program Options}\label{sec:ProgramOptionsAppendix}
307307

308308
\programOption{stellar-zeta-prescription}{}{Prescription for stellar zeta. \\ Options: \lcb\ STARTRACK, SOBERMAN, HURLEY, ARBITRARY \rcb}{SOBERMAN}
309309

310+
\programOption{store-input-files}{}{Enables copying of any specified grid file and/or logfile-definitios file to the COMPAS output container}{TRUE}
311+
310312
\programOption{switch-log}{}{Enables printing of the Switch Log logfile}{FALSE}
311313

312314
\programOption{timestep-multiplier}{}{Multiplicative factor for timestep duration}{1.0}

docs/COMPAS_LaTeX/sections/RevisionHistory.tex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@
7373

7474
\revisionHistoryRow{18 December 2020}{2.12}{Removed references to Mass\_Transfer\_Case\_Initial parameter}{Reinhold Willcox}
7575

76+
\end{tabularx} % why is this too wide?
77+
78+
79+
\begin{tabularx}{\linewidth}{
80+
|>{\hsize=0.8\hsize}X
81+
|>{\hsize=0.3\hsize}X
82+
|>{\hsize=2.1\hsize}X
83+
|>{\hsize=0.8\hsize}X
84+
|
85+
}
86+
87+
\hline %
88+
7689
\revisionHistoryRow{08 January 2021}{2.13}{Added (brief) description of HDF5 logfile support.}{}
7790
\revisionHistoryRow{}{}{Added description of option \mbox{hdf5-buffer-size}.}{}
7891
\revisionHistoryRow{}{}{Added description of option \mbox{hdf5-chunk-size}.}{}
@@ -83,6 +96,7 @@
8396
\revisionHistoryRow{06 April 2021}{2.15}{Added FARMER prescription for option pulsational-pair-instability-prescription}{Lieke van Son}
8497
\revisionHistoryRow{20 April 2021}{2.16}{Added option add-options-to-sysparms}{Jeff Riley}
8598
\revisionHistoryRow{18 May 2021}{2.17}{Changed default LBV prescription}{Tom Wagg}
99+
\revisionHistoryRow{28 July 2021}{2.18}{Added option store-input-files}{Jeff Riley}
86100

87101
\end{tabularx} % why is this too wide?
88102
\normalsize

preProcessing/pythonSubmit.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import os
44
from subprocess import call
55
import re
6+
import ntpath
67

78
# Check if we are using python 3
89
python_version = sys.version_info[0]
910
print("python_version =", python_version)
1011

12+
1113
class pythonProgramOptions:
1214
"""
1315
A class to store and access COMPAS program options in python
@@ -24,7 +26,6 @@ class pythonProgramOptions:
2426
# docker container (src, obj, bin), and the COMPAS executable resides
2527
# in the bin directory (rather than the src directory)
2628
compas_executable_override = os.environ.get('COMPAS_EXECUTABLE_PATH')
27-
print('compas_executable_override', compas_executable_override)
2829

2930
if (compas_executable_override is None):
3031
git_directory = os.environ.get('COMPAS_ROOT_DIR')
@@ -53,7 +54,7 @@ class pythonProgramOptions:
5354

5455
if (compas_logs_output_override is None):
5556
output = os.getcwd()
56-
output_container = None # names the directory to be created and in which log files are created. Default in COMPAS is "COMPAS_Output"
57+
output_container = None # names the directory to be created and in which log files are created. Default in COMPAS is "COMPAS_Output"
5758
else:
5859
output = compas_logs_output_override
5960
output_container = None
@@ -79,18 +80,28 @@ class pythonProgramOptions:
7980
grid_filename = None # grid file name (e.g. 'mygrid.txt')
8081

8182
if grid_filename != None:
82-
if compas_input_path_override == None:
83-
grid_filename = os.getcwd() + '/' + grid_filename.strip("'\"")
84-
else:
85-
grid_filename = compas_input_path_override + '/' + grid_filename.strip("'\"")
83+
# if the grid filename supplied is already fully-qualified, leave it as is
84+
head, tail = ntpath.split(grid_filename) # split into pathname and base filename
85+
86+
if head == '' or head == '.': # no path (or CWD) - add path as required
87+
grid_filename = tail or ntpath.basename(head)
88+
if compas_input_path_override == None:
89+
grid_filename = os.getcwd() + '/' + grid_filename.strip("'\"")
90+
else:
91+
grid_filename = compas_input_path_override + '/' + grid_filename.strip("'\"")
8692

8793
logfile_definitions = None # logfile record definitions file name (e.g. 'logdefs.txt')
8894

8995
if logfile_definitions != None:
90-
if compas_input_path_override == None:
91-
logfile_definitions = os.getcwd() + '/' + logfile_definitions.strip("'\"")
92-
else:
93-
logfile_definitions = compas_input_path_override + '/' + logfile_definitions.strip("'\"")
96+
# if the grid filename supplied is already fully-qualified, leave it as is
97+
head, tail = ntpath.split(grid_filename) # split into pathname and base filename
98+
99+
if head == '' or head == '.': # no path (or CWD) - add path as required
100+
logfile_definitions = tail or ntpath.basename(head)
101+
if compas_input_path_override == None:
102+
logfile_definitions = os.getcwd() + '/' + logfile_definitions.strip("'\"")
103+
else:
104+
logfile_definitions = compas_input_path_override + '/' + logfile_definitions.strip("'\"")
94105

95106
initial_mass = None # initial mass for SSE
96107
initial_mass_1 = None # primary initial mass for BSE
@@ -117,6 +128,8 @@ class pythonProgramOptions:
117128

118129
chemically_homogeneous_evolution = 'PESSIMISTIC' # chemically homogeneous evolution. Options are 'NONE', 'OPTIMISTIC' and 'PESSIMISTIC'
119130

131+
store_input_files = True # store input files in output container?
132+
120133
switch_log = False
121134

122135
common_envelope_alpha = 1.0
@@ -319,6 +332,7 @@ def booleanChoices(self):
319332
self.errors_to_file,
320333
self.allow_rlof_at_birth,
321334
self.allow_touching_at_birth,
335+
self.store_input_files,
322336
self.switch_log,
323337
self.check_photon_tiring_limit
324338
]
@@ -345,6 +359,7 @@ def booleanCommands(self):
345359
'--errors-to-file',
346360
'--allow-rlof-at-birth',
347361
'--allow-touching-at-birth',
362+
'--store-input-files',
348363
'--switch-log',
349364
'--check-photon-tiring-limit'
350365
]
@@ -695,6 +710,8 @@ def generateCommandLineOptionsDict(self):
695710
for i in range(nBoolean):
696711
if booleanChoices[i] == True:
697712
command.update({booleanCommands[i] : ''})
713+
elif booleanChoices[i] == False:
714+
command.update({booleanCommands[i] : 'False'})
698715

699716
for i in range(nNumerical):
700717
if not numericalChoices[i] == None:

src/Log.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,36 @@ void Log::Start(const string p_LogBasePath,
389389
m_Enabled = false; // fail
390390
}
391391
}
392+
393+
// store input files if required
394+
// use Boost to do the copy - copy_file() is available in standard c++17
395+
if (OPTIONS->StoreInputFiles()) { // user wants input files stored in output container?
396+
// yes
397+
string dstPath = m_LogBasePath + "/" + m_LogContainerName + "/"; // destination path (output container)
398+
if (!OPTIONS->GridFilename().empty()) { // user specified a grid file?
399+
try { // yes - copy it
400+
boost::filesystem::path srcPath(OPTIONS->GridFilename()); // grid file fully-qualified name
401+
string dstFn = dstPath + srcPath.filename().string(); // fully-qualified grid filename (inside container)
402+
boost::filesystem::copy_file(OPTIONS->GridFilename(), dstFn, boost::filesystem::copy_option::overwrite_if_exists); // copy grid file - overwrite any existing file (shouldn't be one, but just in case we want this one)
403+
} catch(const boost::filesystem::filesystem_error& e) {
404+
Squawk("ERROR: Unable to copy grid file " + OPTIONS->GridFilename() + " to output container " + dstPath); // announce error
405+
m_Enabled = false; // fail
406+
}
407+
}
408+
409+
// if the user specified a logfile-definitions file, copy it to the output container
410+
411+
if (m_Enabled && !OPTIONS->LogfileDefinitionsFilename().empty()) { // user specified a logfile-definitions file?
412+
try { // yes - copy it
413+
boost::filesystem::path srcPath(OPTIONS->LogfileDefinitionsFilename()); // logfile-definitions file fully-qualified name
414+
string dstFn = dstPath + srcPath.filename().string(); // fully-qualified logfile-definitions filename (inside container)
415+
boost::filesystem::copy_file(OPTIONS->LogfileDefinitionsFilename(), dstFn, boost::filesystem::copy_option::overwrite_if_exists); // copy logfile-definitions file - overwrite any existing file (shouldn't be one, but just in case we want this one)
416+
} catch(const boost::filesystem::filesystem_error& e) {
417+
Squawk("ERROR: Unable to copy logfile-definitions file " + OPTIONS->LogfileDefinitionsFilename() + " to output container " + dstPath); // announce error
418+
m_Enabled = false; // fail
419+
}
420+
}
421+
}
392422
}
393423
}
394424
}

src/Options.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
/* Read the explanations for each of the vectors in Options.h to get a better idea of */
6363
/* what they are for and where the new option should go. */
6464
/* */
65-
/* 10. Add the new option to the following structres in constants.h: */
65+
/* 10. Add the new option to the following structures in constants.h: */
6666
/* */
6767
/* - enum class PROGRAM_OPTION */
6868
/* - const COMPASUnorderedMap<PROGRAM_OPTION, std::string> PROGRAM_OPTION_LABEL */
@@ -148,6 +148,8 @@ void Options::OptionValues::Initialise() {
148148

149149
m_ShortHelp = true;
150150

151+
m_StoreInputFiles = true;
152+
151153
m_SwitchLog = false;
152154

153155

@@ -704,6 +706,11 @@ bool Options::AddOptions(OptionValues *p_Options, po::options_description *p_Opt
704706
po::value<bool>(&p_Options->m_RlofPrinting)->default_value(p_Options->m_RlofPrinting)->implicit_value(true),
705707
("Enable output parameters before/after RLOF (default = " + std::string(p_Options->m_RlofPrinting ? "TRUE" : "FALSE") + ")").c_str()
706708
)
709+
(
710+
"store-input-files",
711+
po::value<bool>(&p_Options->m_StoreInputFiles)->default_value(p_Options->m_StoreInputFiles)->implicit_value(true),
712+
("Store input files in output container (default = " + std::string(p_Options->m_StoreInputFiles ? "TRUE" : "FALSE") + ")").c_str()
713+
)
707714
(
708715
"switch-log",
709716
po::value<bool>(&p_Options->m_SwitchLog)->default_value(p_Options->m_SwitchLog)->implicit_value(true),

src/Options.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class Options {
195195

196196
"rlof-printing",
197197

198+
"store-input-files",
198199
"switch-log",
199200

200201
"timestep-multiplier",
@@ -464,6 +465,7 @@ class Options {
464465

465466
"semi-major-axis-distribution",
466467
"stellar-zeta-prescription",
468+
"store-input-files",
467469
"switch-log",
468470

469471
"use-mass-loss",
@@ -522,6 +524,7 @@ class Options {
522524
"random-seed",
523525
"rlof-printing",
524526

527+
"store-input-files",
525528
"switch-log",
526529

527530
"version", "v"
@@ -573,6 +576,8 @@ class Options {
573576

574577
bool m_ShortHelp; // Flag to indicate whether user wants short help ('-h', just option names) or long help ('--help', plus descriptions)
575578

579+
bool m_StoreInputFiles; // Store input files in output container (default = true)
580+
576581
bool m_SwitchLog; // Print switch log details to file (default = false)
577582

578583

@@ -1291,7 +1296,8 @@ class Options {
12911296
bool RequestedHelp() const { return m_CmdLine.optionValues.m_VM["help"].as<bool>(); }
12921297
bool RequestedVersion() const { return m_CmdLine.optionValues.m_VM["version"].as<bool>(); }
12931298

1294-
bool SwitchLog() const { return OPT_VALUE("switch-log", m_SwitchLog, true); }
1299+
bool StoreInputFiles() const { return m_CmdLine.optionValues.m_StoreInputFiles; }
1300+
bool SwitchLog() const { return m_CmdLine.optionValues.m_SwitchLog; }
12951301

12961302
ZETA_PRESCRIPTION StellarZetaPrescription() const { return OPT_VALUE("stellar-zeta-prescription", m_StellarZetaPrescription.type, true); }
12971303

src/changelog.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,12 @@
757757
// 02.20.02 JR - July 26, 2021 - Defect repair:
758758
// - Add HDF5 support to logging code for SSE/BSE switch log files. Support for HDF5 switch files was inadvertently not added when HDF5 file support as added in v02.18.00 for all standard log files. Switch log files are 'special' (they have extra columns, not part of the 'standard' log file functionality), and that was missed.
759759
// - Also removed '-lsz' from Makefile and Makefile.docker - library not required
760+
// 02.21.00 JR - July 28, 2021 - Enhancement and Defect Repairs:
761+
// - Added code to copy any grid file and/or logfile-definitions file specified to output container.
762+
// - Copying a large grid file could take time, and take up much space, so added new program option '--store-input-files' which is TRUE by default. If FALSE, neither the grid file (if specified) nor the logfile-definitions file (if specified) will be copied to the output container (if TRUE, both will be copied (if specified)).
763+
// - Fixed issue #600: changed pythonSubmit.py to treat fully-qualified grid filenames and fully-qualified logfile-definitions filenames correctly (i.e. don't add CWD if the filename is already fully-qualified).
764+
// - Fixed issue #601: changed pythonSubmit.py to put all boolean parameters on the commandline, with "True" or "False" value.
760765

761-
const std::string VERSION_STRING = "02.20.02";
766+
const std::string VERSION_STRING = "02.21.00";
762767

763768
# endif // __changelog_h__

0 commit comments

Comments
 (0)