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.

Functions

_get_mem_usage()

_get_root_mem_usage(comm)

Returns the memory usage on the 0th processor

_get_max_mem_usage(comm)

Returns the memory usage on the 0th processor

Attributes

_BtoGB

pygsti.baseobjs.profiler._get_mem_usage()
pygsti.baseobjs.profiler._get_root_mem_usage(comm)

Returns the memory usage on the 0th processor

pygsti.baseobjs.profiler._get_max_mem_usage(comm)

Returns the memory usage on the 0th processor

pygsti.baseobjs.profiler._BtoGB
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
  • comm (mpi4py.MPI.Comm optional) – The active MPI communicator.

  • default_print_memcheck (bool, optional) – Whether to print memory checks.

add_time(self, name, start_time, prefix=0)

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

Parameters
  • name (string) – 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_time (float) – The starting time used to compute the elapsed, i.e. the value time.time()-start_time, which is added to the named timer.

  • prefix (int, 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(self, name, inc=1, prefix=0)

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

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

  • inc (int, optional) – The increment (the value to add to the counter).

  • prefix (int, 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(self, name, printme=None, prefix=0)

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

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

  • printme (bool, 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).

  • prefix (int, 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(self, 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
  • name (string) – A label to print before the memory usage number(s).

  • show_minmax (bool, 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(self, 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
  • msg (string) – The message to print.

  • all_ranks (bool, 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

_format_times(self, sort_by='name')

Formats a string to report the timer values recorded in this Profiler.

Parameters

sort_by ({"name","time"}) – What to sort list of timers by.

Returns

str

_format_counts(self, sort_by='name')

Formats a string to report the counter values recorded in this Profiler.

Parameters

sort_by ({"name","count"}) – What to sort list of counts by.

Returns

str

_format_memory(self, sort_by='name')

Formats a string to report the memory usage checkpoints recorded in this Profiler.

Parameters

sort_by ({"name","usage","timestamp"}) – What to sort list of counts by.

Returns

str

__getstate__(self)
__setstate__(self, state_dict)
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).

add_time(self, name, start_time, prefix=0)

Stub function that does nothing

Parameters
  • name (string) – 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_time (float) – The starting time used to compute the elapsed, i.e. the value time.time()-start_time, which is added to the named timer.

  • prefix (int, 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(self, name, inc=1, prefix=0)

Stub function that does nothing

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

  • inc (int, optional) – The increment (the value to add to the counter).

  • prefix (int, 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(self, name, printme=None, prefix=0)

Stub function that does nothing

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

  • printme (bool, 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).

  • prefix (int, 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