pack

qugradlab.pulses.invertible_functions.packaging.pack(tensors: list) Any[source]

Packs the list of input tensors into a single TensorFlow tensor.

Parameters:

tensors (list) – The list of TensorFlow tensors to be packed

Returns:

A TensorFlow tensor with 1 axis consisting of all the input tensors flattened and concatenated.

Return type:

TensorFlow Tensor

pack.inverse()

Unpacks an input iterable x into TensorFlow tensors of the given shapes.

PARAMETERS:
  • x (Iterable) — The iterable to be unpacked.

  • shapes (Iterable[Iterable[int]]) — The shapes of the tensors to be unpacked into.

RETURNS:

A TensorFlow tensor with 1 axis consisting of all the input tensors flattened and concatenated.

RETURN TYPE:

list

pack.specify_parameters()

Allows the shapes to be pre-specified. This removes shapes from the call signature of inverse().

PARAMETERS:
  • shapes (Iterable[Iterable[int]], optional) — The shapes of the tensors to be unpacked into.

RETURNS:

A new InvertibleFunction with the specified parameters pre-specified.

RETURN TYPE:

InvertibleFunction

pack.compose()

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

assert pack.compose(g, *args, **kwargs)(x, *g_args, **g_kwargs)                 == pack(g(x, *g_args, **g_kwargs), *args, **kwargs)

for all inputs x.

PARAMETERS:
  • inner_invertible_function (InvertibleFunction) — The InvertibleFunction be be called first. The output of this InvertibleFunction will be passed to pack().

  • shapes (Iterable[Iterable[int]]) — The shapes of the tensors to be unpacked into.

RETURNS:

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

RETURN TYPE:

InvertibleFunction