QuantumBFS / Yao.jl

Extensible, Efficient Quantum Algorithm Design for Humans.
https://yaoquantum.org
Other
918 stars 119 forks source link

ArrayReg question #442

Closed BoltzmannEntropy closed 1 year ago

BoltzmannEntropy commented 1 year ago

For this circuit:

cr=(
    kron(control(5, (5), 1=>X)) * 
    kron(control(4, (1), 4=>X),H) * 
    kron(control(5, (5), 4=>X)) * 
    kron(control(5, (3), 5=>X)) * 
    kron(I2, I2, I2,H, I2)*
    kron(control(5, (2), 4=>X)) * 
    kron(I2, I2, I2,H, I2)*
    kron(I2, H, control(3, (1), 2=>X)) * 
    kron(control(5, (2), 3=>X)) *     
    kron(I2, H, I2, I2,I2) *
    kron(control(5, (3), 5=>X)) * 
    kron(control(5, (3), 4=>X)) *     
    kron(I2, I2, H, I2,I2)
)

How do I run it on such this input with ArrayReg?

image

Thanks,

Roger-luo commented 1 year ago
join(ghz_state(2), zero_state(3))
ChenZhao44 commented 1 year ago

@Roger-luo gives the simplest way.

And there are two ways I could figure out.

  1. Define a ArrayReg directly with the initial state
  2. Apply a certain circuit to the all zero state to get the desired state.
    
    using Yao
    # method 1
    reg1 = arrayreg(ComplexF64[0, 1/sqrt(2), 1/sqrt(2), 0])
    insert_qubits!(reg1, 3, 3)

method 2

reg2 = zero_state(5) circ = chain(5, put(5, 1=>H), control(5, 1, 2=>X), put(5, 1=>X)) reg2 |> circ

check if their are equivalent

@show fidelity(reg1, reg2)



By the way, I suggest to use `put(5, 3=>H)` instead of `kron(I2, I2, H, I2, I2)` because it is not only convenient but also faster for simulation.
ChenZhao44 commented 1 year ago
join(ghz_state(2), zero_state(3))

I think an additional X gate is still needed here because what he want is |01>+|10> instead of |00>+|11>.

join(
    ghz_state(2) |> put(2, 1=>X), 
    zero_state(3)
)
BoltzmannEntropy commented 1 year ago

Thank you both for your fast responses. I shall test your suggestions.