diff --git a/katas/content/multi_qubit_measurements/full_measurements/index.md b/katas/content/multi_qubit_measurements/full_measurements/index.md index 1ba1afe211..f92f121f07 100644 --- a/katas/content/multi_qubit_measurements/full_measurements/index.md +++ b/katas/content/multi_qubit_measurements/full_measurements/index.md @@ -7,6 +7,6 @@ * 2 if they were in the $\ket{10}$ state, * 3 if they were in the $\ket{11}$ state. -In this task and the subsequent ones the order of qubit states in task description matches the order of qubits in the array (i.e., $\ket{10}$ state corresponds to `qs[0]` in state $\ket{1}$ and `qs[1]` in state $\ket{0}$). +In this task and the subsequent ones the order of qubit states in task description matches the order of qubits in the array (that is, $\ket{10}$ state corresponds to `qs[0]` in state $\ket{1}$ and `qs[1]` in state $\ket{0}$). -The state of the qubits at the end of the operation does not matter. +The state of the qubits at the end of the operation doesn't matter. diff --git a/katas/content/multi_qubit_measurements/full_measurements/solution.md b/katas/content/multi_qubit_measurements/full_measurements/solution.md index c549464417..110b990e4c 100644 --- a/katas/content/multi_qubit_measurements/full_measurements/solution.md +++ b/katas/content/multi_qubit_measurements/full_measurements/solution.md @@ -1,23 +1,23 @@ -First, we measure each of the qubits in the input array, convert the measurement results into integers -and store them in variables `m1` and `m2`. We can decode these results like this: +First, you measure each of the qubits in the input array, convert the measurement results into integers +and store them in variables `m1` and `m2`. You can decode these results like this: -- `m1` is $\ket{0}$ and `m2` is $\ket{0}$: we return $0\cdot2+0 = 0$ -- `m1` is $\ket{0}$ and `m2` is $\ket{1}$: we return $0\cdot2+1 = 1$ -- `m1` is $\ket{1}$ and `m2` is $\ket{0}$: we return $1\cdot2+0 = 2$ -- `m1` is $\ket{1}$ and `m2` is $\ket{1}$: we return $1\cdot2+1 = 3$ +- `m1` is $\ket{0}$ and `m2` is $\ket{0}$: the return value is $0\cdot2+0 = 0$ +- `m1` is $\ket{0}$ and `m2` is $\ket{1}$: the return value is $0\cdot2+1 = 1$ +- `m1` is $\ket{1}$ and `m2` is $\ket{0}$: the return value is $1\cdot2+0 = 2$ +- `m1` is $\ket{1}$ and `m2` is $\ket{1}$: the return value is $1\cdot2+1 = 3$ -In other words, we treat the measurement results as the binary notation of the return value in big-endian notation. +In other words, you treat the measurement results as the binary notation of the return value in big-endian notation. @[solution]({ "id": "multi_qubit_measurements__full_measurements_solution", "codePath": "Solution.qs" }) -We can generalize this code to read out an integer in big-endian notation from a qubit array of arbitrary length using several library operations and functions: +You can generalize this code to read out an integer in big-endian notation from a qubit array of arbitrary length using several library operations and functions: - `MeasureEachZ` measures each of the qubits in the array in the computational basis and returns an array of `Result` data type. - `Reversed` reverses the given array. -- `ResultArrayAsInt` converts an array of bits given as `Result` to an integer, assuming little-endian notation (that's why we have to reverse the array before converting it). +- `ResultArrayAsInt` converts an array of bits given as `Result` to an integer, assuming little-endian notation (that's why you have to reverse the array before converting it). @[solution]({ "id": "multi_qubit_measurements__full_measurements_solution_alt", diff --git a/katas/content/multi_qubit_measurements/index.md b/katas/content/multi_qubit_measurements/index.md index 6ce7a13263..e24f2cd307 100644 --- a/katas/content/multi_qubit_measurements/index.md +++ b/katas/content/multi_qubit_measurements/index.md @@ -5,7 +5,7 @@ "title": "Overview" }) -In the previous kata, we discussed the concept of measurements done on single-qubit systems. +The previous kata discussed the concept of measurements done on single-qubit systems. Building upon those ideas, this kata will introduce you to measurements done on multi-qubit systems, and how to implement such measurements in Q#. This will include measuring a single qubit in a multi-qubit system, as well as measuring multiple qubits simultaneously. @@ -17,27 +17,29 @@ This will include measuring a single qubit in a multi-qubit system, as well as m **What you should know to start working on this kata:** -- Basic linear algebra +- Basic concepts of linear algebra - Single and multi-qubit systems -- Single and multi-qubit gates +- Basic single and multi-qubit gates - Single-qubit system measurements +If you need a refresher on any of these topics, you can check out the previous katas. + ## Types of Measurements There are several types of measurements you can perform on an $n$-qubit system ($n>1$): -- Measuring all the qubits simultaneously in an orthogonal basis ($2^n$ possible outcomes). As we shall see below, this is a direct generalization of orthogonal basis measurements done in single-qubit systems introduced in the previous kata. +- Measuring all the qubits simultaneously in an orthogonal basis ($2^n$ possible outcomes). As you'll see below, this is a direct generalization of orthogonal basis measurements done in single-qubit systems introduced in the previous kata. - Partial measurement: measuring $m$ qubits out of $n$, for $m Solution -Using the expressions $\ket{0} = \frac{1}{\sqrt{2}} \big( \ket{+} + \ket{-} \big)$ and $\ket{1} = \frac{1}{\sqrt{2}} \big( \ket{+} - \ket{-} \big)$, we first express $\ket{\psi}$ in the Pauli X basis. This gives us +Using the expressions $\ket{0} = \frac{1}{\sqrt{2}} \big( \ket{+} + \ket{-} \big)$ and $\ket{1} = \frac{1}{\sqrt{2}} \big( \ket{+} - \ket{-} \big)$, you first express $\ket{\psi}$ in the Pauli X basis. This gives you $$\ket \psi = \frac{2}{3}\ket {00} + \frac{1}{3} \ket {01} + \frac{2}{3}\ket {11} =$$ $$= \frac{2}{3} \big[ \frac{1}{\sqrt{2}}\big(\ket{+} + \ket{-}\big) \otimes \frac{1}{\sqrt{2}} \big(\ket{+} + \ket{-}\big) \big] + \frac{1}{3} \big[ \frac{1}{\sqrt{2}}\big(\ket{+} + \ket{-}\big) \otimes \frac{1}{\sqrt{2}} \big(\ket{+} - \ket{-}\big) \big] + \frac{2}{3} \big[ \frac{1}{\sqrt{2}}\big(\ket{+} - \ket{-}\big) \otimes \frac{1}{\sqrt{2}} \big(\ket{+} - \ket{-}\big) \big] =$$ @@ -155,14 +157,14 @@ After this, the probabilities of measuring each of the four basis vectors is giv -Now, let's see how we can use Q# to solve these two problems. +Now, let's see how you can use Q# to solve these two problems. -1. We start by preparing the state $\ket \psi$. - To do this, we can represent $\ket \psi$ as follows: +1. You start by preparing the state $\ket \psi$. + To do this, you can represent $\ket \psi$ as follows: $$\frac 2 3 \ket{00} + \big( \frac 1 {\sqrt 5} \ket{0} + \frac 2 {\sqrt 5} \ket{1} \big) \frac {\sqrt 5} 3 \ket{1}$$ - This representation tells us how we should rotate individual qubits. -2. To figure out the measurement outcome probabilities in the computational basis, we can just use the `DumpMachine` function that lists probabilities associated with each basis state present in the superposition. -3. To figure out the measurement outcome probabilities in the Pauli X basis, we can apply a transformation that maps the two-qubit Pauli X basis into the two-qubit computational basis. This transformation just applies a Hadamard gate to each of the qubits. + This representation tells you how you should rotate individual qubits. +2. To figure out the measurement outcome probabilities in the computational basis, you can just use the `DumpMachine` function that lists probabilities associated with each basis state present in the superposition. +3. To figure out the measurement outcome probabilities in the Pauli X basis, you can apply a transformation that maps the two-qubit Pauli X basis into the two-qubit computational basis. This transformation just applies a Hadamard gate to each of the qubits. 4. View probabilities of each basis state with the `DumpMachine` function. Thanks to the previous step, the following state equivalence holds: @@ -199,7 +201,7 @@ The amplitudes of the computational basis states after the transformation are th ## Measuring Each Qubit in a System Sequentially -As described in the previous sections, in theory it is possible to measure all the qubits in an $n$-qubit system simultaneously in an orthogonal basis. The post-measurement state of the qubits is then exactly one of the $2^n$ possible basis states. +As described in the previous sections, in theory it's possible to measure all the qubits in an $n$-qubit system simultaneously in an orthogonal basis. The post-measurement state of the qubits is then exactly one of the $2^n$ possible basis states. In practice, this is implemented by measuring all the qubits one after another. For example, if one wants to measure a two-qubit system in the computational basis, one can implement this by first measuring the first qubit in the computational basis to obtain $0$ or $1$, and then measuring the second qubit in the computational basis. This can result in one of the four possible outcomes: $00, 01, 10, 11$. @@ -208,21 +210,21 @@ This can be generalized to measurements in other bases, such as the 2-qubit Paul > Note that measurement of all qubits sequentially can only be done in orthogonal bases $\{ \ket{b_i}\}$, such that each $\ket{b_i}$ is a **tensor product state**. That is, each $\ket{b_i}$ must be of the form $\ket{v_0} \otimes \ket{v_1} \dotsc \otimes \ket{v_{n-1}}$, with each $\ket{v_j}$ being a single-qubit basis state. For example, for the two-qubit Pauli X basis $\ket{++}, \ket{+-}, \ket{-+}, \ket{--}$ each basis state is a tensor product of states $\ket{+}$ and $\ket{-}$, which form a single-qubit basis state. > -> Measuring in orthogonal bases which contain states which are not tensor product states, such as the Bell basis, are trickier to implement, and require appropriate unitary rotations in addition to measuring all qubits one after another. -> We will not discuss such measurements in this kata. +> Measuring in orthogonal bases which contain states which aren't tensor product states, such as the Bell basis, are trickier to implement, and require appropriate unitary rotations in addition to measuring all qubits one after another. +> Such measurements aren't discussed in this kata. > -> If we restrict ourselves to measurements in tensor product states, the distinction between measuring all the qubits simultaneously versus one after another is not important for an ideal quantum computer: in terms of the outcomes and measurement probabilities, both are identical. Furthermore, as long as all the qubits are measured, the sequence in which they are measured is also inconsequential. These factors can be important in the case of real quantum computers with imperfect qubits, but we restrict the discussion to ideal systems in this kata. +> If measurements are restricted to tensor product states, the distinction between measuring all the qubits simultaneously versus one after another is not important for an ideal quantum computer: in terms of the outcomes and measurement probabilities, both approaches are identical. Furthermore, as long as all the qubits are measured, the sequence in which they are measured is also inconsequential. These factors can be important in the case of real quantum computers with imperfect qubits, but the discussion in this kata is limited to ideal systems. @[section]({ "id": "multi_qubit_measurements__measurement_statistics", "title": "Measurement Statistics for Qubit-By-Qubit Full Measurement" }) -This demo illustrates the equivalence of the measurement probabilities for simultaneous measurement on all qubits, and measurements on each of the qubits executed one after another. We show that the measurement probabilities obtained using the `M` operation in Q# are the same as those expected theoretically, using the two-qubit state from the first exercise as an example: +This demo illustrates the equivalence of the measurement probabilities for simultaneous measurement on all qubits, and measurements on each of the qubits executed one after another. It shows that the measurement probabilities obtained using the `M` operation in Q# are the same as those expected theoretically, using the two-qubit state from the first exercise as an example: $$\ket \psi = \frac{1}{3}\ket {00} + \frac{2}{3} \ket {01} + \frac{2}{3}\ket {11}$$ -The simulated probabilities will be different for each run of `DemoBasisMeasurement`. The simulated and theoretical probabilities are not expected to be identical, since measurements are probabilistic. However, we expect the values to be similar, and the simulated probabilities to approach the theoretical probabilities as the parameter `numRuns` is increased. +The simulated probabilities will be different for each run of `DemoBasisMeasurement`. The simulated and theoretical probabilities are not expected to be identical, since measurements are probabilistic. However, the values are expected to be similar, and the simulated probabilities to approach the theoretical probabilities as the parameter `numRuns` is increased. @[example]({ "id": "multi_qubit_measurements__measuring_one_at_a_time", @@ -230,7 +232,7 @@ The simulated probabilities will be different for each run of `DemoBasisMeasurem }) -Full measurements can also be used to identify the state of the system, if it is guaranteed to be in one of several possible orthogonal states. +Full measurements can also be used to identify the state of the system, if it's guaranteed to be in one of several possible orthogonal states. @[exercise]({ "id": "multi_qubit_measurements__full_measurements", @@ -243,21 +245,21 @@ Full measurements can also be used to identify the state of the system, if it is "title": "Partial Measurements" }) -For a system with $n>1$ qubits, it is possible to measure $m1$ qubits, it's possible to measure $m The symbol $\otimes$ represents the tensor product or the Kronecker product of two matrices. It is different from the usual matrix multiplication. +> The symbol $\otimes$ represents the tensor product or the Kronecker product of two matrices. It's different from the usual matrix multiplication. > In the current context, $\ket{b_i} \bra{ b_i} \otimes \mathbb{1}_{n-m}$ simply means that > > - The operator $\ket{b_i} \bra{ b_i}$ acts only on the $m$ qubits being measured. -> - The effect of $P_i$ on the remaining qubits is $\mathbb{1}_{n-m} $, i.e., the identity operator. +> - The effect of $P_i$ on the remaining qubits is $\mathbb{1}_{n-m} $, that is, the identity operator. Analogous to the case for measurements for single-qubit systems, the rules for partial measurement probabilities and outcomes can be summarized as follows: @@ -268,7 +270,7 @@ $$ \frac{P_i \ket{\psi}}{\big|P_i \ket{\psi}\big|}. $$ -For example, consider a two-qubit system in the state $\ket \psi = \frac{1}{\sqrt{2}}\ket{01} - \frac{1}{\sqrt 2}\ket{10}$. Consider a measurement of the first qubit in the computational basis, i.e., in the $\{\ket 0 , \ket 1 \}$ basis. Then, we have two projectors that represent this measurement: +For example, consider a two-qubit system in the state $\ket \psi = \frac{1}{\sqrt{2}}\ket{01} - \frac{1}{\sqrt 2}\ket{10}$. Consider a measurement of the first qubit in the computational basis, that is, in the $\{\ket 0 , \ket 1 \}$ basis. Then, you have two projectors that represent this measurement: $$P_0 = \ket 0\bra 0 \otimes \mathbb{1}$$ $$P_1 = \ket 1 \bra 1 \otimes \mathbb{1}$$ @@ -278,10 +280,10 @@ $$P_0 \ket \psi = \left(\ket 0\bra 0 \otimes \mathbb{1}\right) \frac{1}{\sqrt 2} $$= \frac{1}{\sqrt 2} \big( \ket 0 \braket{0|0} \otimes \mathbb{1} \ket{1} - \ket 0 \braket{0|1} \otimes \mathbb{1} \ket 0 \big) = \frac{1}{\sqrt 2} \ket{01}$$ -Similarly, we obtain +Similarly, you obtain $$P_1 \ket\psi = -\frac{1}{\sqrt 2} \ket{10}$$ -Clearly, we have $\big|P_0 \ket \psi\big| = \big|P_1 \ket \psi\big| = \frac{1}{2}$ in this case. Thus, the probabilities of measuring $0$ and $1$ are both $0.5$, with the post-measurement states of system being $\ket{01}$ and $\ket{10}$, respectively. +Clearly, you have $\big|P_0 \ket \psi\big| = \big|P_1 \ket \psi\big| = \frac{1}{2}$ in this case. Thus, the probabilities of measuring $0$ and $1$ are both $0.5$, with the post-measurement states of system being $\ket{01}$ and $\ket{10}$, respectively. > Similar to the case of single-qubit system measurements, the applicability of the formalism above requires the state of the multi-qubit system, $\ket \psi$, to be normalized. This is required to ensure that all the probabilities of individual outcomes add up to 1. @@ -295,7 +297,7 @@ If only the first qubit is measured in the computational basis, what are the pro
Solution -A measurement outcome of $0$ on the first qubit corresponds to the projection operator $P_0 = \ket{0}\bra{ 0} \otimes \mathbb{1}$. Applying it to the state $\ket \psi$ gives us +A measurement outcome of $0$ on the first qubit corresponds to the projection operator $P_0 = \ket{0}\bra{ 0} \otimes \mathbb{1}$. Applying it to the state $\ket \psi$ gives you $$\big|P_0 \ket{\psi}\big|^2 = \big|\frac{1}{\sqrt{12}} \left(3\ket {00} + \ket{01}\right) \big|^2 = \frac{5}{6}$$ and $$\frac{P_0 \ket{\psi}}{\big|P_0 \ket{\psi}\big|} = \frac{1}{\sqrt{10}} \left( 3\ket{00} + \ket{01}\right)$$ @@ -328,17 +330,16 @@ $$\frac{P_1 \ket{\psi}}{\big|P_1 \ket{\psi}\big|} = \frac{1}{\sqrt{2}} \left(\ke "title": "Measurement Statistics for Partial Measurement" }) -In this demo, we show that the simulated outcome probabilities and post-measurement outcomes match the theoretical values obtained using the projection operators as described above. -We use the Hardy state $\ket \psi = \frac{1}{\sqrt{12}} \big(3\ket{00} + \ket{01} + \ket{10} + \ket{11}\big)$ from the previous exercise and do a computational basis measurement on the first qubit for this purpose. +This demo shows that the simulated outcome probabilities and post-measurement outcomes match the theoretical values obtained using the projection operators as described above. It uses the Hardy state $\ket \psi = \frac{1}{\sqrt{12}} \big(3\ket{00} + \ket{01} + \ket{10} + \ket{11}\big)$ from the previous exercise and do a computational basis measurement on the first qubit for this purpose. -The simulated and theoretical measurement probabilities are not expected to match exactly, but should be close to each other, since measurement is probabilistic. However, the post-measurement states from the simulation should match the expected states calculated in the exercise precisely, since partial state collapse is not a probabilistic process. +The simulated and theoretical measurement probabilities aren't expected to match exactly, but should be close to each other, since measurement is probabilistic. However, the post-measurement states from the simulation should match the expected states calculated in the exercise precisely, since partial state collapse isn't a probabilistic process. @[example]({ "id": "multi_qubit_measurements__partial_measurements_demo", "codePath": "./examples/PartialMeasurementsDemo.qs" }) -In certain situations, it is possible to distinguish between orthogonal states of multi-qubit systems using partial measurements, as illustrated in the next exercise. +In certain situations, it's possible to distinguish between orthogonal states of multi-qubit systems using partial measurements, as illustrated in the next exercise. @[exercise]({ "id": "multi_qubit_measurements__partial_measurements_for_system", @@ -353,9 +354,9 @@ In certain situations, it is possible to distinguish between orthogonal states o Entanglement has an effect on the measurement statistics of the system. If two qubits are entangled, then their measurement outcomes will be correlated, while separable states (which are by definition not entangled) have uncorrelated measurement outcomes. -> It is useful to revisit the concepts of entanglement and separable states, which were introduced in the Multi-Qubit Systems kata. Consider a system of $n>1$ qubits, which we divide into two parts: A, consisting of $m$ qubits, and B, consisting of the remaining $n-m$ qubits. We say that the state $\ket \psi$ of the entire system is separable if it can be expressed as a tensor product of the states of parts A and B: +> It's useful to revisit the concepts of entanglement and separable states, which were introduced in the Multi-Qubit Systems kata. Consider a system of $n>1$ qubits, which is divided into two parts: A, consisting of $m$ qubits, and B, consisting of the remaining $n-m$ qubits. The state $\ket \psi$ of the entire system is separable if it can be expressed as a tensor product of the states of parts A and B: > $$\ket \psi = \ket {\phi_A} \otimes \ket{\phi_B}$$ -> Here $\ket{\phi_A}$ and $\ket{\phi_B}$ are wave functions that describe parts $A$ and $B$, respectively. If it is not possible to express $\ket \psi$ in such a form, then we say that system A is entangled with system B. +> Here $\ket{\phi_A}$ and $\ket{\phi_B}$ are wave functions that describe parts $A$ and $B$, respectively. If it isn't possible to express $\ket \psi$ in such a form, then system A is entangled with system B. Consider a measurement on the subsystem $A$ of a separable state. Let the measurement be done in a basis $\{ \ket{b_0},\dotsc,\ket{b_{2^m-1}}\}$. According to the projection formalism, a projection operator $P_i = \ket{b_i}\bra{b_i} \otimes \mathbb{1}$ is chosen randomly. The corresponding post-measurement state of the system is then given by @@ -378,7 +379,7 @@ Consider two two-qubit states: - The Bell state $\ket{\Phi^{+}} = \frac{1}{\sqrt{2}} \big (\ket{00} + \ket{11}\big)$. - A state $\ket \Theta = \frac{1}{2} \big( \ket{00} + \ket{01} + \ket{10} + \ket{11} \big)$. -For both states, consider a measurement on the first qubit, followed by a measurement on the second qubit, both done in the computational basis. For which state can we expect the measurement outcomes to be correlated? Verify by calculating the sequential measurement probabilities explicitly for both states. +For both states, consider a measurement on the first qubit, followed by a measurement on the second qubit, both done in the computational basis. For which state can you expect the measurement outcomes to be correlated? Verify by calculating the sequential measurement probabilities explicitly for both states.
Solution @@ -391,7 +392,7 @@ For both states, consider a measurement on the first qubit, followed by a measur ## State Modification Using Partial Measurements -For certain multi-qubit systems prepared in a superposition state, it is possible to use partial measurements to collapse a part of the system to some desired state. +For certain multi-qubit systems prepared in a superposition state, it's possible to use partial measurements to collapse a part of the system to some desired state. @[exercise]({ "id": "multi_qubit_measurements__state_modification", @@ -405,8 +406,8 @@ For certain multi-qubit systems prepared in a superposition state, it is possibl }) Any multi-qubit state can be prepared from the $\ket{0...0}$ state using an appropriate combination of quantum gates. -However, sometimes it is easier and more efficient to prepare a state using partial measurements. -You could prepare a simpler state involving additional qubits, which, when measured, result in a collapse of the remaining qubits to the desired state with a high probability. This is called **post-selection**, and is particularly useful if it is easier to prepare the pre-measurement state with the extra qubits than to prepare the desired state directly using unitary gates alone. This is demonstrated by the following exercise. +However, sometimes it's easier and more efficient to prepare a state using partial measurements. +You could prepare a simpler state involving additional qubits, which, when measured, result in a collapse of the remaining qubits to the desired state with a high probability. This is called **post-selection**, and is particularly useful if it's easier to prepare the pre-measurement state with the extra qubits than to prepare the desired state directly using unitary gates alone. This is demonstrated by the following exercise. @[exercise]({ "id": "multi_qubit_measurements__state_preparation_using_partial_measurements", @@ -431,7 +432,7 @@ $$Z = \begin{bmatrix} 1 & 0 \\ 0 & -1\end{bmatrix} = \ket{0}\bra{0} - \ket{1}\br The $Z$ operator has two eigenvalues, $1$ and $-1$, with corresponding eigenvectors $\ket{0}$ and $\ket{1}$. A $Z$-measurement is then a measurement in the $\{\ket{0},\ket{1}\}$ basis, with the measurement outcomes being $1$ and $-1$, respectively. In Q#, by convention, an eigenvalue of $1$ corresponds to a `Result` of `Zero`, while an eigenvalue of $-1$ corresponds to a `Result` of `One`. -Similarly, one can implement measurements corresponding to the Pauli X and Y operators. We summarize the various properties below: +Similarly, one can implement measurements corresponding to the Pauli X and Y operators. This table summarizes the various properties:
@@ -483,7 +484,7 @@ Joint measurements are a generalization of this principle for multi-qubit matric The simplest joint measurement is a parity measurement. A parity measurement treats computational basis vectors differently depending on whether the number of 1s in the basis vector is even or odd. -For example, the operator $Z\otimes Z$, or $ZZ$ in short, is the parity measurement operator for a two-qubit system. The eigenvalues $1$ and $-1$ correspond to the subspaces spanned by basis vectors $\{ \ket{00}, \ket{11} \}$ and $\{ \ket{01}, \ket{10} \}$, respectively. That is, when a $ZZ$ measurement results in a `Zero` (i.e., the eigenvalue $+1$), the post-measurement state is a superposition of only those computational basis vectors which have an even number of 1s. On the other hand, a result of `One` corresponds to a post-measurement state with only computational basis vectors which have an odd number of 1s. +For example, the operator $Z\otimes Z$, or $ZZ$ in short, is the parity measurement operator for a two-qubit system. The eigenvalues $1$ and $-1$ correspond to the subspaces spanned by basis vectors $\{ \ket{00}, \ket{11} \}$ and $\{ \ket{01}, \ket{10} \}$, respectively. That is, when a $ZZ$ measurement results in a `Zero` (that is, the eigenvalue $+1$), the post-measurement state is a superposition of only those computational basis vectors which have an even number of 1s. On the other hand, a result of `One` corresponds to a post-measurement state with only computational basis vectors which have an odd number of 1s. > Let's see what happens to various two-qubit states after the parity measurement. The $Z \otimes Z$ matrix for two qubits is: > @@ -497,7 +498,7 @@ Z \otimes Z = \end{bmatrix} $$ > ->When this transformation is applied to a basis state $\ket{00}$, we get +>When this transformation is applied to a basis state $\ket{00}$, you get > >$$ \begin{bmatrix} @@ -512,11 +513,11 @@ $$ > >Comparing this to the characteristic equation for eigenvectors of $Z \otimes Z$ given by $ Z \otimes Z \ket{\psi} = \lambda \ket{\psi}$, -it is easy to see that $\ket{00}$ belongs to the $+1$ eigenspace, hence the $Z \otimes Z$ measurement will return `Zero` and leave the state unchanged. +it's easy to see that $\ket{00}$ belongs to the $+1$ eigenspace, hence the $Z \otimes Z$ measurement will return `Zero` and leave the state unchanged. > >Similarly, it can easily be verified that $\ket{11}$ also belongs to $+1$ eigenspace, while $\ket{01}$ and $\ket{10}$ belong to the $-1$ eigenspace. > ->Now, what happens if we apply a $Z \otimes Z$ measurement to a superposition state $\alpha \ket{00} + \beta \ket{11}$? We can see that +>Now, what happens if you apply a $Z \otimes Z$ measurement to a superposition state $\alpha \ket{00} + \beta \ket{11}$? You can see that > >$$ \begin{bmatrix} @@ -529,7 +530,7 @@ it is easy to see that $\ket{00}$ belongs to the $+1$ eigenspace, hence the $Z \ \begin{bmatrix} \alpha \\ 0 \\ 0 \\ \beta \end{bmatrix} $$ > ->So this state also belongs to the $+1$ eigenspace, and measuring it will return `Zero` and leave the state unchanged. Similarly, we can verify that an $\alpha \ket{01} + \beta \ket{10}$ state belongs to the $-1$ eigenspace, and measuring it will return `One` without changing the state. +>So this state also belongs to the $+1$ eigenspace, and measuring it will return `Zero` and leave the state unchanged. Similarly, you can verify that an $\alpha \ket{01} + \beta \ket{10}$ state belongs to the $-1$ eigenspace, and measuring it will return `One` without changing the state. Similarly, a parity measurement on a higher number of qubits can be implemented using a $Z \otimes \dotsc \otimes Z$ measurement. @@ -545,7 +546,7 @@ Similarly, a parity measurement on a higher number of qubits can be implemented }) Joint measurement is a generalization of the measurement in the computational basis. -Pauli measurements can also be generalized to a larger number of qubits. A multi-qubit Pauli measurement corresponds to an operator $M_1 \otimes \dotsc \otimes M_n$, with each $M_i$ being from the set of gates $\{X,Y,Z,I\}$. If at least one of the operators is not the identity matrix, then the measurement can result in two outcomes: a `Result` of `Zero` corresponding to eigenvalue $+1$ and a `Result` of `One` corresponding to the eigenvalue $-1$. The corresponding projection operators are the projections onto the corresponding eigenspaces. +Pauli measurements can also be generalized to a larger number of qubits. A multi-qubit Pauli measurement corresponds to an operator $M_1 \otimes \dotsc \otimes M_n$, with each $M_i$ being from the set of gates $\{X,Y,Z,I\}$. If at least one of the operators isn't the identity matrix, then the measurement can result in two outcomes: a `Result` of `Zero` corresponding to eigenvalue $+1$ and a `Result` of `One` corresponding to the eigenvalue $-1$. The corresponding projection operators are the projections onto the corresponding eigenspaces. For example, a Pauli/joint measurement corresponding to the $X\otimes Z$ operator can be characterized as follows:
Pauli Operator
@@ -581,7 +582,7 @@ What are the possible outcomes and their associated probabilities, if a measurem
Solution -The first step towards identifying the outcomes and their probabilities for joint measurements is to identify the eigenvectors corresponding to eigenvalues $\pm1$ of the Pauli operator. We note that since $X\ket{\pm}= \pm\ket{\pm}$, we have +The first step towards identifying the outcomes and their probabilities for joint measurements is to identify the eigenvectors corresponding to eigenvalues $\pm1$ of the Pauli operator. Note that since $X\ket{\pm}= \pm\ket{\pm}$, you have $$XX \ket{++} = \ket{++}$$ $$XX \ket{--} = \ket{--}$$ @@ -590,17 +591,17 @@ $$XX \ket{-+} = -\ket{-+}$$ Thus, the $XX$ operator measures the parity in the Hadamard, or the $\ket{\pm}$ basis. That is, it distinguishes basis states with an even number of $+$'s from basis states which have an odd number of $+$'s. -The projector corresponding to a result of `Zero` is given by $P_{+1} = \ket{++}\bra{++} + \ket{--}\bra{--}$, while the projector corresponding to a result of `One` is given by $P_{-1} = \ket{+-}\bra{+-} + \ket{-+}\bra{-+}$. Then, we note that $P_{+1}$ annihilates states with odd parity, while leaving states with even parity unaffected. That is, for any values of the constants +The projector corresponding to a result of `Zero` is given by $P_{+1} = \ket{++}\bra{++} + \ket{--}\bra{--}$, while the projector corresponding to a result of `One` is given by $P_{-1} = \ket{+-}\bra{+-} + \ket{-+}\bra{-+}$. Then, note that $P_{+1}$ annihilates states with odd parity, while leaving states with even parity unaffected. That is, for any values of the constants $$P_{+1} ( \gamma \ket{++} + \delta \ket{--} ) = ( \gamma \ket{++} + \delta \ket{--} )$$ $$P_{+1} ( \mu \ket{-+} + \nu \ket{+-} ) = 0$$ Similarly, $P_{-1}$ annihilates states with even parity, while leaving states with odd parity unaffected. -Now we express the given state in the Hadamard basis. We note that it is possible to go from the computational basis to the Hadamard basis using the following relations: +Now you express the given state in the Hadamard basis. Note that it's possible to go from the computational basis to the Hadamard basis using the following relations: $$\ket{0} = \frac{1}{\sqrt{2}} \left( \ket{+} + \ket{-} \right)$$ $$\ket{1} = \frac{1}{\sqrt{2}} \left( \ket{+} - \ket{-} \right)$$ -Using these, we obtain +Using these, you obtain $$ \alpha \ket{00} + \beta \ket{01} + \beta \ket{10} + \alpha \ket{11} = (\alpha + \beta) \ket{++} + (\alpha - \beta) \ket{--}$$ Thus, this state has an even parity in the Hadamard basis. It follows that an $XX$ Pauli measurement will result in the outcome `Zero` with probability 1, leaving the state unchanged after the measurement.
@@ -616,4 +617,4 @@ Congratulations! In this kata you learned how to apply measurements on multi-qub - Partial measurements: you measure $m$ qubits out of $n$, for $m< n$ ($2^m$ possible outcomes). - Joint measurement: Pauli measurement of all $n$ qubits ($2$ possible outcomes). -Next, you will implement a quantum algorithm to generate random numbers in "Quantum Random Number Generation" kata. +Next, you'll implement a quantum algorithm to generate random numbers in "Quantum Random Number Generation" kata. diff --git a/katas/content/multi_qubit_measurements/joint_measurements/solution.md b/katas/content/multi_qubit_measurements/joint_measurements/solution.md index 7cbd15af48..bef55dc02b 100644 --- a/katas/content/multi_qubit_measurements/joint_measurements/solution.md +++ b/katas/content/multi_qubit_measurements/joint_measurements/solution.md @@ -1,11 +1,11 @@ -If we were not asked to maintain the state of the qubits, one approach would be to measure both the qubits separately in the computational basis, and check if the result is the same for both the measurements. If the measurement results are equal, the input state must have been a superposition of $\ket{00}$ and $\ket{11}$, while different measurement outcomes will imply that the input state must have been a superposition of $\ket{01}$ and $\ket{10}$. However, in these measurements we will lose the information about the original superposition states: a state $\alpha \ket{00} + \beta \ket{11}$ will collapse to either $\ket{00}$ or $\ket{11}$, and we won't be able to recover the information about the coefficients $\alpha$ and $\beta$. +If you weren't asked to maintain the state of the qubits, one approach would be to measure both the qubits separately in the computational basis, and check if the result is the same for both the measurements. If the measurement results are equal, the input state must have been a superposition of $\ket{00}$ and $\ket{11}$, while different measurement outcomes will imply that the input state must have been a superposition of $\ket{01}$ and $\ket{10}$. However, in these measurements you'll lose the information about the original superposition states: a state $\alpha \ket{00} + \beta \ket{11}$ will collapse to either $\ket{00}$ or $\ket{11}$, and you won't be able to recover the information about the coefficients $\alpha$ and $\beta$. -We need to measure the *parity* of the state without collapsing it all the way to the basis states. Pauli measurements can be used for joint measurements involving multiple qubits. For this task we need to do the $Z \otimes Z$ measurement on both qubits. +You need to measure the *parity* of the state without collapsing it all the way to the basis states. Pauli measurements can be used for joint measurements involving multiple qubits. For this task we need to do the $Z \otimes Z$ measurement on both qubits. A joint measurement using $Z \otimes Z$ operator can be thought of as projecting the measured state to one of the two eigenspaces of $Z \otimes Z$ with $+1$ and $-1$ as the corresponding eigenvalues. The measurement returns `Zero` if the measured state is projected to the space with an eigenvalue of $+1$, and a result of `One` if projected to the space with an eigenvalue of $-1$. -As we've seen in the tutorial, the state $\alpha \ket{00} + \beta \ket{11}$ is an eigenstate of the $Z \otimes Z$ operator with the eigenvalue $+1$, and the state $\alpha \ket{01} + \beta \ket{10}$ is an eigenstate with the eigenvalue $-1$. -Hence, we can use this joint measurement to recognize which of the superposition states we were given while preserving the initial superposition state. +As you've seen in the tutorial, the state $\alpha \ket{00} + \beta \ket{11}$ is an eigenstate of the $Z \otimes Z$ operator with the eigenvalue $+1$, and the state $\alpha \ket{01} + \beta \ket{10}$ is an eigenstate with the eigenvalue $-1$. +Hence, you can use this joint measurement to recognize which of the superposition states you were given while preserving the initial superposition state. In Q#, the operation `Measure` can be used to measure multiple qubits using an array of `Pauli` constants (`PauliI`, `PauliX`, `PauliY`, or `PauliZ`) that define the basis for measurement. diff --git a/katas/content/multi_qubit_measurements/partial_measurements_for_system/solution.md b/katas/content/multi_qubit_measurements/partial_measurements_for_system/solution.md index 7bc7b86ca4..8d6f86abaf 100644 --- a/katas/content/multi_qubit_measurements/partial_measurements_for_system/solution.md +++ b/katas/content/multi_qubit_measurements/partial_measurements_for_system/solution.md @@ -1,4 +1,4 @@ -Since the state of the first qubit is different in these states ($\ket +$ and $\ket -$, respectively), it is sufficient to measure only the first qubit in the Pauli X basis in order to distinguish the two states. Furthermore, this measurement will not change the state of the system, since the post-projection state is identical to the original state regardless of the input state. +Since the state of the first qubit is different in these states ($\ket +$ and $\ket -$, respectively), it's sufficient to measure only the first qubit in the Pauli X basis in order to distinguish the two states. Furthermore, this measurement won't change the state of the system, since the post-projection state is identical to the original state regardless of the input state. @[solution]({ "id": "multi_qubit_measurements__partial_measurements_for_system_solution", diff --git a/katas/content/multi_qubit_measurements/state_modification/index.md b/katas/content/multi_qubit_measurements/state_modification/index.md index 3d860b91e9..b35ef6d9dd 100644 --- a/katas/content/multi_qubit_measurements/state_modification/index.md +++ b/katas/content/multi_qubit_measurements/state_modification/index.md @@ -10,4 +10,4 @@ where the constants $a$ and $b$ satisfying $|a|^2 + |b|^2 = 1$ are unknown. - If $ind$ equals 0, convert the state of the second qubit into $a\ket{0} + b\ket{1}$ - If $ind$ equals 1, convert the state of the second qubit into $b\ket{0} + a\ket{1}$. -The state of the first qubit at the end does not matter (it has to be not entangled with the second qubit). +The state of the first qubit at the end doesn't matter (it has to be not entangled with the second qubit). diff --git a/katas/content/multi_qubit_measurements/state_modification/solution.md b/katas/content/multi_qubit_measurements/state_modification/solution.md index a988be882b..bdd5680c1f 100644 --- a/katas/content/multi_qubit_measurements/state_modification/solution.md +++ b/katas/content/multi_qubit_measurements/state_modification/solution.md @@ -1,6 +1,6 @@ -We note that if we measure the first qubit in the computational basis, then an outcome of $0$ collapses the second qubit to the state $a\ket 0 + b \ket 1$, while an outcome of $1$ collapses the second qubit to the state $b\ket 0 + a \ket 1$. +Note that if you measure the first qubit in the computational basis, then an outcome of $0$ collapses the second qubit to the state $a\ket 0 + b \ket 1$, while an outcome of $1$ collapses the second qubit to the state $b\ket 0 + a \ket 1$. -Thus, if $ind=0$ and we measure $0$ or if $ind=1$ and we measure $1$, then after the measurement the second qubit will be in the desired state. On the other hand, if $ind=1$ and we measure $0$, or if $ind=0$ and we measure $1$, then the state of the second qubit after the measurement is not what we're looking for, but we can adjust it using the Pauli X gate. +Thus, if $ind=0$ and you measure $0$ or if $ind=1$ and we measure $1$, then after the measurement the second qubit will be in the desired state. On the other hand, if $ind=1$ and you measure $0$, or if $ind=0$ and you measure $1$, then the state of the second qubit after the measurement isn't what you're looking for, but you can adjust it using the Pauli X gate. @[solution]({ "id": "multi_qubit_measurements__state_modification_solution", diff --git a/katas/content/multi_qubit_measurements/state_preparation/index.md b/katas/content/multi_qubit_measurements/state_preparation/index.md index 588cf667e8..51b9e09644 100644 --- a/katas/content/multi_qubit_measurements/state_preparation/index.md +++ b/katas/content/multi_qubit_measurements/state_preparation/index.md @@ -6,5 +6,5 @@
Need a hint? Consider a 3-qubit state $\frac{1}{2}(\ket{00} + \ket{01} + \ket{11}) \otimes \ket{0} + \frac{1}{2} \ket{11} \otimes \ket{1}$. - What happens when one measures the third qubit? + What happens when you measure the third qubit?
diff --git a/katas/content/multi_qubit_measurements/state_preparation/solution.md b/katas/content/multi_qubit_measurements/state_preparation/solution.md index 0e1afc10d4..9bf6788c09 100644 --- a/katas/content/multi_qubit_measurements/state_preparation/solution.md +++ b/katas/content/multi_qubit_measurements/state_preparation/solution.md @@ -1,26 +1,26 @@ -While it is possible to prepare the state $\ket \psi$ directly using unitary rotations, it is simpler to use post-selection for preparing it. +While it's possible to prepare the state $\ket \psi$ directly using unitary rotations, it's simpler to use post-selection for preparing it. -Initially we will prepare an equal superposition of all basis states on the first two qubits by applying the **H** gate to each of them, and allocate an extra qubit in the $\ket{0}$ state: +Initially, you prepare an equal superposition of all basis states on the first two qubits by applying the $H$ gate to each of them, and allocate an extra qubit in the $\ket{0}$ state: $$\frac{1}{2} \big(\ket{00} + \ket{01} + \ket{10} + \ket{11}\big) \otimes \ket 0$$ -The state of the first two qubits is a superposition of the state we want to prepare and the $\ket{11}$ state that we would like to discard. +The state of the first two qubits is a superposition of the state you want to prepare and the $\ket{11}$ state that you want to discard. -Now, we want to separate the first three basis states from the last one and to store this separation in the extra qubit. -For example, we can keep the state of the extra qubit $\ket{0}$ for the basis states that we want to keep, and switch it to $\ket{1}$ for the basis states that we would like to discard. +Now, you want to separate the first three basis states from the last one and to store this separation in the extra qubit. +For example, you can keep the state of the extra qubit $\ket{0}$ for the basis states that you want to keep, and switch it to $\ket{1}$ for the basis states that you want to discard. A $CCNOT$ gate can do this, with the first two qubits used as control qubits and the extra qubit as target. -When the gate is applied, the state of the extra qubit will only change to $\ket{1}$ if both control qubits are in the $\ket{11}$ state, which marks exactly the state that we want to discard: +When the gate is applied, the state of the extra qubit will only change to $\ket{1}$ if both control qubits are in the $\ket{11}$ state, which marks exactly the state that you want to discard: $$CCNOT\frac{1}{2} \big(\ket{00\textbf{0}} + \ket{01\textbf{0}} + \ket{10\textbf{0}} + \ket{11\textbf{0}}\big) = \frac{1}{2}\big(\ket{00} + \ket{01} + \ket{10} \big) \otimes \ket{\textbf{0}} + \frac{1}{2}\ket{11} \otimes \ket{\textbf{1}} $$ -Finally, we measure just the extra qubit; this causes a partial collapse of the system to the state defined by the measurement result: -* If the result is $\ket{0}$, the first two qubits collapse to a state that is a linear combination of basis states which had the extra qubit in state $\ket{0}$, i.e., they end up in the target state $\frac{1}{\sqrt3}\big(\ket{00} + \ket{01} + \ket{10}\big)$. -* If the result is $\ket{1}$, the first two qubits collapse to a state $\ket{11}$, so our goal is not achieved. The good thing is, this only happens in 25% of the cases, and we can just reset our qubits to the $\ket{00}$ state and try again. +Finally, you measure just the extra qubit; this causes a partial collapse of the system to the state defined by the measurement result: +* If the result is $\ket{0}$, the first two qubits collapse to a state that is a linear combination of basis states which had the extra qubit in state $\ket{0}$, that is, they end up in the target state $\frac{1}{\sqrt3}\big(\ket{00} + \ket{01} + \ket{10}\big)$. +* If the result is $\ket{1}$, the first two qubits collapse to a state $\ket{11}$, so your goal is not achieved. The good thing is, this only happens in 25% of the cases, and you can just reset our qubits to the $\ket{00}$ state and try again. > Q# has a built-in repeat-until-success (RUS) loop, which comes in handy in this case. -> * We will describe the main operations (applying $H$ and $CCNOT$ gates and the measurement) in the `repeat` part of the loop, which specifies its body. -> * `until` section specifies the condition which will break the loop. In this case the result of the measurement needs to be `Zero` to indicate our success. -> * Finally, the `fixup` section allows us to clean up the results of the loop body execution before trying again if the success criteria is not met. In this case we reset the first two qubits back to the $\ket{00}$ state. +> * The main operations (applying $H$ and $CCNOT$ gates and the measurement) are described in the `repeat` part of the loop, which specifies its body. +> * `until` section specifies the condition which will break the loop. In this case, the result of the measurement needs to be `Zero` to indicate your success. +> * Finally, the `fixup` section allows you to clean up the results of the loop body execution before trying again if the success criteria isn't met. In this case, you reset the first two qubits back to the $\ket{00}$ state. @[solution]({ "id": "multi_qubit_measurements__state_preparation_solution",