util package¶
This module provides utility functions for pyro
Submodules¶
util.io module¶
This manages the reading of the HDF5 output files for pyro.
util.msg module¶
support output in highlighted colors
util.plot_tools module¶
Some basic support routines for configuring the plots during runtime visualization
util.profile module¶
A very simple profiling class, to use to determine where most of the time is spent in a code. This supports nested timers and outputs a report at the end.
Warning: At present, no enforcement is done to ensure proper nesting.
-
class
util.profile.
Timer
(name, stack_count=0)[source]¶ Bases:
object
A single timer – this simply stores the accumulated time for a single named region
-
class
util.profile.
TimerCollection
[source]¶ Bases:
object
A timer collection—this manages the timers and has methods to start and stop them. Nesting of timers is tracked so we can pretty print the profiling information.
To define a timer:
tc = TimerCollection() a = tc.timer('my timer')
This will add ‘my timer’ to the list of Timers managed by the TimerCollection. Subsequent calls to timer() will return the same Timer object.
To start the timer:
a.begin()
and to end it:
a.end()
For best results, the block of code timed should be large enough to offset the overhead of the timer class method calls.
tc.report() prints out a summary of the timing.
util.runparams module¶
basic syntax of the parameter file is:
# simple parameter file
[driver]
nsteps = 100 ; comment
max_time = 0.25
[riemann]
tol = 1.e-10
max_iter = 10
[io]
basename = myfile_
The recommended way to use this is for the code to have a master list of parameters and their defaults (e.g. _defaults), and then the user can override these defaults at runtime through an inputs file. These two files have the same format.
The calling sequence would then be:
rp = RuntimeParameters()
rp.load_params("_defaults")
rp.load_params("inputs")
The parser will determine what datatype the parameter is (string, integer, float), and store it in a RuntimeParameters object. If a parameter that already exists is encountered a second time (e.g., there is a default value in _defaults and the user specifies a new value in inputs), then the second instance replaces the first.
Runtime parameters can then be accessed via any module through the get_param method:
tol = rp.get_param('riemann.tol')
If the optional flag no_new=1 is set, then the load_params function will not define any new parameters, but only overwrite existing ones. This is useful for reading in an inputs file that overrides previously read default values.
-
class
util.runparams.
RuntimeParameters
[source]¶ Bases:
object
-
command_line_params
(cmd_strings)[source]¶ finds dictionary pairs from a string that came from the commandline. Stores the parameters in only if they already exist.
- we expect things in the string in the form:
- [“sec.opt=value”, “sec.opt=value”]
with each opt an element in the list
Parameters: - cmd_strings : list
The list of strings containing runtime parameter pairs
-
load_params
(pfile, no_new=0)[source]¶ Reads line from file and makes dictionary pairs from the data to store.
Parameters: - file : str
The name of the file to parse
- no_new : int, optional
If no_new = 1, then we don’t add any new paramters to the dictionary of runtime parameters, but instead just override the values of existing ones.
-
print_paramfile
()[source]¶ Create a file, inputs.auto, that has the structure of a pyro inputs file, with all known parameters and values
-