ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
readChain.m
Go to the documentation of this file.
1%> \brief
2%> Return a list of objects of class [pm.sampling.FileContentsChain](@ref FileContentsChain)
3%> containing the content(s) of the ParaMonte simulation output chain file(s) whose path(s)
4%> match the specified input ``pattern`` or the simulation
5%> specification ``sampler.spec.outputFileName``.
6%>
7%> \warning
8%> This method is to be only used for post-processing of the output chain file(s) of an already finished simulation.<br>
9%> Although possible, this method is NOT meant to be called by all processes in MPI-parallel simulations.<br>
10%>
11%> \param[in] self : The input parent object of class [pm.sampling.Sampler](@ref Sampler)
12%> which is **implicitly** passed to this dynamic method (not by the user).<br>
13%> \param[in] pattern : The input scalar MATLAB string containing the pattern matching
14%> the desired chain 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 chain 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 ``"_chain.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, default = ``sampler.spec.outputFileName`` or ``"./"``)
29%> \param[in] sep : The input MATLAB string containing the field separator used in the file(s).<br>
30%> (optional, default = ``sampler.spec.outputSeparator`` or automatically inferred.)
31%>
32%> \return
33%> ``chainList`` : The output MATLAB cell array of objects
34%> of class [pm.sampling.FileContentsChain](@ref FileContentsChain),
35%> each of which corresponds to the contents
36%> of a unique chain file.<br>
37%>
38%> \interface{readChain}
39%> \code{.m}
40%>
41%> sampler = pm.sampling.Sampler();
42%> chainList = sampler.readChain();
43%> chainList = sampler.readChain([]);
44%> chainList = sampler.readChain([], []);
45%> chainList = sampler.readChain(pattern);
46%> chainList = sampler.readChain([], sep);
47%> chainList = sampler.readChain(pattern, sep);
48%>
49%> \endcode
50%>
51%> \note
52%> See the documentation of the sampler subclasses
53%> (e.g., [pm.sampling.Paradram](@ref Paradram)) for example usage in action.<br>
54%>
55%> \example{readChain}
56%> \code{.m}
57%>
58%> sampler.readChain("./out/test_run_");
59%>
60%> sampler.spec.outputFileName = "./out/test_run_";
61%> sampler.readChain();
62%>
63%> sampler.readChain("./out/test_run_", ",");
64%>
65%> sampler.spec.outputSeparator = ",";
66%> sampler.readChain("./out/test_run_");
67%>
68%> sampler.spec.outputFileName = "./out/test_run_";
69%> sampler.spec.outputSeparator = ",";
70%> sampler.readChain();
71%>
72%> \endcode
73%>
74%> \final{readChain}
75%>
76%> \author
77%> \JoshuaOsborne, May 21 2024, 12:18 AM, University of Texas at Arlington<br>
78%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
79%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
80function chainList = readChain(self, pattern, sep)
81 if nargin < 3
82 if 0 < pm.array.len(self.spec.outputSeparator)
83 sep = string(self.spec.outputSeparator);
84 else
85 sep = [];
86 end
87 end
88 if nargin < 2
89 if 0 < pm.array.len(self.spec.outputFileName)
90 pattern = string(self.spec.outputFileName);
91 else
92 pattern = [];
93 end
94 end
95 ftype = "chain";
96 pathList = self.findfile(ftype, pattern);
97 chainList = cell(length(pathList), 1);
98 for ifile = length(pathList) : -1 : 1
99 if ~self.silent
100 disp("processing file: """ + pathList(ifile) + """");
101 end
102 chainList{ifile} = pm.sampling.FileContentsChain(pathList(ifile), self.silent, sep);
103 end
104end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared libraries.
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 chain file generated by ...
This is the ParaDRAM class for generating instances of serial and parallel Delayed-Rejection Adaptive...
Definition: Paradram.m:14
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 which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...