InvertibleFunction¶
- class qugradlab.pulses.invertible_functions.InvertibleFunction(func: Callable)[source]¶
Bases:
objectA class representing an invertible function.
Attributes
The inverse of the function
Methods
Wraps the a function in an InvertibleFunction object so that an inverse can be associated with it.
Composes the
InvertibleFunctionwith anotherInvertibleFunctionto create a newInvertibleFunctionalong with the composed inverse. That is the following assertions should hold::.Sets the inverse of the function.
Allows keyword parameters for the function and inverse function to be pre-specified.
- __init__(func: Callable)[source]¶
Wraps the a function in an InvertibleFunction object so that an inverse can be associated with it.
- Parameters:
func (Callable) – The function to be wrapped
- compose(inner_invertible_function: InvertibleFunction, *args, **kwargs) InvertibleFunction[source]¶
Composes the
InvertibleFunctionwith anotherInvertibleFunctionto create a newInvertibleFunctionalong with the composed inverse. That is the following assertions should hold:assert f.compose(g, *f_args, **f_kwargs)(x, *g_args, **g_kwargs) == f(g(x, *g_args, **g_kwargs), *f_args, **f_kwargs)
for all inputs
x.- Parameters:
inner_invertible_function (InvertibleFunction) – The
InvertibleFunctionbe be called first. The output of thisInvertibleFunctionwill be passed to the currentInvertibleFunction.*args – Any additional positional arguments to pass to the function.
**kwargs – Keyword arguments to pass to the function.
Note
Enough positional arguments and keyword arguments need to be passed that the calling
InvertibleFunctionhas only one remaining parameter (input).- Returns:
A new
InvertibleFunctionthat is the composition of the two functions.- Return type:
- set_inverse(inverse_func: Callable)[source]¶
Sets the inverse of the function.
- Parameters:
inverse_func (Callable) – The inverse function
Note
inverse_funcshould satisfy the following assertions:assert inverse_func(self(x, *args, **kwargs), *args, **kwargs) == x assert self(inverse_func(x, *args, **kwargs), *args, **kwargs) == x
for all inputs
x.
- specify_parameters(**kwargs) InvertibleFunction[source]¶
Allows keyword parameters for the function and inverse function to be pre-specified. This generates a new
InvertibleFunctionwithout the specified parameters in the call signatures.- Parameters:
**kwargs – Keyword arguments to pre-specify for the function and inverse function.
- Returns:
A new
InvertibleFunctionwith the specified parameters pre-specified.- Return type:
- property inverse¶
The inverse of the function
- Parameters:
input – The input to the inverse function
*args – Any additional positional arguments to pass to the inverse function.
**kwargs – Keyword arguments to pass to the inverse function.
- Returns:
The result of the inverse function call.
- Return type:
Any
Note
inverse should satisfy the following assertions:
assert self.inverse(self(x, *args, **kwargs), *args, **kwargs) == x assert self(self.inverse(x, *args, **kwargs), *args, **kwargs) == x
for all inputs
x.