qml.transforms.expand_invalid_trainable

expand_invalid_trainable(tape, _depth=10, **kwargs)

Expand out a tape so that it supports differentiation of requested operations.

This is achieved by decomposing all trainable operations that have Operation.grad_method=None until all resulting operations have a defined gradient method, up to maximum depth depth. Note that this might not be possible, in which case the gradient rule will fail to apply.

Parameters
  • tape (QuantumTape) – the input tape to expand

  • depth (int) – the maximum expansion depth

  • **kwargs – additional keyword arguments are ignored

Returns

the expanded tape

Return type

QuantumTape