JuliaQuantumControl / QuantumControl.jl

Julia Framework for Quantum Dynamics and Control
https://juliaquantumcontrol.github.io/QuantumControl.jl/
MIT License
47 stars 6 forks source link

How to use LockedAmplitude? #63

Closed mrs504aa closed 3 months ago

mrs504aa commented 3 months ago

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? Is there any way to put in a time-dependent parameter which should not be optimized?

goerz commented 3 months ago

One thing that pops out is that you didn't actually use the LockedAmplitude in the Hamiltonian.

hamiltonian(HStatic, (HOmega, Omega), (HDelta, Delta))

should be

hamiltonian(HStatic, (HOmega, OmegaAmp), (HDelta, DeltaAmp))

(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)