SchusterLab / rbqoc

Robust Quantum Optimal Control with Trajectory Optimization
https://journals.aps.org/prapplied/abstract/10.1103/PhysRevApplied.17.014036
MIT License
21 stars 3 forks source link

Error in running spin13.jl #6

Closed bobisnot closed 1 year ago

bobisnot commented 1 year ago

I'm also trying to run the optimization for spin13.jl, got the same error in lu.jl which was fixed by adding the codeblock you provided. However, I am now getting the following issue:

julia> run_traj()
ERROR: MethodError: no method matching (Objective{QuadraticCost{n, m, T, SizedMatrix{n, n, T, 2, TData} where TData<:AbstractMatrix{T}, SizedMatrix{m, m, T, 2, TData} where TData<:AbstractMatrix{T}}} where {n, m, T})(::Objective{QuadraticCost{11, 1, Float64, SizedMatrix{11, 11, Float64, 2, Matrix{Float64}}, SizedMatrix{1, 1, Float64, 2, Matrix{Float64}}}}, ::Model)
Closest candidates are:
  (Objective{QuadraticCost{n, m, T, SizedMatrix{n, n, T, 2, TData} where TData<:AbstractMatrix{T}, SizedMatrix{m, m, T, 2, TData} where TData<:AbstractMatrix{T}}} where {n, m, T})(::Objective{QuadraticCost{n, m, T, SizedMatrix{n, n, T, 2, TData} where TData<:AbstractMatrix{T}, SizedMatrix{m, m, T, 2, TData} where TData<:AbstractMatrix{T}}} where {n, m, T}, ::AbstractModel) at ~/.julia/packages/TrajectoryOptimization/gPd37/src/objective.jl:85
Stacktrace:
 [1] Altro.iLQRSolver(prob::Problem{RK3, Float64}, opts::SolverOptions{Float64}, stats::SolverStats{Float64}; kwarg_opts::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Altro ~/.julia/packages/Altro/LQNrj/src/ilqr/ilqr.jl:70
 [2] iLQRSolver
   @ ~/.julia/packages/Altro/LQNrj/src/ilqr/ilqr.jl:44 [inlined]
 [3] Altro.AugmentedLagrangianSolver(prob::Problem{RK3, Float64}, opts::SolverOptions{Float64}, stats::SolverStats{Float64}; solver_uncon::Type{Altro.iLQRSolver}, kwarg_opts::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Altro ~/.julia/packages/Altro/LQNrj/src/augmented_lagrangian/al_solver.jl:52
 [4] ALTROSolver(prob::Problem{RK3, Float64}, opts::SolverOptions{Float64}; infeasible::Bool, R_inf::Float64, solver_uncon::Type, kwarg_opts::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Altro ~/.julia/packages/Altro/LQNrj/src/altro/altro_solver.jl:35
 [5] ALTROSolver (repeats 2 times)
   @ ~/.julia/packages/Altro/LQNrj/src/altro/altro_solver.jl:17 [inlined]
 [6] run_traj(; gate_type::GateType, evolution_time::Float64, solver_type::SolverType, sqrtbp::Bool, integrator_type::IntegratorType, smoke_test::Bool, dt_inv::Int64, constraint_tol::Float64, al_tol::Float64, pn_steps::Int64, max_penalty::Float64, verbose::Bool, save::Bool, max_iterations::Int64, max_cost_value::Float64, qs::Vector{Float64}, benchmark::Bool)
   @ Main ~/Downloads/rbqoc-master/rbqoc/src/spin/spin13.jl:158
 [7] run_traj()
   @ Main ~/Downloads/rbqoc-master/rbqoc/src/spin/spin13.jl:62
 [8] top-level scope
   @ REPL[2]:1

Is there any way to fix this? Thanks!

Originally posted by @bobisnot in https://github.com/SchusterLab/rbqoc/issues/5#issuecomment-1334411654

tpr0p commented 1 year ago

Hey @bobisnot,

Thanks for posting this issue.

It looks like some of the arguments to Objective do not have the expected type. Typically, the coloring in the Julia REPL gives you a lot of information about which arguments match the types from the "closest candidates" (white) and which do not (red). Using this, can you provide information about which arguments don't have the correct type?

bobisnot commented 1 year ago

REPL shows that the following arguments (marked in codeblocks) do not match. I'm not sure what the issue is though.

ERROR: MethodError: no method matching (Objective{QuadraticCost{n, m, T, SizedMatrix{n, n, T, 2, TData} where TData<:AbstractMatrix{T}, SizedMatrix{m, m, T, 2, TData} where TData<:AbstractMatrix{T}}} where {n, m, T})( ::Objective{QuadraticCost{11, 1, Float64, SizedMatrix{11, 11, Float64, 2, Matrix{Float64}}, SizedMatrix{1, 1, Float64, 2, Matrix{Float64}}}} , ::Model) Closest candidates are: (Objective{QuadraticCost{n, m, T, SizedMatrix{n, n, T, 2, TData} where TData<:AbstractMatrix{T}, SizedMatrix{m, m, T, 2, TData} where TData<:AbstractMatrix{T}}} where {n, m, T})( ::Objective{QuadraticCost{n, m, T, SizedMatrix{n, n, T, 2, TData} where TData<:AbstractMatrix{T}, SizedMatrix{m, m, T, 2, TData} where TData<:AbstractMatrix{T}}} where {n, m, T} , ::AbstractModel) at ~/.julia/packages/TrajectoryOptimization/gPd37/src/objective.jl:85

bobisnot commented 1 year ago

Hey @tpr0p , sorry for the bump, I just had another question: Looking into the code a bit, is there a particular reason the XPI gate is written as [0 -im; -im 0] as opposed to just [0 1; 1 0]? Does this global phase help the optimizer somehow? Coderef: https://github.com/SchusterLab/rbqoc/blob/master/src/spin/spin.jl#L319

Thanks!

tpr0p commented 1 year ago

@bobisnot No worries, happy to answer any questions. Unfortunately, I haven't had time to help debug your error. Regarding the gate, see the Rx(theta) definition https://www.quantum-inspire.com/kbase/rx-gate/. Note that Rx(theta) = e^{i \theta X} where X is the Pauli matrix you're familiar with [0 1; 1 0]. The optimizer is phase sensitive, so if you're trying to do a simple state transfer, picking the correct phase will make a difference in the minimum time required to complete that operation.

tpr0p commented 1 year ago

closing due to inactivity. feel free to reopen the issue if this didn’t resolve it