1512 Generate ODE models from yaml template#1518
Conversation
…ts for model itself are missing
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1518 +/- ##
==========================================
+ Coverage 97.46% 97.47% +0.01%
==========================================
Files 190 190
Lines 15966 15966
==========================================
+ Hits 15561 15563 +2
+ Misses 405 403 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mknaranja
left a comment
There was a problem hiding this comment.
Thank you very much for this great feature. So far I have only gone through the documentation. I will try to check functionality and core code more closely but this could maybe help to improve the documentation,
Co-authored-by: Martin J. Kühn <62713180+mknaranja@users.noreply.github.com>
774e5fe to
d552a34
Compare
…custom lower bound
mknaranja
left a comment
There was a problem hiding this comment.
I get memilio-modelgenerator: command not found after pip install -e pycode/memilio-generation and memilio-modelgenerator pycode/examples/modelgenerator/seir.yaml ./
kilianvolmer
left a comment
There was a problem hiding this comment.
Thank you for writing this really good and extensive documentation! I added a few typo fixes. Apart from that I only have three minor concerns/suggestions:
- I think it is quite confusing to add
nullas indicator that there is no upper limit. Maybe this could be changed toNoneor something similar? - Could you please add a sentence on reinstalling memilio-simulation for people who installed it using pypy?
- It took me a second to understand that Development and extension is not about a SEIR model as used in the documentation, but about new features for the generator. Could you maybe add one more sentence on that or move this section to a separate file?
Co-authored-by: Martin J. Kühn <62713180+mknaranja@users.noreply.github.com> Co-authored-by: Kilian Volmer <13285635+kilianvolmer@users.noreply.github.com>
Great points, thank you. Regarding the first point. Internally, PyYAML directly converts |
mknaranja
left a comment
There was a problem hiding this comment.
Thank you for all the continuous changes, I basically have three comments / questions that are remaining:
- Can we do clang-format on the generated files?
- We could probably also generate probabilities for transitions (to R vs to D), right?
- In the SEIRD model, we include D in the total population size for the denominator. The generator probably uses all compartments, right? It is probably to much right now to designate which states should go in the denominator but we should write a comment on this in the documentation and open an issue for this.
Otherwise, I only tested running and looked into the results. I haven't gone through the code line-by-line anymore.
Thank you for the feedback.
|
Co-authored-by: Kilian Volmer <13285635+kilianvolmer@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new Model Generator to the memilio-generation Python package that can generate MEmilio ODE model C++ sources, pybind11 bindings, and a Python example from a YAML/TOML specification (via CLI or Python API), along with documentation and tests.
Changes:
- Introduces
memilio.modelgenerator(schema, validation, generator, CLI) plus Jinja2 templates for C++/pybind/example outputs. - Updates packaging/docs to split “Model Generator” vs “Bindings Generator” dependencies and document the new workflow.
- Adds example configs (SEIR/SEIRD, YAML+TOML) and comprehensive unit tests; adjusts CI to install the
bindingsextra for the generation package.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
pycode/memilio-generation/tests/test_modelgenerator.py |
New unit tests covering parsing/validation/rendering/patching/CLI behavior. |
pycode/memilio-generation/README.md |
Reframes package docs around two tools (bindings generator + model generator) and links to RTD pages. |
pycode/memilio-generation/pyproject.toml |
Adds model-generator runtime deps, moves libclang to optional bindings extra, registers memilio-modelgenerator script, includes templates as package data. |
pycode/memilio-generation/memilio/modelgenerator/validator.py |
New config validator collecting multiple errors into ValidationError. |
pycode/memilio-generation/memilio/modelgenerator/templates/simulation_py.jinja2 |
Template for generated memilio.simulation.<namespace> Python shim importing the compiled module. |
pycode/memilio-generation/memilio/modelgenerator/templates/pybindings_cpp.jinja2 |
Template for generated pybind11 module for the model. |
pycode/memilio-generation/memilio/modelgenerator/templates/parameters_h.jinja2 |
Template for generated parameters.h including constraints and (optional) ContactPatterns. |
pycode/memilio-generation/memilio/modelgenerator/templates/model_h.jinja2 |
Template for generated model.h implementing get_flows for infection/linear/custom transitions. |
pycode/memilio-generation/memilio/modelgenerator/templates/model_cpp.jinja2 |
Minimal translation unit including the generated header. |
pycode/memilio-generation/memilio/modelgenerator/templates/infection_state_h.jinja2 |
Template for generated infection state enum header. |
pycode/memilio-generation/memilio/modelgenerator/templates/example_py.jinja2 |
Template for generated runnable Python example simulation script. |
pycode/memilio-generation/memilio/modelgenerator/templates/CMakeLists_model_txt.jinja2 |
Template for per-model CMake target. |
pycode/memilio-generation/memilio/modelgenerator/schema.py |
New dataclass-based internal config representation. |
pycode/memilio-generation/memilio/modelgenerator/generator.py |
Core implementation: YAML/TOML loading, parsing, rendering, clang-format integration, and patching existing repo files. |
pycode/memilio-generation/memilio/modelgenerator/cli.py |
New CLI entrypoint (memilio-modelgenerator) with preview/write/force modes. |
pycode/memilio-generation/memilio/modelgenerator/__init__.py |
Exposes generator/schema/validator in the package namespace. |
pycode/examples/modelgenerator/seird.yaml |
Example SEIRD config (includes a custom transition). |
pycode/examples/modelgenerator/seir.yaml |
Example SEIR YAML config. |
pycode/examples/modelgenerator/seir.toml |
Example SEIR TOML config. |
docs/source/python/m-modelgenerator.rst |
Full documentation for the new Model Generator. |
docs/source/python/m-generation.rst |
Updates overview/install instructions to distinguish both tools and their dependencies. |
docs/source/python/m-bindingsgenerator.rst |
Adds dedicated docs page for the existing bindings generator content. |
docs/source/cpp/model_creation.rst |
Links C++ model creation docs to the new Model Generator page. |
.github/actions/test-py/action.yml |
CI: installs memilio-generation[bindings,dev] to ensure generation tests have libclang available. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Changes and Information
Please briefly list the changes (main added features, changed items, or corrected bugs) made:
If need be, add additional information and what the reviewer should look out for in particular:
Merge Request - Guideline Checklist
Please check our git workflow. Use the draft feature if the Pull Request is not yet ready to review.
Checks by code author
Checks by code reviewer(s)