Xanadu Quantum Codebook H.7.3

Codercise H.7.3. Use the PREPARE and SELECT procedures you defined above to generate superpositions of two-qubit computational basis states,

    U_list = [np.kron(qml.PauliZ.matrix, qml.PauliZ.matrix), np.kron(qml.PauliZ.matrix,qml.PauliX.matrix), np.kron(qml.PauliX.matrix,qml.PauliZ.matrix), np.kron(qml.PauliX.matrix,qml.PauliX.matrix)]

    qml.QubitUnitary(PREPARE(beta_list**2), wires=aux)
    SELECT(U_list)



    return qml.state()

beta_list = np.array([1, 0, 0, 1])
normalized_coefficients = [quantum_memory(beta_list)[i].item() for i in range(0, 20, 5)]
print("The amplitudes on the main register are proportional to", normalized_coefficients, ".")

Error: unsupported operand type(s) for *: ‘function’ and ‘function’

I don’t understand why this error is there?

Hey @Monit_Sharma,

The answer to your last forum post is relevant here as well: Exercise H.6.1(b)

Hope that helps!

Hey @isaacdevlugt ,

I am stuck at the same exercice. So far I have written:

    U_list = [np.kron(qml.I.compute_matrix(), qml.I.compute_matrix()),
              np.kron(qml.I.compute_matrix(), qml.X.compute_matrix()),
              np.kron(qml.X.compute_matrix(), qml.I.compute_matrix()),
              np.kron(qml.X.compute_matrix(), qml.X.compute_matrix())]

    beta_squared = [i ** 2 for i in beta_list]
    beta_normalized = beta_squared / np.linalg.norm(beta_squared)
    
    qml.QubitUnitary(PREPARE(beta_normalized), wires = aux)
    SELECT(U_list)

    return qml.state()

beta_list = [1, 0, 0, 1]
normalized_coefficients = [quantum_memory(beta_list)[i].item() for i in range(0, 20, 5)]
print("The amplitudes on the main register are proportional to", normalized_coefficients, ".")

But I still have the same error message:

Incorrect: your quantum memory isn’t producing the right amplitudes.

I have tried so many different things, and I even get the good amplitudes (I guess) for the specific example of the Bell state printed.

The amplitudes on the main register are proportional to [(0.7071067811865477+0j), 0j, 0j, (0.7071067811865472+0j)] .

Can you explain to me where I am wrong?

Thanks in advance.

Hi @dylanlaplacemermoud, our team is taking a look at your question. We’ll be back with an answer shortly.

1 Like

Hi @CatalinaAlbornoz , thank you very much!

Hello @dylanlaplacemermoud

I have run your code on my computer and it does give the right answer, so I’m a little puzzled as to what’s going on. My hypothesis is that one of your previously defined functions may not be exactly right, but it wasn’t caught by the tests.

To help you debug, here’s what you should be getting when you run quantum_memory([1,4,2,9]):

tensor([0.09901475+0.j, 0.        +0.j, 0.        +0.j, 0.        +0.j,
        0.        +0.j, 0.39605902+0.j, 0.        +0.j, 0.        +0.j,
        0.        +0.j, 0.        +0.j, 0.19802951+0.j, 0.        +0.j,
        0.        +0.j, 0.        +0.j, 0.        +0.j, 0.89113279+0.j], requires_grad=True)

If this is what you’re getting, let me know and we can try to keep debugging from there!

Cheers,

Alvaro

Hi @Alvaro_Ballon ,

Thank you so much for your answer. The thing is that, while I was trying to solve some errors that I had before, I rewrite the PREPARE part just before this function, on the same cell to easily have access to it. After reading your message, I commented it and my answer is accepted.

Cheers,
Dylan

I’m glad to see that you found the solution @dylanlaplacemermoud !

1 Like