Skip to content

Commit

Permalink
Katas UI string review - Single-qubit gates (#1758)
Browse files Browse the repository at this point in the history
Co-authored-by: Mariia Mykhailova <[email protected]>
  • Loading branch information
SoniaLopezBravo and tcNickolas authored Jul 26, 2024
1 parent 7790378 commit 7346dcb
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 56 deletions.
8 changes: 4 additions & 4 deletions katas/content/single_qubit_gates/amplitude_change/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
We can recognize that we need to use one of the rotation gates Rx, Ry, and Rz (named because they "rotate" the qubit state in the three dimensional space visualized as the Bloch sphere about the x, y, and z axes, respectively), since they involve angle parameters. Of these three gates, only Ry rotates the basis states $\ket{0}$ and $\ket{1}$ to have real amplitudes (the other two gates introduce complex coefficients).
You can recognize that you need to use one of the rotation gates Rx, Ry, and Rz (named because they "rotate" the qubit state in the three dimensional space visualized as the Bloch sphere about the x, y, and z axes, respectively), since they involve angle parameters. Of these three gates, only Ry rotates the basis states $\ket{0}$ and $\ket{1}$ to have real amplitudes (the other two gates introduce complex coefficients).

As a reminder,

Expand All @@ -20,8 +20,8 @@ R_y(\theta)\ket{0} =
$$

Recall that when applying a gate, you can tell what its matrix does to the basis states by looking at its columns: the first column of the matrix is the state into which it will transform the $\ket{0}$ state, and the second column is the state into which it will transform the $\ket{1}$ state.
One of the examples used by the testing harness has $\beta = 0.6, \gamma = 0.8$ and $\alpha = \frac{\pi}{3} = 1.0472$.
Since $\cos \frac{\pi}{3} = 0.5$ and $\sin \frac{\pi}{3} = 0.8660$, working to 4 decimal places, we can use $\frac{\theta}{2} = \alpha$ to compute:
One of the examples used by the testing harness has $\beta = 0.6, \gamma = 0.8$ and $\alpha = \frac{\pi}{3} 1.0472$.
Since $\cos \frac{\pi}{3} = 0.5$ and $\sin \frac{\pi}{3} = 0.8660$, working to 4 decimal places, you can use $\frac{\theta}{2} = \alpha$ to compute:

$$
R_{y}(\theta) \ket{\psi}=
Expand All @@ -33,7 +33,7 @@ R_{y}(\theta) \ket{\psi}=
\begin{bmatrix}-0.3928\\ 0.9196\\ \end{bmatrix}
$$

Notice that we used $\frac{\theta}{2} = \alpha$; this means that in the Q# code we need to pass the angle $\theta = 2\alpha$.
Notice that $\frac{\theta}{2} = \alpha$; this means that in the Q# code you need to pass the angle $\theta = 2\alpha$.

@[solution]({
"id": "single_qubit_gates__amplitude_change_solution",
Expand Down
6 changes: 3 additions & 3 deletions katas/content/single_qubit_gates/basis_change/solution.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
We can recognize that the Hadamard gate changes states $\ket{0}$ and $\ket{1}$ to $\ket{+}$ and $\ket{-}$, respectively, and vice versa.
You can recognize that the Hadamard gate changes states $\ket{0}$ and $\ket{1}$ to $\ket{+}$ and $\ket{-}$, respectively, and vice versa.

As a reminder, the Hadamard gate is defined by the following matrix:

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

For example, we can work out $H\ket{1}$ as follows:
For example, you can work out $H\ket{1}$ as follows:

$$
H\ket{1}=
Expand All @@ -17,7 +17,7 @@ H\ket{1}=
\frac{1}{\sqrt{2}} \big(\ket{0} - \ket{1}\big) = \ket{-}
$$

Similarly, we can consider the effect of the Hadamard gate on the superposition state $\ket{\psi} = 0.6\ket{0} + 0.8\ket{1}$ (rounding the numbers to 4 decimal places):
Similarly, you can consider the effect of the Hadamard gate on the superposition state $\ket{\psi} = 0.6\ket{0} + 0.8\ket{1}$ (rounding the numbers to 4 decimal places):

$$
H|\psi⟩ =
Expand Down
8 changes: 4 additions & 4 deletions katas/content/single_qubit_gates/complex_phase/solution.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
We know that:
You know that:

$$
R1(\alpha)=
\begin{bmatrix}1 & 0 \\ 0 & \color{red}{e^{i\alpha}}\end{bmatrix}
$$

So we have:
So you have:

$$
R1(\beta \ket{0} + \gamma \ket{1}) =
Expand All @@ -18,8 +18,8 @@ $$

> Suppose now that $\alpha = \frac{\pi}{2}$.
> Then $e^{i\alpha}= \cos\frac{\pi}{2} + i\sin\frac{\pi}{2}$.
> And, since $\cos\frac{\pi}{2}= 0$ and $\sin\frac{\pi}{2} = 1$, then we have that $\cos\frac{\pi}{2} + i \sin\frac{\pi}{2} = i$, and
> $R1(\frac{\pi}{2}) = S$, which we used in the second solution to the task "Relative Phase i".
> And, since $\cos\frac{\pi}{2}= 0$ and $\sin\frac{\pi}{2} = 1$, then you have that $\cos\frac{\pi}{2} + i \sin\frac{\pi}{2} = i$, and
> $R1(\frac{\pi}{2}) = S$, which you used in the second solution to the task "Relative Phase i".
@[solution]({
"id": "single_qubit_gates__complex_phase_solution",
Expand Down
6 changes: 3 additions & 3 deletions katas/content/single_qubit_gates/global_phase_i/solution.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
We need to apply a gate which applies a global phase of $i$, i.e. $\ket{\psi} \rightarrow i\ket{\psi}$.
You need to apply a gate which applies a global phase of $i$, that is, $\ket{\psi} \rightarrow i\ket{\psi}$.
The matrix representation of such a gate is $\begin{bmatrix} i & 0 \\ 0 & i \end{bmatrix} = i\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = iI$.
Since we are restricted to the Pauli gates, we use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$.
Since you're restricted to the Pauli gates, you can use the property that a product of any two distinct Pauli gates equals the third gate with a $+i$ or a $-i$ global phase, therefore the product of all three Pauli gates is $XYZ = iI$.
$$
\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} =
\begin{bmatrix} i & 0 \\ 0 & i \end{bmatrix}
$$

> Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence we first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate.
> Remember the rightmost gates in mathematical notation are applied first in Q# code. Hence you first apply the $Z$ gate, followed by the $Y$ gate, and finally the $X$ gate.
@[solution]({
"id": "single_qubit_gates__global_phase_i_solution",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

**Goal**: Change the state of the qubit to $- \beta \ket{0} - \gamma \ket{1}$.

> This change on its own is not observable - there is no experiment you can do on a standalone qubit to figure out whether it acquired the global phase or not.
> This change on its own is not observable - there's no experiment you can do on a standalone qubit to figure out whether it acquired the global phase or not.
> However, you can use a controlled version of this operation to observe the global phase it introduces.
> This is used in later katas as part of more complicated tasks.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
A global phase is a phase factor that multiplies the entire quantum state. It is not observable when measuring the qubit's state, as the probabilities remain unchanged. However, it is significant when considering quantum state transformations.
A global phase is a phase factor that multiplies the entire quantum state. It isn't observable when measuring the qubit's state, as the probabilities remain unchanged. However, it's significant when considering quantum state transformations.

Our task is to implement an operation that transforms the given qubit state from $\ket{\psi} = \beta \ket{0} + \gamma \ket{1}$ to $- \beta \ket{0} - \gamma \ket{1}$.

To do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pauli X gate can be used to achieve this effect when applied in succession twice.
To do that, you use a sequence of gates. The Pauli Z gate followed by the Pauli X gate can be used to achieve this effect when applied in succession twice.

1. **Apply the Pauli Z gate**: The Z gate multiplies the $\ket{1}$ state by $-1$ but does not change the $\ket{0}$ state, converting our state $\beta \ket{0} + \gamma \ket{1}$ to $\beta \ket{0} - \gamma \ket{1}$.
1. **Apply the Pauli Z gate**: The Z gate multiplies the $\ket{1}$ state by $-1$ but doen't change the $\ket{0}$ state, converting our state $\beta \ket{0} + \gamma \ket{1}$ to $\beta \ket{0} - \gamma \ket{1}$.

The matrix representation of the Z gate is:

Expand All @@ -13,7 +13,7 @@ To do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pau
\begin{bmatrix}1 & 0 \\ 0 & -1 \end{bmatrix}
$$

2. **Apply the Pauli X gate**: The X gate flips the $\ket{0}$ and $\ket{1}$ basis states, converting our $\beta \ket{0} - \gamma \ket{1}$ state to $\beta \ket{1} - \gamma \ket{0}$.
2. **Apply the Pauli X gate**: The X gate flips the $\ket{0}$ and $\ket{1}$ basis states, converting $\beta \ket{0} - \gamma \ket{1}$ state to $\beta \ket{1} - \gamma \ket{0}$.

The matrix representation of the X gate is:

Expand All @@ -22,7 +22,7 @@ To do that, we utilize a sequence of gates. The Pauli Z gate followed by the Pau
\begin{bmatrix}0 & 1 \\ 1 & 0\end{bmatrix}
$$

3. **Repeat the Z and X gates**: Applying the Z gate again will multiply the $\ket{1}$ state (that used to be $\ket{0}$), converting our state $\beta \ket{1} - \gamma \ket{0}$ to $- \beta \ket{1} - \gamma \ket{0}$. Finally, the second X gate will restore the original basis states, but now with both amplitudes having acquired an additional phase of $-1$. This means our state has been multiplied by $-1$, achieving the required global phase change.
3. **Repeat the Z and X gates**: Applying the Z gate again will multiply the $\ket{1}$ state (that used to be $\ket{0}$), converting the state $\beta \ket{1} - \gamma \ket{0}$ to $- \beta \ket{1} - \gamma \ket{0}$. Finally, the second X gate will restore the original basis states, but now with both amplitudes having acquired an additional phase of $-1$. This means the state has been multiplied by $-1$, achieving the required global phase change.

@[solution]({
"id": "single_qubit_gates__global_phase_minusone_solution",
Expand Down
Loading

0 comments on commit 7346dcb

Please sign in to comment.