Single Qubit Programs Solutions

Quantum Gates as Matrices Solutions

Solutions for the exercises in Try Your Hand.

    1. The amplitude images/_pragprog/svg-584.png. Thus, the probability of the qubit collapsing to 0 is images/_pragprog/svg-585.png.

      The amplitude images/_pragprog/svg-586.png. So the probability of the qubit collapsing to 1 is images/_pragprog/svg-587.png

      The sum of these probabilities is images/_pragprog/svg-588.png. Since the sum is less than 1, the vector doesn’t represent a valid quantum state.

    2. The amplitude images/_pragprog/svg-589.png. Thus, the probability of the qubit collapsing to 0 is images/_pragprog/svg-590.png.

      The amplitude images/_pragprog/svg-591.png. So the probability of the qubit collapsing to 1 is images/_pragprog/svg-592.png

      The sum of these probabilities is images/_pragprog/svg-593.png. Since the sum is, for all intents and purposes, 1, the vector represents a valid quantum state.

    1. The qubelets before and after the Z gate are shown here:

      images/quantum_states_algebra/1_Z_Qubelets.png

      The Z gate inverts only the triangle images/_pragprog/svg-18.png qubelet.

    2. The left qubelet only has a triangle images/_pragprog/svg-18.png qubelet. Thus, images/_pragprog/svg-175.png. And the quantum state of the qubit before the Z gate acts on it is:

      images/_pragprog/svg-block-535.png

      After the Z gate acts on the qubit, the triangle images/_pragprog/svg-18.png qubelet is inverted. So images/_pragprog/svg-594.png. And the quantum state after the Z gate acts on it is:

      images/_pragprog/svg-block-536.png
    1. The qubelets before and after the H gate acts on the qubit is shown in the following figure:

      images/quantum_states_algebra/1_H_Qubelets.png

      The H gate splits the triangle images/_pragprog/svg-18.png qubelet into a pentagon images/_pragprog/svg-17.png qubelet and an inverted triangle images/_pragprog/svg-18.png qubelet.

    2. The left qubelet only has a triangle images/_pragprog/svg-18.png qubelet. Thus, images/_pragprog/svg-175.png. And the quantum state of the qubit before the H gate acts on it is:

      images/_pragprog/svg-block-537.png

      After the H gate acts on the qubit, the triangle images/_pragprog/svg-18.png qubelet is split into a pentagon images/_pragprog/svg-17.png qubelet and an inverted triangle images/_pragprog/svg-18.png qubelet. The amplitudes are:

      images/_pragprog/svg-block-538.png

      Wrting the amplitudes in vector form, we get:

      images/_pragprog/svg-block-539.png
      1. The operation is:

        images/_pragprog/svg-block-540.png
      2. The first column of the images/_pragprog/svg-184.png matrix is:

        images/_pragprog/svg-block-541.png
      1. The operation is:

        images/_pragprog/svg-block-542.png
      2. The complete images/_pragprog/svg-184.png matrix is:

        images/_pragprog/svg-block-543.png
      1. This qubit has two pentagon images/_pragprog/svg-17.png qubelets and one inverted triangle images/_pragprog/svg-18.png qubelet. Thus, its normalized quantum state is:

        images/_pragprog/svg-block-544.png

        The negative sign for the amplitude associated with images/_pragprog/svg-18.png indicates that the triangle qubelet is inverted.

        The vector for this quantum state is:

        images/_pragprog/svg-block-545.png

        The probabilities of the qubit collapsing to 0 and 1 are:

        images/_pragprog/svg-block-546.png
      2. When the NOT gate acts on the qubit with two pentagon images/_pragprog/svg-17.png qubelets and an inverted triangle images/_pragprog/svg-18.png qubelet, it switches the two pentagon images/_pragprog/svg-17.png qubelets to two triangle images/_pragprog/svg-18.png qubelets, and it switches the inverted triangle images/_pragprog/svg-18.png qubelet to an inverted pentagon images/_pragprog/svg-17.png qubelet, as shown in the following figure:

        images/quantum_gates_algebra/NOT_Gate_Two_Pentagons_One_Inverted_Triangle.png

        The normalized quantum state of the blended qubit on the right is:

        images/_pragprog/svg-block-547.png

        (Note the inverted pentagon images/_pragprog/svg-17.png qubelet drawn on the right of the right qubit. This placement reflects that the NOT gate switched the inverted triangle images/_pragprog/svg-18.png qubelet in the left qubit.)

        Writing this quantum state in vector form, we get:

        images/_pragprog/svg-block-548.png

        The probabilities of the qubit collapsing to 0 and 1 are:

        images/_pragprog/svg-block-549.png

        The probabilities of the qubit collapsing to 0 and 1, respectively, get switched after the NOT gate acts on the qubit. In other words, when a NOT gate acts on a blended qubit, the probabilities of collapsing to the classical states 0 or 1 are switched.

      3. To calculate the quantum state of the qubit after the NOT gate acts on it, multiply the images/_pragprog/svg-184.png matrix by the vector for the initial quantum state as follows:

        images/_pragprog/svg-block-550.png

        This quantum state is identical to the one obtained by analyzing the NOT gate operation using qubelets.

      1. The operation is:

        images/_pragprog/svg-block-551.png
      2. The first column of the images/_pragprog/svg-185.png matrix is:

        images/_pragprog/svg-block-552.png
      1. The operation is:

        images/_pragprog/svg-block-553.png
      2. The complete images/_pragprog/svg-185.png matrix is:

        images/_pragprog/svg-block-554.png
      1. This qubit has one pentagon images/_pragprog/svg-17.png qubelet and two inverted triangle images/_pragprog/svg-18.png qubelets. Thus, it’s normalized quantum state is:

        images/_pragprog/svg-block-555.png

        The negative size for the amplitude associated with images/_pragprog/svg-18.png indicates that the triangle qubelet is inverted.

        The vector for this quantum state is:

        images/_pragprog/svg-block-556.png
      2. When the Z gate acts on the qubit with one pentagon images/_pragprog/svg-17.png qubelet and two inverted triangle images/_pragprog/svg-18.png qubelets, it’ll leave the pentagon qubelet alone but will switch the triangle qubelets, as shown in the following figure:

        images/quantum_gates_algebra/Z_Gate_1_Pentagon_2_Inverted_Triangles.png

        The normalized quantum state of the blended qubit on the right is:

        images/_pragprog/svg-block-557.png

        Writing this quantum state in vector form, we get:

        images/_pragprog/svg-block-558.png
      3. To calculate the quantum state of the qubit after the Z gate acts on it, multiply the images/_pragprog/svg-185.png matrix by the vector for the initial quantum state, as follows:

        images/_pragprog/svg-block-559.png

        This quantum state is identical to the one obtained by analyzing the Z gate operation using qubelets.

Gate Matrix Restrictions Solutions

Solutions for the exercises in Try Your Hand.

    1. To determine the Hermitian matrix, first get its transpose, images/_pragprog/svg-595.png, by switching the matrix’s rows and columns:

      images/_pragprog/svg-block-560.png

      Next, replace each element with its complex conjugate:

      images/_pragprog/svg-block-561.png
    2. To check if this matrix represents a quantum gate, first calculate the product matrix, images/_pragprog/svg-218.png:

      images/_pragprog/svg-block-562.png

      To multiply these matrices, we’ll use the method described in Multiplying Matrices. According to this method, we’ll get the product matrix by working out each column of the product individually. The first column of the product matrix is:

      images/_pragprog/svg-block-563.png

      The second column of the product is:

      images/_pragprog/svg-block-564.png

      Arrange these columns to get the product:

      images/_pragprog/svg-block-565.png

      Since the product images/_pragprog/svg-218.png isn’t the identity matrix, images/_pragprog/svg-207.png isn’t a valid quantum gate matrix.

    1. To determine the Hermitian matrix, first get its transpose, images/_pragprog/svg-596.png, by switching the matrix’s rows and columns:

      images/_pragprog/svg-block-566.png

      Next, replace each element with its complex conjugate:

      images/_pragprog/svg-block-567.png

      This matrix for the images/_pragprog/svg-227.png gate is identical to the images/_pragprog/svg-240.png matrix for the images/_pragprog/svg-438.png gate.

    2. To see if this matrix represents a quantum gate, first calculate the product matrix, images/_pragprog/svg-597.png:

      images/_pragprog/svg-block-568.png

      To multiply these matrices, we’ll use the method described in Multiplying Matrices. According to this method, we’ll get the product matrix by working out each column of the product individually. The first column of the product matrix is:

      images/_pragprog/svg-block-569.png

      The second column of the product matrix is:

      images/_pragprog/svg-block-570.png

      Arrange these columns to get the product:

      images/_pragprog/svg-block-571.png

      Since the product is the identity matrix, it represents a quantum gate. In fact, the images/_pragprog/svg-227.png gate is one of the predefined gates in the IBM Quantum Computer.

    1. To determine the Hermitian matrix, first get its transpose, images/_pragprog/svg-598.png, by switching the matrix’s rows and columns:

      images/_pragprog/svg-block-572.png

      Since each element of the matrix is real, this matrix is the conjugate transpose. In other words,

      images/_pragprog/svg-block-573.png
    2. To see if this matrix represents a quantum gate, first calculate the product matrix images/_pragprog/svg-599.png:

      images/_pragprog/svg-block-574.png

      To multiply these matrices, we’ll use the method described in Multiplying Matrices. According to this method, we’ll get the product matrix by working out each column of the product individually. The first column of the product matrix is:

      images/_pragprog/svg-block-575.png

      The second column of the product matrix is:

      images/_pragprog/svg-block-576.png

      Arrange these columns to get the product:

      images/_pragprog/svg-block-577.png

      Since this product is the identity matrix, the images/_pragprog/svg-183.png matrix represents the H gate.

    1. To get the images/_pragprog/svg-232.png matrix for images/_pragprog/svg-233.png, set images/_pragprog/svg-135.png, images/_pragprog/svg-600.png, and images/_pragprog/svg-601.png:

      images/_pragprog/svg-block-578.png

      Noting that images/_pragprog/svg-602.png, images/_pragprog/svg-603.png, the above matrix simplifies to:

      images/_pragprog/svg-block-579.png

      Using Euler’s formula:

      images/_pragprog/svg-block-580.png

      And,

      images/_pragprog/svg-block-581.png

      Substituting these terms back in the matrix images/_pragprog/svg-230.png:

      images/_pragprog/svg-block-582.png
    2. To determine the Hermitian matrix, first get its transpose:

      images/_pragprog/svg-block-583.png

      Next, replace each element of the matrix with its conjugate:

      images/_pragprog/svg-block-584.png
    3. To check if the images/_pragprog/svg-232.png matrix is unitary, first calculate the product matrix images/_pragprog/svg-604.png:

      images/_pragprog/svg-block-585.png

      To multiply these matrices, we’ll use the method described in Multiplying Matrices. According to this method, we’ll get the product matrix by working out each column of the product individually. The first column of the product matrix is:

      images/_pragprog/svg-block-586.png

      The second column of the product matrix is:

      images/_pragprog/svg-block-587.png

      Arrange these columns to get the product:

      images/_pragprog/svg-block-588.png

      Since the product is the identity matrix, matrix images/_pragprog/svg-232.png is unitary.

    4. To determine the parameters for the Universal gate, images/_pragprog/svg-231.png, associated with images/_pragprog/svg-605.png, equate the images/_pragprog/svg-231.png matrix with that of images/_pragprog/svg-605.png:

      images/_pragprog/svg-block-589.png

      The idea in these types of matrix equations is to compare the respective elements in the matrix on the left to the one on the right. Start with the element on the right that has the fewest parameters. Thus, looking at the top left element from both matrices:

      images/_pragprog/svg-block-590.png

      Next, equate the bottom left (second row, first column) elements in both matrices:

      images/_pragprog/svg-block-591.png

      Since the imaginary part on the right is images/_pragprog/svg-336.png, the imaginary part on the left, images/_pragprog/svg-606.png, must also be images/_pragprog/svg-336.png. The smallest such angle is 270° or:

      images/_pragprog/svg-block-592.png

      This value also makes the real part, images/_pragprog/svg-607.png.

      Finally, to compute images/_pragprog/svg-129.png, compare the top right (first row, second column) terms from both matrices:

      images/_pragprog/svg-block-593.png

      Since the real part on the right is 0, the real part on the left, images/_pragprog/svg-608.png, is also 0:

      images/_pragprog/svg-block-594.png

      A quick check confirms that this value of images/_pragprog/svg-129.png makes the imaginary part on the right, images/_pragprog/svg-609.png, equal to 1 as required.

      Note that we only needed three of the four element comparisons to get the three parameters for the images/_pragprog/svg-231.png gate. You can verify, though, that these three values correctly equate to the fourth element on the bottom right of the right matrix stated earlier.

      The Universal gate that implements the images/_pragprog/svg-605.png matrix is images/_pragprog/svg-610.png.

      1. To compute the quantum state when the images/_pragprog/svg-611.png gate acts on the images/_pragprog/svg-17.png qubit, calculate the following:

        images/_pragprog/svg-block-595.png

        Or, writing the quantum state as an equation:

        images/_pragprog/svg-block-596.png
      2. To compute the probabilities of the qubit collapsing to the idealized states, take the squares of the amplitudes but use the conjugate complexes, as explained in Measuring Magnitudes of Complex Numbers:

        images/_pragprog/svg-block-597.png

        And,

        images/_pragprog/svg-block-598.png
      3. The quantum program is listed here:

         qreg q[1];
         creg c[1];
         
         u3(pi/3,pi/2,-pi/2) q[0];
         measure q[0] -> c[0];
      4. The output of this program is shown in the following figure:

        images/quantum_gates_algebra/0_U3_60_90_270_Measure_Output.png

        Yes, the likelihoods of finding 0 or 1 in the classical registers is roughly 75% or 25%, respectively. These match the probabilities of the q[0] qubit collapsing to images/_pragprog/svg-17.png or images/_pragprog/svg-18.png, respectively, as calculated earlier.

      1. The quantum program for the circuit with back-to-back Universal gates is listed here:

        1: qreg q[1];
        2: creg c[1];
        3: 
        4: u3(pi/3,pi/2,-pi/2) q[0];
        5: u3(pi/3,3*pi/2,pi/2) q[0];
        6: measure q[0] -> c[0];

        The images/_pragprog/svg-611.png gate is declared on line 5.

      2. The output of this program is shown in the following figure:

        images/quantum_gates_algebra/Back_to_Back_U3_Gates_Output.png

        The images/_pragprog/svg-611.png gate restores the quantum state of the q[0] back to images/_pragprog/svg-17.png. In other words, since this gate is the Hermitian matrix of the images/_pragprog/svg-233.png gate, it reverses the action on the qubit and puts it back to the original state before these gates acted on it. Thus, the concept of back-to-back gates defined by matrices that are Hermitians of each other is similar to what you saw earlier in Back-to-Back H Gates: The First Hint of Taming Randomness.

      1. The quantum program for this circuit is as follows:

         qreg q[1];
         creg c[1];
         u3(pi/3,pi/2,-pi/2) q[0];
         u3(pi/3,pi/4,-pi/2) q[0];
         measure q[0] -> c[0];
      2. The output of this program is shown here:

        images/quantum_gates_algebra/0_U3_U3_Measure_Output.png

        In this case, the q[0] qubit isn’t restored to its original images/_pragprog/svg-17.png state as in the previous part. Both U3 gates have the same images/_pragprog/svg-612.png, which determines the numbers of pentagon images/_pragprog/svg-17.png and triangle images/_pragprog/svg-18.png qubelets in the quantum state, and the same images/_pragprog/svg-613.png. But they have different values for the second parameter, images/_pragprog/svg-97.png, which measures the relative difference between the orientations of the pentagon images/_pragprog/svg-17.png and triangle images/_pragprog/svg-18.png qubelets. Because the second U3 gate’s images/_pragprog/svg-97.png angle doesn’t exactly “twist back” the effect of the first gate on the qubelets, the quantum state isn’t restored. Hence, the qubit doesn’t go back to images/_pragprog/svg-17.png after the second U3 gate and remains in a blended state. When this blended qubit is measured, it collapses to either images/_pragprog/svg-17.png or images/_pragprog/svg-18.png. As a result, the classical register records both the 0 and 1 states.

  1. Let images/_pragprog/svg-614.png be the quantum state of the qubit before it’s acted on by the images/_pragprog/svg-239.png gate. Then, the following matrix equation defines how the images/_pragprog/svg-239.png gates modifies this quantum state:

    images/_pragprog/svg-block-599.png

    To get images/_pragprog/svg-614.png, pre-multiply both sides by the images/_pragprog/svg-241.png matrix’s Hermitian, images/_pragprog/svg-615.png:

    images/_pragprog/svg-block-600.png

    Note that images/_pragprog/svg-616.png. Thus, images/_pragprog/svg-617.png, the identity matrix. As a result, the left-hand side simplifies to images/_pragprog/svg-614.png. After substituting images/_pragprog/svg-240.png for images/_pragprog/svg-618.png on the right-hand side, the above equation reduces to:

    images/_pragprog/svg-block-601.png

    Thus, the original quantum state before the images/_pragprog/svg-239.png gate operates on it is:

    images/_pragprog/svg-block-602.png

Analyzing Quantum Gate Matrices Solutions

Solutions for the exercises in Try Your Hand.

    1. The equation for the given quantum state, images/_pragprog/svg-194.png, is:

      images/_pragprog/svg-block-603.png

      Compare this equation with that of the general quantum state:

      images/_pragprog/svg-block-604.png

      The images/_pragprog/svg-243.png term injects the complex number into the equation for the state. To determine the value of images/_pragprog/svg-97.png, relate the corresponding terms in the general equation with that of the given quantum state images/_pragprog/svg-194.png:

      images/_pragprog/svg-block-605.png

      The real term, images/_pragprog/svg-244.png, must be 0 since the right-hand side is a pure complex number:

      images/_pragprog/svg-block-606.png

      Further, images/_pragprog/svg-619.png confirms that the calculations for images/_pragprog/svg-97.png are right. Thus, the angle images/_pragprog/svg-97.png, the relative difference between the orientations of the pentagon images/_pragprog/svg-17.png and triangle images/_pragprog/svg-18.png qubelets, is 90°.

      To calculate images/_pragprog/svg-95.png, the angle which the quantum state vector leans away from the vertical on the Bloch sphere, compare the amplitudes for images/_pragprog/svg-17.png and images/_pragprog/svg-18.png in the general equation for the quantum state with that for images/_pragprog/svg-194.png:

      images/_pragprog/svg-block-607.png

      Calculate images/_pragprog/svg-95.png from the amplitude for images/_pragprog/svg-17.png as follows:

      images/_pragprog/svg-block-608.png

      Setting images/_pragprog/svg-612.png in the amplitude for images/_pragprog/svg-18.png, images/_pragprog/svg-620.png, gives images/_pragprog/svg-621.png, validating that our calculations are correct.

      Thus, the parameters for the images/_pragprog/svg-622.png gate are:

      images/_pragprog/svg-block-609.png

      Since we are working on images/_pragprog/svg-17.png, we only need to look at the first column of the gate matrix for U3 which doesn’t rely on images/_pragprog/svg-129.png. So, any value of images/_pragprog/svg-129.png can be used as it’ll not affect the behavior of the gate on images/_pragprog/svg-17.png.

      Recall from Number of Qubelets Define the Amplitudes, the number of pentagon images/_pragprog/svg-17.png and triangle images/_pragprog/svg-18.png qubelets in the qubit are related as follows:

      images/_pragprog/svg-block-610.png

      These parameters for the images/_pragprog/svg-231.png gate puts the images/_pragprog/svg-17.png qubit in the quantum state images/_pragprog/svg-194.png having an equal number of pentagon images/_pragprog/svg-17.png and triangle images/_pragprog/svg-18.png qubelets, with the triangle images/_pragprog/svg-18.png qubelets rotated 90° anticlockwise, as shown in the following figure:

      images/quantum_gates_algebra/One_Pentagon_One_Triangle_Quarter_Rotated.png

      This quantum state is identical to the one worked out in the previous section using the qubelets approach.

      The probabilities of the qubit collapsing to images/_pragprog/svg-17.png or images/_pragprog/svg-18.png, respectively, is the “square” of the amplitudes:

      images/_pragprog/svg-block-611.png

      Notice that to compute the probability of collapsing to images/_pragprog/svg-18.png, the amplitude is a complex number, so we multiply by its complex conjugate.

    2. The quantum circuit is shown here:

      images/quantum_gates_algebra/0_U3_90_90_0_Measure.png

      The quantum program is the following:

       qreg q[1];
       creg c[1];
       
       u3(pi/2,pi/2,0) q[0];
       measure q[0] -> c[0];

      The output of this program is shown in the following figure:

      images/quantum_gates_algebra/U3_90_90_0_Measure_Output.png

      The classical registers won’t log the angles of the pentagon images/_pragprog/svg-17.png and triangle images/_pragprog/svg-18.png qubelets. But the classical states recorded match the probabilities of the qubit collapsing to images/_pragprog/svg-17.png or images/_pragprog/svg-18.png, respectively, calculated in the previous part.

    3. The quantum program is as follows:

       qreg q[1];
       creg c[1];
       
       u3(pi/2,pi/2,0) q[0];
       s q[0];
       measure q[0] -> c[0];

      The output of this program is shown.

      images/quantum_gates_algebra/U3_90_90_0_S_Measure_Output.png

      Since the S gate only rotates the pentagon images/_pragprog/svg-18.png qubelets but doesn’t split any qubelets, the relative number of pentagon images/_pragprog/svg-17.png and images/_pragprog/svg-18.png qubelets remains the same. Consequently, the probabilities of the qubit collapsing to images/_pragprog/svg-17.png or images/_pragprog/svg-18.png don’t change and, hence, the classical states recorded in the classical registers will also be similar to what was recorded in the previous part.

    4. No, you can’t confirm whether the pentagon images/_pragprog/svg-18.png qubelets are rotated since the gates didn’t change the relative number of pentagon images/_pragprog/svg-17.png and triangle images/_pragprog/svg-18.png qubelets. (In later sections you’ll learn to write programs that validate the qubelet rotations.)

  1. The vector for the general quantum state images/_pragprog/svg-194.png is:

    images/_pragprog/svg-block-612.png

    The images/_pragprog/svg-97.png parameter, which measures the relative difference in orientations between the pentagon images/_pragprog/svg-17.png and the triangle images/_pragprog/svg-18.png qubelets, is associated with the triangle images/_pragprog/svg-18.png qubelets. Thus, turning both qubelets by the same angle doesn’t change the quantum state. Redraw the qubit on the right so that the pentagon images/_pragprog/svg-17.png qubelet is rotated back to the non-rotated state by turning both qubelets 90° clockwise, as shown in the following figure:

    images/quantum_gates_algebra/Which_Gate_to_Rotate_Pentagon_Qubelets_Rotated_Right_Qubit.png

    The required gate leaves the pentagon images/_pragprog/svg-17.png qubelet alone. Thus, the top left element of the gate’s matrix must be 1:

    images/_pragprog/svg-block-613.png

    The images/_pragprog/svg-507.png indicates that those corresponding terms aren’t yet known.

    This gate doesn’t take a qubelet of one type and change it to the other type by splitting or switching the qubelet. As a result, the non-diagonal terms in the gate’s matrix are 0:

    images/_pragprog/svg-block-614.png

    (If the gate were to split qubelets, for example, then the non-diagonal terms would be nonzero.)

    The triangle images/_pragprog/svg-18.png qubelet is rotated 90° clockwise. This rotation is governed by the following equation:

    images/_pragprog/svg-block-615.png

    Substitute images/_pragprog/svg-352.png for images/_pragprog/svg-97.png (the sign is negative because the rotation is clockwise):

    images/_pragprog/svg-block-616.png

    Thus, the gate matrix is:

    images/_pragprog/svg-block-617.png

    Since this matrix must be Hermitian for a quantum gate, you can confirm that something is 1. Hence, this matrix matches that of the images/_pragprog/svg-239.png gate.

    Although this problem is ostensibly about rotating a pentagon images/_pragprog/svg-17.png qubelet, it’s actually equivalent to rotating the triangle images/_pragprog/svg-18.png qubelet.

Solutions: Quantum Gates and How to Use Them

Solutions for the exercises in Try Your Hand.

    1. False. The Y gate switches and rotates qubelets. That is, when it acts on, say, a triangle images/_pragprog/svg-18.png qubelet, it’ll switch it to a pentagon images/_pragprog/svg-17.png qubelet and rotate it. But it won’t split qubelets. Hence, it doesn’t take an idealized quantum state and put it in a blended state.

    2. False. Both the images/_pragprog/svg-227.png and T gates leave the images/_pragprog/svg-17.png qubelets alone but rotate the triangle images/_pragprog/svg-18.png qubelets. So they’ll have no effect on the images/_pragprog/svg-17.png qubit but will rotate the triangle images/_pragprog/svg-18.png qubelets in the images/_pragprog/svg-18.png qubit.

    3. True. The S gate rotates the triangle images/_pragprog/svg-18.png qubelets 90°, or a quarter turn anticlockwise. The images/_pragprog/svg-298.png gate rotates the triangle images/_pragprog/svg-18.png qubelets 45°, or a one-eighth turn clockwise. Both leave the pentagon images/_pragprog/svg-17.png qubelets alone. Thus, two images/_pragprog/svg-298.png gates rotate the triangle images/_pragprog/svg-18.png qubelets by 90°, or a quarter turn clockwise, reversing the action of the S gate.

    4. True. The S gate rotates the triangle images/_pragprog/svg-18.png qubelets 90°, or a quarter turn anticlockwise. The T gate rotates the triangle images/_pragprog/svg-18.png qubelets by 45°, or a one-eighth turn anticlockwise. Thus, when both gates operate on the triangle images/_pragprog/svg-18.png qubelets, the total rotation is images/_pragprog/svg-623.png° anticlockwise.

    5. True. The images/_pragprog/svg-285.png gate splits qubelets like the H gate, although asymmetrically. Nonetheless, it puts an idealized qubit, images/_pragprog/svg-17.png or images/_pragprog/svg-18.png, into a blended state.

    1. The quantum state after the Y gate acts on the images/_pragprog/svg-17.png qubit is shown in the following figure:

      images/quantum_gates_algebra/Y_Gate_on_0_Qubelets.png
    2. If the NOT (X) gate were to act on the images/_pragprog/svg-17.png qubit, the pentagon images/_pragprog/svg-17.png qubit would be switched to a triangle images/_pragprog/svg-18.png qubit but wouldn’t be rotated, as shown in the next figure:

      images/quantum_gates_algebra/X_Gate_on_0_Qubelets.png
    3. Regardless of how the triangle images/_pragprog/svg-18.png qubelet is rotated, it’ll always collapse to the idealized images/_pragprog/svg-18.png qubit, which logs a 1 in the classical register. Thus, in both cases, the outputs will be identical.

  1. As each gate acts on the images/_pragprog/svg-17.png qubit, it affects the qubelets as follows:

    First X Gate

    Switches the images/_pragprog/svg-17.png qubit to images/_pragprog/svg-18.png. The qubit will contain only a triangle images/_pragprog/svg-18.png qubelet.

    T Gate

    Rotates the triangle images/_pragprog/svg-18.png qubelet by 45°, or a one-eighth turn anticlockwise.

    Second X Gate

    Switches the images/_pragprog/svg-18.png qubit to images/_pragprog/svg-17.png. The 45°-rotated triangle images/_pragprog/svg-18.png qubelet is switched to a 45°-rotated pentagon images/_pragprog/svg-17.png qubelet.

    The action of these three gates is summarized in the following figure:

    images/quantum_gates_algebra/0_X_T_X_Measure_Labeled.png

    Thus, this circuit rotates the pentagon images/_pragprog/svg-17.png qubelet.

    1. The program for this circuit is as follows:

       qreg q[1];
       creg c[1];
       
       h q[0];
       sdg q[0];
       h q[0];
       measure q[0] -> c[0];
    2. The output of this program is shown in the following figure:

      images/quantum_gates_algebra/0_H_Sdag_H_Measure_Output.png

      The output shows a 0 or 1 logged in the classical register with about the same probabilities. This distribution indicates that the q[0] qubit collapses about equally to the idealized qubits, images/_pragprog/svg-17.png or images/_pragprog/svg-18.png. This suggests that the q[0] qubit was in a blended state before it was collapsed by the Measure gate. Had the second H gate reversed the effect of the first H gate, the q[0] qubit would be put back to images/_pragprog/svg-17.png.

      The reason why the second H gate, despite being its own adjoint, doesn’t reverse the effect of the first H gate on the qubit is that the images/_pragprog/svg-239.png gate spins the triangle images/_pragprog/svg-18.png qubelets by –90°, or a quarter turn clockwise. As a direct result of this extra rotation, the triangle images/_pragprog/svg-18.png qubelets are no longer aligned with the pentagon images/_pragprog/svg-17.png qubelets, as shown in the following figure:

      images/quantum_gates_algebra/S_Gate_on_Blended_Qubelets_solutions_copy.png

      When the right qubit gets split by the second H gate, the triangle images/_pragprog/svg-18.png qubelets can’t cancel out, thereby leaving the qubit in a blended state, as shown in the next figure:

      images/quantum_gates_algebra/H_Gate_on_Misaligned_Qubelets_solutions_copy.png

      This is the first time you’re seeing a quantum state where the qubelets of the same type have different angles. In the next section, you’ll learn how to deal with such quantum states. For now, it’s enough to recognize that the triangle images/_pragprog/svg-18.png qubelets can’t cancel out to give an idealized state. Thus, the qubit remains in a blended state.

    3. The quantum program for this circuit is listed as follows:

       qreg q[1];
       creg c[1];
       
       h q[0];
       sdg q[0];
      »s q[0];
       h q[0];
       measure q[0] -> c[0];

      This program is the same as that in the previous part other than declaring the S gate as highlighted.

      You should get an output for this program that is similar to the one shown.

      This time, the classical register only logs 0, indicating that the second H gate successfully put the q[0] qubit in its original idealized state, images/_pragprog/svg-17.png. The reason for this is that the S gate spun the triangle images/_pragprog/svg-18.png qubelets back by 90°, or a quarter turn anticlockwise, and aligned them. As a result, the second H gate could cancel out the triangle images/_pragprog/svg-18.png qubelets from the quantum state.

      images/quantum_gates_algebra/0_H_Sdag_S_H_Measure_Output.png
    1. The code listing for this circuit is as follows:

       qreg q[1];
       creg c[1];
       
       rx(pi/3) q[0];
       measure q[0] -> c[0];
    2. The vector for the images/_pragprog/svg-17.png qubit in q[0] is:

      images/_pragprog/svg-block-618.png

      Thus, the quantum state images/_pragprog/svg-195.png after the images/_pragprog/svg-294.png acts on the images/_pragprog/svg-17.png qubit is:

      images/_pragprog/svg-block-619.png
    3. The vector for images/_pragprog/svg-195.png is:

      images/_pragprog/svg-block-620.png

      Thus, the ratio of pentagon images/_pragprog/svg-17.png to triangle images/_pragprog/svg-18.png qubelets is images/_pragprog/svg-160.png.

    4. To get the angles of rotation of the qubelets, compare the vector for images/_pragprog/svg-195.png with that for the general quantum state. Thus, the pentagon images/_pragprog/svg-17.png qubelets aren’t rotated, but the triangle images/_pragprog/svg-18.png qubelets are rotated by --90°, or a quarter turn clockwise.

    5. Probability of images/_pragprog/svg-195.png collapsing to the idealized states is the squares of their respective amplitudes. Thus, the probability of images/_pragprog/svg-195.png collapsing to images/_pragprog/svg-17.png is:

      images/_pragprog/svg-block-621.png

      Similarly, the probability of images/_pragprog/svg-195.png collapsing to images/_pragprog/svg-18.png is:

      images/_pragprog/svg-block-622.png

      Because the amplitude for images/_pragprog/svg-18.png is a complex number, we multiply it by its complex conjugate instead of directly squaring it.

    6. The output of running this program should be similar to the following figure:

      images/quantum_gates_algebra/Rx_60_Gate_Output.png

      The probabilities of recording the 0 and 1 bits in the classical register, about 75% and 25%, respectively, match those calculated in the previous part.

Sequence of Gates as Matrix Multiplication Solutions

Solutions for the exercises in Try Your Hand.

    1. No. The correct way to multiply the gate matrices is:

      images/_pragprog/svg-block-623.png

      The gate matrices are written in the reverse direction from the order in which the gates act on the qubit.

    2. Yes. The images/_pragprog/svg-271.png gate reverses the action of the T gate so, in effect, the qubit isn’t affected by those gates. In terms of matrices, the images/_pragprog/svg-83.png state is calculated as follows:

      images/_pragprog/svg-block-624.png

      Note that images/_pragprog/svg-272.png is the Hermitian of images/_pragprog/svg-268.png. So, images/_pragprog/svg-624.png, resulting in the simplification of the previous equation.

    3. Yes. The Hermitian of the images/_pragprog/svg-241.png matrix, images/_pragprog/svg-625.png, is just images/_pragprog/svg-240.png. So the given matrix multiplication works out as follows:

      images/_pragprog/svg-block-625.png

      This equation represents the circuit in which the H gate first acts on the images/_pragprog/svg-17.png qubit followed by the S gate, as shown in the figure for this part.

    4. Yes. The S gate rotates the triangle images/_pragprog/svg-18.png qubelets by a quarter turn anticlockwise. The images/_pragprog/svg-271.png gate then rotates the triangle images/_pragprog/svg-18.png qubelets a one-eighth turn clockwise. Thus, the net rotation of the triangle images/_pragprog/svg-18.png qubelets is a one-eighth turn anticlockwise. This rotation corresponds to just applying the T gate in place of the S and images/_pragprog/svg-271.png gates.

      We can also show this mathematically in terms of matrices. Start with the following equation, which directly uses the gate matrices as the gates appear in the circuit but in the reverse order:

      images/_pragprog/svg-block-626.png

      Next, recognize that the images/_pragprog/svg-268.png matrix is the square root of the images/_pragprog/svg-240.png matrix. Thus, replace images/_pragprog/svg-240.png with images/_pragprog/svg-626.png in the previous equation:

      images/_pragprog/svg-block-627.png

      The last equation was simplified by noticing that images/_pragprog/svg-627.png.

    5. Yes. The matrix multiplications for this sequence of gates to compute the final state images/_pragprog/svg-83.png is:

      images/_pragprog/svg-block-628.png

      Writing out the actual gate matrices for the H and Z gates, the previous equation becomes:

      images/_pragprog/svg-block-629.png

      The matrix in the previous equation corresponds to the NOT (X) gate. Thus, the final quantum state can be written as:

      images/_pragprog/svg-block-630.png
    1. No. This circuit won’t return anything since the qubit isn’t collapsed.

      To get this circuit to run on a quantum computer, add a classical register and a Measure gate, as shown in the following figure:

      images/quantum_gates_algebra/0_H_SDag_Rx_30_T_Rx_90_Measure.png
    2. The quantum program for the circuit in the previous part is listed here:

       qreg q[1];
       creg c[1];
       
       h q[0];
       sdg q[0];
       rx(pi/6) q[0];
       t q[0];
       rx(pi/2) q[0];
       measure q[0] -> c[0];
    3. The probabilities of the qubit collapsing to the idealized states are calculated by multiplying the respective amplitudes by their conjugate complexes as follows:

      images/_pragprog/svg-block-631.png

      And,

      images/_pragprog/svg-block-632.png

      As an additional check, these probabilities add up to 1, indicating that the qubit collapses to either one of these two idealized states.

    4. The output of running this program should be similar to the following figure:

      images/quantum_gates_algebra/0_H_SDag_Rx_30_T_Rx_90_Output.png

      The probabilities of recording 0 and 1 bits in the classical register, about 23% and 76%, respectively, match those calculated in the previous part.

    1. The quantum state images/_pragprog/svg-195.png is:

      images/_pragprog/svg-block-633.png
    2. The quantum state vector in the Visualizations tab is identical to what’s calculated in the previous part.

    3. The probabilities of the qubit collapsing to the idealized states are calculated by multiplying the respective amplitudes by their complex conjugates as follows:

      images/_pragprog/svg-block-634.png

      And,

      images/_pragprog/svg-block-635.png
    4. The code listing for this circuit is the following:

       qreg q[1];
       creg c[1];
       
       h q[0];
       s q[0];
       h q[0];
       measure q[0] -> c[0];
    5. The output of running this program should be similar to the following figure:

      images/quantum_gates_algebra/0_H_S_H_Measure_Output.png

      The probabilities of recording 0 and 1 bits in the classical register, each about 50%, match those calculated in earlier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.44.23