In PennyLane, CNOTs can be applied using qml.CNOT and the following syntax:

def circuit(): qml.CNOT(wires=[control, target])

where control and target are the wire labels (e.g., qml.CNOT(wires=[0, 1])).

Write a circuit that implements a gate between two qubits. Test it out on all four computational basis states. What are the resulting states? Express your answer in a dictionary that takes the form of a truth table, i.e., a table that details a set of output bits given the set of input bits:

As an explicit example, the truth table of is

or to submit your code

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

Learning Objectives:

  • Define and apply entangling operations to multi-qubit systems.
  • Define the controlled-NOT (CNOT) gate, and write its matrix representation.
  • Define and apply general controlled operations.