I am contemplating writing a macro @parameterized
that turns
@parameterized function ControlField(
t; # variable
ΔT₁, ΔT₂, ΔT₃, ϕ₁=0.0, ϕ₂=0.0, ϕ₃=0.0, E₀₁, E₀₂, E₀₃, # parameters
a::Float64=100.0 # constants (deteced by having type annotation)
)
_tanhfield(t; E₀=E₀₃, t₁=(ΔT₁+ΔT₂), t₂=(ΔT₁+ΔT₂+ΔT₃), a=E.a) * cos(ϕ₃)
end
into
struct ControlField <: ParameterizedFunction
parameters::ComponentVector{Float64,Vector{Float64},Tuple{Axis{(ΔT₁=1, ΔT₂=2, ΔT₃=3, ϕ₁=4, ϕ₂=5, ϕ₃=6, E₀₁=7, E₀₂=8, E₀₃=9)}}}
a::Float64
end
# Maybe also a nice keyword-argument constructor here.
function (E::ControlField)(t)
@unpack E₀₃, ΔT₁, ΔT₂, ΔT₃, ϕ₃ = E.parameters
_tanhfield(t; E₀=E₀₃, t₁=(ΔT₁+ΔT₂), t₂=(ΔT₁+ΔT₂+ΔT₃), a=E.a) * sin(ϕ₃)
end
Question 1: That seems like it should be doable, right? (Anybody getting hooked to write part of that macro for me? ) The @unpack
in the output would have to be handled via macroexpand
, right? Any other useful tips for going about this?
Question 2: Is my understanding correct that any code using that macro would need to import the names used in the expanded version:
using ComponentArrays: ComponentVector, Axis
using UnPack: @unpack # not needed if I'm using `macroexpand`, I guess
using QuantumPropagators.Controls: ParameterizedFunction
Or is there some way where these names only need to be available in the place where the macro is being defined?