Stock in Problem H.6.1 summations of Unitaries

main = 1
n_bits = 2
dev = qml.device("default.qubit", wires=n_bits)

def add_two_unitaries(U, V):
    """A circuit to apply the sum of two unitaries non-deterministically.
    
    Args:
        U (array): A unitary matrix, stored as a complex array.
        V (array): A unitary matrix, stored as a complex array.
    """
    qml.Hadamard(wires=aux)
    ##################
    # YOUR CODE HERE #
    ##################
    qml.ControlledQubitUnitary(U, control_wires = [1,0], wires = 2) + 
    qml.ControlledQubitUnitary(V, control_wires = [1,0], wires = 2)
    qml.Hadamard(wires=aux)

I am trying to do linear combinations in this way. Where it went wrong conceptually not able to figure it out.

Hi @SUDHIR_KUMAR_SAHOO ,

Make sure to take a clear look at the figure showed right before the codercise. How many control wires do you actually need? What does it mean that the dot of the control for U is not fully coloured? What can you find in the documentation for ControlledQubitUnitary?

Also, note that you have a trailing + in your first line. This is not how addition works here :wink:

I hope this helps you! :smiley:

1 Like

Hello @CatalinaAlbornoz ,

I got your point it should be kU + V. However, I wont understand the constant here is k is we to take as \sqrt(1/2)?

aux = 0
main = 1
n_bits = 2
dev = qml.device("default.qubit", wires=n_bits)

def add_two_unitaries(U, V):
    """A circuit to apply the sum of two unitaries non-deterministically.
    
    Args:
        U (array): A unitary matrix, stored as a complex array.
        V (array): A unitary matrix, stored as a complex array.
    """
    qml.Hadamard(wires=aux)
    ##################
    # YOUR CODE HERE #
    ##################
    qml.ControlledQubitUnitary(U, control_wires = [1,0], wires = 2)
    qml.ControlledQubitUnitary(V, control_wires = [0,1], wires = 2)
    qml.Hadamard(wires=aux)

Hi @SUDHIR_KUMAR_SAHOO, there’s actually no constant k here. What I meant is that you should take a look at your control wires. If you look closely there’s actually just one control wire for U and V.

If you look at the tip in this codercise it says:

Use qml.ControlledQubitUnitary to apply these unitaries with control bits.

What are these control bits? They’re not the same as control wires, so what are they? The answer is in the documentation!

Also, notice that you have something called “aux” and something called “main” at the beginning of the code. What are they referring to?

I hope this helps you!