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.io.read(filename)[source]

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

util.io.read_bcs(f)[source]

read in the boundary condition record from the HDF5 file

util.msg module

support output in highlighted colors

util.msg.bold(string)[source]

Output a string in a bold weight

util.msg.fail(string)[source]

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

util.msg.success(string)[source]

Output a string to the terminal colored green to indicate success

util.msg.warning(string)[source]

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

begin()[source]

Start timing

end()[source]

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:

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.

report()[source]

Generate a timing summary report

timer(name)[source]

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

Parameters
namestr

Name of the timer

Returns
outTimer object

A timer object corresponding to the name.

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_stringslist

The list of strings containing runtime parameter pairs

get_param(key)[source]

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.

Parameters
filestr

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_all_params()[source]

Print out all runtime parameters and their values

print_paramfile()[source]

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

print_sphinx_tables(outfile='params-sphinx.inc')[source]

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

print_unused_params()[source]

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

write_params(f)[source]

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

util.runparams.is_float(string)[source]

is the given string a float?

util.runparams.is_int(string)[source]

is the given string an interger?