I experiment with Yao.jl and I am puzzled with the ‘Measure’-blocks ‘operator’ argument. I assumed that the input state would end up with an eigenstate of the operator-matrix - but this seems not to be true.
Here is my code and arguments in the comments
using Yao, LinearAlgebra
# only for simplifying the output
function simplify(A)
if isreal(A)
A = round.(real.(A), digits=4)
end
if reduce(*,collect(Iterators.flatten(isinteger.(A))))
A = round.(Int64,A)
end
return A
end
⊗(a,b)=kron(a,b)
θ = π/8
op_block= Ry(2*θ) * Z * Ry(-2*θ)
bell = ArrayReg(1/sqrt(2)*[1.0+0.0im;0;0;1])
inp = copy(bell) # we save bell for later use
#--------- IMPORTANT ----------------------
inp|> Measure(2, locs=1, operator=op_block)
# inp is NOW collapsed state
println("measure at 1: ",simplify(state(inp)))
#=
OUTPUT:
measure at 1: [0.1464; -0.3536; -0.3536; 0.8536;;]
measure all: [0.8536; 0.3536; 0.3536; 0.1464;;]
OR
measure at 2: [0.8536; 0.3536; 0.3536; 0.1464;;]
measure all: [0.1464; -0.3536; -0.3536; 0.8536;;]
-------------------------------------------------
=#
#=
the inp-state should now be in an eigenstate of the
operator 'op_full_mat = Matrix(mat(op_block) ⊗ mat(I2))'
'op_full_mat' is Hermitian and unary and has
eigenstates with eigenvalues ±1 :
v1≈[0.92; 0; 0.38; 0] v2≈[0; 0.92; 0; 0.38]
v3≈[-0.38; 0; 0.92; 0] v4≈[0; -0.38; 0; 0.92;]
Bell can be decribed in this basis:
bell = Φ⁺ = 0.65*v1 + 0.27*v2 -0.27*v3 + 0.65*v4
(since Φ⁺ is a unit vector this is one too)
where I would interpret '0.65' as a probability amplitude that
the system collapses to eigenvector v1 -> P(v1)= 0.65^2
By the way: The output reveals only 2 different results -
but there are 4 eigenstates of 'op_full_mat' ???
No difference if locs=1 or locs=2 or AllLocs ?
WHERE is my misconception??
=#
# we now extend the operator Identity at least significant qubit
op_full_mat = Matrix(mat(op_block) ⊗ mat(I2))
op_full = GeneralMatrixBlock(op_full_mat)
inp = copy(bell) # we save bell for later use
inp|> Measure(2, operator=op_full)
# inp is NOW collapsed state
println("measure all: ",simplify(state(inp)))
# we now extend the operator Identity a least significant qubit
op_full_mat = Matrix(mat(I2) ⊗ mat(op_block) )
op_full = GeneralMatrixBlock(op_full_mat)
inp = copy(bell) # we save bell for later use
inp|> Measure(2, operator=op_full)
# inp is NOW collapsed state
display(simplify(state(inp)))
Has anybody a hint WHERE am I wrong with my thoughts?