State preparation with pennylane


I am interested to know whether the following is possible with Pennylane:

To prepare a state (given \theta and \phi) from |0\rangle to |\psi\rangle where |\psi\rangle = \cos(\frac{\theta}{2})|0\rangle + e^{i\phi}\sin(\frac{\theta}{2}) that can be represented on a Bloch sphere.

Kind regards!

Hi @avinash_ch,

Certainly, this is a fairly easy modification of the qubit rotation example here:

The main difference is you will need to change to a measurement appropriate for the state you want to measure. This can be done either:

  • via extra fixed rotations (to rotate the |1> state into your desired target state |\psi>
  • by using the general-purpose Hermitian measurement operator, and supplying the matrix of |\psi><\psi|

In addition, you can also check out the following post for some example code:

@josh @nathan Thank you. I will check it.