ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
readRestart.m
Go to the documentation of this file.
1%> \brief
2%> Return a list of objects of superclass [pm.sampling.FileContentsRestart](@ref FileContentsRestart)
3%> containing the contents of a (set of) ParaMonte simulation output restart file(s) whose paths match
4%> the specified input ``pattern`` or the simulation specification ``sampler.spec.outputFileName``.<br>
5%>
6%> \warning
7%> This function is to be only used for post-processing of the output restart file(s) of an already finished simulation.<br>
8%> Although possible, this method is **not** meant to be called by all processes in MPI-parallel simulations.<br>
9%>
10%> \param[in] sampler : The input object of superclass [pm.sampling.Sampler](@ref Sampler)
11%> whose type and properties determine the type of the output object(s).<br>
12%> (**optional**. If empty, it is set to [pm.sampling.Sampler()](@ref Sampler).)
13%> \param[in] pattern : The input scalar MATLAB string containing the pattern matching
14%> the desired restart file(s) whose contents is to be read.<br>
15%> The specified ``pattern`` only needs to partially identify
16%> the name of the simulation to which the restart file belongs.<br>
17%> For example, specifying ``"./mydir/mysim"`` as input will
18%> lead to a search for file(s) beginning with ``"mysim"`` and
19%> ending with ``"_restart.txt"`` inside the directory ``"./mydir/"``.<br>
20%> If there are multiple files matching in the input ``pattern``,
21%> then all such files will be read and returned as elements of a list.<br>
22%> If the specified pattern is a valid existing URL, the file will be
23%> downloaded as a temporary file to the local system, its contents
24%> shall be parsed and the file will be subsequently removed.<br>
25%> If the input ``pattern`` is empty, then the method will search
26%> for any possible candidate files with the appropriate suffix
27%> in the current working directory.<br>
28%> (**optional**. If empty, it is set to ``sampler.spec.outputFileName`` or if empty, it is set to ``"./"``.)
29%>
30%> \return
31%> ``restartList`` : The output MATLAB cell array of objects of superclass [pm.sampling.FileContentsRestart](@ref FileContentsRestart),
32%> each of which corresponds to the contents of a unique ParaMonte sampler restart file.<br>
33%> <ol>
34%> <li> If the input argument ``sampler`` is of type [pm.sampling.Sampler](@ref Sampler),
35%> then the output array elements are of type [pm.sampling.FileContentsRestart](@ref FileContentsRestart).<br>
36%> <li> If the input argument ``sampler`` is of type [pm.sampling.Paradram](@ref Paradram),
37%> then the output array elements are of type [pm.sampling.FileContentsRestartDRAM](@ref FileContentsRestartDRAM).<br>
38%> </ol>
39%>
40%> \interface{readRestart}
41%> \code{.m}
42%>
43%> restartList = pm.sampling.readRestart();
44%> restartList = pm.sampling.readRestart([], []);
45%> restartList = pm.sampling.readRestart([], pattern);
46%> restartList = pm.sampling.readRestart(sampler, []);
47%> restartList = pm.sampling.readRestart(sampler, pattern);
48%>
49%> \endcode
50%>
51%> \warning
52%> Currently, only the restart output files in ASCII format can be read via this method.<br>
53%> The binary restart files are not meant to be parsed via this method.<br>
54%> To request for ASCII restart output files in simulations,
55%> set the input simulation specification,<br>
56%> \code{.m}
57%> sampler.spec.outputRestartFileFormat = "ascii";
58%> \endcode
59%> where ``sampler`` can be an instance of any one of the ParaMonte
60%> sampler classes, such as [pm.sampling.Paradram](@ref Paradram).<br>
61%>
62%> \warning
63%> Avoid using this routine for very large long simulations.<br>
64%> Reading the full restart file of a large-scale simulation problem
65%> can be extremely memory-intensive.<br>
66%>
67%> \note
68%> See the documentation of the subclasses of [pm.sampling.Sampler](@ref Sampler)
69%> (e.g., [pm.sampling.Paradram](@ref Paradram)) for example usage in action.<br>
70%>
71%> \example{readRestart}
72%> \code{.m}
73%>
74%> sampler = pm.sampling.Sampler();
75%>
76%> restartList = pm.sampling.readRestart([], "./out/test_run_");
77%> restartList = pm.sampling.readRestart(sampler, "./out/test_run_");
78%>
79%> sampler.spec.outputFileName = "./out/test_run_";
80%>
81%> restartList = pm.sampling.readRestart(sampler, []);
82%> restartList = pm.sampling.readRestart(sampler);
83%>
84%> \endcode
85%>
86%> \final{readRestart}
87%>
88%> \author
89%> \AmirShahmoradi, Saturday Nov 2 2024, 11:11 PM, Dallas, TX.<br>
90%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
91function restartList = readRestart(sampler, pattern)
92
93 if nargin < 1
94 sampler = [];
95 end
96 if isempty(sampler)
97 sampler = pm.sampling.Sampler();
98 end
99
100 if nargin < 2
101 if 0 < pm.array.len(sampler.spec.outputFileName)
102 pattern = string(sampler.spec.outputFileName);
103 else
104 pattern = [];
105 end
106 end
107
108 pathList = sampler.findfile("restart", pattern);
109 restartList = cell(numel(pathList), 1);
110 for ifile = numel(pathList) : -1 : 1
111
112 if ~sampler.silent
113 disp("processing file: """ + pathList(ifile) + """");
114 end
115
116 if isequal(class(sampler), "pm.sampling.Sampler")
117 restartList{ifile} = pm.sampling.FileContentsRestart(pathList(ifile), sampler.silent);
118 elseif isequal(class(sampler), "pm.sampling.Paradram")
119 restartList{ifile} = pm.sampling.FileContentsRestartDRAM(pathList(ifile), sampler.silent);
120 else
121 help("pm.sampling.readRestart")
122 disp("class(sampler)");
123 disp( class(sampler) );
124 error ( newline ...
125 + "Invalid input ``sampler`` object type." + newline ...
126 + "See the documentation displayed above for more " + newline ...
127 + "information on possible values for ``sampler`` argument." + newline ...
128 + newline ...
129 );
130 end
131
132 end
133
134end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared library directories.
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
This is the base class for generating objects that contain the contents of a restart file generated b...
This is the base class for generating objects that contain the contents of a restart file generated b...
This is the ParaDRAM class for generating instances of serial and parallel Delayed-Rejection Adaptive...
Definition: Paradram.m:18
This is the base class for the ParaMonte sampler routines.
Definition: Sampler.m:21
function parallel()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...
function readRestart(in sampler, in pattern)
Return a list of objects of superclass pm.sampling.FileContentsRestart containing the contents of a (...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...