Io module¶
Input-Output handling
Handles all the input/output of the code (at least most of it). If something is printed that does not satisfy you (number of decimals, for instance, in the output files), you only have to find the called function and change a number.
Whenever the arguments of the functions are command_line
or
data
, no mention of them will be done - as it is now clear. On the
contrary, if there are more arguments, they will be detailled.
This module also defines a new class File
, that extends
file
, which provides a tail function. It is used in
sampler.read_args_from_chain()
.
Finally, the way the error messages are displayed is set there, along with ascii-art for the exclamation mark sign.
-
io_mp.
log_parameters
(data, command_line)[source]¶ Write the first lines of the log.param
Writes the beginning of log.param, starting with the header with the cosmological code version and potential git hash and branch name, and then recopies entirely the input parameter file.
-
io_mp.
log_likelihood_parameters
(likelihood, command_line)[source]¶ Write down the interpreted .data file of the input likelihood to log.param
Warning
Since version 2.0.2, the lines are not copied verbatim, they are first interpreted, then copied. This allows for overriding of parameters from the input.param file.
-
io_mp.
log_cosmo_arguments
(data, command_line)[source]¶ Write down the cosmo_arguments used to log.param
Third function called when writing log.param. It is understood here that all the other parameters for the cosmological modules are set to their default value directly in the program.
It is written as an update for the dictionary cosmo_arguments (i.e. as
dict.update()
and not asdict =
) in order not to erase previously initialized data.
-
io_mp.
log_default_configuration
(data, command_line)[source]¶ Log the .conf file to log.param
Fourth and last function called when writing log.param. Only useful if you have several versions of your cosmological code installed in different locations, or different versions of Clik. But, as you never know what might go wrong, it is logged everytime !
TODO: should the root be still logged? (@packaging)
-
io_mp.
print_parameters
(out, data)[source]¶ Will print the parameter names. In the code,
out
is simply the standard output, as this information will not be printed on the output file.Indeed, you will be able to recover these information from the log.param.
Warning
Please pay attention to the fact that, once launched, the order of the parameters in log.param is crucial, as is it the only place where it is stored.
-
io_mp.
print_vector
(out, N, loglkl, data)[source]¶ Print the last accepted values to
out
Parameters: out (list) – Array containing both standard output and the output file.
This way, if you run in interactive mode, you will be able to monitor the progress of the chain.
N (int) – Multiplicity of the point, i.e. number of times the code stayed at this particular place.
loglkl (float) – Value of the (- log likelihood) at this point
.. note (:) –
It is the last_accepted point that is printed, and not the current one (obviously, as one does not know yet the multiplicity of the current one !)
-
io_mp.
refresh_file
(data)[source]¶ Closes and reopen the output file to write any buffered quantities
-
io_mp.
create_output_files
(command_line, data)[source]¶ Automatically create a new name for the chain.
This routine takes care of organising the folder for you. It will automatically generate names for the new chains according to the date, number of points chosen.
Warning
The way these names are generated (with the proper number of _, __, -, and their placement) is exploited in the rest of the code in various places. Please keep that in mind if ever you are in the mood of changing things here.
-
io_mp.
get_tex_name
(name, number=1)[source]¶ Simplistic tex name transformer.
Essentially tries to add a backslash in front of known possible greek letters, and insert curly brackets { } around statement following an _ or a ^. It will also try to include the scale into the name in a nice way.
Note
This might easily fail on simple names, like beta_plus_lambda. In this case, please use an extra plot file with the command line option
-extra plot_file
, or come up with a better function !Note
This function returns immediatly with the unmodified name if it already contains the LaTeX symbol for math, $.
Parameters: name (str) – Input name Keyword Arguments: number (float) – Scale
-
io_mp.
write_covariance_matrix
(covariance_matrix, names, path)[source]¶ Store the covariance matrix to a file
-
io_mp.
pretty_print
(string, status, return_string=False)[source]¶ Return the string formatted according to its status
The input is a potentially long message, describing the problem. According to the severity of its status (so far, ‘error’ will exit the program, whereas ‘warning’ and ‘info’ will go through anyway).
Standard length has been defined globally, as well as the ascii-art dictionary of arrays START_LINE.
-
class
io_mp.
File
[source]¶ Bases:
file
New class of file, to provide an equivalent of the tail command (on linux).
It will be used when starting from an existing chain, and avoids circling through an immense file.
-
exception
io_mp.
LockError
[source]¶ Bases:
exceptions.Exception
Warning
in the process of being tested
-
LOCK_FAILED
= 1¶
-
-
io_mp.
lock
(file, flags)[source]¶ Lock a given file to prevent other instances of the code to write to the same file.
Warning
in the process of being tested
-
exception
io_mp.
MyError
(message)[source]¶ Bases:
exceptions.Exception
Base class defining the general presentation of error messages
Reformat the name of the class for easier reading
-
exception
io_mp.
CosmologicalModuleError
(message)[source]¶ Bases:
io_mp.MyError
For all problems linked to the cosmological module
Reformat the name of the class for easier reading
-
exception
io_mp.
ConfigurationError
(message)[source]¶ Bases:
io_mp.MyError
Missing files, libraries, etc...
Reformat the name of the class for easier reading
-
exception
io_mp.
MissingLibraryError
(message)[source]¶ Bases:
io_mp.MyError
Missing Cosmo module, Planck, ...
Reformat the name of the class for easier reading
-
exception
io_mp.
LikelihoodError
(message)[source]¶ Bases:
io_mp.MyError
Problems when computing likelihood, missing nuisance, etc...
Reformat the name of the class for easier reading
-
exception
io_mp.
FiducialModelWritten
(message)[source]¶ Bases:
io_mp.MyError
Used to exit the code in case of writing a fiducial file
Reformat the name of the class for easier reading
-
exception
io_mp.
AnalyzeError
(message)[source]¶ Bases:
io_mp.MyError
Used when encountering a fatal mistake in analyzing chains
Reformat the name of the class for easier reading