1
$\begingroup$

Hi I'm new to QC and doing some katas in Q#. I got stuck on this excercise and would appreciate help: Quantum circuit to get following state qubit: $\alpha|0\rangle + \beta|1\rangle$ when the input is $|0\rangle$ and of course $|\alpha|^2+|\beta|^2=1$.

Thanks!

$\endgroup$
2
  • 2
    $\begingroup$ In the future, when you find an answer to your own question, you could answer it yourself. This helps people that may have the same question in the future. But if you want to delete it, you can do it yourself instead of changing the title to "Please delete this question". $\endgroup$
    – epelaaez
    Jun 12 at 18:13
  • $\begingroup$ Measurement will do the thing. $\endgroup$
    – narip
    Jun 13 at 4:24
2
$\begingroup$

Looking at the list of the intrinsic gates available in Q#, and keeping in mind that we need a gate with the first column being $\begin{bmatrix} \alpha \\ \beta \end{bmatrix}$, you can notice that the gate with all real coefficients is the Ry gate.

Now you need to find $\theta$ such that $\cos\frac{\theta}{2}=\alpha$ and $\sin\frac{\theta}{2}=\beta$. We can use these two equations to solve for $\theta$: $\theta = 2\arctan\frac{\beta}{\alpha}$. To compute $\theta$ we can use ArcTan2 library function:

Ry(2.0 * ArcTan2(beta, alpha), q);
$\endgroup$
1
$\begingroup$

First, note that the input (in vector form) will be $\begin{bmatrix} 1 \\ 0 \end{bmatrix}$. And you want the output to be $\begin{bmatrix} \alpha \\ \beta \end{bmatrix}$. Therefore, the matrix that represents the gate you want needs to have the vector you want as output on the first column.

To see what the second column needs to be, let’s look at the general expression of a unitary matrix. This is

$$ \begin{bmatrix} a & b \\ -e^{i \phi}b^* & e^{i \phi}a^* \end{bmatrix} $$

Therefore, plugging in the first column and solving for the elements of the second column, the form of the matrix you want is

$$ \begin{bmatrix} \alpha & \beta^* \\ \beta & -\alpha^* \end{bmatrix} $$

Here we choose $a=\alpha$, $b=\beta^*$ (to make sure the complex conjugate one is in the top row; but you don't need to worry about this if $\alpha, \beta \in \mathbb{R}$) and $\phi = \pi$. An example of this type of matrix is the Hadamard, that you can get by making $\alpha=\beta=\frac{1}{\sqrt{2}}$.

$$ H= \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} $$

I’m not sure how to do it in Q#, but to do this in Qiskit, define an np.array with the matrix you want. Then, create the matrix by running gate = UnitaryGate(your_matrix). Then, just append the gate as you normally would: qc.append(gate, [qubits]). However, you need to look out for Qiskit’s indexing. For more info on this, checkout this answer.

$\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.