Giter Club home page Giter Club logo

quantumnldiffeq.jl's Introduction

QuantumNLDiffEq.jl

Installation

]add https://github.com/SciML/QuantumNLDiffEq.jl

Usage

using DifferentialEquations, Yao, QuantumNLDiffEq
# Making the ODEProblem
function f(u, p, t)
	λ, κ = p
	return -1*λ*u*+ tan*t))
end
prob = ODEProblem(f, [1.0], (0.0, 0.9), [8.0, 0.1])
function loss_func(a, b)
	return (a - b)^2
end

#Making the DQC
DQC = [QuantumNLDiffEq.DQCType(afm = QuantumNLDiffEq.ChebyshevSparse(2), fm = chain(6, [put(i=>Ry(0)) for i in 1:6]), cost = [Add([put(6, i=>Z) for i in 1:6])], var = dispatch(EasyBuild.variational_circuit(6,5), :random), N = 6)]
config = DQCConfig(abh = QuantumNLDiffEq.Floating(), loss = loss_func)
M = range(start=0; stop=0.9, length=20)
evalue(M) = [QuantumNLDiffEq.calculate_evalue(DQC[1], DQC[1].cost, prob.u0[1], config.abh, params[1], M[x], M[1]) for x in 1:length(M)]
params = [Yao.parameters(DQC[1].var)]

#Training the circuit
QuantumNLDiffEq.train!(DQC, prob, config, M, params)

#Plotting the solution
using Plots
new_M = range(start=0; stop=0.9, length=100)
Plots.plot(new_M, reduce(vcat, real.(evalue(new_M))), xlabel="x", ylabel="f(x)", legend=false)

example1

quantumnldiffeq.jl's People

Contributors

varlad avatar chrisrackauckas avatar dependabot[bot] avatar thazhemadam avatar devmotion avatar ranocha avatar

Stargazers

Tong Han avatar Lasse Peters avatar Xiu-zhe (Roger) Luo avatar Jeongwhan Choi avatar Aleksander Wennersteen avatar Coleton avatar Rahul Manavalan avatar Chris Muir avatar Claudio Moroni avatar  avatar anand jain avatar Anas Abdelrehim avatar Ilia Ilmer avatar john avatar Elías Snorrason avatar ChangXin Sun avatar Elias Carvalho avatar Pengfei Song avatar

Watchers

 avatar  avatar Yingbo Ma avatar Vaibhav Kumar Dixit avatar  avatar Rahul Manavalan avatar

quantumnldiffeq.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Track progress of training loop

(Paraphrased)
The train! statement in the README.md example runs in rougly 7.5 minutes on my machine. I forgot that steps=300 by default.

  • Add a @progress macro from ProgressLogging.jl to the training loop in train!.
  • Add training loop tracker via callback (cb) as a kwarg to train!.

Originally posted by @elisno in #1 (comment)

Licensing issues

This issue has been created to discuss the license of this library further going on.
No new PRs will be made by the author of this issue, before this issue is resolved

cc: @ChrisRackauckas

The meaning of M in the test case and how to plot the solution after train.

Question❓
I have run the test case in the repository. I have a question what is the meaning of M? Does it be a simulation duration? because the plot uses new_M for the x-axis. In addition, if M is the simulation duration when I tried to change M from 0.9 to 10 I got the error that DomainError with 1.001001001001001: asin(x) is not defined for |x| > 1.. If M is not the simulation duration, then how could I generate the solution after train and plot it?

Them you for your time.

Error when using DQCType.

I tried to solve the example of the package as follows:

using DifferentialEquations, Yao, QuantumNLDiffEq
# Making the ODEProblem
function f(u, p, t)
	λ, κ = p
	return -1*λ*u*(κ + tan(λ*t))
end
prob = ODEProblem(f, [1.0], (0.0, 0.9), [8.0, 0.1])
function loss_func(a, b)
	return (a - b)^2
end

#Making the DQC
DQC = [QuantumNLDiffEq.DQCType(afm = QuantumNLDiffEq.ChebyshevTower(2), fm = chain(6, [put(i=>Ry(0)) for i in 1:6]), cost = [Add([put(6, i=>Z) for i in 1:6])], var = dispatch(EasyBuild.variational_circuit(6,5), :random), N = 6)]
config = DQCConfig(abh = QuantumNLDiffEq.Floating(), loss = loss_func)
M = range(start=0; stop=0.9, length=21)
evalue(M) = [QuantumNLDiffEq.calculate_evalue(DQC[1], DQC[1].cost, prob.u0[1], config.abh, params[1], M[x], M[1]) for x in 1:length(M)]
params = [Yao.parameters(DQC[1].var)]

#Training the circuit
QuantumNLDiffEq.train!(DQC, prob, config, M, params, steps = 1000)

I got the error as follows:

MethodError: no method matching +(::NamedTuple{(:afm, :fm, :cost, :var, :N, :evol), Tuple{NamedTuple{(:pc,), Tuple{Float64}}, Vararg{Nothing, 5}}}, ::Base.RefValue{Any})

Closest candidates are:
  +(::Any, ::Any, ::Basic, ::Any...)
   @ SymEngine C:\Users\htran\.julia\packages\SymEngine\hozAR\src\mathops.jl:51
  +(::Any, ::Any, ::Any, ::Any...)
   @ Base operators.jl:578
  +(::Union{InitialValues.NonspecificInitialValue, InitialValues.SpecificInitialValue{typeof(+)}}, ::Any)
   @ InitialValues C:\Users\htran\.julia\packages\InitialValues\OWP8V\src\InitialValues.jl:154
  ...

This error happened even though I tried with Julia 1.8, 1.9, or 1.10 for ChebyshevTower and ChebyshevSparse and did not happen for Product
Please help me on how to fix it.

Make test case from README.md example

I cannot reproduce this plot from the current example.
I can reproduce the plot from the MWE after updating Yao.jl (see #3 (comment))

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 #1 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.