Source code for qugradlab.pulses.invertible_functions.scaling

 1"""A collection of reversible rescalings for contructing pulse sequences."""
 2
 3import numpy as np
 4
[docs] 5def linear_rescaling(x: np.ndarray[complex], 6 min: complex, 7 max: complex 8 ) -> np.ndarray[complex]: 9 """ 10 Rescales an input `x` in the range [-1, 1] to the range [`min`, `max`] with 11 -1 being mapped to `min` and 1 being mapped to `max`. 12 13 Parameters 14 ---------- 15 x: NDArray[Shape[s := Any_Shape], complex] 16 The input to be rescaled 17 min: complex 18 The minimum value of the rescaled range 19 max: complex 20 The maximum value of the rescaled range 21 22 Returns 23 ------- 24 NDArray[Shape[s], complex] 25 The rescaled input 26 27 Note 28 ---- 29 :func:`linear_rescaling()` is an instance of :class:`.InvertibleFunction`. 30 31 Methods 32 ------- 33 linear_rescaling.inverse 34 The inverse linear rescaling 35 36 PARAMETERS: 37 * **x** (*NDArray[Shape[s := Any_Shape], complex]*) — 38 The rescaled value to be unscaled 39 * **min** (*complex*) — 40 The minimum value of the rescaled range 41 * **max** (*complex*) — 42 The maximum value of the rescaled range 43 44 RETURNS: 45 The unscaled value 46 47 RETURN TYPE: 48 NDArray[Shape[s], complex] 49 linear_rescaling.specify_parameters 50 Allows the maximum and minimum values to be pre-specified. This removes 51 them from the call signature. If only one of ``max`` or ``min`` is 52 passed, then only the value speficied is removed from the call 53 signature. 54 55 PARAMETERS: 56 * **min** (*complex, optional*) — 57 The minimum value of the rescaled range 58 * **max** (*complex, optional*) — 59 The maximum value of the rescaled range 60 61 RETURNS: 62 A new :class:`.InvertibleFunction` with the specified parameters 63 pre-specified. 64 65 RETURN TYPE: 66 InvertibleFunction 67 68 linear_rescaling.compose 69 Composes the :func:`linear_rescaling()` with another 70 :class:`.InvertibleFunction` to create a new 71 :class:`.InvertibleFunction` along with the composed inverse. That is 72 the following assertions should hold:: 73 74 assert linear_rescaling.compose(g, *args, **kwargs)(x, *g_args, **g_kwargs) \ 75 == linear_rescaling(g(x, *g_args, **g_kwargs), *args, **kwargs) 76 77 for all inputs ``x``. 78 79 PARAMETERS: 80 * **inner_invertible_function** (*InvertibleFunction*) — 81 The :class:`.InvertibleFunction` be be called first. The output of 82 this :class:`.InvertibleFunction` will be passed to 83 :func:`linear_rescaling()`. 84 * **min** (*complex*) — 85 The minimum value of the rescaled range 86 * **max** (*complex*) — 87 The maximum value of the rescaled range 88 89 RETURNS: 90 A new :class:`.InvertibleFunction` that is the composition of the 91 two functions. 92 93 RETURN TYPE: 94 InvertibleFunction 95 """ 96 ...