Skip to content

Commit 07998cc

Browse files
committed
Add derivative for GuidedAmplitude
1 parent 1ece6f0 commit 07998cc

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/derivs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using QuantumPropagators.Generators: Generator, Operator, _make_generator, evaluate
2-
using QuantumPropagators.Amplitudes: LockedAmplitude, ShapedAmplitude
2+
using QuantumPropagators.Amplitudes: LockedAmplitude, ShapedAmplitude, GuidedAmplitude
33

44

55
"""Get a vector of the derivatives of `generator` w.r.t. each control.
@@ -102,3 +102,6 @@ get_control_deriv(ampl::LockedAmplitude, control) = 0.0
102102

103103
get_control_deriv(ampl::ShapedAmplitude, control) =
104104
(control ampl.control) ? LockedAmplitude(ampl.shape) : 0.0
105+
106+
get_control_deriv(ampl::GuidedAmplitude, control) =
107+
(control ampl.control) ? LockedAmplitude(ampl.shape) : 0.0

test/test_derivs.jl

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using Test
22
using LinearAlgebra
33
using QuantumControl.Controls: get_control_deriv, get_control_derivs
4-
using QuantumPropagators.Generators
5-
using QuantumPropagators.Controls
64
using QuantumPropagators: Generator, Operator
5+
using QuantumPropagators.Controls: evaluate, get_controls
76
using QuantumControlTestUtils.RandomObjects: random_matrix, random_state_vector
87
using QuantumControl.Interfaces: check_generator, check_amplitude
9-
using QuantumPropagators.Amplitudes: LockedAmplitude, ShapedAmplitude
8+
using QuantumPropagators.Amplitudes: LockedAmplitude, ShapedAmplitude, GuidedAmplitude
109
import QuantumPropagators
1110
import QuantumControl
1211

@@ -166,3 +165,29 @@ end
166165
@test get_control_deriv(ampl2, control2) == LockedAmplitude(ampl2.shape)
167166

168167
end
168+
169+
170+
@testset "GuidedAmplitude get_control_derivs" begin
171+
172+
shape(t) = 1.0
173+
guide(t) = 0.1
174+
control(t) = 0.5
175+
tlist = [0.0, 0.5, 1.0]
176+
177+
ampl1 = GuidedAmplitude(control; shape, guide)
178+
ampl2 = GuidedAmplitude(control, tlist; shape, guide)
179+
180+
@test get_control_deriv(ampl1, t -> 0.0) == 0.0
181+
@test get_control_deriv(ampl1, shape) == 0.0
182+
@test get_control_deriv(ampl1, control) == LockedAmplitude(shape)
183+
184+
@test get_control_deriv(ampl2, t -> 0.0) == 0.0
185+
@test get_control_deriv(ampl2, shape) == 0.0
186+
control2 = get_controls(ampl2)[1]
187+
@test control2 control # should have been discretized
188+
@test ampl2.shape shape # should have been discretized
189+
@test control2 isa Vector{Float64}
190+
@test ampl2.shape isa Vector{Float64}
191+
@test get_control_deriv(ampl2, control2) == LockedAmplitude(ampl2.shape)
192+
193+
end

0 commit comments

Comments
 (0)