Skip to content

How to use LockedAmplitude? #63

Closed
Closed

Description

@mrs504aa

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?

Activity

  1. goerz commented on Apr 16, 2024

    @goerz
    Member

    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)

  2. locked and limited conversation to collaborators on Apr 16, 2024
  3. converted this issue into a discussion #64 on Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions