diff --git a/src/pymoca/backends/casadi/model.py b/src/pymoca/backends/casadi/model.py
index 8b788f4..a668e6f 100644
--- a/src/pymoca/backends/casadi/model.py
+++ b/src/pymoca/backends/casadi/model.py
@@ -767,6 +767,7 @@ class Model:
             alg_states = OrderedDict([(s.symbol.name(), s) for s in self.alg_states])
             inputs = OrderedDict([(s.symbol.name(), s) for s in self.inputs])
             parameters = OrderedDict([(s.symbol.name(), s) for s in self.parameters])
+            constants = OrderedDict([(s.symbol.name(), s) for s in self.constants])
 
             all_states = OrderedDict()
             all_states.update(states)
@@ -774,9 +775,11 @@ class Model:
             all_states.update(alg_states)
             all_states.update(inputs)
             all_states.update(parameters)
+            all_states.update(constants)
 
             # For now, we only eliminate algebraic states.
-            do_not_eliminate = set(list(der_states) + list(states) + list(inputs) + list(parameters))
+            do_not_eliminate = set(list(der_states) + list(states) + list(inputs)
+                                   + list(parameters) + list(constants))
 
             # When doing a `detect_aliases` pass multiple times, we have to avoid
             # handling aliases we already handled before as their states no longer

CasADi: a constant is allowed to be a canonical variable but it is not handled properly
The problem is well explained in the following example:

## Constant

If `c` is a constant then it may become a canonical variable with z as an alias but it will raise an error.

```modelica
model ConstantAlias

Real x;
Real z;
constant Real c=0;

equation

der(x) = c;
z = c;

end ConstantAlias;
```

```python
options = {'detect_aliases': True}
model = transfer_model(model_folder, 'ConstantAlias', options)
```

```
INFO:pymoca:Detecting aliases
Traceback (most recent call last):
  File "/home/pietro/anaconda3/envs/pymocaExp/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-d427935174b8>", line 32, in <module>
    model = transfer_model(model_folder, 'ConstantAlias', options)
  File "/home/pietro/Desktop/Thesis/git/pymoca/src/pymoca/backends/casadi/api.py", line 477, in transfer_model
    return _compile_model(model_folder, model_name, compiler_options)
  File "/home/pietro/Desktop/Thesis/git/pymoca/src/pymoca/backends/casadi/api.py", line 119, in _compile_model
    model.simplify(compiler_options)
  File "/home/pietro/Desktop/Thesis/git/pymoca/src/pymoca/backends/casadi/model.py", line 844, in simplify
    canonical_state = all_states[canonical]
KeyError: 'c'
```

## Parameter 

If `c` is a parameter then there are no problems:

```modelica
model ParameterAlias

Real x;
Real z;
parameter Real c=0;

equation

der(x) = c;
z = c;

end ParameterAlias;
```

```python
options = {'detect_aliases': True}
model = transfer_model(model_folder, 'ParameterAlias', options)
```
diff --git a/test/gen_casadi_test.py b/test/gen_casadi_test.py
index 2adf5e5..28b7666 100644
--- a/test/gen_casadi_test.py
+++ b/test/gen_casadi_test.py
@@ -1388,6 +1388,54 @@ class GenCasadiTest(unittest.TestCase):
         self.assert_model_equivalent_numeric(casadi_model, ref_model)
         self.assertEqual(casadi_model.states[0].aliases, {'-alias_neg', 'alias_pos'})
 
+    def test_constant_aliases(self):
+        txt = """
+            model ConstantAlias
+
+              Real x;
+              Real z;
+              constant Real c = 0;
+
+              equation
+
+              der(x) = c;
+              z = c;
+
+            end ConstantAlias;
+        """
+
+        ast_tree = parser.parse(txt)
+        casadi_model = gen_casadi.generate(ast_tree, 'ConstantAlias')
+        casadi_model.simplify({'detect_aliases': True})
+
+        c = casadi_model.constants[0]
+        self.assertSetEqual(c.aliases, {'z'})
+        self.assertEqual(len(casadi_model.alg_states), 0)
+
+    def test_parameter_aliases(self):
+        txt = """
+            model ParameterAlias
+
+              Real x;
+              Real z;
+              parameter Real c = 0;
+
+              equation
+
+              der(x) = c;
+              z = c;
+
+            end ParameterAlias;
+        """
+
+        ast_tree = parser.parse(txt)
+        casadi_model = gen_casadi.generate(ast_tree, 'ParameterAlias')
+        casadi_model.simplify({'detect_aliases': True})
+
+        p = casadi_model.parameters[0]
+        self.assertSetEqual(p.aliases, {'z'})
+        self.assertEqual(len(casadi_model.alg_states), 0)
+
     def test_simplify_expand_vectors(self):
         # Create model, cache it, and load the cache
         compiler_options = \

pip install -e .[all]
parse_log_pytest
requirements.txt
pytest coverage flake8
apt-get update apt-get install -y gcc
3.7
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
aiofiles==22.1.0
aiosqlite==0.19.0
antlr4-python3-runtime==4.7.2
anyio==3.7.1
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
attrs==24.2.0
Babel==2.14.0
backcall==0.2.0
beautifulsoup4==4.13.3
bleach==6.0.0
cached-property==1.5.2
casadi==3.7.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
cffi==1.15.1
charset-normalizer==3.4.1
coverage==7.2.7
cycler==0.11.0
debugpy==1.7.0
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
exceptiongroup==1.2.2
fastjsonschema==2.21.1
flake8==5.0.4
fonttools==4.38.0
fqdn==1.5.1
idna==3.10
importlib-metadata==6.7.0
importlib-resources==5.12.0
iniconfig==2.0.0
ipykernel==6.16.2
ipython==7.34.0
ipython-genutils==0.2.0
isoduration==20.11.0
jedi==0.19.2
Jinja2==3.1.6
json5==0.9.16
jsonpointer==3.0.0
jsonschema==4.17.3
jupyter-events==0.6.3
jupyter-server==1.24.0
jupyter-ydoc==0.2.5
jupyter_client==7.4.9
jupyter_core==4.12.0
jupyter_server_fileid==0.9.3
jupyter_server_ydoc==0.8.0
jupyterlab==3.6.8
jupyterlab-pygments==0.2.2
jupyterlab_server==2.24.0
kiwisolver==1.4.5
lxml==5.3.1
MarkupSafe==2.1.5
matplotlib==3.5.3
matplotlib-inline==0.1.6
mccabe==0.7.0
mistune==3.0.2
mpmath==1.3.0
nbclassic==1.2.0
nbclient==0.7.4
nbconvert==7.6.0
nbformat==5.8.0
nest-asyncio==1.6.0
notebook==6.5.7
notebook_shim==0.2.4
numpy==1.21.6
packaging==24.0
pandocfilters==1.5.1
parso==0.8.4
pexpect==4.9.0
pickleshare==0.7.5
Pillow==9.5.0
pkgutil_resolve_name==1.3.10
pluggy==1.2.0
prometheus-client==0.17.1
prompt_toolkit==3.0.48
psutil==7.0.0
ptyprocess==0.7.0
pycodestyle==2.9.1
pycparser==2.21
pyflakes==2.5.0
Pygments==2.17.2
-e git+https://github.com/pymoca/pymoca.git@955a9f3e549ac04bc5eea43f3623e1b970c8a277#egg=pymoca
pyparsing==3.1.4
pyrsistent==0.19.3
pytest==7.4.4
python-dateutil==2.9.0.post0
python-json-logger==3.0.1
pytz==2025.2
PyYAML==6.0.1
pyzmq==26.2.1
requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
scipy==1.7.3
Send2Trash==1.8.3
six==1.17.0
sniffio==1.3.1
soupsieve==2.4.1
sympy==1.10.1
terminado==0.17.1
tinycss2==1.2.1
tomli==2.0.1
tornado==6.2
traitlets==5.9.0
typing_extensions==4.7.1
uri-template==1.3.0
urllib3==2.0.7
wcwidth==0.2.13
webcolors==1.13
webencodings==0.5.1
websocket-client==1.6.1
y-py==0.6.2
ypy-websocket==0.8.4
zipp==3.15.0

name: pymoca
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - aiofiles==22.1.0
      - aiosqlite==0.19.0
      - antlr4-python3-runtime==4.7.2
      - anyio==3.7.1
      - argon2-cffi==23.1.0
      - argon2-cffi-bindings==21.2.0
      - arrow==1.2.3
      - attrs==24.2.0
      - babel==2.14.0
      - backcall==0.2.0
      - beautifulsoup4==4.13.3
      - bleach==6.0.0
      - cached-property==1.5.2
      - casadi==3.7.0
      - cffi==1.15.1
      - charset-normalizer==3.4.1
      - coverage==7.2.7
      - cycler==0.11.0
      - debugpy==1.7.0
      - decorator==5.1.1
      - defusedxml==0.7.1
      - entrypoints==0.4
      - exceptiongroup==1.2.2
      - fastjsonschema==2.21.1
      - flake8==5.0.4
      - fonttools==4.38.0
      - fqdn==1.5.1
      - idna==3.10
      - importlib-metadata==6.7.0
      - importlib-resources==5.12.0
      - iniconfig==2.0.0
      - ipykernel==6.16.2
      - ipython==7.34.0
      - ipython-genutils==0.2.0
      - isoduration==20.11.0
      - jedi==0.19.2
      - jinja2==3.1.6
      - json5==0.9.16
      - jsonpointer==3.0.0
      - jsonschema==4.17.3
      - jupyter-client==7.4.9
      - jupyter-core==4.12.0
      - jupyter-events==0.6.3
      - jupyter-server==1.24.0
      - jupyter-server-fileid==0.9.3
      - jupyter-server-ydoc==0.8.0
      - jupyter-ydoc==0.2.5
      - jupyterlab==3.6.8
      - jupyterlab-pygments==0.2.2
      - jupyterlab-server==2.24.0
      - kiwisolver==1.4.5
      - lxml==5.3.1
      - markupsafe==2.1.5
      - matplotlib==3.5.3
      - matplotlib-inline==0.1.6
      - mccabe==0.7.0
      - mistune==3.0.2
      - mpmath==1.3.0
      - nbclassic==1.2.0
      - nbclient==0.7.4
      - nbconvert==7.6.0
      - nbformat==5.8.0
      - nest-asyncio==1.6.0
      - notebook==6.5.7
      - notebook-shim==0.2.4
      - numpy==1.21.6
      - packaging==24.0
      - pandocfilters==1.5.1
      - parso==0.8.4
      - pexpect==4.9.0
      - pickleshare==0.7.5
      - pillow==9.5.0
      - pkgutil-resolve-name==1.3.10
      - pluggy==1.2.0
      - prometheus-client==0.17.1
      - prompt-toolkit==3.0.48
      - psutil==7.0.0
      - ptyprocess==0.7.0
      - pycodestyle==2.9.1
      - pycparser==2.21
      - pyflakes==2.5.0
      - pygments==2.17.2
      - pyparsing==3.1.4
      - pyrsistent==0.19.3
      - pytest==7.4.4
      - python-dateutil==2.9.0.post0
      - python-json-logger==3.0.1
      - pytz==2025.2
      - pyyaml==6.0.1
      - pyzmq==26.2.1
      - requests==2.31.0
      - rfc3339-validator==0.1.4
      - rfc3986-validator==0.1.1
      - scipy==1.7.3
      - send2trash==1.8.3
      - six==1.17.0
      - sniffio==1.3.1
      - soupsieve==2.4.1
      - sympy==1.10.1
      - terminado==0.17.1
      - tinycss2==1.2.1
      - tomli==2.0.1
      - tornado==6.2
      - traitlets==5.9.0
      - typing-extensions==4.7.1
      - uri-template==1.3.0
      - urllib3==2.0.7
      - wcwidth==0.2.13
      - webcolors==1.13
      - webencodings==0.5.1
      - websocket-client==1.6.1
      - y-py==0.6.2
      - ypy-websocket==0.8.4
      - zipp==3.15.0
prefix: /opt/conda/envs/pymoca

test/gen_casadi_test.py::GenCasadiTest::test_constant_aliases
test/gen_casadi_test.py::GenCasadiTest::test_1based_indexing_error test/gen_casadi_test.py::GenCasadiTest::test_2d_index_at_wrong_symbol_error test/gen_casadi_test.py::GenCasadiTest::test_aircraft test/gen_casadi_test.py::GenCasadiTest::test_alias_relation test/gen_casadi_test.py::GenCasadiTest::test_array_3d test/gen_casadi_test.py::GenCasadiTest::test_array_expand test/gen_casadi_test.py::GenCasadiTest::test_arrayexpressions test/gen_casadi_test.py::GenCasadiTest::test_assigning_without_index test/gen_casadi_test.py::GenCasadiTest::test_assigning_without_index_nested test/gen_casadi_test.py::GenCasadiTest::test_attributes test/gen_casadi_test.py::GenCasadiTest::test_builtin test/gen_casadi_test.py::GenCasadiTest::test_cache test/gen_casadi_test.py::GenCasadiTest::test_cache_delay_arguments test/gen_casadi_test.py::GenCasadiTest::test_cat_params test/gen_casadi_test.py::GenCasadiTest::test_codegen test/gen_casadi_test.py::GenCasadiTest::test_connector_hq test/gen_casadi_test.py::GenCasadiTest::test_connector_hqz test/gen_casadi_test.py::GenCasadiTest::test_delay test/gen_casadi_test.py::GenCasadiTest::test_delay_for_loop test/gen_casadi_test.py::GenCasadiTest::test_delay_for_loop_with_expand_vectors test/gen_casadi_test.py::GenCasadiTest::test_derivative_initialization test/gen_casadi_test.py::GenCasadiTest::test_double_function_call test/gen_casadi_test.py::GenCasadiTest::test_duplicate test/gen_casadi_test.py::GenCasadiTest::test_estimator test/gen_casadi_test.py::GenCasadiTest::test_expand_vectors_derivative_naming test/gen_casadi_test.py::GenCasadiTest::test_forloop test/gen_casadi_test.py::GenCasadiTest::test_function_call test/gen_casadi_test.py::GenCasadiTest::test_if_else test/gen_casadi_test.py::GenCasadiTest::test_index_at_wrong_symbol_error test/gen_casadi_test.py::GenCasadiTest::test_indexing_error test/gen_casadi_test.py::GenCasadiTest::test_inheritance test/gen_casadi_test.py::GenCasadiTest::test_inheritance_instantiation test/gen_casadi_test.py::GenCasadiTest::test_inline_input_assignment test/gen_casadi_test.py::GenCasadiTest::test_interpolate test/gen_casadi_test.py::GenCasadiTest::test_iterative_simplification test/gen_casadi_test.py::GenCasadiTest::test_iterative_simplification_large test/gen_casadi_test.py::GenCasadiTest::test_logic test/gen_casadi_test.py::GenCasadiTest::test_matrixexpressions test/gen_casadi_test.py::GenCasadiTest::test_nested_classes test/gen_casadi_test.py::GenCasadiTest::test_nested_constants test/gen_casadi_test.py::GenCasadiTest::test_nested_equations_indexing test/gen_casadi_test.py::GenCasadiTest::test_nested_equations_indexing_hard_2d test/gen_casadi_test.py::GenCasadiTest::test_nested_equations_indexing_hard_3d test/gen_casadi_test.py::GenCasadiTest::test_nested_indexing_error test/gen_casadi_test.py::GenCasadiTest::test_nested_indices_hard test/gen_casadi_test.py::GenCasadiTest::test_nested_indices_simple test/gen_casadi_test.py::GenCasadiTest::test_parameter_aliases test/gen_casadi_test.py::GenCasadiTest::test_simplify_alias_small_nominal test/gen_casadi_test.py::GenCasadiTest::test_simplify_all test/gen_casadi_test.py::GenCasadiTest::test_simplify_detect_alias_conflicting_start test/gen_casadi_test.py::GenCasadiTest::test_simplify_detect_aliases test/gen_casadi_test.py::GenCasadiTest::test_simplify_detect_negative_alias test/gen_casadi_test.py::GenCasadiTest::test_simplify_differentiated_state test/gen_casadi_test.py::GenCasadiTest::test_simplify_eliminable_variable_expression test/gen_casadi_test.py::GenCasadiTest::test_simplify_eliminable_variable_expression_if_else test/gen_casadi_test.py::GenCasadiTest::test_simplify_eliminate_constant_assignments test/gen_casadi_test.py::GenCasadiTest::test_simplify_expand_mx test/gen_casadi_test.py::GenCasadiTest::test_simplify_expand_vectors test/gen_casadi_test.py::GenCasadiTest::test_simplify_reduce_affine_expression test/gen_casadi_test.py::GenCasadiTest::test_simplify_reduce_affine_expression_loop test/gen_casadi_test.py::GenCasadiTest::test_simplify_replace_constant_values test/gen_casadi_test.py::GenCasadiTest::test_simplify_replace_parameter_expressions test/gen_casadi_test.py::GenCasadiTest::test_simplify_replace_parameter_values test/gen_casadi_test.py::GenCasadiTest::test_simplify_replace_parameter_values_and_expressions test/gen_casadi_test.py::GenCasadiTest::test_size_one_array test/gen_casadi_test.py::GenCasadiTest::test_skip_annotations test/gen_casadi_test.py::GenCasadiTest::test_spring test/gen_casadi_test.py::GenCasadiTest::test_state_annotator test/gen_casadi_test.py::GenCasadiTest::test_tree_lookup test/gen_casadi_test.py::GenCasadiTest::test_type test/gen_casadi_test.py::GenCasadiTest::test_unit_type test/gen_casadi_test.py::GenCasadiTest::test_unit_type_array test/gen_casadi_test.py::GenCasadiTest::test_unit_type_vector test/gen_casadi_test.py::GenCasadiTest::test_unspecified_dimensions test/gen_casadi_test.py::GenCasadiTest::test_variable_metadata_function test/gen_casadi_test.py::GenCasadiTest::test_wrong_unspecified_dimensions
src/pymoca/backends/casadi/model.py
src/pymoca/backends/casadi/model.py