QuantumNLDiffEq.jl icon indicating copy to clipboard operation
QuantumNLDiffEq.jl copied to clipboard

Error when using DQCType.

Open HuynhTran0301 opened this issue 1 year ago • 1 comments
trafficstars

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.

HuynhTran0301 avatar Mar 07 '24 01:03 HuynhTran0301

@HuynhTran0301 Ah, sorry for the long wait. I was unaware of the issues opened. I'll take a deeper look at both this and your other issue tomorrow. Feel free to ping me for any issues or questions regarding this repo henceforth.

VarLad avatar Jun 19 '24 05:06 VarLad