ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
Sampler.m
Go to the documentation of this file.
1%> \brief
2%> This is the base class for the ParaMonte sampler routines.
3%>
4%> \note
5%> See below for information on the attributes (properties).
6%>
7%> \note
8%> See below for information on the methods.
9%>
10%> \note
11%> Given the basic primitive nature of this class, it does not have a custom constructor.<br>
12%> Users should always use the subclasses of this base class.<br>
13%>
14%> \final{Sampler}
15%>
16%> \author
17%> \JoshuaOsborne, May 21 2024, 12:43 AM, University of Texas at Arlington<br>
18%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
19%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
20classdef Sampler < pm.matlab.Handle
21
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23
24 properties(Access = public)
25 %>
26 %> ``input``
27 %>
28 %> The ``public`` scalar MATLAB string representing the path to an external
29 %> input file that contains the simulation specification namelist(s).<br>
30 %>
31 %> \warning
32 %> <b>Use this optional argument only if you know what you are doing</b>.<br>
33 %> Specifying an input simulation file will force the ParaMonte sampler
34 %> to ignore all other simulation specifications set by the user via
35 %> the ``spec`` component of the sampler instance.<br>
36 %>
37 input = "";
38 %>
39 %> ``checked``
40 %>
41 %> The ``public`` scalar MATLAB logical.<br>
42 %> If set to ``true``, then the checked (verified) versions of the
43 %> ParaMonte MATLAB shared libraries will be used for simulations.<br>
44 %> This means that most function calls and computations will be
45 %> checked at runtime to ensure correctness, at the cost of
46 %> noticeably slower runtime simulation speeds.<br>
47 %> Set this option to ``true`` only for diagnostics, testing, and development.<br>
48 %> If set to empty, the sampler will first search for the non-checked version
49 %> and if none found, will search for a checked version of the library.<br>
50 %>
51 checked = [];
52 %>
53 %> ``mpiname``
54 %>
55 %> The ``public`` scalar MATLAB string representing the (vendor) name of the
56 %> MPI runtime library. The following three library names are supported:<br>
57 %> <ol>
58 %> <li> ``"impi"`` : The Intel MPI runtime library (Windows/Linux).<br>
59 %> <li> ``"mpich"`` : The MPICH MPI runtime library (Linux/macOS).<br>
60 %> <li> ``"openmpi"`` : The OpenMPI runtime library (Linux/macOS).<br>
61 %> </ol>
62 %> These names are normally one of the possible
63 %> values returned by [pm.lib.mpi.choices()](@ref choices).<br>
64 %> By default, the ParaMonte samplers should be capable of detecting
65 %> the right MPI runtime libraries and the ParaMonte library files.<br>
66 %> If the automated MPI detection fails or for any reason, or you want to use
67 %> a non-preferred non-default MPI library, you can set this argument explicitly
68 %> to one of the values returned by [pm.lib.mpi.choices()](@ref choices) to enable
69 %> your preferred choice of MPI-enabled ParaMonte libraries.<br>
70 %>
71 %> Beware that you must launch MATLAB with an ``mpiexec`` binary that
72 %> comes with the same MPI library vendor string specified for ``mpiname``.<br>
73 %>
74 %> The simulation task will mostly likely fail if the MPI-parallel ParaMonte
75 %> shared libraries corresponding to the specified value for ``mpiname``
76 %> do not exist in the ParaMonte package.<br>
77 %> For example,<br>
78 %> <ol>
79 %> <li> On Windows, only ParaMonte library
80 %> builds with Intel MPI are generally supported.<br>
81 %> <li> On Linux, the ParaMonte library builds with
82 %> all MPI libraries listed above are supported,
83 %> but there is no guarantee of their availability in
84 %> the package. Only the MPI-parallel ParaMonte library
85 %> names returned by [pm.lib.mpi.choices()](@ref choices)
86 %> are guaranteed to exist.<br>
87 %> <li> On Darwin (macOS), the ParaMonte shared library builds
88 %> with MPICH and OpenMPI libraries are generally supported,
89 %> but there is no guarantee of the availability of all of them
90 %> in the ParaMonte package, unless the corresponding name is among
91 %> the names returned by [pm.lib.mpi.choices()](@ref choices).<br>
92 %> </ol>
93 %>
94 %> \warning
95 %> <b>Use this optional argument only if you know its ramifications</b>.<br>
96 %> This option should rarely be needed in any normal MPI simulation.<br>
97 %> The default value for ``mpiname`` is an empty string, implying
98 %> no specific use of MPI-enabled ParaMonte library routines,
99 %> unless the ``mpiexec`` launcher with more than one process
100 %> is detected at runtime.<br>
101 %>
102 mpiname = "";
103 %>
104 %> ``silent``
105 %>
106 %> The ``public`` scalar MATLAB logical (Boolean) indicator which is ``false`` by default.<br>
107 %> If it is set to ``true``, it will silence all output postprocessing messages.<br>
108 %>
109 %> \note
110 %> Setting ``mpiname`` to a non-empty string
111 %> will automatically set ``silent`` to ``true``.<br>
112 %>
113 silent = false;
114 %>
115 %> ``spec``
116 %>
117 %> The ``public`` MATLAB structure containing all simulation specifications.<br>
118 %> All specifications are set to appropriate default values at runtime.<br>
119 %> Set the `spec` attributes to the desired values of your choice
120 %> to override the default simulation specifications.<br>
121 %>
122 spec = [];
123 end
124
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126
127 properties(Access = public, Hidden)
128 %>
129 %> ``mexname``
130 %>
131 %> A ``Hidden`` scalar MATLAB string containing the name of the MEX file containing all ParaMonte sampler interfaces.<br>
132 %>
133 %> \warning
134 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
135 %>
136 mexname = "pm_sampling";
137 %>
138 %> ``libtype``
139 %>
140 %> A ``Hidden`` scalar MATLAB string containing the type of the ParaMonte Fortran library that is to be called.<br>
141 %> Although both ``static`` and ``shared`` may be possible, this value must always remain as ``shared``.<br>
142 %>
143 %> \warning
144 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
145 %>
146 libtype = "shared";
147 %>
148 %> ``partype``
149 %>
150 %> A ``Hidden`` scalar MATLAB string containing the parallelization type of the ParaMonte Fortran library that is to be called.<br>
151 %> Although the default value is ``serial``, the class methods will internally set this component to the right parallelization type at runtime.<br>
152 %>
153 %> \warning
154 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
155 %>
156 partype = "serial";
157 %>
158 %> ``memtype``
159 %>
160 %> A ``Hidden`` scalar MATLAB string containing the memory usage type of the ParaMonte Fortran library that is to be called.<br>
161 %> Although both ``heap`` and ``stack`` may be possible, this value must always remain as ``heap``.<br>
162 %>
163 %> \warning
164 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
165 %>
166 memtype = "heap";
167 %>
168 %> ``bldtype``
169 %>
170 %> A ``Hidden`` scalar MATLAB string containing the build type of the ParaMonte Fortran library that is to be called.<br>
171 %> The value of this component is determined at runtime depending on the availability of the ParaMonte Fortran library.<br>
172 %> The runtime value is among the values returned by the ParaMonte MATLAB library function [pm.lib.bldtypes()](@ref bldtypes).<br>
173 %>
174 %> \warning
175 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
176 %>
177 bldtype = ""; % build type
178 %>
179 %> ``clstype``
180 %>
181 %> A ``Hidden`` scalar MATLAB string containing the type of the ParaMonte Fortran library parallelization that is to be called.<br>
182 %> Although the default value is ``serial``, the class methods will internally set this component to the right parallelization type at runtime.<br>
183 %>
184 %> \warning
185 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
186 %>
187 clstype = ""; % compiler/linker suite
188 %>
189 %> ``name``
190 %>
191 %> A ``Hidden`` scalar MATLAB string containing the name of the user-created object of superclass [pm.sampling.Sampler](@ref Sampler).<br>
192 %> This name is determined at runtime via the MATLAB intrinsic function ``inputname()``.<br>
193 %>
194 %> \warning
195 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
196 %>
197 name = "self";
198 %>
199 %> ``weblinks``
200 %>
201 %> A ``Hidden`` scalar MATLAB object of class [pm.lib.weblinks](@ref weblinks) containing the relevant ParaMonte library web links.<br>
202 %>
203 %> \warning
204 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
205 %>
206 weblinks = [];
207 %>
208 %> ``matpath``
209 %>
210 %> A ``Hidden`` scalar MATLAB string containing the contents of the MATLAB ``path`` variable at runtime.<br>
211 %>
212 %> \warning
213 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
214 %>
215 matpath = []; % MATLAB paths.
216 %>
217 %> ``method``
218 %>
219 %> A ``Hidden`` scalar MATLAB string containing the name of the ParaMonte sampler subclass that the user has instantiated at runtime.<br>
220 %>
221 %> \warning
222 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
223 %>
224 method = "";
225 %>
226 %> ``ndim``
227 %>
228 %> A ``Hidden`` scalar MATLAB whole-number containing the user-specified value
229 %> for the number of dimensions of the mathematical density function to be sampled.<br>
230 %>
231 %> \warning
232 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
233 %>
234 ndim = [];
235 %>
236 %> ``nml``
237 %>
238 %> A ``Hidden`` scalar MATLAB string containing all the sampler specifications to be passed to the sampler as a Fortran namelist.<br>
239 %>
240 %> \warning
241 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
242 %>
243 nml = [];
244 %>
245 %> ``libspec``
246 %>
247 %> Optional scalar MATLAB string containing a list of colon-(:)-separated
248 %> configurations of the kernel shared library to be used for the sampling task.<br>
249 %> The most important of all is the compiler suite with which the library is built.<br>
250 %>
251 %> \warning
252 %> <b>Use this optional argument only if you know what you are doing</b>.<br>
253 %> The specified value for ``libspec`` is parsed internally to match a
254 %> corresponding library path name within the ParaMonte library.<br>
255 %> The simulations will fail if no such directory can be found.<br>
256 %>
257 libspec = "nocheck";
258 end
259
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261
262 methods(Access = public)
263
264 %> \brief
265 %> Return a scalar object of class [pm.sampling.Sampler``.<br>
266 %>
267 %> \details
268 %> This is the constructor of the class [pm.sampling.Sampler](@ref Sampler).<br>
269 %> This class is not meant to be accessed by the end users.<br>
270 %> It merely serves as the blueprint for the subclasses of [pm.sampling.Sampler](@ref Sampler)
271 %> accessible to the end users.<br>
272 %>
273 %> \param[in] method : The input scalar MATLAB string containing
274 %> the name of the target ParaMonte sampler.<br>
275 %>
276 %> \return
277 %> ``self`` : The output scalar object of class [pm.sampling.Sampler](@ref Sampler).<br>
278 %>
279 %> \interface{Sampler}
280 %> \code{.m}
281 %>
282 %> sampler = pm.sampling.Sampler();
283 %> sampler = pm.sampling.Sampler([]);
284 %> sampler = pm.sampling.Sampler(method);
285 %>
286 %> \endcode
287 %>
288 %> \final{Sampler}
289 %>
290 %> \author
291 %> \JoshuaOsborne, May 21 2024, 12:52 AM, University of Texas at Arlington<br>
292 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
293 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
294 function self = Sampler(method)
295 if nargin < 1
296 self.method = "sampler";
297 else
298 self.method = string(method);
299 end
300 self.weblinks = pm.lib.weblinks();
301 if self.method == "ParaDRAM"
302 self.spec = pm.sampling.SpecDRAM(self.method);
303 elseif self.method == "ParaNest"
304 self.spec = pm.sampling.SpecNest(self.method);
305 elseif self.method == "sampler"
306 self.spec = pm.sampling.SpecBase(self.method);
307 else
308 error ( newline ...
309 + "Unrecognized or unsupported ParaMonte sampler: " + self.method + newline ...
310 + newline ...
311 );
312 end
313 %filePath = mfilename("fullpath"); addpath(genpath(filePath),"-begin");
314 self.name = string(inputname(1));
315 end
316
317 reportList = readReport(self, pattern)
318 restartList = readRestart(self, pattern)
319 chainList = readChain(self, pattern, sep)
320 sampleList = readSample(self, pattern, sep)
321 progressList = readProgress(self, pattern, sep)
322
323 end
324
325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326
327 methods(Hidden)
328
329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330
331 run(self, getLogFunc, ndim)
332
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334
335 fileList = findfile(self, ftype, pattern);
336
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338
339 ppm = getppm(self)
340
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342
343 finalize(self)
344
345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346
347 end
348
349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350
351end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared library directories.
function vendor(in name)
Return the MPI library vendor name from the input MPI name based on the internal ParaMonte shared lib...
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
function version(in silent)
Return a scalar MATLAB string containing the latest available ParaMonte MATLAB version newer than the...
function bldtypes()
Return a list of MATLAB strings containing the names of all currently possible builds of the ParaMont...
function choices()
Return the ParaMonte-preferred MPI library vendor name(s) as used in naming the ParaMonte MATLAB shar...
This is the base class for generating subclass of MATLAB handle superclass whose annoying methods are...
Definition: Handle.m:24
This is the base class for the ParaMonte sampler routines.
Definition: Sampler.m:21
function readSample(in self, in pattern, in sep)
Return a list of objects of superclass pm.sampling.FileContentsSample containing the content(s) of th...
function run(in self, in getLogFunc, in ndim)
Perform the basic runtime checks for the sampler and return nothing.
Property mexname
Definition: Sampler.m:144
function getLogFuncConcurrent(in state)
function Sampler(in method)
Return a scalar object of class [pm.sampling.Sampler``.
Property matpath
Definition: Sampler.m:231
Property method
Definition: Sampler.m:241
Property weblinks
Definition: Sampler.m:221
Property partype
Definition: Sampler.m:166
function readReport(in self, in pattern)
Return a list of objects of class pm.sampling.FileContentsReport containing the content(s) of the Par...
Property libtype
Definition: Sampler.m:155
function readChain(in self, in pattern, in sep, in varargin)
Return a list of objects of superclass pm.sampling.FileContentsChain containing the content(s) of the...
Property spec
Definition: Sampler.m:129
function getppm(in self)
Generate and return the relevant Post-Processing Message (ppm) for the current ParaMonte sampler to b...
Property libspec
Definition: Sampler.m:277
Property nml
Definition: Sampler.m:262
Property ndim
Definition: Sampler.m:252
Property name
Definition: Sampler.m:211
Property bldtype
Definition: Sampler.m:189
function getLogFuncWrapped(in state)
Property silent
Definition: Sampler.m:119
Property clstype
Definition: Sampler.m:200
function findfile(in self, in ftype, in pattern)
Return a vector of MATLAB strings containing the fully-resolved paths matching the input pattern.
function readRestart(in self, in pattern)
Return a list of objects of class pm.sampling.FileContentsRestart containing the content(s) of the Pa...
Property checked
Definition: Sampler.m:55
function readProgress(in self, in pattern, in sep)
Return a list of objects of class pm.sampling.FileContentsProgress containing the content(s) of the P...
Property mpiname
Definition: Sampler.m:107
function finalize(in self)
Finalize the ParaMonte MATLAB sampler simulation run and return nothing.
Property input
Definition: Sampler.m:40
Property memtype
Definition: Sampler.m:177
function compiler()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...
function getLogFunc(in point)
function parallel()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...
function readChain(in sampler, in pattern, in sep, in varargin)
Return a list of objects of superclass pm.sampling.FileContentsChain containing the contents of a (se...
function readProgress(in sampler, in pattern, in sep)
Return a list of objects of superclass pm.sampling.FileContentsProgress containing the contents of a ...
function readReport(in sampler, in pattern)
Return a list of objects of superclass pm.sampling.FileContentsReport containing the contents of a (s...
function readRestart(in sampler, in pattern)
Return a list of objects of superclass pm.sampling.FileContentsRestart containing the contents of a (...
function readSample(in sampler, in pattern, in sep)
Return a list of objects of superclass pm.sampling.FileContentsSample containing the contents of a (s...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...