Is there any way to extract the name of the parameter from the ODE function

I want to extract the name of the parameter from the ODE function to make the tuple out of given parameters.
For example, we have an ODE function:

function f(du,u,p,t)
  a, b = p
  x = u
  du[1] = a * x+b * x^2

and I want to create a tuple for the parameters automatically according to the function, like:

para_tuple = (a = 1,b = 2)

How can I do that? (may use @ntuple function in DrWatson.jl.

Many thanks!

I don’t quite get the question. Try again with a bit more detail? You can use a NamedTuple for p though.

Hi Chirs!
Thanks so much for your time!
Usually, we define an ODEproblem with a vector para = [1.0,2.0] like:

function f!(du,u,p,t)
  a, b = p
  x = u
  du[1] = a * x+b * x^2
u0 = [0.0]
para = [1.0,2.0]
prob = ODEProblem(f,u0,(0.0,100.0),para)

My question is, how can I create a namedtuple like para_tuple = (a = 1.0,b = 2.0) after the definition of prob?

I know NamedTuple, but how can I use it for p? Sorry I tried several times inside functionf! or like NamedTuple(prob.p) but it doesn’t work.

Many thanks man.

Just pass it in to ODEProblem

Sorry… still unclear. Could you be more specific?
NamedTuple should be key-value pairs if I am not wrong, but there is no value inside the function f!

also, how can I output it in ODEProblem? I think there is no field in prob.f or prob.p.

prob = ODEProblem(f,u0,(0.0,100.0),para_tuple) and then you can use it as p.

Sorry for the unclear message.
of course I know I can use a tuple (or dict) like para_tuple = (a = 1,b = 2) when defining an ODEProblem.

My question is, can I create a parameter tuple by an existing ODEProblem? I want to do this because the BifurcationKit.jl only accept parameters in tuples but I want to do the bifurcation analysis automatically after plotting the trajectory.

Until now that package can’t support the direct use of ODEProblem, so I want to ask about a possible transition between vector to tuple for parameters.

I just don’t understand what you mean by this sentence. Can you show an example of the code you would like to work? Maybe that would explain the idea.

What I have right now:

  • a defined ODE problem prob:
function f!(du,u,p,t)
  k1, k2, k3 = p
  x = u
  du[1] = k1 * x+ k2 * x^2 +k3
u0 = [0.0]
tspan = (0.0,100.0)
para = [1.0, 2.0, 1.0]   #parameters in vector form
prob = ODEProblem(f!,u0,tspan,para)

What I want then:

  • generate a tuple para_tuple from the prob which saves the keys as well as values of the parameter p :

para_tuple = (k1 = 1.0, k2 = 2.0, k3 = 1.0)

So that I can use it to define a BifurcationProblem (which requires the parameter tuple:

prob_bifur = BifurcationProblem(f!, u0, para_tuple, (@lens _.k1) )

If you just always use para_tuple, then your f code would still work and prob.p would be what you want. That seems like the most straightforward way?

Yes, you are right. But I am thinking of building a general function or module that can create parameter tuples for different models. I think I would try DrWatson.jl to find the possibility.

Still thank you Chris, for your time and your extraordinary work!