3
$\begingroup$

For example, we can create a single qubit state with a polar angle of $\pi/2$ with the Hadamard gate. But, can we create a state such as this,

$$\Psi = \cos(\pi/8)|0\rangle + \sin(\pi/8)|1\rangle$$

where the polar angle does not equal $\pi/2$, in QISkit?

$\endgroup$
4
$\begingroup$

You use the standard rotations. In this case, you're looking for the ry operator (rotation around the y-axis). To rotate the state vector counter-clockwise around the unit circle by $\theta$, call ry with $2\theta$ or in your case $\frac{2\pi}{8}$ applied to state $|0\rangle$.

from qiskit import *
import numpy as np
q = QuantumRegister(1)
qc = QuantumCircuit(q)
qc.ry(2*np.pi/8,q)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.