Rumoca
Try Rumoca in your browser! - No installation required.
A Modelica compiler written in Rust. Rumoca parses Modelica source files and exports to the DAE IR Format (supporting both implicit and explicit model serialization), or via user-customizable templates using MiniJinja. The DAE IR format is consumed by Cyecca for model simulation, analysis, and Python library integration with CasADi, SymPy, and other backends.
Note: Rumoca is in early development. While already usable for many practical tasks, you may encounter issues. Please file bug reports to help improve the compiler.
Quick Start
# Install
# Compile to DAE IR (JSON)
# Format Modelica files
# Lint Modelica files
Installation
Rust (Compiler, Formatter, Linter)
Python
The Python package bundles the Rust compiler, so no separate Rust installation is needed:
# Compile a Modelica file
=
# Get as JSON string or Python dict
=
=
# Compile from string
=
Rust Library
[]
= "0.7"
use Compiler;
Tools
| Tool | Description |
|---|---|
rumoca |
Main compiler - parses Modelica and exports DAE IR (JSON) |
rumoca-fmt |
Code formatter for Modelica files (like rustfmt) |
rumoca-lint |
Linter for Modelica files (like clippy) |
rumoca-lsp |
Language Server Protocol server for editor integration |
MSL Compatibility
Rumoca is tested against the Modelica Standard Library 4.1.0.
| Status | Count | Percentage | Description |
|---|---|---|---|
| Parsed | 2551/2551 | 100% | All .mo files parse successfully |
| Compiled | 2283/2283 | 100% | All models compile to DAE ✅ |
| Balanced | 791 | 34.6% | Fully determined (equations = unknowns) |
| Partial | 1280 | 56.1% | Under-determined by design (external connectors) |
| Unbalanced | 212 | 9.3% | Needs further work |
Partial models have external connector flow variables that receive equations when connected in a larger system.
Benchmark (AMD Ryzen 9 7950X, 16 cores):
| Phase | Cold | Warm | Rate |
|---|---|---|---|
| Parse (2551 files) | 0.80s | 0.80s | 3,189 files/sec |
| Flatten (6491 classes) | 1.51s | 1.50s | 4,311 classes/sec |
| Compile (2283 models) | 22.75s | 3.68s | 100 / 620 models/sec |
| Total | 25.06s | 5.98s | 4.2x speedup |
Caching:
- In-memory caches (extends chain, resolved classes): Built during flatten phase (~1.5s), reset between runs
- DAE disk cache (
~/.cache/rumoca/dae/): Stores compiled model results, provides 6x speedup on balance phase
# Run the MSL balance test
# Clear disk caches for cold-start benchmark
Language Support:
| Category | Supported |
|---|---|
| Classes | model, class, block, connector, record, type, package, function |
| Equations | Simple, connect (flow/potential), if, for, when |
| Expressions | Binary/unary ops, function calls, if-expressions, arrays |
| Type prefixes | flow, discrete, parameter, constant, input, output |
| Packages | Nested packages, package.mo/package.order, MODELICAPATH |
| Imports | Qualified, renamed, unqualified (.*), selective ({a,b}) |
| Functions | Single/multi-output, tuple equations (a,b) = func() |
| Built-ins | der, pre, reinit, time, trig, array functions |
| Events | noEvent, smooth, sample, edge, change, initial, terminal |
Partial Support:
| Feature | Status |
|---|---|
| Algorithm sections | Parsed; assignments not yet counted in balance check |
| Connect equations | Flow/potential semantics; stream not supported |
| External functions | external recognized; no linking |
| Inner/outer | Basic resolution; nested scopes in progress |
| Complex type | Record expansion; operator overloading in progress |
Not Yet Implemented:
| Feature | Notes |
|---|---|
| Stream connectors | inStream, actualStream operators |
| Redeclarations | redeclare, replaceable parsed only |
| Overloaded operators | operator class prefix recognized only |
| State machines | Synchronous language elements (Ch. 17) |
| Expandable connectors | Dynamic connector sizing |
| Overconstrained connectors | Connections.root, branch, etc. |
What Works Well (100% compile rate achieved):
- All MSL packages compile successfully
- Complex type support (operator record)
- Replaceable package/model resolution (Medium.*, etc.)
- Deep inheritance chain type lookup
- ModelicaServices stubs
Known Limitations (212 unbalanced models):
| Category | Notes |
|---|---|
| Algorithm sections | Assignments not yet counted as equations |
| Stream connectors | inStream/actualStream not implemented |
| External functions | Functions without equation bodies |
| Operator records | Operator overloading not implemented |
Custom Code Generation
Rumoca supports MiniJinja templates for custom code generation:
Example template:
# Generated from {{ dae.model_name }}
{% for name, comp in dae.x | items %}
{{ name }}: {{ comp.type_name }} (start={{ comp.start }})
{% endfor %}
See examples/templates/ for complete examples (CasADi, SymPy, Base Modelica).
VSCode Extension
Search for "Rumoca Modelica" in the VSCode Extensions marketplace, or install from the marketplace page.

The extension includes a bundled rumoca-lsp language server - no additional installation required.
Features:
- Syntax highlighting (semantic tokens)
- Real-time diagnostics with type checking
- Autocomplete for keywords, built-in functions, and class members
- Go to definition / Find references
- Document symbols and outline
- Code formatting
- Hover information
- Signature help
- Code folding
- Inlay hints
- Code lens with reference counts
- Rename symbol
- Call hierarchy
- Document links
Configuring Library Paths:
Alternatively, set the MODELICAPATH environment variable. See the extension documentation for details.
WebAssembly (Browser)
Rumoca compiles to WebAssembly, enabling browser-based Modelica compilation without a backend server.
Features:
- Parse and compile Modelica models in the browser
- DAE IR (JSON) generation
- Template rendering with MiniJinja
- Multi-threaded compilation using Web Workers
Try the Demo:
# Open http://localhost:8080/examples/wasm_editor/index.html
The demo provides a Monaco-based editor with:
- Split-pane Modelica and Jinja2 template editing
- Real-time template preview
- DAE IR JSON export
- Autocomplete for template variables (
dae.x,dae.u, etc.)
Integration with Cyecca
=
# Use model for simulation, analysis, code generation, etc.
Architecture
Modelica Source -> Parse -> Flatten -> BLT -> DAE -> DAE IR (JSON)
(AST) (Flat) (Match) (DAE)
|
Cyecca
|
CasADi/SymPy/JAX/etc.
Structural Analysis:
- Hopcroft-Karp matching (O(E√V)) for equation-variable assignment
- Tarjan's SCC algorithm for topological ordering and algebraic loop detection
- Pantelides algorithm for DAE index reduction (detects high-index systems)
- Tearing for algebraic loops (reduces nonlinear system size)
Development
Formatter:
Configuration (.rumoca_fmt.toml):
= 2
= false
= 100
= 1
Linter:
Available Rules:
| Rule | Level | Description |
|---|---|---|
naming-convention |
note | CamelCase for types, camelCase for variables |
missing-documentation |
note | Classes without documentation strings |
unused-variable |
warning | Declared but unused variables |
undefined-reference |
error | References to undefined variables |
parameter-no-default |
help | Parameters without default values |
empty-section |
note | Empty equation or algorithm sections |
magic-number |
help | Magic numbers that should be constants |
complex-expression |
note | Overly complex/deeply nested expressions |
inconsistent-units |
warning | Potential unit inconsistencies |
redundant-extends |
warning | Duplicate or circular extends |
Configuration (.rumoca_lint.toml):
= "warning"
= ["magic-number", "missing-documentation"]
= false
Caching
Rumoca uses multi-level caching: in-memory caches for session-level performance (parsed classes, resolved definitions), and a persistent disk cache (~/.cache/rumoca/dae/) that works like ccache for CI pipelines. The disk cache is invalidated when source files or the compiler version change.
Roadmap
Export Targets:
Import Targets:
- Base Modelica (MCP-0031) - interface with OpenModelica, Dymola, etc.
Contributing
Contributions welcome! All contributions must be made under the Apache-2.0 license.
License
Apache-2.0 (LICENSE)
Citation
See Also
- Modelica IR - DAE IR specification
- Cyecca - Model simulation, analysis, and code generation
- Modelica Language