How can I get the amplitude of qubit after collapse

For the entanglement qubits, when we measure one qubits, the other qubits will collapse to a quantum state. How can I get the amplitude of other qubits. An example is as follows:

The init quantum state: \frac{1}{2}|0>|0> + \frac{1}{2}|0>|1> + \frac{1}{\sqrt{2}}|1>|0> + 0|1>|1>

\Rightarrow \frac{1}{2}|0>(\frac{1}{\sqrt{2}}|0> + \frac{1}{\sqrt{2}}|1>) + \frac{1}{\sqrt{2}}|1>(1|0> + 0|1>)

So it means that for the first qubit, we have \frac{1}{2} probability of measuring 1 and \frac{1}{2} probability of measuring 0.
When we measure the first qubit, if the result of qubit 1 is 0, then the second qubit will collapse to \frac{1}{\sqrt{2}}|0> + \frac{1}{\sqrt{2}}|1>. And if the result of qubit 1 is 1, then the second qubit will collapse to 1|0> + 0|1>.
This is a very interesting phenomenon, but how do we implement it in pennylane. When I use mid-measure, the output of other qubit has no influence. Any help will be appreciated.

Sorry about the mistake, the quantum state should be as follows:
\Rightarrow \frac{1}{\sqrt{2}}|0>(\frac{1}{\sqrt{2}}|0> + \frac{1}{\sqrt{2}}|1>) + \frac{1}{\sqrt{2}}|1>(1|0> + 0|1>)

Hi @cheng!

Thank you very much for your question!

If I understand it correctly, you want to create a circuit which has that state. Is that right?

If that’s the case then you can use our AmplitudeEmbedding template.

You could use it as follows:

import pennylane as qml
from pennylane import numpy as np
dev = qml.device('default.qubit',wires=2)

@qml.qnode(dev)
def circuit(f):
    qml.AmplitudeEmbedding(features=f, wires=range(2))
    return qml.state()

print(circuit(f=[1/2, 1/2, 1/np.sqrt(2), 0]))
qml.draw_mpl(circuit)(f=[1/2, 1/2, 1/np.sqrt(2), 0])

As you can see in the output, the probability amplitudes are what you included in ‘f’.

Now, if what you want to see is samples, then you can try adding a number of shots to the device and then getting ‘samples’ as the return.

dev = qml.device('default.qubit',wires=2, shots=10)

@qml.qnode(dev)
def circuit(f):
    qml.AmplitudeEmbedding(features=f, wires=range(2))    
    return qml.sample(qml.PauliZ(0)), qml.sample(qml.PauliZ(1))

print(circuit(f=[1/2, 1/2, 1/np.sqrt(2), 0]))

I ran this once and got
[[ 1 -1 -1 1 1 -1 -1 1 1 1]
[ 1 1 1 1 -1 1 1 1 -1 1]]

The first line is the first qubit and the second line is the second qubit. A ‘1’ means that the qubit was on the |0⟩ state, and a ‘-1’ means that the qubit was in the |1⟩ state.

What you can see from the results is that every time you get a |1⟩ state in the first qubit you get a |0⟩ state in the second one.

Please let me know if this solves your question!

I also encourage you to read this ‘how-to’ about measurements in PennyLane.

Hi @CatalinaAlbornoz,
Thanks for your reply. Very clear presentation. Actually, when I use qml.counts(), I can get every combination. And I can see that there is no ‘10’. I think it is the same result as you. But I want to ask if is there any way that I can get the amplitude of the second qubit after measuring the first qubit.

Hi @cheng, thank you for the clarification. Unfortunately you can’t do this with PennyLane at the moment but we’re thinking of implementing it so stay tuned!