-
I noticed that there are ShapedAmplitude and LockedAmplitude described in the documentation. I happen to calculate a optimization problem in which there is one time-dependent parameter that I don't want to optimize. So I defined this parameter as shape(t) = blackman(t, TimeList[1], TimeList[end]) * Omega
OmegaAmp = LockedAmplitude(shape, TimeList) And I have another time-dependent parameter to be optimized shape(t) = -cos(2pi * t / FinalTime) * 0.2 + 0.3
DeltaAmp = ShapedAmplitude(t -> Delta, TimeList; shape=shape) The I throw them into the Hamiltonian which is hamiltonian(HStatic, (HOmega, Omega), (HDelta, Delta)) When I defined the problem, there is a warning says that ┌ Warning: Collected amplitudes are of disparate types
└ @ QuantumPropagators.Generators C:\Users\mrs504aa\.julia\packages\QuantumPropagators\Ndzht\src\generators.jl:388 And when I run the optimization, an error message shows up ┌ Error: `get_control_derivs(generator, controls)` must be defined.
│ exception =
│ type LockedPulseAmplitude has no field control
│ Stacktrace:
│ [1] getproperty
│ @ .\Base.jl:37 [inlined]
│ [2] get_control_deriv(ampl::QuantumPropagators.Amplitudes.LockedPulseAmplitude, control::Vector{Float64})
│ @ QuantumControlBase C:\Users\mrs504aa\.julia\packages\QuantumControlBase\WEAnn\src\derivs.jl:101
│ [3] get_control_deriv(generator::QuantumPropagators.Generators.Generator{Matrix{ComplexF64}, Any}, control::Vector{Float64})
│ @ QuantumControlBase C:\Users\mrs504aa\.julia\packages\QuantumControlBase\WEAnn\src\derivs.jl:61
│ [4] get_control_derivs(generator::QuantumPropagators.Generators.Generator{Matrix{ComplexF64}, Any}, controls::Tuple{Vector{Float64}})
│ @ QuantumControlBase C:\Users\mrs504aa\.julia\packages\QuantumControlBase\WEAnn\src\derivs.jl:20
│ [5] check_generator(generator::QuantumPropagators.Generators.Generator{Matrix{ComplexF64}, Any}; state::Vector{ComplexF64}, tlist::Vector{Float64}, for_mutable_state::Bool, for_immutable_state::Bool, for_expval::Bool, for_gradient_optimization::Bool, atol::Float64, quiet::Bool, _message_prefix::String)
│ @ QuantumControlBase C:\Users\mrs504aa\.julia\packages\QuantumControlBase\WEAnn\src\check_generator.jl:75
└ @ QuantumControlBase C:\Users\mrs504aa\.julia\packages\QuantumControlBase\WEAnn\src\check_generator.jl:90 My question is that did I mis-understand the usage of LockedAmplitude? New edit: Delta = -18.0 * 2pi # MHz
Omega = 2.8 * 2pi # MHz
C6 = 24 * 5.75^6 * 2pi # MHz um^6
R = 5.5 # um
SWAPGate = zeros(ComplexF64, 4, 4)
SWAPGate[1, 1] = 1
SWAPGate[2, 3] = 1
SWAPGate[3, 2] = 1
SWAPGate[4, 4] = 1
TargetGate = SWAPGate
FinalTime = 1.0
TimeStep = 0.005
TimeList = collect(range(0, FinalTime, step=TimeStep))
function TwoRydbergHamiltonian(; Omega, Delta)
HStatic = zeros(ComplexF64, 4, 4)
HStatic[4, 4] = C6 / R^6
HOmega = zeros(ComplexF64, 4, 4)
# I deleted the details of the defination.
HDelta = zeros(ComplexF64, 4, 4)
# I deleted the details of the defination.
return hamiltonian(HStatic, (HOmega, Omega), (HDelta, Delta))
end
shape(t) = blackman(t, TimeList[1], TimeList[end]) * Omega
OmegaAmp = LockedAmplitude(shape, TimeList)
shape(t) = -cos(2pi * t / FinalTime) * 0.2 + 0.3
DeltaAmp = ShapedAmplitude(t -> Delta, TimeList; shape=shape)
Hamiltonian = TwoRydbergHamiltonian(Omega=OmegaAmp, Delta=DeltaAmp) Then I define the basis and trajectories InitialBasis = [zeros(ComplexF64, 4) for i in 1:4]
for i in 1:4
InitialBasis[i][i] = 1
end
TargetBasis = TargetGate * InitialBasis
Trajectories = [
Trajectory(initial_state=Psi, target_state=PsiTarget, generator=Hamiltonian) for
(Psi, PsiTarget) ∈ zip(InitialBasis, TargetBasis)
] The problem and solver codes are Problem = ControlProblem(
Trajectories,
TimeList;
iter_stop=100,
J_T=J_T_ss,
check_convergence=res -> begin
(
(res.J_T > res.J_T_prev) &&
(res.converged = true) &&
(res.message = "Loss of monotonic convergence")
)
((res.J_T <= 1e-3) && (res.converged = true) && (res.message = "J_T < 10⁻³"))
end,
prop_method=Cheby,
use_threads=true,
)
Opt_Result = optimize(Problem; method=GRAPE) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
One thing that pops out is that you didn't actually use the
should be
(BTW, if you ever want someone else to read your code, don't use CamelCase for variable names in Julia. CamelCase indicates Module or Types names) |
Beta Was this translation helpful? Give feedback.
Great, thanks for the clarification! It looks like you found a bug! JuliaQuantumControl/QuantumControlBase.jl#77