3.8.3. qupulse.utils.types

class qupulse.utils.types.HashableNumpyArray[source]

Bases: numpy.ndarray

Make numpy arrays hashable.

Example usage: my_array = np.zeros([1, 2, 3, 4]) hashable = my_array.view(HashableNumpyArray)

class qupulse.utils.types.TimeType(value=0.0)[source]

Bases: object

This type represents a rational number with arbitrary precision.

Internally it uses gmpy2.mpq() (if available) or fractions.Fraction

property denominator
classmethod from_float(value, absolute_error=None)[source]

Convert a floating point number to a TimeType using one of three modes depending on absolute_error.

The default str(value) guarantees that all floats have a different result with sensible rounding. This was chosen as default because it is the expected behaviour most of the time if the user defined the float from a literal in code.

Parameters
  • value (float) – Floating point value to convert to arbitrary precision TimeType

  • absolute_error (Optional[float]) –

    • None: Use str(value) as a proxy to get consistent precision

    • 0: Return the exact value of the float i.e. float(0.8) == 3602879701896397 / 4503599627370496

    • 0 < absolute_error <= 1: Use absolute_error to limit the denominator

Raises

ValueError – If absolute_error is not None and not 0 <= absolute_error <= 1

Return type

TimeType

classmethod from_fraction(numerator, denominator)[source]

Convert a fraction to a TimeType.

Parameters
  • numerator (int) – Numerator of the time fraction

  • denominator (int) – Denominator of the time fraction

Return type

TimeType

property numerator
qupulse.utils.types.time_from_float(value, absolute_error=None)[source]

See TimeType.from_float().

Return type

TimeType

class qupulse.utils.types.DocStringABCMeta[source]

Bases: abc.ABCMeta

Metaclass that copies/refers to docstrings of the super class.

class qupulse.utils.types.SingletonABCMeta(name, bases, dct)[source]

Bases: qupulse.utils.types.DocStringABCMeta

Metaclass that enforces singletons

class qupulse.utils.types.SequenceProxy(inner)[source]

Bases: collections.abc.Sequence

count(value) → integer -- return number of occurrences of value[source]
index(value[, start[, stop]]) → integer -- return first index of value.[source]

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.