Controlled Hadamard Gate

Hi sorry I am new here but is there an existing controlled Hadamard gate, or do I have to program one using QubitUnitary?

Hi @leongfy! You can use qml.ctrl to create a controlled Hadamard gate :slight_smile:

@qml.qnode(dev)
def circuit(x):
    qml.RY(x, wires=0)
    qml.ctrl(qml.Hadamard, control=0)(wires=1)
    return qml.expval(qml.PauliZ(1))

>>> circuit(0.3)
tensor(0.97766824, requires_grad=True)

Since PennyLane does not have a native controlled Hadamard gate, this is being decomposed under-the-hood:

>>> print(qml.draw(circuit)(0.3))
 0: ──RY(0.3)──╭ControlledPhaseShift(1.57)──╭C─────────╭ControlledPhaseShift(1.57)──┤
 1: ───────────╰ControlledPhaseShift(1.57)──╰RX(1.57)──╰ControlledPhaseShift(1.57)──┤ ⟨Z⟩