Utilities¶
TOAST contains a variety of utilities for controlling the runtime environment, logging, timing, streamed random number generation, quaternion operations, FFTs, and special function evaluation. In some cases these utilities provide a common interface to compile-time selected vendor math libraries.
Environment Control¶
The run-time behavior of the TOAST package can be controlled by the manipulation of several environment variables. The current configuration can also be queried.
-
class
toast.utils.
Environment
¶ Global runtime environment.
This singleton class provides a unified place to parse environment variables at runtime and to change global settings that impact the overall package.
-
current_threads
(self: toast._libtoast.Environment) → int¶ Return the current threading concurrency in use.
-
function_timers
(self: toast._libtoast.Environment) → bool¶ Return True if function timing has been enabled.
-
get
() → toast._libtoast.Environment¶ Get a handle to the global environment class.
-
log_level
(self: toast._libtoast.Environment) → str¶ Return the string of the current Logging level.
-
max_threads
(self: toast._libtoast.Environment) → int¶ Returns the maximum number of threads used by compiled code.
-
print
(self: toast._libtoast.Environment) → None¶ Print the current environment to STDOUT.
-
set_log_level
(self: toast._libtoast.Environment, level: str) → None¶ Set the Logging level.
Parameters: level (str) – one of DEBUG, INFO, WARNING, ERROR or CRITICAL. Returns: None
-
set_threads
(self: toast._libtoast.Environment, nthread: int) → None¶ Set the number of threads in use.
Parameters: nthread (int) – The number of threads to use. Returns: None
-
signals
(self: toast._libtoast.Environment) → List[str]¶ Return a list of the currently available signals.
-
tod_buffer_length
(self: toast._libtoast.Environment) → int¶ Returns the number of samples to buffer for TOD operations.
-
use_mpi
(self: toast._libtoast.Environment) → bool¶ Return True if TOAST was compiled with MPI support and MPI is supported in the current runtime environment.
-
version
(self: toast._libtoast.Environment) → str¶ Return the current source code version string.
-
Logging¶
Although python provides logging facilities, those are not accessible to C++. The logging class provided in TOAST is usable from within the compiled libtoast code and also from python, and uses logging level independent from the builtin python logger.
-
class
toast.utils.
Logger
¶ Simple Logging class.
This class mimics the python logger in C++. The log level is controlled by the TOAST_LOGLEVEL environment variable. Valid levels are DEBUG, INFO, WARNING, ERROR and CRITICAL. The default is INFO.
-
critical
(self: toast._libtoast.Logger, msg: str) → None¶ Print a CRITICAL level message.
Parameters: msg (str) – The message to print. Returns: None
-
debug
(self: toast._libtoast.Logger, msg: str) → None¶ Print a DEBUG level message.
Parameters: msg (str) – The message to print. Returns: None
-
error
(self: toast._libtoast.Logger, msg: str) → None¶ Print an ERROR level message.
Parameters: msg (str) – The message to print. Returns: None
-
get
() → toast._libtoast.Logger¶ Get a handle to the global logger.
-
info
(self: toast._libtoast.Logger, msg: str) → None¶ Print an INFO level message.
Parameters: msg (str) – The message to print. Returns: None
-
warning
(self: toast._libtoast.Logger, msg: str) → None¶ Print a WARNING level message.
Parameters: msg (str) – The message to print. Returns: None
-
Vector Math Operations¶
The following functions …
-
toast.utils.
vsin
(in: buffer, out: buffer) → None¶ Compute the Sine for an array of float64 values.
The results are stored in the output buffer. To guarantee SIMD vectorization, the input and output arrays should be aligned (i.e. use an AlignedF64).
Parameters: - in (array_like) – 1D array of float64 values.
- out (array_like) – 1D array of float64 values.
Returns: None
Random Number Generation¶
The following functions …
-
toast._libtoast.
rng_dist_uint64
(key1: int, key2: int, counter1: int, counter2: int, data: buffer) → None¶ Generate random unsigned 64bit integers.
The provided input array is populated with values. The dtype of the input array should be compatible with unsigned 64bit integers. To guarantee SIMD vectorization, the input array should be aligned (i.e. use an AlignedU64).
Parameters: - key1 (uint64) – The first element of the key.
- key2 (uint64) – The second element of the key.
- counter1 (uint64) – The first element of the counter.
- counter2 (uint64) – The second element of the counter. This is effectively the sample index in the stream defined by the other 3 values.
- data (array) – The array to populate.
Returns: None.