3.9. qupulse.utils

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

Functions

_fallback_is_close(a, b, *[, rel_tol, abs_tol])

Copied from https://docs.python.org/3/library/math.html Does no error checks.

_fallback_pairwise(iterable)

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

checked_int_cast(x[, epsilon])

forced_hash(obj)

Try to produce a hash from obj by nested conversions to hashable types.

grouper(iterable, n[, fillvalue])

Collect data into fixed-length chunks or blocks

is_integer(x[, epsilon])

pairwise(iterable)

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

replace_multiple(s, replacements)

Replace multiple strings at once.

class qupulse.utils.cached_property(func)[source]

Bases: object

qupulse.utils.checked_int_cast(x: Union[float, int, numpy.ndarray], epsilon: float = 1e-06) int[source]
qupulse.utils.forced_hash(obj) int[source]

Try to produce a hash from obj by nested conversions to hashable types.

Mapping -> frozendict AbstractSet -> frozenset ndarray -> bytes or nested tuples Sequence -> tuple

qupulse.utils.is_integer(x: numbers.Real, epsilon: float = 1e-06) bool[source]
qupulse.utils.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)

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: Iterable[qupulse.utils._T]) Iterator[Tuple[qupulse.utils._T, qupulse.utils._T]]

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

Parameters

iterable – Iterable to iterate over pairwise

Returns

An iterable that yields neighbouring elements

qupulse.utils.replace_multiple(s: str, replacements: Mapping[str, str]) str[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’

Modules

qupulse.utils.numeric

qupulse.utils.performance

qupulse.utils.sympy

qupulse.utils.tree

This module contains a tree implementation.

qupulse.utils.types