Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary evaluation of chi #38

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@
ϵ⁽ⁱ⁾ = wrk.pulses0
ϵ⁽ⁱ⁺¹⁾ = wrk.pulses1

if haskey(wrk.kwargs, :chi)
chi! = wrk.kwargs[:chi]

Check warning on line 120 in src/optimize.jl

View check run for this annotation

Codecov / codecov/patch

src/optimize.jl#L120

Added line #L120 was not covered by tests
else
# we only want to evaluate `make_chi` if `chi` is not a kwarg
J_T_func = wrk.kwargs[:J_T]
chi! = make_chi(J_T_func, wrk.objectives)
end

if skip_initial_forward_propagation
@info "Skipping initial forward propagation"
else
Expand Down Expand Up @@ -145,7 +153,7 @@
try
while !wrk.result.converged
i = i + 1
krotov_iteration(wrk, ϵ⁽ⁱ⁾, ϵ⁽ⁱ⁺¹⁾)
krotov_iteration(wrk, ϵ⁽ⁱ⁾, ϵ⁽ⁱ⁺¹⁾, chi!)
update_result!(wrk, i)
update_hook!(wrk, i, ϵ⁽ⁱ⁺¹⁾, ϵ⁽ⁱ⁾)
info_tuple = info_hook(wrk, i, ϵ⁽ⁱ⁺¹⁾, ϵ⁽ⁱ⁾)
Expand Down Expand Up @@ -207,11 +215,10 @@
_eval_mu(μ::AbstractMatrix, _...) = μ


function krotov_iteration(wrk, ϵ⁽ⁱ⁾, ϵ⁽ⁱ⁺¹⁾)
function krotov_iteration(wrk, ϵ⁽ⁱ⁾, ϵ⁽ⁱ⁺¹⁾, chi!)

χ = [propagator.state for propagator in wrk.bw_propagators]
J_T_func = wrk.kwargs[:J_T]
chi! = get(wrk.kwargs, :chi, make_chi(J_T_func, wrk.objectives))
tlist = wrk.result.tlist
N_T = length(tlist) - 1
N = length(wrk.objectives)
Expand Down
Loading