Errors in N.3.2a

def create_entangled(alpha):

    """ Subcircuit that creates the entangled state
    Args:
        - alpha (float): angle parameterizing the subcircuit.
    """
    
    # Write your circuit here
    dev = qml.device("default.qubit", wires=2)

    # Define the quantum circuit
    @qml.qnode(dev)
    def circuit(alpha):
        qml.Hadamard(wires=0)
        qml.CNOT(wires=[0, 1])
        qml.RZ(alpha, wires=0)
        return qml.probs(wires=[0, 1])

Error is not able to figured out.

Hello @SUDHIR_KUMAR_SAHOO ! Welcome to the forum!

For this codercise, you are asked to complete the circuit using any quantum gate you like, as long as you can prepare the assigned state:

\vert \psi \rangle = \cos\left(\frac{\alpha}{2}\right)\vert 00 \rangle + \sin\left(\frac{\alpha}{2}\right)\vert 11 \rangle.

In your code, you are creating a qnode and outputing the probabilities on a computational basis, which is not the point of the exercise. You don’t need to overcomplicate it :wink:

I hope it helps! :slightly_smiling_face:

def create_entangled(alpha):

    """ Subcircuit that creates the entangled state
    Args:
        - alpha (float): angle parameterizing the subcircuit.
    """
    
    # Write your circuit here
    dev = qml.device("default.qubit", wires=2)

    # Define the quantum circuit
    @qml.qnode(dev)
    def circuit(alpha):
        qml.Hadamard(wires=0)
        qml.CNOT(wires=[0, 1])
        qml.RZ(alpha, wires=0)
        return qml.state(wires=[0, 1])

Actually we have to return the state so I have used qml.state() Still I am not getting where I went wrong.

Not really, you just need to prepare the state :wink:

No need to set up a qnode here :slight_smile:

1 Like

Got it thank you. for your help. BUt error is still persist not able to figure it out where it is going wrong.

def create_entangled(alpha):

    """ Subcircuit that creates the entangled state
    Args:
        - alpha (float): angle parameterizing the subcircuit.
    """
    
    # Write your circuit here
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    qml.RZ(alpha, wires=0)
    return qml.state()

I have tried many ways still not able to figure it out please some one help. @ludmilaaasb

def create_entangled(alpha):

    """ Subcircuit that creates the entangled state
    Args:
        - alpha (float): angle parameterizing the subcircuit.
    """
    
    # Write your circuit here
    qml.Hadamard(wires = 0)
    qml.CNOT(wires = [0,1])
    np.sqrt(2)*qml.RY(alpha,wires = 0)
    return qml.probs(wires = [0,1])

   

Hello @SUDHIR_KUMAR_SAHOO

Your code still has a couple of mistakes. I suggest going back a few steps and trying to understand the exercise command. Also, you could try a simple debugging exercise: run locally your solution and check if is compatible with the proposed state \vert \psi \rangle = \cos\left(\frac{\alpha}{2}\right)\vert 00 \rangle + \sin\left(\frac{\alpha}{2}\right)\vert 11 \rangle.

For example, you can choose a couple of values for \alpha and see if \vert \psi \rangle is correct.

Besides,

I don’t understand why are you trying to multiply the RY gate by this scalar value. :thinking:

And finally, there is no need to return qml.state(). In the codercise statement is indicated that you should complete the circuit using any quantum gates you like. :blush:

def create_entangled(alpha):

    """ Subcircuit that creates the entangled state
    Args:
        - alpha (float): angle parameterizing the subcircuit.
    """
    
    # Write your circuit here
    qml.RY(alpha/2, wires = 0)
    qml.CNOT(wires=[0, 1])
    return qml.probs(wires = [0,1])

I have tried this way also just to make entanglenment. Actually I need to learn partial trace application which is goint to help in my project so from three days I am trying this hurdle not able to do where I went wrong.

If we multiply RY(\alpha) gate it can produce RY(\alpha)|0> to \ \ \cos(\alpha)|0> + \sin(\alpha)|1> . Then applying CNOT() I can produce desire state.

You are almost there. Once again, there is no need to return anything in the code. You are supposed to complete it using just quantum gates/operators. You can safely remove the last line of your code. :smiling_face:

There is a small mistake here. As a hint, take a look at the operator RY matrix, which is available on the documentation page:

R_y(\phi) = e^{-i\phi\sigma_y/2} = \begin{bmatrix} \cos(\phi/2) & -\sin(\phi/2) \\ \sin(\phi/2) & \cos(\phi/2) \end{bmatrix}.

I hope it helps! :slight_smile:

1 Like
def create_entangled(alpha):

    """ Subcircuit that creates the entangled state
    Args:
        - alpha (float): angle parameterizing the subcircuit.
    """
    
    # Write your circuit here
    
    qml.RY(alpha, wires=0)
    qml.CNOT(wires = [0,1])

Thanks for your help. I thought I need to return the state. so tried in that way. But now it works thank you so much.

1 Like