# What is the collapsed state by measuring in arbitrary basis

**URL:** https://discourse.julialang.org/t/what-is-the-collapsed-state-by-measuring-in-arbitrary-basis/125939
**Category:** Quantum
**Created:** [February 15, 2025, 2:50pm UTC](https://discourse.julialang.org/t/what-is-the-collapsed-state-by-measuring-in-arbitrary-basis/125939 "2025-02-15T14:50:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![yao\_novice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yao_novice/32/212085_2.png) [@yao\_novice](https://discourse.julialang.org/u/yao_novice)
#### Post date: [February 15, 2025, 2:50pm UTC](https://discourse.julialang.org/t/what-is-the-collapsed-state-by-measuring-in-arbitrary-basis/125939/1 "2025-02-15T14:50:41Z")

</div>

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

```julia
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?

```julia
Measure(2, X⊗Y, locs=1)

```

---

<div class="post-metadata">

### Author: ![1115](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1115/32/4465_2.png) [@1115](https://discourse.julialang.org/u/1115)
#### Post date: [February 17, 2025, 12:25am UTC](https://discourse.julialang.org/t/what-is-the-collapsed-state-by-measuring-in-arbitrary-basis/125939/2 "2025-02-17T00:25:17Z")

</div>

> measure qubit 1 in this basis v

This is a bit confusing, do you mean you redefined two qubits in this four state space by mapping them to 00, 01, 10, 11? If this is true, I will redefine my measurement observable.

For Q1: it depends on which computational basis are you choosing. If you want to measure X⊗Y in the original basis, then please apply U’ to switch back.

For Q2: If you measure at location 1, then the operator to be measured must also be defined on 1 qubit.

---

<div class="post-metadata">

### Author: ![yao\_novice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yao_novice/32/212085_2.png) [@yao\_novice](https://discourse.julialang.org/u/yao_novice)
#### Post date: [February 17, 2025, 7:08am UTC](https://discourse.julialang.org/t/what-is-the-collapsed-state-by-measuring-in-arbitrary-basis/125939/3 "2025-02-17T07:08:52Z")

</div>

I am confused now too:  
@Q1: Measuring q1 (least significant) of \psi in basis v - what is the collapsed state in v? As you say I need to use U’ to return to v basis.  
@Q2: I see clearer now: operator X\otimes Y means Y on q1 and X on q2 - only on locs=1 is a contradiction!  
Thanx for clarification
