Earlier, we learned how to create a gate using and A similar circuit identity can be constructed for the controlled- using controlled- () and

In PennyLane, the controlled- is available as qml.CZ, and can be called in the same way as qml.CNOT.

Complete the function imposter_cz below to reveal the relationship.

dev = qml.device("default.qubit", wires=2)

# Prepare a two-qubit state; change up the angles if you like
phi, theta, omega = 1.2, 2.3, 3.4


@qml.qnode(device=dev)
def true_cz(phi, theta, omega):
prepare_states(phi, theta, omega)

##################
# YOUR CODE HERE #
##################

# IMPLEMENT THE REGULAR CZ GATE HERE

return qml.state()


@qml.qnode(dev)
def imposter_cz(phi, theta, omega):
prepare_states(phi, theta, omega)

##################
# YOUR CODE HERE #
##################

# IMPLEMENT CZ USING ONLY H AND CNOT

return qml.state()


print(f"True CZ output state {true_cz(phi, theta, omega)}")
print(f"Imposter CZ output state {imposter_cz(phi, theta, omega)}")

or to submit your code

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

Learning Objectives:

  • Define and apply a set of common multi-qubit operations: the controlled-Z, Toffoli, and SWAP gates.
  • Express common 3-qubit operations in terms of 1- and 2-qubit operations.