Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply! on cuzero_state register throws "clocs not defined error" in instruct! call. #81

Closed
t-rothe opened this issue May 19, 2023 · 2 comments

Comments

@t-rothe
Copy link

t-rothe commented May 19, 2023

A (seemingly) simple setup of trying to run apply!() on a cuzero_state(4) register:

proxy_reg = zero_state(4) |> CuYao.cu
apply!(proxy_reg, pqc_circuit)

This, however, throws an error:

UndefVarError: clocs not defined

Stacktrace:
[1] instruct!(#unused#::Val{2}, state::CuArray{ComplexF64, 1, CUDA.Mem.DeviceBuffer}, U1::SparseArrays.SparseMatrixCSC{ComplexF64, Int64}, locs::Tuple{Int64})
@ CuYao C:\Users\trothe.julia\packages\CuYao\P3wMR\src\gpuapplys.jl:49

And indeed the referenced source in CuYao declares:

function instruct!(::Val{2}, state::DenseCuVecOrMat, U1::SDSparseMatrixCSC, locs::Tuple{Int})
    instruct!(Val(2), state, Matrix(U1), locs, clocs, cval)
end

Which obviously can't work. Anyone knows why this piece is in the source in this way? And what makes my case special in that I couldn't find a similar issue in the issue trace? This seems as something that happens even for the most simple YaoBlocks and registers. The non-cuda version in Yao works just fine.

If that helps, the pqc_circuit mentioned above is the following:

pqc_circuit = nqubits: 4
chain
├─ Subroutine: (1, 2, 3, 4)
│  └─ kron
│     ├─ 1=>rot(Z, -1.0300292665315807)
│     ├─ 2=>rot(Z, -0.5556806707931512)
│     ├─ 3=>rot(Z, -1.6820465862121425)
│     └─ 4=>rot(Z, -1.6440950194679396)
├─ Subroutine: (1, 2, 3, 4)
│  └─ kron
│     ├─ 1=>rot(Y, 0.3001850517270027)
│     ├─ 2=>rot(Y, 0.41386690250976577)
│     ├─ 3=>rot(Y, -0.6562405862159898)
│     └─ 4=>rot(Y, 0.6502920336992778)
├─ control(1)
│  └─ (2,) X
├─ control(3)
│  └─ (4,) X
├─ Subroutine: (1, 2, 3, 4)
│  └─ kron
│     ├─ 1=>rot(Z, 2.4875529584638456)
│     ├─ 2=>rot(Z, 1.9337138528264264)
│     ├─ 3=>rot(Z, -1.3241302236114942)
│     └─ 4=>rot(Z, -0.6202813142456156)
├─ Subroutine: (1, 2, 3, 4)
│  └─ kron
│     ├─ 1=>rot(Y, 0.017415280987295396)
│     ├─ 2=>rot(Y, -0.8955835562683527)
│     ├─ 3=>rot(Y, 0.2029372375119746)
│     └─ 4=>rot(Y, -0.23288875605647713)
├─ control(2)
│  └─ (3,) X
├─ Subroutine: (1, 2, 3, 4)
│  └─ kron
│     ├─ 1=>rot(Z, -0.47153618078694515)
│     ├─ 2=>rot(Z, -1.2530556792651808)
│     ├─ 3=>rot(Z, 0.07989281174479339)
│     └─ 4=>rot(Z, -0.3709523749972201)
├─ Subroutine: (1, 2, 3, 4)
│  └─ kron
│     ├─ 1=>rot(Y, -0.8946015745750833)
│     ├─ 2=>rot(Y, 2.025043826440464)
│     ├─ 3=>rot(Y, 1.3762548604704439)
│     └─ 4=>rot(Y, 0.10249825960394013)
├─ control(1)
│  └─ (2,) X
├─ control(3)
│  └─ (4,) X
├─ Subroutine: (1, 2, 3, 4)
│  └─ kron
│     ├─ 1=>rot(Z, 1.9134004355076004)
│     ├─ 2=>rot(Z, 3.0154690647788396)
│     ├─ 3=>rot(Z, 0.15234390317820548)
│     └─ 4=>rot(Z, -1.4601520334711449)
├─ Subroutine: (1, 2, 3, 4)
│  └─ kron
│     ├─ 1=>rot(Y, -0.24473432855217372)
│     ├─ 2=>rot(Y, 2.6328232746477367)
│     ├─ 3=>rot(Y, 0.5156461987188995)
│     └─ 4=>rot(Y, -0.24391982101446646)
└─ control(2)
   └─ (3,) X

I'm using latest CuYao v0.3.3 and other CUDA.jl related things are running fine. Julia v1.9.0 on Windows 11, CUDA v11.8.0.

@GiggleLiu
Copy link
Member

GiggleLiu commented May 20, 2023

Thanks for your issue, but there is not gpuapplys.jl file anymore. Could you please test on the latest version of CuYao?
It should be

(CuYao) pkg> st CuYao
Project CuYao v0.3.7

@t-rothe
Copy link
Author

t-rothe commented May 20, 2023

You're right. Compats of YaoExtensions and QuadDIRECT.jl were shadowing v0.3.7. Thanks a lot and issue solved!

@t-rothe t-rothe closed this as completed May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants