Tim-Salzmann/l4casadi

Questions about mpc_mlp_example.py

Closed this issue · 8 comments

Hello:
I would like to ask why I need to execute several lines when solving mpc

  for i in range(N):
      x_l.append(solver.get(i, "x"))
  params = learned_dyn_model.get_params(np.stack(x_l, axis=0))
  for i in range(N):
      solver.set(i, "p", params[i])

I understand that the main purpose is to perform a first-order Taylor expansion and restore the original output of the model, but shouldn't it be in differential form, i.e. df_a? Isn't this in line with the explicit dynamics definition process,like this

image

Hi,

I understand that the main purpose is to perform a first-order Taylor expansion and restore the original output of the model, but shouldn't it be in differential form, i.e. df_a? Isn't this in line with the explicit dynamics definition process,like this

Yes, I think this is correct and Acados expects the dynamics model to be in differential form. However this is unrelated to the code you show.

The code does exactly what you say. It taylor approximates the model around each node and updates the model at each node. Hence the for loop. The learned dyn model should be in differential form.

Let me know if this answers your problems!

Tim

Thanks for your answer! I understand what you mean. If there is a pytorch model, it should be trained in a differential way, right? Can it support discrete dynamics models (trained using pytorch)?

image

Is it possible to define the dynamics model in discrete form (and train the pytorch model) and then define it in discrete form in acados

Can you train a discrete dynamics model in PyTorch?

Yes

Can you include it in CasADi via L4CasADi?

Yes

Can you include it in an MPC problem defined in CasADi?

Yes

Can you include it in an MPC problem defined in Acados?

I am not sure. This depends if Acados supports something like this and is a question for the Acados Forum.

Hope this helps
Tim

Thanks for your help!

Hello,
may I ask what the main purpose of this line of code is to swap the rows and columns to conform to the order defined by Casadi's notation (column priority)?

  return [a_t.cpu().numpy(), f_a.cpu().numpy(), df_a.transpose(-2, -1).cpu().numpy()

I think this is to bring it in the correct form for the Taylor Approximation

df_a is of shape [out_dims, in_dims] but the casadi Taylor (see above) expects [in_dims , out_dims].

Best
Tim

Thank you for your answer.