Skip to content

Commit

Permalink
Adapt to mandatory method in propagate
Browse files Browse the repository at this point in the history
  • Loading branch information
goerz committed Nov 27, 2023
1 parent 83295ce commit 2d045f3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
8 changes: 7 additions & 1 deletion examples/perfect_entanglers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ objectives = [
# We can analyze how all of the basis states evolve under the guess controls in
# one go:

guess_states = propagate_objectives(objectives, tlist; use_threads=true);
using QuantumPropagators: Cheby

guess_states = propagate_objectives(objectives, tlist; method=Cheby, use_threads=true);

# The gate implemented by the guess controls is

Expand Down Expand Up @@ -346,6 +348,7 @@ opt_states = propagate_objectives(
IdDict(zip(get_controls(objectives), opt_result.optimized_controls))
),
tlist;
method=Cheby,
use_threads=true
);

Expand Down Expand Up @@ -468,6 +471,7 @@ problem = ControlProblem(
objectives=objectives,
tlist=tlist,
iter_stop=100,
prop_method=Cheby,
J_T=J_T_PE,
chi=chi_pe,
check_convergence=res -> begin
Expand Down Expand Up @@ -509,6 +513,7 @@ opt_states = propagate_objectives(
IdDict(zip(get_controls(objectives), opt_result.optimized_controls))
),
tlist;
method=Cheby,
use_threads=true
);

Expand Down Expand Up @@ -568,6 +573,7 @@ opt_states_direct = propagate_objectives(
IdDict(zip(get_controls(objectives), opt_result_direct.optimized_controls))
),
tlist;
method=Cheby,
use_threads=true
);

Expand Down
10 changes: 8 additions & 2 deletions examples/simple_state_to_state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ projectdir(names...) = joinpath(PROJECTDIR, names...)
datadir(names...) = projectdir("data", names...)

using QuantumControl
using QuantumPropagators: ExpProp

#jl using Test
#jl println("")
Expand Down Expand Up @@ -103,7 +104,7 @@ function plot_control(pulse::Vector, tlist)
plot(tlist, pulse, xlabel="time", ylabel="amplitude", legend=false)
end

plot_control::T, tlist) where {T<:Function} = plot_control([ϵ(t) for t in tlist], tlist);
plot_control::Function, tlist) = plot_control([ϵ(t) for t in tlist], tlist);
#-
fig = plot_control(ϵ, tlist)
#jl display(fig)
Expand Down Expand Up @@ -137,8 +138,9 @@ using QuantumControl.Functionals: J_T_sm
problem = ControlProblem(
objectives=objectives,
tlist=tlist,
pulse_options=Dict(),
iter_stop=500,
prop_method=ExpProp,
pulse_options=Dict(),
J_T=J_T_sm,
check_convergence=res -> begin
((res.J_T < 1e-3) && (res.converged = true) && (res.message = "J_T < 10⁻³"))
Expand All @@ -150,9 +152,11 @@ problem = ControlProblem(

# Before running the optimization procedure, we first simulate the dynamics under the guess field $\epsilon_{0}(t)$. The following solves equation of motion for the defined objective, which contains the initial state $\ket{\Psi_{\init}}$ and the Hamiltonian $\op{H}(t)$ defining its evolution.


guess_dynamics = propagate_objective(
objectives[1],
problem.tlist;
method=ExpProp,
storage=true,
observables=-> abs.(Ψ) .^ 2,)
)
Expand Down Expand Up @@ -184,6 +188,7 @@ opt_result_LBFGSB = @optimize_or_load(
datadir("TLS", "GRAPE_opt_result_LBFGSB.jld2"),
problem;
method=:grape,
prop_method=ExpProp,
force=true,
info_hook=(
GRAPELinesearchAnalysis.plot_linesearch(datadir("TLS", "Linesearch", "LBFGSB")), #md
Expand Down Expand Up @@ -270,6 +275,7 @@ using QuantumControl.Controls: substitute
opt_dynamics = propagate_objective(
substitute(objectives[1], IdDict=> opt_result_LBFGSB.optimized_controls[1])),
problem.tlist;
method=ExpProp,
storage=true,
observables=-> abs.(Ψ) .^ 2,)
)
Expand Down
38 changes: 16 additions & 22 deletions src/workspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,34 +185,28 @@ function GrapeWrk(problem::QuantumControlBase.ControlProblem; verbose=false)
fw_storage = [init_storage(obj.initial_state, tlist) for obj in objectives]
kwargs[:piecewise] = true # only accept piecewise propagators
fw_prop_method = [
Val(
QuantumControlBase.get_objective_prop_method(
obj,
:fw_prop_method,
:prop_method;
kwargs...
)
QuantumControlBase.get_objective_prop_method(
obj,
:fw_prop_method,
:prop_method;
kwargs...
) for obj in objectives
]
bw_prop_method = [
Val(
QuantumControlBase.get_objective_prop_method(
obj,
:bw_prop_method,
:prop_method;
kwargs...
)
QuantumControlBase.get_objective_prop_method(
obj,
:bw_prop_method,
:prop_method;
kwargs...
) for obj in objectives
]
grad_prop_method = [
Val(
QuantumControlBase.get_objective_prop_method(
obj,
:grad_prop_method,
:bw_prop_method,
:prop_method;
kwargs...
)
QuantumControlBase.get_objective_prop_method(
obj,
:grad_prop_method,
:bw_prop_method,
:prop_method;
kwargs...
) for obj in objectives
]

Expand Down
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ include("download_dumps.jl")
# Note: comment outer @testset to stop after first @safetestset failure
@time @testset verbose = true "GRAPE.jl Package" begin

print("\n* Pulse Optimization (test_pulse_optimization.jl)")
println("\n* Pulse Optimization (test_pulse_optimization.jl)")
@time @safetestset "Pulse Optimization" begin
include("test_pulse_optimization.jl")
end

print("\n* Emptry Optimization (test_empty_optimization.jl)")
println("\n* Empty Optimization (test_empty_optimization.jl)")
@time @safetestset "Empty Optimization" begin
include("test_empty_optimization.jl")
end

print("\n* Taylor Gradient (test_taylor_grad.jl):")
println("\n* Taylor Gradient (test_taylor_grad.jl):")
@time @safetestset "Taylor Gradient" begin
include("test_taylor_grad.jl")
end

print("\n* Example 1 (examples/simple_state_to_state.jl):")
@time @safetestset "Example 1" begin
println("\n* Example 1 (examples/simple_state_to_state.jl):")
@time @safetestset "Example 1 (simple_state_to_state)" begin
include(joinpath("examples", "simple_state_to_state.jl"))
end

print("\n* Example 2 (examples/perfect_entanglers.jl):")
@time @safetestset "Example 2" begin
println("\n* Example 2 (examples/perfect_entanglers.jl):")
@time @safetestset "Example 2 (perfect_entanglers)" begin
include(joinpath("examples", "perfect_entanglers.jl"))
end

Expand Down

0 comments on commit 2d045f3

Please sign in to comment.