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 %> \devnote
188 %> The attribute name ``clstype`` stands for *Compiler/Linker Suit* type.<br>
189 %>
190 clstype = ""; % compiler/linker suite
191 %>
192 %> ``name``
193 %>
194 %> A ``Hidden`` scalar MATLAB string containing the name of the
195 %> user-created object of superclass [pm.sampling.Sampler](@ref Sampler).<br>
196 %> This name is determined at runtime via the MATLAB intrinsic function ``inputname()``.<br>
197 %>
198 %> \warning
199 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
200 %>
201 name = "sampler";
202 %>
203 %> ``weblinks``
204 %>
205 %> A ``Hidden`` scalar MATLAB object of class [pm.lib.weblinks](@ref weblinks) containing the relevant ParaMonte library web links.<br>
206 %>
207 %> \warning
208 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
209 %>
210 weblinks = [];
211 %>
212 %> ``matpath``
213 %>
214 %> A ``Hidden`` scalar MATLAB string containing the contents of the MATLAB ``path`` variable at runtime.<br>
215 %>
216 %> \warning
217 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
218 %>
219 matpath = []; % MATLAB paths.
220 %>
221 %> ``method``
222 %>
223 %> A ``Hidden`` scalar MATLAB string containing the name of the ParaMonte sampler subclass that the user has instantiated at runtime.<br>
224 %>
225 %> \warning
226 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
227 %>
228 method = "";
229 %>
230 %> ``ndim``
231 %>
232 %> A ``Hidden`` scalar MATLAB whole-number containing the user-specified value
233 %> for the number of dimensions of the mathematical density function to be sampled.<br>
234 %>
235 %> \warning
236 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
237 %>
238 ndim = [];
239 %>
240 %> ``nml``
241 %>
242 %> A ``Hidden`` scalar MATLAB string containing all the sampler specifications to be passed to the sampler as a Fortran namelist.<br>
243 %>
244 %> \warning
245 %> This ``Hidden`` class component must not be accessed by the end users of the library.<br>
246 %>
247 nml = [];
248 %>
249 %> ``libspec``
250 %>
251 %> Optional scalar MATLAB string containing a list of colon-(``:``)-separated
252 %> configurations of the kernel shared library to be used for the sampling task.<br>
253 %> The most important of all is the compiler suite with which the library is built.<br>
254 %>
255 %> \warning
256 %> <b>Use this optional argument only if you know what you are doing</b>.<br>
257 %> The specified value for ``libspec`` is parsed internally to match a
258 %> corresponding library path name within the ParaMonte library.<br>
259 %> The simulations will fail if no such directory can be found.<br>
260 %>
261 libspec = "nocheck";
262 end
263
264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265
266 methods(Access = public)
267
268 %> \brief
269 %> Return a scalar object of class [pm.sampling.Sampler``.<br>
270 %>
271 %> \details
272 %> This is the constructor of the class [pm.sampling.Sampler](@ref Sampler).<br>
273 %> This class is not meant to be accessed by the end users.<br>
274 %> It merely serves as the blueprint for the subclasses of [pm.sampling.Sampler](@ref Sampler)
275 %> accessible to the end users.<br>
276 %>
277 %> \param[in] method : The input scalar MATLAB string containing
278 %> the name of the target ParaMonte sampler.<br>
279 %>
280 %> \return
281 %> ``self`` : The output scalar object of class [pm.sampling.Sampler](@ref Sampler).<br>
282 %>
283 %> \interface{Sampler}
284 %> \code{.m}
285 %>
286 %> sampler = pm.sampling.Sampler();
287 %> sampler = pm.sampling.Sampler([]);
288 %> sampler = pm.sampling.Sampler(method);
289 %>
290 %> \endcode
291 %>
292 %> \final{Sampler}
293 %>
294 %> \author
295 %> \JoshuaOsborne, May 21 2024, 12:52 AM, University of Texas at Arlington<br>
296 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
297 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
298 function self = Sampler(method)
299 if nargin < 1
300 self.method = "sampler";
301 else
302 self.method = string(method);
303 end
304 self.weblinks = pm.lib.weblinks();
305 if self.method == "ParaDRAM"
306 self.spec = pm.sampling.SpecDRAM(self.method);
307 elseif self.method == "ParaNest"
308 self.spec = pm.sampling.SpecNest(self.method);
309 elseif self.method == "sampler"
310 self.spec = pm.sampling.SpecBase(self.method);
311 else
312 error ( newline ...
313 + "Unrecognized or unsupported ParaMonte sampler: " + self.method + newline ...
314 + newline ...
315 );
316 end
317 %filePath = mfilename("fullpath"); addpath(genpath(filePath),"-begin");
318 self.name = string(inputname(1));
319 end
320
321 reportList = readReport(self, pattern)
322 restartList = readRestart(self, pattern)
323 chainList = readChain(self, pattern, sep)
324 sampleList = readSample(self, pattern, sep)
325 progressList = readProgress(self, pattern, sep)
326 run(self, getLogFunc, ndim)
327
328 end
329
330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331
332 methods(Hidden)
333
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335
336 fileList = findfile(self, ftype, pattern);
337
338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339
340 ppm = getppm(self)
341
342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343
344 finalize(self)
345
346 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347
348 end
349
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351
352end
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:235
Property method
Definition: Sampler.m:245
Property weblinks
Definition: Sampler.m:225
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:281
Property nml
Definition: Sampler.m:266
Property ndim
Definition: Sampler.m:256
Property name
Definition: Sampler.m:215
Property bldtype
Definition: Sampler.m:189
function getLogFuncWrapped(in state)
Property silent
Definition: Sampler.m:119
Property clstype
Definition: Sampler.m:203
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 verified(in varval, in vartype, in maxlen)
Return true if and only if the input varval conforms with the specified input type vartype and maximu...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...