ComputationalPhysiology / gotran

Library for declaring and translating ODEs
http://computationalphysiology.github.io/gotran/
GNU Lesser General Public License v3.0
2 stars 1 forks source link

Inconstistent state order between Python and C when using enum-based indexing #1

Closed KGHustad closed 4 years ago

KGHustad commented 4 years ago

With the model specified by the following file, sincos.ode, there's a difference in the ordering of states in the generated Python code and in the generated C code using enum-based indexing.

states("main",
s = 0,
c = 1)

expressions("main")
ds_dt = -c
dc_dt = s

We then generate code with the following commands

gotran2py sincos.ode
gotran2c sincos.ode --code.body.use_enum=1

The C code ends up reordering the states in the enum declaration, whereas Python keeps the states in the order they were declared in sincos.ode.

C

enum state {
  STATE_c,
  STATE_s,
  NUM_STATES,
};

Python

s, c = states

We should make the ordering consistent to avoid confusing bugs when mixing Python and C.