SciML / QuantumNLDiffEq.jl

MIT License
18 stars 4 forks source link

Make test case from README.md example #3

Closed elisno closed 2 years ago

elisno commented 2 years ago

I cannot reproduce this plot from the current example. I can reproduce the plot from the MWE after updating Yao.jl (see https://github.com/SciML/QuantumNLDiffEq.jl/issues/3#issuecomment-1079982349)

It would be nice to make a test case that reproduces the plot, or rather the resulting expectation values.

MWE

julia> begin
           using Yao, QuantumNLDiffEq
           M = range(start=0; stop=0.9, length=20)
           cost = sum([put(6, i=>Z) for i in 1:6])
           var = dispatch(EasyBuild.variational_circuit(6,5), :random)
           quantum_feature_map_circuit = chain(6, [put(i=>Ry(0)) for i in 1:6])
           params = parameters(var)
           u_0 = 1.0
           N = 6
       end

julia> train!(quantum_feature_map_circuit, cost, var, M, N, 1.0, params)

julia> e = [expect(cost, zero_state(N)=>QuantumNLDiffEq.new_circuit(quantum_feature_map_circuit, var, i, params, N; mapping=QuantumNLDiffEq.Chebyshev())) .+ u_0 .- expect(cost, zero_state(N)=>QuantumNLDiffEq.new_circuit(quantum_feature_map_circuit, var, M[1], params, N; mapping=QuantumNLDiffEq.Chebyshev()))  for i in M]

julia> import Plots

julia> Plots.plot(M, real.(e))

Expected plot

download

Actual plot

download

_Originally posted by @elisno in https://github.com/SciML/QuantumNLDiffEq.jl/pull/1#discussion_r835925088_

elisno commented 2 years ago

@VarLad Can you share any references for the circuit that you are trying to optimize here?

VarLad commented 2 years ago

@elisno The library is currently broken and will be fixed after an update from Yao :)

elisno commented 2 years ago

You're right. I managed to reproduce the expected plot from the MWE after checking out the master-branch of Yao.jl.

(QuantumNLDiffEq) pkg> st
     Project QuantumNLDiffEq v0.0.1
      Status `/workspaces/QuantumNLDiffEq.jl/Project.toml`
  [587475ba] Flux v0.12.9
  [91a5bcdd] Plots v1.27.3
  [5872b779] Yao v0.7.1 `https://github.com/QuantumBFS/Yao.jl.git#master`
  [418bc28f] YaoBlocks v0.12.1 `https://github.com/QuantumBFS/Yao.jl.git:lib/YaoBlocks#master`
  [e88e6eb3] Zygote v0.6.37
elisno commented 2 years ago

Adding a test for this should resolve the issue. I'll keep it open for now.

VarLad commented 2 years ago

@elisno The instructions were there in README.md already though :stuck_out_tongue:

elisno commented 2 years ago

Fair enough 😄, but the installation instructions omitted the fact that Yao.jl#master was required.

The broken plot was based on YaoBlocks#master, but Yao v0.7.1.


Everything works after adding

pkg> add Yao#master

Added this suggestion to the PR ( https://github.com/SciML/QuantumNLDiffEq.jl/pull/1/files#r835944190)

VarLad commented 2 years ago

@elisno Sorry, I'm not sure if Yao#master is needed :sweat_smile: The plot in README.md was generated using the stable version of Yao and master of YaoBlocks

elisno commented 2 years ago

@VarLad I think you can link #1 to this issue in the PR description before merging.

Fixes #3
VarLad commented 2 years ago

@elisno I think this issue is resolved since Yao released a new version

elisno commented 2 years ago

@elisno I think this issue is resolved since Yao released a new version

Yes you're right. I closed the associated PR once you updated the tests. I forgot this issue in the cleanup.