{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Measurements for single-qubit systems\n", "\n", "This tutorial introduces you to measurements done on single-qubit systems. The concept of a measurement is a central part of quantum mechanics, as well as quantum algorithms. Single-qubit measurements, as their name implies are measurements on single qubits. The outcomes of a measurement in quantum mechanics are probabilistic, and in general, change the state of the qubit depending on the outcome of the measurement. \n", "\n", "We recommend to go through the [tutorial that introduces single-qubit gates](../SingleQubitGates/SingleQubitGates.ipynb) before starting this one.\n", "\n", "This tutorial covers the following topics:\n", "\n", "* Computational basis measurements\n", "* Pauli basis measurements\n", "* Measurements in arbitrary orthogonal bases\n", "* Representing measurements as projector operators\n", "$\\renewcommand{\\ket}[1]{\\left\\lvert#1\\right\\rangle}$\n", "$\\renewcommand{\\bra}[1]{\\left\\langle#1\\right\\rvert}$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Computational basis measurements\n", "In this section, we will discuss the simplest type of qubit measurements - measurements in the computational basis. (This is the \"default\" type of measurements - unless otherwise specified, \"measurement\" refers to this type.)\n", "\n", "The state $\\ket{\\psi}$ of a single qubit can always be expressed in [Dirac notation](../Qubit/Qubit.ipynb#Dirac-Notation) as \n", "$$\\ket{\\psi} = \\alpha \\ket{0} + \\beta \\ket{1},$$\n", "where $\\alpha$ and $\\beta$ are complex numbers, and the state is normalized, i.e., $|\\alpha|^2 + |\\beta|^2 = 1$. \n", "\n", "We can examine the qubit to get some information about its state - *measure* its state. Similar to the classical case of examining a bit, the outcome of a measurement can be $0$ or $1$. But, unlike the classical case, quantum measurement is a probabilistic process. \n", "The probabilities of the measurement outcomes being $0$ and $1$ are $|\\alpha|^2$ and $|\\beta|^2$, respectively. Additionally, the state of the qubit is modified by the measurement: if the outcome of the measurement is $0$, then the post-measurement state of the qubit is $\\ket{0}$, and if the outcome is $1$, the state is $\\ket{1}$. In quantum mechanics, this is referred to as the [collapse of the wave function](https://en.wikipedia.org/wiki/Wave_function_collapse).\n", "\n", "Computational basis measurement outcomes and their probabilities are summarized in the table below:\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Measurement outcomeProbability of outcomeState after measurement
$0$$|\\alpha|^2$$\\ket 0$
$1$$|\\beta|^2$$\\ket 1$
\n", "\n", "> Unlike quantum gates which are unitary and reversible operations, measurements are neither unitary nor reversible. Since the outcomes of a measurement are probabilistic, any two isolated qubits which are initially prepared in identical superposition states are in general not guaranteed to have the same measurement outcomes after each qubit has been measured separately. As we will see below, measurements are modeled by projection operators instead of unitary operators.\n", ">\n", "> Additionally, the assumption of the wave function being **normalized** is important, since the probability outcomes must sum up to $1$. If the wave function is not normalized, it is important to normalize it first in order to obtain the correct measurement probabilities." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 1: The probability outcomes for a specific state\n", "\n", "The qubit is in the following state:\n", "$$\\ket \\psi = 0.6 \\ket 0 + 0.8 \\ket 1 \\equiv \\begin{bmatrix} 0.6 \\\\ 0.8\\end{bmatrix}.$$\n", "\n", "If this qubit is measured in the computational basis, what are the outcome probabilities?\n", "\n", "*Can't come up with a solution? See the explained solution in the [Single-Qubit System Measurements Workbook](./Workbook_SingleQubitSystemMeasurements.ipynb#Exercise-1:-The-probability-outcomes-for-a-specific-state).*\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Demo: Implementing measurement in Q# using the M operation\n", "\n", "In this demo, we prepare a qubit in the state we've seen in Exercise 1, and then measure it in the computational basis. In Q#, single-qubit measurements in the computational basis can be implemented using the [M operation](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic.m). It will return the constant `Zero` if measurement result was $0$ or the constant `One` if the measurement result was $1$. `Zero` and `One` are constants of type `Result`.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "// Run this cell using Ctrl+Enter (⌘+Enter on Mac)\n", "// Run the next cell to see the output\n", "\n", "open Microsoft.Quantum.Diagnostics;\n", "open Microsoft.Quantum.Math;\n", "\n", "operation SimpleMeasurementDemo () : Unit {\n", " use q = Qubit();\n", " // Prepare the qubit in the superposition state\n", " // |𝜓❭ = 0.6 |0❭ + 0.8 |1❭\n", " Ry(2.0 * ArcTan2(0.8, 0.6), q);\n", "\n", " Message(\"Qubit in state |𝜓❭:\");\n", " DumpMachine();\n", "\n", " Message(\"Measuring the qubit...\");\n", " let outcome = (M(q) == One ? 1 | 0);\n", "\n", " Message($\"The measurement outcome is {outcome}.\");\n", " Message(\"Post-measurement state of the qubit:\");\n", " DumpMachine();\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%simulate SimpleMeasurementDemo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> If you run the cell above multiple times, you will notice that whenever the measurement outcome is $1$, the post-measurement state of the qubit is $\\ket 1$, and similarly for $0$. This is in line with our expectation that after the measurement the wave function 'collapses' to the corresponding state." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Demo: Measurement statistics\n", "\n", "The following cell contains code demonstrating that the theoretical and experimental values of the probability outcomes indeed match with each other. We repeatedly prepare the same state $\\ket \\psi = 0.6 \\ket 0 + 0.8 \\ket 1$ and measure it in the computational basis $100$ times. At the end, we expect $0$ to be measured approximately $36$ times, and $1$ to be measured approximately $64$ times. Note that since measurements are probabilistic, we do not expect the results to match these values exactly." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "open Microsoft.Quantum.Diagnostics;\n", "open Microsoft.Quantum.Math;\n", "\n", "operation MeasumentStatisticsDemo () : Unit {\n", " mutable countZero = 0;\n", " let numRuns = 100;\n", " use q = Qubit();\n", " for i in 1 .. numRuns {\n", " // Prepare the qubit in the superposition state\n", " // |𝜓❭ = 0.6 |0❭ + 0.8 |1❭\n", " Ry(2.0 * ArcTan2(0.8, 0.6), q);\n", "\n", " // Measure in the computational basis, and update the counts according to the outcomes\n", " if M(q) == Zero {\n", " set countZero += 1;\n", " } \n", " // Reset the qubit for use in the next iteration\n", " Reset(q);\n", " }\n", " let countOne = numRuns - countZero;\n", " \n", " Message($\"Simulated probability of measuring 0 is 0.{countZero}.\");\n", " Message($\"Theoretical probability of measuring 0 is 0.36.\");\n", " \n", " Message($\"Simulated probability of measuring 1 is 0.{countOne}.\");\n", " Message($\"Theoretical probability of measuring 0 is 0.64.\");\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%simulate MeasumentStatisticsDemo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Measurements can be used to distinguish orthogonal states. We start with an exercise for distinguishing between the computational basis states, and discuss the general case of arbitrary basis measurements later in the tutorial.\n", "\n", "### Exercise 2: Distinguish $|0\\rangle$ and $|1\\rangle$\n", "\n", "**Input:** A qubit which is guaranteed to be in either the $|0\\rangle$ or the $|1\\rangle$ state.\n", "\n", "**Output:** `true` if the qubit was in the $|0\\rangle$ state, or `false` if it was in the $|1\\rangle$ state. The state of the qubit at the end of the operation does not matter." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%kata T2_IsQubitZero\n", "\n", "operation IsQubitZero (q : Qubit) : Bool {\n", " // The operation M will measure a qubit in the computational basis (|0⟩ and |1⟩ basis)\n", " // and return Zero if the observed state was |0⟩ or One if the state was |1⟩.\n", " // Measuring a basis state will yield the result matching that state deterministically.\n", " // To answer the question, you need to perform the measurement and check whether the result\n", " // equals One - either directly or using library function IsResultOne.\n", " //\n", " // Type the following: return M(q) == Zero;\n", " // Then run the cell using Ctrl+Enter (⌘+Enter on macOS).\n", "\n", " // ...\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Can't come up with a solution? See the explained solution in the [Single-Qubit System Measurements Workbook](./Workbook_SingleQubitSystemMeasurements.ipynb#Exercise-2:-Distinguish-$|0\\rangle$-and-$|1\\rangle$).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Measurements in the Pauli bases\n", "So far, we have discussed measurements done in the computational basis, i.e., the $\\{ \\ket 0, \\ket 1\\}$ basis. \n", "\n", "It is also possible to implement measurements in other orthogonal bases, such as the [Pauli X basis](../SingleQubitGates/SingleQubitGates.ipynb#Pauli-Gates), which consists of the two vectors $\\ket + = \\frac1{\\sqrt2} \\big(\\ket 0 +\\ket 1\\big)$, and $\\ket - = \\frac1{\\sqrt2} \\big(\\ket 0 -\\ket 1\\big)$. Q# has a built-in operation [Measure](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic.measure) for measurements in the Pauli bases. \n", "\n", "> The `Measure` operation can be used for measuring multiple qubits in a multi-qubit system; however, in this tutorial we only consider measurements for single-qubit systems.\n", "\n", "The eigenvalues of a Pauli matrix are $\\pm 1$, with one eigenvector corresponding to each eigenvalue. For any chosen Pauli basis, the `Measure` operation returns `Zero` if the measurement outcome corresponds to the eigenvalue $+1$, and returns `One` if the measurement outcome corresponds to the eigenvalue $-1$. As in the case of the computational basis measurements, the wave function of the qubit collapses to the corresponding state after the measurement is executed. \n", "\n", "The probabilities of the outcomes are defined using a similar rule: to measure a state $\\ket \\psi$ in a Pauli basis $\\{ \\ket {b_0}, \\ket {b_1}\\}$, we represent it as a linear combination of the basis vectors\n", "$$\\ket \\psi = c_0 \\ket {b_0} + c_1 \\ket {b_1}$$\n", "\n", "The probabilities of outcomes $0$ and $1$ will be defined as $|c_0|^2$ and $|c_1|^2$, respectively.\n", "\n", "> Computational basis measurement is often referred to as measurement in Pauli Z basis. Indeed, the eigenvectors of the Z gate are $\\ket 0$ and $\\ket 1$, with eigenvalues $+1$ and $-1$, respectively." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 3: Distinguish $|+\\rangle$ and $|-\\rangle$ using the `Measure` operation\n", "\n", "**Input**: A qubit which is guaranteed to be in either the $\\ket +$ state, or the $\\ket -$ state.\n", "\n", "**Output**: `true` if the qubit is in the $\\ket -$ state, or `false` if it was in the $\\ket +$ state. \n", "\n", "> To perform a single-qubit measurement in a certain Pauli basis using the `Measure` operation, \n", "> you need to pass it two parameters: first, an array of one `Pauli` constant (`PauliX`, `PauliY` or `PauliZ`), and second, an array of one qubit you want to measure." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%kata T3_IsQubitMinus\n", "\n", "operation IsQubitMinus (q : Qubit) : Bool {\n", " // ...\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Can't come up with a solution? See the explained solution in the [Single-Qubit System Measurements Workbook](./Workbook_SingleQubitSystemMeasurements.ipynb#Exercise-3:-Distinguish-$|+\\rangle$-and-$|-\\rangle$-using-the-Measure-operation).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Measurements in arbitrary orthogonal bases\n", "It is possible to measure a qubit in orthogonal bases other than the Pauli bases. Suppose one wants to measure a qubit in an orthonormal basis $\\ket {b_0}$ and $\\ket {b_1}$. Let the state of the qubit be represented by the normalized vector $\\ket \\psi$. Then, one can always express the state in terms of the basis vectors $\\ket{b_0}$ and $\\ket{b_1}$, i.e., there exist complex numbers $c_0, c_1$, such that \n", "$$\n", "\\ket \\psi = c_0 \\ket {b_0} + c_1 \\ket {b_1}.\n", "$$\n", "The rule for obtaining the probabilities of measurement outcomes is exactly the same as that for the computation basis measurement. For a measurement in a $\\{ b_0, b_1\\}$ basis we get\n", "- Outcome $b_0$ with probability $|c_0|^2$, and the post-measurement state of the qubit $\\ket {b_0}$;\n", "- Outcome $b_1$ with probability $|c_1|^2$, and the post-measurement state of the qubit $\\ket {b_1}$.\n", "\n", "This can be summarized in the following table:\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Measurement outcomeProbability of outcomeState after measurement
$b_0$$|c_0|^2$$\\ket{b_0}$
$b_1$$|c_1|^2$$\\ket{b_1}$
\n", "\n", "As before, the assumption of $\\ket \\psi$ being normalized is important, since it guarantees that the two probabilities add to $1$.\n", "\n", "> As you may recall, a [global phase](../Qubit/Qubit.ipynb#Relative-and-Global-Phase) is said to be hidden or unobservable. \n", "This is explained by the fact that global phases have no impact on quantum measurements. For example, consider two isolated qubits which are in (normalized) states $\\ket \\psi$ and $e^{i\\theta}\\ket \\psi$. \n", "If both are measured in an orthogonal basis $\\{ \\ket{b_0},\\ket{b_1}\\}$, the probabilities of measuring $b_0$ or $b_1$ are identical in both cases, since $|\\bra{b_i}\\ket{\\psi}|^2 = |\\bra{b_i}e^{i\\theta}\\ket{\\psi}|^2 $. \n", "Similarly, for either qubit, if $b_i$ is the measurement outcome, the post-measurement state of the qubit is $\\ket{b_i}$ for both qubits. Hence, the measurements are independent of the global phase $\\theta$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> ### Measurements as projection operations\n", "Quantum measurements are modeled by orthogonal projection operators. An orthogonal projection operator is a matrix $P$ which satisfies the following property:\n", "$$\n", "P^2 = P^\\dagger = P.\n", "$$\n", "(As usual, the $\\dagger$ symbol denotes conjugate transposition.) \n", ">\n", "> Using the [ket-bra representation](../SingleQubitGates/SingleQubitGates.ipynb#Ket-bra-Representation), one can represent a projection matrix in the Dirac notation.\n", "For example, one may construct a projector onto the $\\ket{0}$ subspace as:\n", "$$\n", "P = \\ket 0 \\bra 0 \\equiv \\begin{bmatrix} 1 & 0 \\\\ 0 & 0\\end{bmatrix}.\n", "$$\n", ">\n", ">A measurement in an orthogonal basis $\\{ \\ket{b_0}, \\ket{b_1}\\}$ is described by a pair of projectors $P_0 = \\ket{b_0}\\bra{b_0}$ and $P_1 = \\ket{b_1}\\bra{b_1}$. Since $\\ket{b_0}$ and $\\ket{b_1}$ are orthogonal, their projectors are also orthogonal, i.e., $P_0 P_1 = P_1 P_0 = 0$. The rules for measurements in this basis can then be summarized as follows: \n", "- Measuring a qubit in a state $\\ket \\psi$ is done by picking one of these projection operators at random.\n", "- Projection $P_0$ is chosen with probability $|P_0 \\ket{\\psi}|^2$, and the projector $P_1$ is chosen with probability $|P_1\\ket{\\psi}|^2$.\n", "- If projector $P_0$ is chosen, the post-measurement state of the qubit is given by\n", "$$\n", "\\frac1{|P_0 \\ket{\\psi}|}P_0 \\ket\\psi,\n", "$$\n", "and similarly for $P_1$.\n", ">\n", ">Although this formalism looks different from the previous sections, it is in fact equivalent. If $\\ket \\psi = c_0 \\ket{b_0} + c_1 \\ket{b_1}$, we have \n", "$$\n", "P_0 \\ket \\psi = c_0 \\ket{b_0}, \\text{so that } | P_0\\ket \\psi| = c_0,\n", "$$\n", "and similarly, \n", "$$\n", "P_1 \\ket \\psi = c_1 \\ket{b_1}, \\text{so that } |P_1\\ket \\psi| = c_1.\n", "$$\n", ">\n", ">Thus, as before, the probability of measuring $b_0$ is $|P_0\\ket\\psi|^2 = |c_0|^2$, and the probability of measuring $b_1$ is $|P_1\\ket\\psi|^2 = |c_1|^2$. Similarly, one can verify that the post-measurement outcomes are also $\\ket{b_0}$ and $\\ket{b_1}$ respectively (up to unobservable global phases).\n", ">\n", ">Although the projector formalism for single-qubit systems may seem superfluous, its importance will become clear later, while considering measurements for multi-qubit systems." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Arbitrary basis measurements implementation\n", "In the previous section, we discussed measurements in Pauli bases using the built-in `Measure` operation. We will now show that using just unitary rotation matrices and computation basis measurements it is always possible to measure a qubit in any orthogonal basis. \n", "\n", "Consider a state $ \\ket \\psi = c_0 \\ket {b_0} + c_1 \\ket {b_1} $ which we would like to measure in an orthonormal basis $\\{ \\ket{b_0}, \\ket{b_1}\\}$. First, we construct the following unitary matrix:\n", "$$\n", "U = \\ket{0} \\bra{b_0} + \\ket{1} \\bra{b_1}\n", "$$\n", "\n", "The conjugate transpose of this unitary is the operator \n", "$$\n", "U^\\dagger = \\ket{b_0} \\bra{0} + \\ket{b_1} \\bra{1}\n", "$$\n", "\n", "(One may verify that $U$ is indeed a unitary matrix, by checking that $U^\\dagger U = U U^\\dagger = I$.)\n", "\n", "Note that the effect of these matrices on the two bases is the following:\n", "\\begin{align}\n", "U\\ket{b_0} &= \\ket{0}; & U\\ket{b_1} &= \\ket{1}\\\\\n", "U^\\dagger \\ket{0} &= \\ket{b_0}; & U^\\dagger \\ket 1 &= \\ket{b_1}.\n", "\\end{align}\n", "\n", "In order to implement a measurement in the $\\{ \\ket{b_0}, \\ket{b_1}\\}$ basis, we do the following:\n", "\n", "1. Apply $U$ to $\\ket \\psi$. \n", " The resulting state is $U\\ket \\psi = c_0 \\ket 0 + c_1 \\ket 1 $.\n", "2. Measure the state $U\\ket{\\psi}$ in the computational basis. \n", " The outcomes $0$ and $1$ occur with probabilities $|c_0|^2$ and $|c_1|^2$.\n", "3. Apply $U^\\dagger$ to the post-measurement state. \n", " This transforms the states $\\ket 0$ and $\\ket 1$ to the states $\\ket{b_0}$ and $\\ket{b_1}$, respectively.\n", "\n", "Thus, $b_0$ and $b_1$ are measured with probabilities $|c_0|^2$ and $|c_1|^2$, respectively, with the end state being $\\ket{b_0}$ and $\\ket{b_1}$ - which is exactly the measurement we want to implement. \n", "\n", "This procedure can be used to distinguish arbitrary orthogonal states as well, as will become clear from the following exercises." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 4: The outcome probabilities for a measurement in a specified basis\n", "
    \n", "
  1. What are the outcome probabilities of measuring a qubit in the $\\ket{0}$ state in the Pauli X basis, i.e., the $\\{ \\ket +, \\ket -\\}$ basis?
  2. \n", "
  3. What are the outcome probabilities of measuring a qubit in the $0.6\\ket{0} + 0.8 \\ket{1}$ state in the Pauli Y basis, i.e., the $\\{ \\ket i, \\ket{-i}\\}$ basis?
  4. \n", "
\n", "\n", "*Can't come up with a solution? See the explained solution in the [Single-Qubit Measurement Tutorial Workbook](./Workbook_SingleQubitSystemMeasurements.ipynb#Exercise-4:-The-outcome-probabilities-for-a-measurement-in-a-specified-basis).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 5: Distinguishing orthogonal states - 1\n", "\n", "**Input:** A qubit which is guaranteed to be in either the $\\ket {\\psi_+}$ or the $\\ket{\\psi_-} $ state, where $\\ket {\\psi_+} = 0.6\\ket 0 + 0.8 \\ket 1 $ and $\\ket {\\psi_-} = -0.8\\ket 0 + 0.6 \\ket 1$.\n", "\n", "**Output:** `true` if the qubit was in the $\\ket {\\psi_+}$ state, or `false` if it was in the $\\ket{\\psi_-} $ state. The state of the qubit at the end of the operation does not matter.\n", "\n", "
\n", "
\n", " Need a hint? Click here\n", " A suitable $R_y$ rotation can be used to go from the computational basis $\\{ \\ket 0, \\ket 1 \\}$ to the $\\{ \\ket{\\psi_+}, \\ket{\\psi_-} \\}$ basis and vice versa. \n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%kata T5_IsQubitPsiPlus\n", "\n", "open Microsoft.Quantum.Math;\n", "\n", "operation IsQubitPsiPlus (q : Qubit) : Bool {\n", " // ...\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Can't come up with a solution? See the explained solution in the [Single-Qubit Measurement Tutorial Workbook](./Workbook_SingleQubitSystemMeasurements.ipynb#Exercise-5:-Distinguishing-orthogonal-states---1).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 6: Distinguishing orthogonal states - 2\n", "\n", "**Inputs:** \n", "\n", "1. Angle $\\alpha$, in radians, represented as a `Double`.\n", "2. A qubit which is guaranteed to be in either the $|A\\rangle$ or the $|B\\rangle$ state, where $|A\\rangle = \\cos \\alpha |0\\rangle - i \\sin \\alpha |1\\rangle$ and $|B\\rangle = - i \\sin \\alpha |0\\rangle + \\cos \\alpha |1\\rangle$.\n", "\n", "**Output:** `true` if the qubit was in the $|A\\rangle$ state, or `false` if it was in the $|B\\rangle$ state. The state of the qubit at the end of the operation does not matter.\n", "\n", "
\n", "
\n", " Need a hint? Click here\n", " An $R_x$ rotation can be used to go from the computational basis $\\{ \\ket 0, \\ket 1 \\}$ to the $\\{ \\ket{A}, \\ket{B} \\}$ basis and vice versa. \n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%kata T6_IsQubitA\n", "\n", "operation IsQubitA (alpha : Double, q : Qubit) : Bool {\n", " // ...\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Can't come up with a solution? See the explained solution in the [Single-Qubit Measurement Tutorial Workbook](./Workbook_SingleQubitSystemMeasurements.ipynb#Exercise-6:-Distinguishing-orthogonal-states---2).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 7: Measurement in the $\\ket A$, $\\ket B$ basis\n", "\n", "**Inputs:** \n", "1. Angle $\\alpha$, in radians, represented as a `Double`.\n", "1. A qubit in some unknown state.\n", "\n", "\n", "**Output:** Implement a measurement in the $\\{\\ket A$, $\\ket B\\}$ basis. Same as in the previous exercise, $|A\\rangle = \\cos \\alpha |0\\rangle - i \\sin \\alpha |1\\rangle$ and $|B\\rangle = - i \\sin \\alpha |0\\rangle + \\cos \\alpha |1\\rangle$. Return `Zero` if the measurement outcome is $A$, and `One` if the outcome is $B$. \n", "The state of the qubit after the measurement should correspond to the measurement result.\n", "\n", "
\n", "
\n", " Need a hint? Click here\n", " An $R_x$ rotation can be used to go from the computational basis $\\{ \\ket 0, \\ket 1 \\}$ to the $\\{ \\ket{A}, \\ket{B} \\}$ basis and vice versa. \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%kata T7_MeasureInABBasis\n", "\n", "operation MeasureInABBasis (alpha: Double, q : Qubit) : Result {\n", " // ...\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Can't come up with a solution? See the explained solution in the [Single-Qubit Measurement Tutorial Workbook](./Workbook_SingleQubitSystemMeasurements.ipynb#Exercise-7:-Measurement-in-the-$\\ket-A$,-$\\ket-B$-basis).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conclusion\n", "\n", "Congratulations! You have learned enough to try solving the first part of the [Measurements kata](../../Measurements/Measurements.ipynb). \n", "When you are done with that, you can continue to the next tutorial in the series to learn about [measurements for multi-qubit systems](../MultiQubitSystemMeasurements/MultiQubitSystemMeasurements.ipynb)." ] } ], "metadata": { "kernelspec": { "display_name": "Q#", "language": "qsharp", "name": "iqsharp" }, "language_info": { "file_extension": ".qs", "mimetype": "text/x-qsharp", "name": "qsharp", "version": "0.24" } }, "nbformat": 4, "nbformat_minor": 4 }