TransWikia.com

Circuit to transform $|0rangle$ into $alpha|0rangle + beta|1rangle$ for any $alpha, beta$

Quantum Computing Asked by user15791 on July 11, 2021

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|0rangle + beta|1rangle$ when the input is $|0rangle$ and of course $|alpha|^2+|beta|^2=1$.

Thanks!

2 Answers

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.

Answered by epelaaez on July 11, 2021

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 $cosfrac{theta}{2}=alpha$ and $sinfrac{theta}{2}=beta$. We can use these two equations to solve for $theta$: $theta = 2arctanfrac{beta}{alpha}$. To compute $theta$ we can use ArcTan2 library function:

Ry(2.0 * ArcTan2(beta, alpha), q);

Answered by Mariia Mykhailova on July 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP