TransWikia.com

Creating a W state for $2^k$ qubits

Quantum Computing Asked by Übermensch on September 5, 2021

This question is available in Quantum Katas here

In Task 2.6 of this notebook, we are required to create the W State for $2^k$ qubits.

Input: $?=2^?$ qubits in the |0…0⟩ state.

Goal: Change the state of the qubits to the W state – an equal superposition of ? basis states on ? qubits which have Hamming weight of 1.

For example, for $?=4$ the required state is $frac{1}{2}(|1000⟩+|0100⟩+|0010⟩+|0001⟩)$

And since this problem is taken from Katas, it came with a solution which is as follows:
s

operation WState_PowerOfTwo (qs : Qubit[]) : Unit is Adj+Ctl {
    let N = Length(qs);

    if (N == 1) {
        // base of recursion: |1⟩
        X(qs[0]);
    } else {
        let K = N / 2;
        using (anc = Qubit()) {
            H(anc);
            
            (ControlledOnInt(0, WState_PowerOfTwo))([anc], qs[0 .. K - 1]);
            (ControlledOnInt(1, WState_PowerOfTwo))([anc], qs[K .. N - 1]);

            for (i in K .. N - 1) {
                CNOT(qs[i], anc);
            }
        }
    }
}

While there is absolutely nothing wrong with the proposed answer, I was trying to solve this task without using an ancilla qubit, here’s my approach to this question:

operation WState_PowerOfTwo (qs : Qubit[]) : Unit {
    let length_qs = Length(qs);
    if (length_qs == 1){
        X(qs[0]);
    }
    else{
    H(qs[0]);
    
    for(i in 1..length_qs-1){
        if(i != length_qs-1){
            for (j in 0..i-1){
                X(qs[j]);
            }
            Controlled H(qs[0..i-1], qs[i]);
            for (j in 0..i-1){
                X(qs[j]);
            }
        }
        else{
            for (j in 0..i-1){
                X(qs[j]);
            }
            Controlled X(qs[0..i-1], qs[i]);
            for (j in 0..i-1){
                X(qs[j]);
            }
        }
    }
}
}

This logics works fine till N=2 but it shows the following error when testing for hidden cases:

The desired state for N = 1
# wave function for qubits with ids (least to most significant): 0
∣0❭:     0.000000 +  0.000000 i  ==                          [ 0.000000 ]                   
∣1❭:     1.000000 +  0.000000 i  ==     ******************** [ 1.000000 ]     --- [  0.00000 rad ]
The actual state:
# wave function for qubits with ids (least to most significant): 0
∣0❭:     0.000000 +  0.000000 i  ==                          [ 0.000000 ]                   
∣1❭:     1.000000 +  0.000000 i  ==     ******************** [ 1.000000 ]     --- [  0.00000 rad ]
Test case passed
The desired state for N = 2
# wave function for qubits with ids (least to most significant): 0;1
∣0❭:     0.000000 +  0.000000 i  ==                          [ 0.000000 ]                   
∣1❭:     0.707107 +  0.000000 i  ==     ***********          [ 0.500000 ]     --- [  0.00000 rad ]
∣2❭:     0.707107 +  0.000000 i  ==     ***********          [ 0.500000 ]     --- [  0.00000 rad ]
∣3❭:     0.000000 +  0.000000 i  ==                          [ 0.000000 ]                   
The actual state:
# wave function for qubits with ids (least to most significant): 0;1
∣0❭:     0.000000 +  0.000000 i  ==                          [ 0.000000 ]                   
∣1❭:     0.707107 +  0.000000 i  ==     ***********          [ 0.500000 ]     --- [  0.00000 rad ]
∣2❭:     0.707107 +  0.000000 i  ==     ***********          [ 0.500000 ]     --- [  0.00000 rad ]
∣3❭:     0.000000 +  0.000000 i  ==                          [ 0.000000 ]                   
Test case passed
Testing on hidden test cases...
Released qubits are not in zero state.
Try again!

I cannot find a root for this problem, is there any error in my logic or am I missing something here?

One Answer

Yes, there is an error in your logic.

If you take the task one step further, to $N = 4$, the desired state is $frac{1}{2}(|1000rangle + |0100rangle + |0010rangle + |0001rangle)$, and the state your solution prepares is $frac{1}{sqrt2}|1000rangle + frac{1}{2}|0100rangle + frac{1}{2sqrt2}(|0010rangle + |0001rangle)$. You can see this for yourself if you modify the testing harness in VS or VS Code to have AssertEqualOnZeroState(4, WState_PowerOfTwo, WState_PowerOfTwo_Reference, true, "N = 4"); so that it prints the expected state and the actual state when testing your solution.

You have a linear combination of the right basis states but the amplitudes are incorrect, since you apply

  • one H gate to modify the amplitude of the state in which $1$ is in the first position,
  • two H gates to modify the amplitude of the state in which $1$ is in the second position,
  • and three H gates to modify the amplitude of the states in which $1$ is in the third or fourth positions.

It is possible to solve this task without allocating extra qubits, but you'll need to use arbitrary rotations to adjust the amplitudes with more control than the H gate allows; for example, on the first step you'll need to convert $|0000rangle$ to $frac{1}{2}|1000rangle + frac{sqrt3}{2}|0000rangle$ so that the amplitude of the first state is correct. You can check the reference solution for task 2.7 for this approach.

Answered by Mariia Mykhailova on September 5, 2021

Add your own answers!

Ask a Question

Get help from others!

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