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

PastaQ integration

Roger-luo opened this issue · comments

This issue has been tagged for a bounty during #unitaryHACK

See GTorlai/PastaQ.jl#120

I'll try working on this

@Roger-luo Anyway to get the list of gates being used and their positions from a block?

Also, can you give more details about what exactly do you want?

I just took a look here https://github.com/GTorlai/PastaQ.jl/blob/master/src/circuits/gates.jl
Can't Yao already convert to matrices?

Anyway to get the list of gates being used and their positions from a block?
take a look at https://github.com/QuantumBFS/YaoBlocksQASM.jl/blob/main/src/qasm.jl#L16 ?

Also, can you give more details about what exactly do you want?

I've showed some PoC demos in the PastaQ PR, which detail do you want to know?

I just took a look here https://github.com/GTorlai/PastaQ.jl/blob/master/src/circuits/gates.jl
Can't Yao already convert to matrices?

PastaQ is a simulator that uses tensor network for simulation, which in principle will be much faster than a full amplitude simulation. I'm not sure why we care about the ability of converting to matrices, this is irrelatvent.

Unfortunately, PastaQ re-invent a lot of wheels, so reading its code might be confusing for those who aren't familiar, the part actually relevant to the integration is mainly in https://github.com/GTorlai/PastaQ.jl/blob/master/src/circuits/runcircuit.jl#L23

I've to parse into the types specified by PastaQ right?
Where all the gatenames are given here https://github.com/GTorlai/PastaQ.jl/blob/master/src/circuits/gates.jl?

@Roger-luo Please confirm, you need something like this right?

julia> testgate = chain(3, put(2 => X), put(3 => im*Y), repeat(H, 1:2), put(1:2 => chain(2, put(1 => X))), put(1 => shift(π/2)), put(1 => shift(π/4)))
nqubits: 3
chain
├─ put on (2)
│  └─ X
├─ put on (3)
│  └─ [+im] Y
├─ repeat on (1, 2)
│  └─ H
├─ put on (1, 2)
│  └─ chain
│     └─ put on (1)
│        └─ X
├─ put on (1)
│  └─ shift(1.5707963267948966)
└─ put on (1)
   └─ shift(0.7853981633974483)


julia> generate_prog(testgate, 3)
7-element Vector{Any}:
 ("X", [2])
 ("iY", [3])
 ("H", [1])
 ("H", [2])
 ("X", [2])
 ("Phase", [1])
 ("π/8", [1])

Yes, the easiest way of implementing it is to implment a register that contains a Vector{Any} and keep pushing tuple into it when you see a leaf.

I guess I've to cover all the gates from https://github.com/GTorlai/PastaQ.jl/blob/master/src/circuits/gates.jl

genlist!(prog, blk::XGate, locs, controls) = push!(prog, ("X", locs))

just use @eval in this case. If you submit a PR, it might be easier to help you.

@Roger-luo Okay...

Regarding what I need to do next, here's some hint I guess.....

using YaoBase
struct PastaQReg{State <: Union{MPS, MPO}} <: AbstractRegister
    state::State
    # there might be some other meta info
    # but I just ignore them for now
end

then define how certain gates are applied to this register

instruct!(r::PastaQReg, gate::Val{:X}, locs::Tuple{N, Int}) where N = # how you apply an X gate to the MPS/MPO at locations given by the tuple locs
instruct!(r::PastaQReg, gate::Val{:X}, locs::Tuple{N, Int}, control_locs::NTuple{C, Int}, control_bits::NTuple{C, Int}) where {N, C} where N = # how you apply a controlled X gate to the MPS/MPO

So.... I basically only need to complete that struct PastaQReg?

there are two options now since you implement the genlist already, you can also choose to generate the list and overload apply! so that you can apply the state to the register.

you can also choose to generate the list and overload apply! so that you can apply the state to the register.

Thats a little bit confusing....
Can you explain a bit more?

wrap this method in a apply! overloaded for PastaQReg instead of overloading instruct!

https://github.com/GTorlai/PastaQ.jl/blob/acd5e2d85199f26c8ff840cdeee9aac98c79dbb2/src/circuits/runcircuit.jl#L54

What would be the fields in

struct PastaQReg{State <: Union{MPS, MPO}} <: AbstractRegister
    state::State
    # there might be some other meta info
    # but I just ignore them for now
end

? Is state the only field?

apply!(r::PastaQReg) = runciruit(nqubits(r), genlist(r))
Something like this?

yeah something like that, state is the only field.

Uhhhh....

julia> struct PastaQReg{State <: Union{MPS, MPO}} <: AbstractRegister
           state::State
       end
ERROR: invalid subtyping in definition of PastaQReg

please open a PR first I can help there

closing this since we have YaoPastaQ done now. But I think we still need some further work to make the experience more seamlessly. Please refer to YaoPastaQ issue board for who find this.

@Roger-luo is this unitaryHack considered complete? What about the bounty?

Yes this should be considered complete. Did you get the bounty? If not I'll ask unitary fund about it.

Nope, atleast not yet

Thanks for looking into it though

@crazy4pi314 can we also mark this as completed? thanks! the corresponding repo is: https://github.com/QuantumBFS/YaoPastaQ.jl/

@VarLad just want to check this with you, did you get the bounty?