Best type for passing parameters to an ODE

New to julia, apologies if this is trivial. I am struggling to work out how to pass parameters to an ODE.

In short, I have two systems: one 7N dimensional (with N in the hundreds or thousands) and a 7-D one. I am not even at the point of running the 7N-D version, but in planning to do this: parameters of that one are both vectors with N entries and N\times N-matrices.

Every run of the ODE, I choose different values of the parameters and need to run the 7-D version first, picking the relevant parameters. So I cannot manually prepare a vector of parameters (and I most definitely cannot do in the 7N-D version).

What I have this far is a Dict() with a load of different fields (“keys”/“values” pairs?). I do something like

p_tmp = Dict()
for curr_param in ["eta", "xi", "d", "epsilon", "gamma", "beta"]
    p_tmp[curr_param] = p[curr_param][p["idx_positive_IC"]]
end

to pick up the relevant parameters for the 7-D version. Then set up the solver and call.

prob = ODEProblem(SLLLDUU_rhs, IC, (tspan[1], tspan[end]), p_tmp)
sol = solve(prob)

I get the error

ERROR: ArgumentError: This problem does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin. Please use `remake`with the `p` keyword argument as a vector of values (paying attention toparameter order) or pass `interpret_symbolicmap = false` as a keyword argument

It is my understanding that I should be using remake, but I don’t understand the purpose of that function and I don’t like using things I don’t understand. Or I could transform to a NamedTuple using something like

p_tmp = NamedTuple([pair for pair in p_tmp])

But that fails (ERROR: TypeError: in typeassert, expected Symbol, got a value of type String). Or I could use ComponentArrays, but I am not sure how that would scale up to entries that are matrices. (Actually, not sure about that for NamedTuples either.)

Anyway, any recommendations on what to do? Thanks!!

ComponentArrays.jl might be what you’re looking for: they appear as AbstractVectors but have keys in the same way structs do to be accessed with the dot . notation.

2 Likes

Looks good indeed, thanks… I was trying to convert my Dict to that and failing miserably, so instead I load all my parameters in a ComponentArray from the start and I seem to be on the right track.

But now that raises another issue, which I will ask about in the general usage category because it is not specific to modelling.

NamedTuples are also good if all you need is to unpack some parameters