util package

This module provides utility functions for pyro


util.io module

This manages the reading of the HDF5 output files for pyro.


read an HDF5 file and recreate the simulation object that holds the data and state of the simulation.


read in the boundary condition record from the HDF5 file

util.msg module

support output in highlighted colors


Output a string in a bold weight


Output a string to the terminal and abort if we are running non-interactively. The string is colored red to indicate a failure


Output a string to the terminal colored green to indicate success


Output a string to the terminal colored orange to indicate a warning

util.plot_tools module

Some basic support routines for configuring the plots during runtime visualization

util.plot_tools.setup_axes(myg, num)[source]

create a grid of axes whose layout depends on the aspect ratio of the domain

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


Start timing


Stop timing. This does not destroy the timer, it simply stops it from counting time.

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:


and to end it:


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.


Generate a timing summary report


Create a timer with the given name. If one with that name already exists, then we return that timer.


Name of the timer

outTimer object

A timer object corresponding to the name.

util.runparams module

basic syntax of the parameter file is:

# simple parameter file

nsteps = 100         ; comment
max_time = 0.25

tol = 1.e-10
max_iter = 10

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()

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


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


The list of strings containing runtime parameter pairs


returns the value of the runtime parameter corresponding to the input key

load_params(pfile, no_new=0)[source]

Reads line from file and makes dictionary pairs from the data to store.


The name of the file to parse

no_newint, 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 out all runtime parameters and their values


Create a file, inputs.auto, that has the structure of a pyro inputs file, with all known parameters and values


Output Sphinx-formatted tables for inclusion in the documentation. The table columns will be: param, default, description.


Print out the list of parameters that were defined by never used


Write the runtime parameters to an HDF5 file. Here, f is the h5py file object


is the given string a float?


is the given string an interger?