Generating C code from JuMP.jl model

I have defined an MILP model in JuMP.jl. This model works great. Now I would like to implement it on a real time controller in C.

Is there a way to generate C code for my model so that I can just copy paste it into my project?

There are some frameworks that offer this:

Is there any way to do this with JuMP?

2 Likes

What exactly is your “real-time controller”? JuMP does not have any facilities for C-code generation, but depending on what your target platform is, there may be other options than going through C code.

1 Like

See also: Code generation · Issue #124 · JuliaControl/ModelPredictiveControl.jl · GitHub

Probably not possible now, but perhaps in the future.

1 Like

I think its a cortex M33, need to double check this. Dont want to bother the hardware people during the weekend :wink:

That’s interesting! But I’m glad I’m not the only one looking at this.

1 Like

JuMP does not support transpiling to C, and it is not a feature that we have planned on our roadmap. (Just use cvxpy/cvxgen?)

1 Like

Also if I understand correctly this wouldn’t just require JuMP but also an actual solver to generate the code from?

Yes, but most applicable solvers (e.g., SCS, ECOS) are in C and pretty trivial to compile.

In theory this could be done. JuMP ends up calling the C interfaces via ccall, so we “know” what C code to write. We just don’t currently trace these calls, and the various bridge reformulations mean that the user’s original JuMP model is often quite dissimilar to what actually gets solved. We also have limited support for parameters, which is a key component of how cvxpygen works.

3 Likes