CuYao.jl icon indicating copy to clipboard operation
CuYao.jl copied to clipboard

BUG with `put` function.

Open frankwswang opened this issue 6 years ago • 3 comments

MWE:

julia> using CuYao

julia> c1 = put(10, (7,8,9)=>chain(3, chain(3, chain(3, chain(3, put(3, 1=>Ry(pi)), put(3, 2=>Ry(pi)))))))
nqubits: 10
put on (7, 8, 9)
└─ chain
   └─ chain
      └─ chain
         └─ chain
            ├─ put on (1)
            │  └─ rot(Y gate, 3.141592653589793)
            └─ put on (2)
               └─ rot(Y gate, 3.141592653589793)


julia> rand_state(10, nbatch = 1000) |> cu |> c1
ArrayReg{1000, Complex{Float64}, CuArray...}
    active qubits: 10/10

julia> c2 = put(11, (7,8,9,10)=>chain(4, chain(4, chain(4, chain(4, put(4, 1=>Ry(pi)), put(4, 2=>Ry(pi)))))))
nqubits: 11
put on (7, 8, 9, 10)
└─ chain
   └─ chain
      └─ chain
         └─ chain
            ├─ put on (1)
            │  └─ rot(Y gate, 3.141592653589793)
            └─ put on (2)
               └─ rot(Y gate, 3.141592653589793)


julia> rand_state(11, nbatch = 1000) |> cu |> c2
ERROR: CUDA error: device kernel image is invalid (code #200, ERROR_INVALID_IMAGE)

julia> c3 = put(11, (7,8,9)=>chain(3, chain(3, chain(3, chain(3, put(3, 1=>Ry(pi)), put(3, 2=>Ry(pi)))))))
nqubits: 11
put on (7, 8, 9)
└─ chain
   └─ chain
      └─ chain
         └─ chain
            ├─ put on (1)
            │  └─ rot(Y gate, 3.141592653589793)
            └─ put on (2)
               └─ rot(Y gate, 3.141592653589793)


julia> rand_state(11, nbatch = 1000) |> cu |> c3
ArrayReg{1000, Complex{Float64}, CuArray...}
    active qubits: 11/11

frankwswang avatar Aug 06 '19 13:08 frankwswang

The static matrix in kernel is too large, please use

c2 = concentrate(11, chain(4, chain(4, chain(4, chain(4, put(4, 1=>Ry(pi)), put(4, 2=>Ry(pi)))))), 7:10)

GiggleLiu avatar Aug 07 '19 04:08 GiggleLiu

put is not suited for large blocks, since it will use static gates to avoid allocation, speed up the simulation. Which is not proper for large blocks.

For CPU, it coverts the gate to a dynamic matrix if the gate matrix is too large, however, the same trick is not possible for CuYao, I can fix it by throwing a better error message.

GiggleLiu avatar Aug 07 '19 04:08 GiggleLiu

I tagged this because we need better error message

Roger-luo avatar Aug 07 '19 19:08 Roger-luo