QuantumBFS / Yao.jl

Extensible, Efficient Quantum Algorithm Design for Humans.

Home Page:https://yaoquantum.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strange behavior of 1-qbit circuit

erlebach opened this issue · comments

I have created a simple circuit with a single qbit, and defined a simple function creating a qbit. Applying the circuit to this qbit several times in a row changes the state of the input qbit. I demonstrate this below:

using cuYao, Plots

X1 = chain(1, put(1 => X))
bb = ArrayReg(bit"1")
state(bb  |> X1) 
state(bb |> X1)

Each time I apply the circuit to bb, the quantum bit flips. That would imply that the input qbit bb changes. The output of the code above, typed into REPL, is:

julia> state(bb |> X1)
2×1 Matrix{ComplexF64}:
 1.0 + 0.0im
 0.0 + 0.0im

julia> state(bb |> X1)
2×1 Matrix{ComplexF64}:
 0.0 + 0.0im
 1.0 + 0.0im

Why should it change? I do not understand. Thank you for any insight!

I answered my own question. I read that |> is equivalent to apply!, which overwrites the qbit that went through the circuit. So my question is: what was the rationale for overloading the pipe operator |>? I thought this operator was equivalent to | in the bash shell, it is very useful for clearer mathematical expressions. Overwriting it to mean apply! seems to complicate matters. Why not overload it to mean apply?

In an actual quantum computer, are there situations where the input qbit to a unitary transformation actually changes as the output is computed? I was not aware of that fact.

Thanks!

 Gordon

Hi thanks for the issue. It's been my greatest gripe since the beginning of this overload. Mainly because it cannot represent the in place behavior of apply!. But this is the only available pipe operator at the moment in Julia.

in quantum physics because there is non-cloning algorithm, a register is alway mutated in-place physically. Thus in practice we find this is quite convenient.

There has been proposal on supporting !> as a pipe operator that denotes in-place function more explicitly which is something we can consider in the future.