Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Fix get_control_deriv for LockedAmplitude
Browse files Browse the repository at this point in the history
  • Loading branch information
goerz committed Apr 17, 2024
1 parent e462ece commit 4d130e1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/derivs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ get_control_deriv(operator::Operator, control) = nothing

# Amplitudes

get_control_deriv(ampl::LockedAmplitude, control) =
(control ampl.control) ? LockedAmplitude(ampl.shape) : 0.0
get_control_deriv(ampl::LockedAmplitude, control) = 0.0

get_control_deriv(ampl::ShapedAmplitude, control) =
(control ampl.control) ? LockedAmplitude(ampl.shape) : 0.0
43 changes: 43 additions & 0 deletions test/test_derivs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using QuantumPropagators.Controls
using QuantumPropagators: Generator, Operator
using QuantumControlTestUtils.RandomObjects: random_matrix, random_state_vector
using QuantumControl.Interfaces: check_generator, check_amplitude
using QuantumPropagators.Amplitudes: LockedAmplitude, ShapedAmplitude


_AT(::Generator{OT,AT}) where {OT,AT} = AT
Expand Down Expand Up @@ -118,3 +119,45 @@ end
@test check_generator(H; state=Ψ, tlist, for_gradient_optimization=true)

end


@testset "LockedAmplitude get_control_derivs" begin

shape(t) = 1.0
tlist = [0.0, 0.5, 1.0]

ampl1 = LockedAmplitude(shape)
ampl2 = LockedAmplitude(shape, tlist)

@test get_control_deriv(ampl1, t -> 0.0) == 0.0
@test get_control_deriv(ampl1, shape) == 0.0

@test get_control_deriv(ampl2, t -> 0.0) == 0.0
@test get_control_deriv(ampl2, shape) == 0.0

end


@testset "ShapedAmplitude get_control_derivs" begin

shape(t) = 1.0
control(t) = 0.5
tlist = [0.0, 0.5, 1.0]

ampl1 = ShapedAmplitude(control; shape)
ampl2 = ShapedAmplitude(control, tlist; shape)

@test get_control_deriv(ampl1, t -> 0.0) == 0.0
@test get_control_deriv(ampl1, shape) == 0.0
@test get_control_deriv(ampl1, control) == LockedAmplitude(shape)

@test get_control_deriv(ampl2, t -> 0.0) == 0.0
@test get_control_deriv(ampl2, shape) == 0.0
control2 = get_controls(ampl2)[1]
@test control2 control # should have been discretized
@test ampl2.shape shape # should have been discretized
@test control2 isa Vector{Float64}
@test ampl2.shape isa Vector{Float64}
@test get_control_deriv(ampl2, control2) == LockedAmplitude(ampl2.shape)

end

0 comments on commit 4d130e1

Please sign in to comment.