Hi,
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!
nathan
September 18, 2019, 7:25pm
2
Hi @avinash_ch ,
Certainly, this is a fairly easy modification of the qubit rotation example here: https://pennylane.readthedocs.io/en/latest/tutorials/pennylane_run_qubit_rotation.html#qubit-rotation
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|
josh
September 18, 2019, 8:11pm
3
In addition, you can also check out the following post for some example code:
And just for completeness, here is the full optimization:
import pennylane as qml
from pennylane import numpy as np
dev = qml.device('default.qubit', wires=2)
@qml.qnode(dev)
def circuit(x, target_observable=None):
qml.RX(x[0], wires=0)
qml.RY(x[1], wires=0)
qml.RZ(x[2], wires=0)
qml.CNOT(wires=[0, 1])
return qml.expval.Hermitian(target_observable, wires=[0, 1])
target_state = 1/np.sqrt(2) * np.array([1,0,0,1])
target_herm_op = np.outer(target_state.conj(), target_state)
…
@josh @nathan Thank you. I will check it.