Codercise I.1.1: Potential issue?

Hi PennyLane team!

I keep getting this error message when running my code in the IDE: Error: '__import__'. I think my solution is correct, I ran it locally and get the same result as the example, but I’m not sure if I’m missing something. Here is my code:

def normalize_state(alpha, beta):
    """Compute a normalized quantum state given arbitrary amplitudes.
    
    Args:
        alpha (complex): The amplitude associated with the |0> state.
        beta (complex): The amplitude associated with the |1> state.
        
    Returns:
        array[complex]: A vector (numpy array) with 2 elements that represents
        a normalized quantum state.
    """

    ##################
    # YOUR CODE HERE #
    ##################

    # CREATE A VECTOR [a', b'] BASED ON alpha AND beta SUCH THAT |a'|^2 + |b'|^2 = 1
    state_vector = np.array([alpha, beta])
    normalization_factor = np.sqrt(abs(state_vector * np.conj(state_vector)).sum())
    normalized_state = state_vector / normalization_factor
    # RETURN A VECTOR
    return normalized_state

Perhaps I was meant to do the normalization before turning alpha and beta into a state vector?

Thank you in advance for any help or guidance!

P.S. I had to include an abs() call to handle the very small imaginary component in the that appears when doing state_vector * np.conj(state_vector) in normalization_factor. I think that is just part of the limitations of floating point arithmetic, i.e. a floating-point error.
P.P.S. Here is a screenshot of the IDE:

Hello @smujahed, welcome to the forum!

Thank you for bringing this to our attention, we’ll have to look into this. Other solutions using, for example, np.linalg.norm to calculate the norm of the vector do work on our side.

Try this so that you’re not stuck while we work on a fix.

Cheers!

Alvaro