2%> This is the base
class for generating objects
3%> that contain the contents of a report file
4%> generated by a ParaMonte sampler.<br>
7%> This
class is meant to be primarily internally
8%> used by the ParaMonte MATLAB library samplers.<br>
9%> See the documentation of the
class constructor.
12%> See below
for information on the attributes (properties).<br>
15%> See below
for information on the methods.<br>
23%> \JoshuaOsborne, May 21 2024, 1:13 AM, University of Texas at Arlington<br>
24%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
25%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
28 properties(Access =
public)
30 %> ``stats`` : The scalar MATLAB ``
struct`` containing the set of
31 %> computed properties extracted from the report file.<br>
35 %> ``contents`` : The scalar MATLAB
string containing the entire
36 %> contents of the report file with all Carriage Return
37 %> characters removed (relevant only to Windows OS).<br>
41 %> ``lineList`` : The vector of MATLAB strings containing the set of
42 %> all lines in the report file with all Carriage Return
43 %> and New Line characters removed.<br>
49 % % The scalar MATLAB ``
struct`` containing the sampler
50 % % setup information extracted from the report file.
56 % % The scalar MATLAB ``
struct`` containing the set of
57 % % simulation specifications extracted from the report file.
66 indentLen = 4; % indent length of the records
67 dsymLen = 2; % assume a minimum length of two of decoration symbols.
68 dsym =
''; % decoration symbol to be determined at runtime (currently ``%``).
73 methods(Access =
public)
76 %> Return a scalar
object of
class [pm.sampling.FileContentsReport](@ref
FileContentsReport).<br>
78 %> This is the constructor of the
class [pm.sampling.FileContentsReport](@ref
FileContentsReport).<br>
80 %> \param[in] file : The input scalar MATLAB
string containing the path to an external report file.<br>
81 %> \param[in] silent : See the corresponding argument of [pm.io.FileContents](@ref
FileContents)
class.<br>
82 %> (**optional**. The
default is set by [pm.io.FileContents](@ref
FileContents).)
83 %> \param[in] method : The input scalar MATLAB
string
84 %> containing the sampling method
name.<br>
85 %> The input value must be any of the following:<br>
87 %> <li> ``
"ParaDRAM"``
88 %> <li> ``
"ParaDISE"``
89 %> <li> ``
"ParaNest"``
91 %> (**optional**. If missing, some of the report file contents may not be properly parsed.)
94 %> ``self`` : The output scalar
object of
class [pm.sampling.FileContentsReport](@ref
FileContentsReport).<br>
100 %> contents = pm.sampling.FileContentsReport(file, [])
101 %> contents = pm.sampling.FileContentsReport(file, silent)
102 %> contents = pm.sampling.FileContentsReport(file, [], [])
103 %> contents = pm.sampling.FileContentsReport(file, silent, [])
104 %> contents = pm.sampling.FileContentsReport(file, silent, method)
111 %> \JoshuaOsborne, May 21 2024, 1:30 AM, University of Texas at Arlington<br>
112 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
113 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
118 self = self@pm.io.FileContents(file, silent);
120 self.
method = convertStringsToChars(method);
121 self.prefix = [self.method, self.prefix];
123 % remove any CARRIAGE RETURN.
124 self.contents = strrep(fileread(file),
char(13),
'');
125 self.contents = strrep(self.contents, newline, [
' ', newline]);
126 self.lineList = strsplit(self.contents, newline);
127 self.lineListLen = length(self.lineList);
128 iend = 1; % the line we are about to parse.
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 %%%% determine the decoration symbol and read the
banner.
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 % Here we assume the first non-empty line starts with the symbol character (likely ``%``).
136 ibeg = self.skipNull(iend);
137 failed = self.lineListLen < ibeg || length(self.lineList{ibeg}) < 4;
139 line = self.lineList{ibeg};
140 failed = any(line(1) ~= line(2 : 4));
142 iend = self.skipFull(ibeg + 1);
143 failed = self.lineListLen < iend;
148 self.banner = self.concat(self.lineList(ibeg : iend));
150 self.warn(line,
"Failed to detect the decoration symbol used in the report file.");
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 %%%% read the ParaMonte MATLAB library
interface specifications
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 %self.setup.library.interface = self.parseSection(
"interface.specifications");
159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 %self.setup.library.compiler.version = self.parseSection(
"compiler.version");
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 %%%% read the ParaMonte MATLAB library
compiler options
167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 %self.setup.library.compiler.options = self.parseSection(
"compiler.options");
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 %%%% read the Runtime platform specifications
173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 %self.setup.platform = self.parseSection(
"runtime.platform.specifications");
177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 %%%% read the simulation environment
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 %self.setup.io = self.parseSection(
"simulation.environment");
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 %%%% read the simulation specifications
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 %self.spec.base = self.parseSection(
"simulation.specifications.base");
188 %
if self.method ==
"ParaDRAM" || self.method ==
"ParaDISE"
189 % self.spec.mcmc = self.parseSection(
"simulation.specifications.mcmc");
190 % self.spec.dram = self.parseSection(
"simulation.specifications.dram");
191 %elseif self.method ==
"ParaNest"
192 % self.spec.nest = self.parseSection(
"simulation.specifications.nest");
195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 %%%%
statistics:
this must be always the last item to parse
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 self.checkpoint(
"parsing the simulation statistics...", 1);
203 item = self.lineList{iend};
205 self.spinner.spin(iend / self.lineListLen);
207 if strcmp(item(1 : min(6, length(item))),
'stats.')
209 % first non-empty line.
210 ibeg = self.skipNull(iend + 1);
211 failed = self.lineListLen < ibeg;
213 iend = self.skipFull(ibeg + 1);
214 failed = self.lineListLen < iend;
216 % Retrieve the value.
217 % The strategy is to read all values as table by dumping
218 % the value in a temporary file and reading it as a table.
219 tempfile = tempname();
220 fid = fopen(tempfile,
"w");
221 fprintf(fid, self.concat(strtrim(self.lineList(ibeg : iend - 1))));
223 value = readtable(tempfile);
224 %self.(strtrim(item)).value = value;
225 eval([
'self.', strtrim(item),
'.value = value;']);
229 % Retrieve the description.
231 ibeg = self.skipNull(iend + 1);
232 iend = self.skipFull(ibeg + 1);
233 if ~all(self.isdesc(self.lineList(ibeg : iend - 1)))
234 self.warn(
string(ibeg) + "-" +
string(iend), "A description record does not contain """ +
string(self.prefix) + """");
236 % Concatenate lines and remove prefixes from each description lines.
237 desc = strrep(self.concat(strtrim(self.lineList(ibeg : iend - 1))), self.prefix, '');
238 eval(['self.', strtrim(item), '.description = desc;']);
239 %self.(strtrim(item)).description = desc;
245 if self.lineListLen < iend
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 end % methods(Access = public)
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 methods(Hidden, Static)
263 %function reportParseFailure(topic)
264 % topic =
string(strtrim(strrep(strrep(topic, newline, ' '),
char(13), ' ')));
265 % warning ( newline ...
266 % + "Failed to parse the record """ + topic + """. " + newline ...
267 % + "The structure of the report file appears to have been compromised. Skipping..." + newline ...
272 %function reportMissingValue(topic)
273 % topic =
string(strtrim(strrep(strrep(topic, newline, ' '),
char(13), ' ')));
274 % warning ( newline ...
275 % + "Failed to parse the value corresponding to the record """ + topic + """. " + newline ...
276 % + "The structure of the report file appears to have been compromised. Skipping..." + newline ...
281 function str = concat(lines)
282 % Concatenate the elements of an input cell array by
283 % the new line character and return the result as a single
string.
284 str =
string(join(lines, newline));
289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 %function result = isSectionHeader(self, record)
294 % result = self.dsymLen < length(record) && contains(record(1 : self.dsymLen), self.dsym);
297 %function stopBeforeNextSectionHeader(self)
298 % % NOTE: if it is already within a section header, it will skip it and
find the next section header.
299 % record = self.lineList{iend};
300 % isCurrentSectionHeader = self.dsymLen < length(record) && contains(record(1 : self.dsymLen), self.dsym);
302 %
if iend == self.lineListLen
305 % record = self.lineList{iend};
306 %
if self.dsymLen < length(record) && contains(record(1 : self.dsymLen), self.dsym)
307 %
if isCurrentSectionHeader
315 % isCurrentSectionHeader =
false;
322 %function skipCurrentSectionHeader(self)
324 % record = self.lineList{iend};
325 %
if self.dsymLen < length(record) && contains(record(1 : self.dsymLen), self.dsym)
327 %
if iend == self.lineListLen
337 %function section = parseSection(self, topic)
338 % ilineLastSuccess = iend;
339 % topic = lower(topic);
341 % topicFound =
false;
344 %
if self.lineListLen <= iend
347 % record = lower(self.lineList{iend});
348 %
if contains(record, topic)
356 % self.skipCurrentSectionHeader();
358 % self.stopBeforeNextSectionHeader();
359 % section = self.concat(lineStart, iend);
361 % self.reportParseFailure(topic);
362 % iend = ilineLastSuccess;
366 function result = isdesc(self, record)
367 result = contains(record, self.prefix);
370 function iend = skipNull(self, ibeg)
371 % skip the empty lines after the current
372 % until encountering the first non-empty line.
375 if self.lineListLen < iend
377 elseif ~isempty(strtrim(self.lineList{iend}))
384 function iend = skipFull(self, ibeg)
385 % skip the nonempty lines after the current
386 % until encountering the first empty line.
389 if self.lineListLen < iend
391 elseif isempty(strtrim(self.lineList{iend}))
400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared libraries.
function version(in silent)
Return a scalar MATLAB string containing the latest available ParaMonte MATLAB version newer than the...
function banner()
Return a scalar MATLAB string containing the ParaMonte MATLAB library banner.
This is the base class for generating objects that contain the contents of a report file generated by...
function skipNull(in self, in ibeg)
function isdesc(in self, in record)
function skipFull(in self, in ibeg)
static function concat(in lines)
function FileContentsReport(in file, in silent, in method)
Return a scalar object of class pm.sampling.FileContentsReport.
This is the base class for generating objects that contain the contents of a given file.
function compiler()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...
function find(in vendor)
Return a list of scalar MATLAB strings containing the paths to all detected mpiexec binaries installe...
function statistics()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...