qml.devices.qubit.adjoint_vjp

adjoint_vjp(tape, cotangents, state=None)[source]

The vector jacobian product used in reverse-mode differentiation.

Implements the adjoint method outlined in Jones and Gacon to differentiate an input tape.

After a forward pass, the circuit is reversed by iteratively applying adjoint gates to scan backwards through the circuit.

Note

The adjoint differentiation method has the following restrictions:

  • Cannot differentiate with respect to observables.

  • Observable being measured must have a matrix.

Parameters
  • tape (QuantumTape) – circuit that the function takes the gradient of

  • cotangents (Tuple[Number]) –

    gradient vector for output parameters. For computing the full Jacobian, the cotangents can be batched to vectorize the computation. In this case, the cotangents can have the following shapes. batch_size below refers to the number of entries in the Jacobian:

    • For a state measurement, cotangents must have shape (batch_size, 2 ** n_wires).

    • For n expectation values, the cotangents must have shape (n, batch_size). If n = 1, then the shape must be (batch_size,).

  • state (TensorLike) – the final state of the circuit; if not provided, the final state will be computed by executing the tape

Returns

gradient vector for input parameters

Return type

Tuple[Number]

Contents

Using PennyLane

Release news

Development

API

Internals