InvertibleFunction

class qugradlab.pulses.invertible_functions.InvertibleFunction(func: Callable)[source]

Bases: object

A class representing an invertible function.

Attributes

inverse

The inverse of the function

Methods

__init__

Wraps the a function in an InvertibleFunction object so that an inverse can be associated with it.

compose

Composes the InvertibleFunction with another InvertibleFunction to create a new InvertibleFunction along with the composed inverse. That is the following assertions should hold::.

set_inverse

Sets the inverse of the function.

specify_parameters

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 InvertibleFunction with another InvertibleFunction to create a new InvertibleFunction along 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:

Note

Enough positional arguments and keyword arguments need to be passed that the calling InvertibleFunction has only one remaining parameter (input).

Returns:

A new InvertibleFunction that is the composition of the two functions.

Return type:

InvertibleFunction

set_inverse(inverse_func: Callable)[source]

Sets the inverse of the function.

Parameters:

inverse_func (Callable) – The inverse function

Note

inverse_func should 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 InvertibleFunction without the specified parameters in the call signatures.

Parameters:

**kwargs – Keyword arguments to pre-specify for the function and inverse function.

Returns:

A new InvertibleFunction with the specified parameters pre-specified.

Return type:

InvertibleFunction

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.