ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
FileContentsRestart.m
Go to the documentation of this file.
1%> \brief
2%> This is the base class for generating objects
3%> that contain the contents of a restart file
4%> generated by a ParaMonte sampler.<br>
5%>
6%> \details
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.<br>
10%>
11%> \note
12%> See below for information on the attributes (properties).<br>
13%>
14%> \note
15%> See below for information on the methods.<br>
16%>
17%> \return
18%> An object of class [pm.sampling.FileContentsRestart](@ref FileContentsRestart).<br>
19%>
20%> \final{FileContentsRestart}
21%>
22%> \author
23%> \JoshuaOsborne, May 21 2024, 3:19 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>
26classdef FileContentsRestart < pm.io.FileContents
27
28 properties(Access = public)
29 %>
30 %> ``count`` : The scalar MATLAB integer containing the number of
31 %> restart entries in the specified restart file.<br>
32 %>
33 count = [];
34 %>
35 %> ``ndim`` : The scalar MATLAB integer containing the number of
36 %> dimensions of the domain of the objective function.<br>
37 %>
38 ndim = [];
39 %>
40 %> ``domainAxisName`` : The vector of MATLAB strings of size ``ndim`` containing
41 %> the domain axes names of the density function explored.<br>
42 %>
43 domainAxisName = [];
44 %>
45 %> ``contents`` : The scalar MATLAB string containing the entire
46 %> contents of the restart file with all Carriage Return
47 %> characters removed (relevant only to Windows OS).<br>
48 %>
49 contents = [];
50 end
51
52 properties(Hidden)
53 method = '';
54 lineList = [];
55 lineListLen = [];
56 ilast = 0; % index that is always set to the last line number read.
57 end
58
59 methods(Access = public)
61 %> \brief
62 %> Return a scalar object of class [pm.sampling.FileContentsRestart](@ref FileContentsRestart).<br>
63 %>
64 %> \details
65 %> This is the constructor of the class [pm.sampling.FileContentsRestart](@ref FileContentsRestart).<br>
66 %>
67 %> \param[in] file : The input scalar MATLAB string containing the path to an external restart file.<br>
68 %> \param[in] silent : See the corresponding argument of [pm.io.FileContents](@ref FileContents) class.<br>
69 %> (**optional**. The default is set by [pm.io.FileContents](@ref FileContents).)
70 %> \param[in] method : The input scalar MATLAB string containing the sampling method name.<br>
71 %> The input value must be any of the following:<br>
72 %> <ol>
73 %> <li> ``"ParaDRAM"``
74 %> <li> ``"ParaDISE"``
75 %> <li> ``"ParaNest"``
76 %> </ol>
77 %> (**optional**. If missing, some of the restart file contents will not be (properly) parsed.)
78 %>
79 %> \return
80 %> ``self`` : The output scalar object of class [pm.sampling.FileContentsRestart](@ref FileContentsRestart).
81 %>
82 %> \interface{FileContentsRestart}
83 %> \code{.m}
84 %>
85 %> contents = pm.sampling.FileContentsRestart(file)
86 %> contents = pm.sampling.FileContentsRestart(file, [])
87 %> contents = pm.sampling.FileContentsRestart(file, silent)
88 %> contents = pm.sampling.FileContentsRestart(file, [], [])
89 %> contents = pm.sampling.FileContentsRestart(file, silent, [])
90 %> contents = pm.sampling.FileContentsRestart(file, silent, method)
91 %>
92 %> \endcode
93 %>
94 %> \final{FileContentsRestart}
95 %>
96 %> \author
97 %> \JoshuaOsborne, May 21 2024, 3:25 AM, University of Texas at Arlington<br>
98 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
99 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
100 function self = FileContentsRestart(file, silent, method)
101 if nargin < 2
102 silent = [];
103 end
104 self = self@pm.io.FileContents(file, silent);
105 if 2 < nargin
106 self.method = convertStringsToChars(method);
107 end
108
109 %%%%
110 %%%% remove any CARRIAGE RETURN.
111 %%%%
112
113 self.contents = strrep(fileread(file), char(13), '');
114 self.lineList = strsplit(self.contents, newline);
115 self.lineListLen = length(self.lineList);
116
117 % find the field names in the file.
118 %fields = [];
119 %for ilast = 1 : self.lineListLen
120 % line = self.lineList{ilast};
121 % if isletter(line(1))
122 % if ~any(contains(fields, line))
123 % fields = [fields, line];
124 % else
125 % break;
126 % end
127 % end
128 %end
129
130 %%%%
131 %%%% Read restart meta data (ndim, domainAxisName).
132 %%%%
133
134 %%%% This is the old DRAM-specific approach where we inferred the ndim value from the file contents.
135
136 % self.ndim = 0;
137 % rowOffset = 1;
138 % while ~contains(self.lineList(rowOffset), "proposalMean")
139 % rowOffset = rowOffset + 1;
140 % if self.lineListLen < rowOffset
141 % error ( newline ...
142 % + "Failed to detect any field named ""proposalMean""" + newline ...
143 % + "in the specified restart file:" + newline ...
144 % + newline ...
145 % + pm.io.tab + file + newline ...
146 % + newline ...
147 % + "The file structure may have been compromized." + newline ...
148 % + newline ...
149 % );
150 % end
151 % end
152 % rowOffset = rowOffset + 1; % the first numeric value of proposalMean.
153 % while ~isnan(str2double(self.lineList{self.ndim + rowOffset}))
154 % self.ndim = self.ndim + 1;
155 % end
156 % if self.ndim == 0
157 % error ( newline ...
158 % + "Failed to infer the value of ``ndim``." + newline ...
159 % + "from the specified restart file:" + newline ...
160 % + newline ...
161 % + pm.io.tab + file + newline ...
162 % + newline ...
163 % + "The file structure may have been compromized." + newline ...
164 % + newline ...
165 % );
166 % end
167
168 %%%% This is the new approach where the ndim value is explicitly written in the file along with domainAxisName.
169
170 if ~contains(self.lineList(1), "ndim") || ~contains(self.lineList(3), "domainAxisName")
171 error ( newline ...
172 + "The structure of the specified restart file appears to have been compromised:" + newline ...
173 + newline ...
174 + pm.io.tab + file + newline ...
175 + newline ...
176 + "The first line of the restart file must match ""ndim""." + newline ...
177 + "The third line of the restart file must match ""domainAxisName""." + newline ...
178 + newline ...
179 );
180 else
181 self.ndim = str2double(self.lineList(2));
182 self.domainAxisName = strings(self.ndim, 1);
183 for idim = 1 : self.ndim
184 self.domainAxisName(idim) = string(self.lineList(3 + idim));
185 end
186 end
187
188 self.ilast = 3 + self.ndim;
189
190 end % constructor
191
192 end % methods(Access = public)
193
194end % classdef
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared libraries.
function index(in array)
Given array(1 : n), return the array index indx(1 : n) such that array(indx) is in ascending order.
This is the base class for generating objects that contain the contents of a restart file generated b...
function FileContentsRestart(in file, in silent, in method)
Return a scalar object of class pm.sampling.FileContentsRestart.
This is the base class for generating objects that contain the contents of a given file.
Definition: FileContents.m:27
function find(in vendor)
Return a list of scalar MATLAB strings containing the paths to all detected mpiexec binaries installe...
function tab()
Return a scalar MATLAB string containing 4 blank characters equivalent to a tab character.