What does Yao.Measure do with argument operator?

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?

The output reveals only 2 different results - there are 4 eigenstates of ‘op_full_mat’ ???

If the operator has degenerate eigenvalues, the measurement operation collapses the state to a subspace, rather than a single eigenvector.

julia> eigen(Matrix(mat(op_block) ⊗ mat(I2))).values
4-element Vector{Float64}:
 -0.9999999999999984
 -0.9999999999999984
  1.0
  1.0
1 Like

When I constructed the eigenstates
\begin{pmatrix} \cos(\theta) \\ \sin(\theta) \end{pmatrix} \otimes |0\rangle
and so on … I did know the eigenvalues remained -1,+1 but I had no idea that this leads to a degeneration: 4 states, 2 values.
I thought of this for weeks and you solved it in a minute - thumbs up
and thank you so much (you prevented me from headaches)
This topic is solved