Skip to content

Commit

Permalink
Merge pull request #82 from JuliaQuantumControl/abstract-optimization…
Browse files Browse the repository at this point in the history
…-result

Make `GrapeResult` an `AbstactOptimizationResult`
  • Loading branch information
goerz authored Sep 16, 2024
2 parents 5f7fad5 + 9fa893d commit 768f41f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 61 deletions.
3 changes: 0 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ QuantumGradientGenerators = "a563f35e-61db-434d-8c01-8b9e3ccdfd85"

[weakdeps]
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
Krotov = "b05dcdc7-62f6-4360-bf2c-0898bba419de"


[extensions]
GRAPEOptimExt = "Optim"
GRAPEKrotovExt = "Krotov"
# GRAPELBFGSBExt = "LBFGSB"
# Cannot load GRAPELBFGSBExt as an extension if LBFGSB is a hard
# dependency. See `include` in `src/GRAPE.jl`.

[compat]
Dates = "1"
LBFGSB = "0.4"
Krotov = ">=0.7.1"
LinearAlgebra = "1"
Optim = "1"
Printf = "1"
Expand Down
54 changes: 0 additions & 54 deletions ext/GRAPEKrotovExt.jl

This file was deleted.

9 changes: 6 additions & 3 deletions src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ function optimize_grape(problem)
local Ψₖ = prop_step!(wrk.fw_propagators[k])
if haskey(wrk.fw_prop_kwargs[k], :callback)
local cb = wrk.fw_prop_kwargs[k][:callback]
local observables = get(wrk.fw_prop_kwargs[k], :observables, _StoreState())
local observables =
get(wrk.fw_prop_kwargs[k], :observables, _StoreState())
cb(wrk.fw_propagators[k], observables)
end
(Φₖ !== nothing) && write_to_storage!(Φₖ, n + 1, Ψₖ)
Expand Down Expand Up @@ -293,7 +294,8 @@ function optimize_grape(problem)
χ̃ₖ = prop_step!(wrk.bw_grad_propagators[k])
if haskey(wrk.bw_grad_prop_kwargs[k], :callback)
local cb = wrk.bw_grad_prop_kwargs[k][:callback]
local observables = get(wrk.fw_prop_kwargs[k], :observables, _StoreState())
local observables =
get(wrk.fw_prop_kwargs[k], :observables, _StoreState())
cb(wrk.bw_grad_propagators[k], observables)
end
if supports_inplace(Ψₖ)
Expand Down Expand Up @@ -395,7 +397,8 @@ function optimize_grape(problem)
prop_step!(wrk.bw_propagators[k])
if haskey(wrk.bw_prop_kwargs[k], :callback)
local cb = wrk.bw_prop_kwargs[k][:callback]
local observables = get(wrk.bw_prop_kwargs[k], :observables, _StoreState())
local observables =
get(wrk.bw_prop_kwargs[k], :observables, _StoreState())
cb(wrk.bw_propagators[k], observables)
end
end
Expand Down
9 changes: 8 additions & 1 deletion src/result.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using QuantumControl.QuantumPropagators.Controls: get_controls, discretize
using QuantumControl: AbstractOptimizationResult
using Printf
using Dates

Expand Down Expand Up @@ -26,7 +27,7 @@ The attributes of a `GrapeResult` object include
All of the above attributes may be referenced in a `check_convergence` function
passed to [`optimize(problem; method=GRAPE)`](@ref QuantumControl.optimize(::ControlProblem, ::Val{:GRAPE}))
"""
mutable struct GrapeResult{STST}
mutable struct GrapeResult{STST} <: AbstractOptimizationResult
tlist::Vector{Float64}
iter_start::Int64 # the starting iteration number
iter_stop::Int64 # the maximum iteration number
Expand Down Expand Up @@ -107,3 +108,9 @@ GRAPE Optimization Result
- Ended at $(r.end_local_time) ($(Dates.canonicalize(Dates.CompoundPeriod(r.end_local_time - r.start_local_time))))
"""
)


function Base.convert(::Type{GrapeResult}, result::AbstractOptimizationResult)
defaults = Dict{Symbol,Any}(:f_calls => 0, :fg_calls => 0,)
return convert(GrapeResult, result, defaults)
end

0 comments on commit 768f41f

Please sign in to comment.