QuantumBFS / Yao.jl

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

variational_circuit not matched #436

Closed erlebach closed 1 year ago

erlebach commented 1 year ago

I am running the notebook 2.yao_basics on a Macbook pro with the M1 chip under Big Sur using Julia 1.8.2 . I execute:

variational_circuit(5, 3, [1=>2, 2=>3, 3=>4, 4=>5, 5=>1]) |> plot

and get the error message:

ERROR: MethodError: no method matching variational_circuit(::Int64, ::Int64, ::Vector{Pair{Int64, Int64}})
Closest candidates are:
  variational_circuit(::Type{T}, ::Any, ::Any, ::Any; mode, do_cache, entangler) where T at ~/.julia/packages/Yao/0nkX6/src/EasyBuild/variational_circuit.jl:97
  variational_circuit(::Int64, ::Int64; kwargs...) at ~/.julia/packages/Yao/0nkX6/src/EasyBuild/variational_circuit.jl:116
  variational_circuit(::Type{T}, ::Int64; kwargs...) where T at ~/.julia/packages/Yao/0nkX6/src/EasyBuild/variational_circuit.jl:112
  ...
Stacktrace:
 [1] top-level scope
   @ ~/src/2022/Yao.jl/notebooks/quick-start/2.yao_basics.jl:100

Why is this happening?

Here is my Project.toml:

[deps]
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"

The Manifest is 300+ lines, so I am not posting it. But I am attaching it. Apparently, I cannot attach toml files. Presumably for security reasons.

Any insight will be appreciated. Thanks.

 Gordon
GiggleLiu commented 1 year ago

Thanks for reporting the issue, the documentation seems to be outdated, we will update it soon. In your case, a minimal fix is adding a parameter type as the first argument

julia> variational_circuit(Float64, 5, 3, [1=>2, 2=>3, 3=>4, 4=>5, 5=>1])

julia> variational_circuit(5, 3)

The previous implementation does not consider generic types, like symbolic parameters. In the latest version, we make the interface more generic, this is why we need a new argument.

The docstring is usually updated more frequently than the tutorial. You can check the docstring by typing ? in an REPL, followed by the function that you want to query.

help?> variational_circuit
search: variational_circuit

  variational_circuit([T=Float64], nbit[, nlayer][, pairs]; mode=:Split, do_cache=false, entangler=cnot)
erlebach commented 1 year ago

Thank you!