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

Ambiguity error in YaoSym

GiggleLiu opened this issue · comments

julia> using Yao

julia> using SymEngine
 
julia> expect(put(5, 2=>X), ket"00111" => put(5, 2=>rot(Y, Basic(:Z))))

MethodError: instruct!(::Array{SymEngine.Basic,2}, ::Val{:Ry}, ::Tuple{Int64}, ::SymEngine.Basic) is ambiguous. Candidates:

instruct!(state::Union{AbstractArray{T,1}, AbstractArray{T,2}}, ::Val{:Ry}, ::Tuple{Int64}, theta::Number) where {T, N} in YaoArrayRegister at /home/leo/.julia/dev/YaoArrayRegister/src/instruct.jl:367

instruct!(state::Union{AbstractArray{T,1}, AbstractArray{T,2}}, g::Val, locs::Union{Int64, Tuple{Vararg{Int64,N1}}}, theta::SymEngine.Basic) where {T, N1} in YaoSym at /home/leo/.julia/packages/YaoSym/uilj7/src/symengine/instruct.jl:29

Possible fix, define

instruct!(::Union{AbstractArray{T,1}, AbstractArray{T,2}}, ::Val{:Ry}, ::Tuple{Int64}, ::SymEngine.Basic) where T

instruct!(::YaoArrayRegister.ArrayReg{1,SymEngine.Basic,Array{SymEngine.Basic,2}}, ::Val{:Ry}, ::Tuple{Int64}, ::SymEngine.Basic)@instruct.jl:38
apply!(::YaoArrayRegister.ArrayReg{1,SymEngine.Basic,Array{SymEngine.Basic,2}}, ::YaoBlocks.PutBlock{5,1,YaoBlocks.RotationGate{1,SymEngine.Basic,YaoBlocks.ConstGate.YGate}})@put_block.jl:172
|>(::YaoArrayRegister.ArrayReg{1,SymEngine.Basic,Array{SymEngine.Basic,2}}, ::YaoBlocks.PutBlock{5,1,YaoBlocks.RotationGate{1,SymEngine.Basic,YaoBlocks.ConstGate.YGate}})@abstract_block.jl:38
expect(::YaoBlocks.PutBlock{5,1,YaoBlocks.ConstGate.XGate}, ::Pair{YaoArrayRegister.ArrayReg{1,SymEngine.Basic,Array{SymEngine.Basic,2}},YaoBlocks.PutBlock{5,1,YaoBlocks.RotationGate{1,SymEngine.Basic,YaoBlocks.ConstGate.YGate}}})@blocktools.jl:134
top-level scope@Local: 1[inlined]

This issue does not exist anymore.

julia> using Yao

julia> using SymEngine

julia> expect(put(5, 2=>X), ket"00111" => put(5, 2=>rot(Y, Basic(:Z))))
-2*sin((1/2)*Z)*cos((1/2)*Z)