Goal: Measure a 2 qubit state \quad\displaystyle{ |\psi\rangle = \frac{1}{5} \begin{pmatrix} 4 \\ 2i\\ 1\\ -2\\ \end{pmatrix} } in the basis of the eigenvectors of operator X \otimes Y
This basis is
\quad\displaystyle{
\frac{1}{\sqrt{2}} \left[
\begin{pmatrix}
0 \\
1\\
-i\\
0\\
\end{pmatrix},\,
\begin{pmatrix}
i \\
0\\
0\\
1\\
\end{pmatrix},\,
\begin{pmatrix}
0 \\
1\\
i\\
0\\
\end{pmatrix},\,
\begin{pmatrix}
-i \\
0\\
0\\
1\\
\end{pmatrix}
\right]
}=\left[\phi_1, \phi_2, \phi_3,\phi_4\right]=v
I want only measure qubit 1 in this basis v
I calculate the unitary matrix
\displaystyle{ U = \Sigma_i|e_i\rangle \langle \phi_i|
}
afterwards the input state for measuring \psi_s = U\psi
using Yao, LinearAlgebra
# only for simplifying the output
function simp(A)
r=real(A); img = imag(A)
R = round.(r, digits=4)
Im = round.(img, digits=4)
return R + 1.0im*Im
end
# my state to measure
ψ=1/5*[4;2.0im;1;-2.0]
⊗(x,y)=kron(x,y)
op= mat(X ⊗ Y)
dec = eigen(op)
#### the eigenvalues are degenerate!
#ϕ_n = [dec.vectors[:, i] for i in 1:4]
#println("eigenbasis:");
#[println(simp(sqrt(2)*ϕ_n[i])," ") for i in 1:4]
# we construct the orthonormal basis and
# pretend not to know these are eigenvectors of 'op'
ϕ_n = 1/sqrt(2)*[
[0;1;-1im;0],
[1im;0;0;1],
[0;1;1im;0],
[-1im;0;0;1],
]
# amplitudes of ψ in this eigenbasis
λs = [(b' * ψ) for b in ϕ_n];
println("amplitudes of ψ in ϕ_n:")
display(simp(5*sqrt(2)*λs))
# verify decomposition
println("ψ again?")
println(simp(5*reduce(+, [λs[i]*ϕ_n[i] for i in 1:4])))
# U=Σ_i (|e_i⟩⟨ϕ_i|) for measure in ϕ_n base
U=reduce(+,[I[1:4, i] * ϕ_n[i]' for i in 1:4])
ψ_s = U * ψ # simulated |ψ⟩ for measuring in ϕ_n
println("simulated ψ_s for different basis ϕ_n ")
display(simp(5*sqrt(2)*ψ_s))
println()
# measuring least significant qubit =1
reg=ArrayReg(ψ_s)
r=measure!(reg,1)
println("collapsed state of q1 : **", r.buf,"**")
println("collapsed state in comp_base × sqrt(10) ")
println( simp(sqrt(10)*state(reg)))
Question 1: Is the real collapsed state only substituting |00> by \phi_1,
|01> by \phi_2 and so on - or do I have apply the inverse U^\dagger to this state?
Question 2: Why does measure with a ‘Measure’-block do not work?
Measure(2, X⊗Y, locs=1)