3.8. qupulse.utils

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

Functions

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])

replace_multiple(s, replacements)

Replace multiple strings at once.

to_next_multiple(sample_rate, quantum[, ...])

Construct a helper function to expand a duration to one corresponding to valid sample multiples according to the arguments given.

class cached_property(func)[source]

Bases: object

checked_int_cast(x: float | int | ndarray, epsilon: float = 1e-06) int[source]
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

is_integer(x: Real, epsilon: float = 1e-06) bool[source]
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.

class pairwise(iterable, /)

Bases: object

Return an iterator of overlapping pairs taken from the input iterator.

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

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’

to_next_multiple(sample_rate: ExpressionLike, quantum: int, min_quanta: int | None = None) Callable[[ExpressionScalar], ExpressionLike][source]

Construct a helper function to expand a duration to one corresponding to valid sample multiples according to the arguments given. Useful e.g. for PulseTemplate.pad_to’s ‘to_new_duration’-argument.

Parameters:
  • sample_rate – sample rate with respect to which the duration is evaluated.

  • quantum – number of samples to whose next integer multiple the duration shall be rounded up to.

  • min_quanta – number of multiples of quantum not to fall short of.

Returns:

A function that takes a duration as input, and returns a duration rounded up to the next valid samples count in given sample rate. The function returns 0 if duration==0, <0 is not checked if min_quanta is None.

Modules

numeric

performance

sympy

tree

This module contains a tree implementation.

types