Complete the circuit_as_function QNode below that implements the quantum circuit shown below and returns the expectation value on the first wire. The params argument of circuit_as_function is an np.ndarray representing in that order.

The backend will then plot a cross-section of the circuit, where the axis is defined by angles and the axis is output_values. With the given definition of output_values, all the parameters are constant except the angle on the gate on the first wire. Feel free to change angles and output_values so check how the circuit depends on different variables!

or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Interpret a quantum circuit as a function.
  • Find first and higher order derivatives of quantum circuits.
  • Use optimizers to find extrema of quantum circuit cost functions.