Skip to content

Conversation

micahkc
Copy link

@micahkc micahkc commented May 8, 2025

No description provided.

Signed-off-by: micahkc <mkcondie01@gmail.com>
@micahkc micahkc force-pushed the casadi-dae-template branch from e762954 to a2c2378 Compare June 11, 2025 22:10
Signed-off-by: micahkc <mkcondie01@gmail.com>
casadi dae templates
Signed-off-by: micahkc <mkcondie01@gmail.com>
@micahkc micahkc force-pushed the casadi-dae-template branch from a2c2378 to 04c2c9e Compare June 11, 2025 22:16
@JuliusFrontzek
Copy link

Thanks for the great work! I am looking forward to this PR.

I would like to give some feedback as I am having three issues with it so far, for which I am providing two simple example models:

model TestModel
    input Real u;
    output Real x2;
    parameter Real c1 = 1.0;
    parameter Real c2 = c1;
    Real x1;
equation
    der(x1) = c1*x1 + u;
    der(x2) = c2*x2;
end TestModel;

When running rumoca ./tests/models/TestModel.mo -t ./tests/templates/casadi_dae.jinja > ./tests/test_model.py on this model, the resulting Python file contains these lines:

        # Declare p

        c1 = dae.add('c1', 'parameter', 'tunable', dict(start = 1.0))
        c2 = dae.add('c2', 'parameter', 'tunable', dict(start = c1))

which throws this error in CasADi:

NotImplementedError: Wrong number or type of arguments for overloaded function 'DaeBuilder_add'.
  Possible prototypes are:
    add(self,str,dict)
    add(self,str,str,dict)
    add(self,str,str,str,dict)
    add(self,str,str,str,MX,dict)
  You have: '(DaeBuilder,str,str,str,str:MX)'

Because instead of a numeric starting value, the MX variable c1 is passed. For now, I can manually replace these alias assignments, but since they're pretty common in flattened Modelica files, I assume that this should be treated differently in the future.

When fixing this error by manually replacing c2 with c1 in the second ode and removing c2 altogether, I run into another problem: The output (which is simply the state x2 in this case) is not recognized, but I assume that this is a known limitation for now.

Finally, when adding exponents in my equations, I get an "UNHANDLED OP" statement in the Python code.
E.g.:

model TestModel2
    Real x1;
equation
    der(x1) = x1 ^ 2;
end TestModel2;

After running rumoca ./tests/models/TestModel2.mo -t ./tests/templates/casadi_dae.jinja > ./tests/test_model2.py the resulting Python file contains this snippet

 dae.eq(der_x1, (x1 UNHANDLED OP: {
    "Exp": {
        "location": {
            "end": 0,
            "end_column": 0,
            "end_line": 0,
            "file_name": "",
            "start": 0,
            "start_column": 0,
            "start_line": 0,
        },
        "text": "",
        "token_number": 0,
        "token_type": 0,
    },
} 2.0))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants