Order of active qubits in a chain
wildart opened this issue · comments
I'm working on Microsoft quantum katas using Yao, and I got a question about multi-qubit interactions. In an exercise 4 from Multi-Qubit Systems notebook., it is required to transform |00⟩
into 1/2(|00⟩-|01⟩+|10⟩-|11⟩)
. The solution to the problem is comes from decomposition of 1/2(|00⟩-|01⟩+|10⟩-|11⟩)
into 1/√2(|0⟩+|1⟩) ⊗ 1/√2(|0⟩-|1⟩)
, and presented as application of H gate to the first qubit, and X gate followed by H gate to the second qubit:
julia> (ket"0" |> H)*(ket"0" |> X |>H)
0.5|00⟩ + -0.5|01⟩ + 0.5|10⟩ + -0.5|11⟩
If I try to use chain
& put
functions, enumerating qubits following an above decomposition, the result is different from the above:
julia> ket"00" |> chain(2, put(1=>H), put(2=>X), put(2=>H))
0.5|00⟩ + 0.5|01⟩ + -0.5|10⟩ + -0.5|11⟩
However, if I reverse order of qubits, I get the correct result:
julia> ket"00" |> chain(2, put(2=>H), put(1=>X), put(1=>H))
0.5|00⟩ + -0.5|01⟩ + 0.5|10⟩ + -0.5|11⟩
How is the qubits numbered in the chain? From the Programming with Yao tutorial (comments on the first diagram example), the first chain solution should work correctly.
See https://yaoquantum.org/BitBasis.jl/stable/tutorial/ for bit number convention in Yao - Yao's bit endian follows how you read them from an array, so the first qubit is from right-hand side.
So it's like big-endian format, or more correctly most significant bit (MSB) order. Got it. Little-endian indeed.
It is little-endian format, same as reading an integer.