PennyLane for arbitrary control

Let’s consider that i encoded my data into a quantum state like this: U|0> = |psi>. Finally, i want to design a Hadamard test classifier.
image . My goal is to calculate inner product between quantum state for train and quantum state for test data: like this <psi|phi>. i know i can do it with swap test. i want to check with Hadamard test as well.

Hi @sassan_moradi,

It seems that you’d be on the right track, having the train and test data prepared at the beginning of the circuit could be a nice start. Was there perhaps a part of using PennyLane to implement the Hadamard test that you found challenging where we could try helping?

i need to implement the controlled unitary by Pennylane. i know how to use block encoding to define a controlled unitary. But for having 5 qubits i need to define a 32*32 which is tedious. Is there an another method to implement an arbitrary single controlled operation?

You might want to take at the ControlledQubitUnitary operation or the ctrl transform.

Hope those help :slight_smile: