3.8. qupulse.utils

This package contains utility functions and classes as well as custom sympy extensions(hacks).

qupulse.utils.sympy

qupulse.utils.tree

This module contains a tree implementation.

qupulse.utils.types

qupulse.utils.checked_int_cast(x, epsilon=1e-06)[source]
Return type

int

qupulse.utils.is_integer(x, epsilon=1e-06)[source]
Return type

bool

qupulse.utils.isclose()

Determine whether two floating point numbers are close in value.

rel_tol

maximum difference for being considered “close”, relative to the magnitude of the input values

abs_tol

maximum difference for being considered “close”, regardless of the magnitude of the input values

Return True if a is close in value to b, and False otherwise.

For the values to be considered close, the difference between them must be smaller than at least one of the tolerances.

-inf, inf and NaN behave similarly to the IEEE 754 Standard. That is, NaN is not close to anything, even itself. inf and -inf are only close to themselves.

qupulse.utils.pairwise(iterable, zip_function=<class 'itertools.zip_longest'>, **kwargs)[source]

s -> (s0,s1), (s1,s2), (s2, s3), …

Parameters
  • iterable (Iterable[Any]) – Iterable to iterate over pairwise

  • zip_function – Either zip or itertools.zip_longest(default)

  • **kwargs – Gets passed to zip_function

Return type

Iterable[Tuple[Any, Any]]

Returns

An iterable that yield neighbouring elements

qupulse.utils.replace_multiple(s, replacements)[source]

Replace multiple strings at once. If multiple replacements overlap the precedence is given by the order in replacements.

For pyver >= 3.6 (otherwise use OrderedDict) >>> assert replace_multiple(‘asdf’, {‘asd’: ‘1’, ‘asdf’, ‘2’}) == ‘asd1’ >>> assert replace_multiple(‘asdf’, {‘asdf’: ‘2’, ‘asd’, ‘1’}) == ‘2’

Return type

str