pygsti.baseobjs.profiler

Defines the Profiler class and supporting functionality

Module Contents

Classes

Profiler

Profiler objects are used for tracking both time and memory usage.

DummyProfiler

A dummy profiler that doesn't do anything.

class pygsti.baseobjs.profiler.Profiler(comm=None, default_print_memcheck=False)

Bases: object

Profiler objects are used for tracking both time and memory usage.

Parameters

commmpi4py.MPI.Comm optional

The active MPI communicator.

default_print_memcheckbool, optional

Whether to print memory checks.

Construct a new Profiler instance.

Parameters

commmpi4py.MPI.Comm, optional

MPI communicator so only profile and print messages on root proc.

add_time(name, start_time, prefix=0)

Adds an elapsed time to a named “timer”-type accumulator.

Parameters
namestring

The name of the timer to add elapsed time into (if the name doesn’t exist, one is created and initialized to the elapsed time).

start_timefloat

The starting time used to compute the elapsed, i.e. the value time.time()-start_time, which is added to the named timer.

prefixint, optional

Prefix to the timer name the current stack depth and this number of function names, starting with the current function and moving the call stack. When zero, no prefix is added. For example, with prefix == 1, “Total” might map to “ 3: myFunc: Total”.

Returns

None

add_count(name, inc=1, prefix=0)

Adds a given value to a named “counter”-type accumulator.

Parameters
namestring

The name of the counter to add val into (if the name doesn’t exist, one is created and initialized to val).

incint, optional

The increment (the value to add to the counter).

prefixint, optional

Prefix to the timer name the current stack depth and this number of function names, starting with the current function and moving the call stack. When zero, no prefix is added. For example, with prefix == 1, “Total” might map to “ 3: myFunc: Total”.

Returns

None

memory_check(name, printme=None, prefix=0)

Record the memory usage at this point and tag with a name.

Parameters
namestring

The name of the memory checkpoint. (Later, memory information can be organized by checkpoint name.)

printmebool, optional

Whether or not to print the memory usage during this function call (if None, the default, then the value of default_print_memcheck specified during Profiler construction is used).

prefixint, optional

Prefix to the timer name the current stack depth and this number of function names, starting with the current function and moving the call stack. When zero, no prefix is added. For example, with prefix == 1, “Total” might map to “ 3: myFunc: Total”.

Returns

None

print_memory(name, show_minmax=False)

Prints the current memory usage (but doesn’t store it).

Useful for debugging, this function prints the current memory usage - optionally giving the mininum, maximum, and average across all the processors.

Parameters
namestring

A label to print before the memory usage number(s).

show_minmaxbool, optional

If True and there are multiple processors, print the min, average, and max memory usage from among the processors. Note that this will invoke MPI collective communication and so this print_memory call must be executed by all the processors. If False and there are multiple processors, only the rank 0 processor prints output.

Returns

None

print_message(msg, all_ranks=False)

Prints a message to stdout, possibly from all ranks.

A utility function used in debugging, this function offers a convenient way to print a message on only the root processor or on all processors.

Parameters
msgstring

The message to print.

all_ranksbool, optional

If True, all processors will print msg, preceded by their rank label (e.g. “Rank4: “). If False, only the rank 0 processor will print the message.

Returns

None

class pygsti.baseobjs.profiler.DummyProfiler

Bases: object

A dummy profiler that doesn’t do anything.

A class which implements the same interface as Profiler but which doesn’t actually do any profiling (consists of stub functions).

Construct a new DummyProfiler instance.

add_time(name, start_time, prefix=0)

Stub function that does nothing

Parameters

namestring

The name of the timer to add elapsed time into (if the name doesn’t exist, one is created and initialized to the elapsed time).

start_timefloat

The starting time used to compute the elapsed, i.e. the value time.time()-start_time, which is added to the named timer.

prefixint, optional

Prefix to the timer name the current stack depth and this number of function names, starting with the current function and moving the call stack. When zero, no prefix is added. For example, with prefix == 1, “Total” might map to “ 3: myFunc: Total”.

Returns

None

add_count(name, inc=1, prefix=0)

Stub function that does nothing

Parameters

namestring

The name of the counter to add val into (if the name doesn’t exist, one is created and initialized to val).

incint, optional

The increment (the value to add to the counter).

prefixint, optional

Prefix to the timer name the current stack depth and this number of function names, starting with the current function and moving the call stack. When zero, no prefix is added. For example, with prefix == 1, “Total” might map to “ 3: myFunc: Total”.

Returns

None

memory_check(name, printme=None, prefix=0)

Stub function that does nothing

Parameters

namestring

The name of the memory checkpoint. (Later, memory information can be organized by checkpoint name.)

printmebool, optional

Whether or not to print the memory usage during this function call (if None, the default, then the value of default_print_memcheck specified during Profiler construction is used).

prefixint, optional

Prefix to the timer name the current stack depth and this number of function names, starting with the current function and moving the call stack. When zero, no prefix is added. For example, with prefix == 1, “Total” might map to “ 3: myFunc: Total”.

Returns

None