Is Y equivalent to( S X Sdg)?

I have this code here to solve " I.14 Multi-qubit gate challenge" of the codebook here .

https://codebook.xanadu.ai/I.14
I could not figure out why state|11> is wrong, any idea

dev = qml.device("default.qubit", wires=3)

# State of first 2 qubits
state = [0, 1]

@qml.qnode(device=dev)
def apply_control_sequence(state):
    # Set up initial state of the first two qubits
    if state[0] == 1:
        qml.PauliX(wires=0)
    if state[1] == 1:
        qml.PauliX(wires=1) 

    # Set up initial state of the third qubit - use |->
    # so we can see the effect on the output
    qml.PauliX(wires=2)
    qml.Hadamard(wires=2)
    
    ##################
    # YOUR CODE HERE #
    ##################
    
    # IMPLEMENT THE MULTIPLEXER
    # IF STATE OF FIRST TWO QUBITS IS 01, 
    #APPLY X TO THIRD QUBIT
    qml.PauliX(wires=0)
    qml.Toffoli(wires=[0,1,2])
    qml.PauliX(wires=0)

    # IF STATE OF FIRST TWO QUBITS IS 10,
    #APPLY Z TO THIRD QUBIT

    qml.PauliX(wires=1)
    qml.Hadamard(2)
    qml.Toffoli(wires=[0,1,2])
    qml.Hadamard(2)
    qml.PauliX(wires=1)

    # IF STATE OF FIRST TWO QUBITS IS 11, 
    #APPLY Y TO THIRD QUBIT
    qml.S(2)
    qml.Toffoli(wires=[0,1,2])
    qml.adjoint(qml.S(2))
  
    return qml.state()
    

print(apply_control_sequence(state))

I got this error:

Incorrect: your circuit does not have the correct action on |11>.

Hi @Afrah, you’re almost there!

Take a close look at the ordering of the gates in the last part of your code. Is it the same to apply S first or adjoint(S) first?
I hope this hint helps you!

I had the same problem and I think I understand the root of the confusion.

The matrix decomposition of transformation Y= S X S^\dagger, but as the codebook emphasises, the order of which matrix are multiplied is right to left and the order of circuits is read left to right. So in this circuit, we will actually see S^\dagger come first, and S come last.

We couldn’t observe this when we considered the matrix decomposition of Z=HXH, since the Hadamard is its own adjoint and thus the order of which we keep first or last doesn’t matter.

1 Like