Skip to content

1512 Generate ODE models from yaml template#1518

Merged
mknaranja merged 29 commits into
mainfrom
1512-Automatic-generation-of-ODE-model
May 12, 2026
Merged

1512 Generate ODE models from yaml template#1518
mknaranja merged 29 commits into
mainfrom
1512-Automatic-generation-of-ODE-model

Conversation

@HenrZu
Copy link
Copy Markdown
Contributor

@HenrZu HenrZu commented Mar 26, 2026

Changes and Information

Please briefly list the changes (main added features, changed items, or corrected bugs) made:

  • Given a configuration template (yaml,toml), we generate the C++ source files and also the python bindings for this model (+ Python example)
  • Can be started via CLI or Python file

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

  • Every addressed issue is linked (use the "Closes #ISSUE" keyword below).
  • New code adheres to coding guidelines.
  • No large data files have been added (files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • Tests are added for new functionality and a local test run was successful (with and without OpenMP).
  • Appropriate documentation within the code (Doxygen) for new functionality has been added in the code.
  • Appropriate external documentation (ReadTheDocs) for new functionality has been added to the online documentation and checked in the preview.
  • Proper attention to licenses, especially no new third-party software with conflicting license has been added.
  • (For ABM development) Checked benchmark results and ran and posted a local test above from before and after development to ensure performance is monitored.

Checks by code reviewer(s)

  • Corresponding issue(s) is/are linked and addressed.
  • Code is clean of development artifacts (no deactivated or commented code lines, no debugging printouts, etc.).
  • Appropriate unit tests have been added, CI passes, code coverage and performance is acceptable (did not decrease).
  • No large data files added in the whole history of commits(files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • On merge, add 2-5 lines with the changes (main added features, changed items, or corrected bugs) to the merge-commit-message. This can be taken from the briefly-list-the-changes above (best case) or the separate commit messages (worst case).

@HenrZu HenrZu linked an issue Mar 30, 2026 that may be closed by this pull request
2 tasks
@HenrZu HenrZu marked this pull request as ready for review March 30, 2026 09:49
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.47%. Comparing base (46f65b5) to head (c6fe442).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@HenrZu HenrZu requested a review from mknaranja March 30, 2026 13:58
Copy link
Copy Markdown
Member

@mknaranja mknaranja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Comment thread docs/source/python/m-generation.rst Outdated
Comment thread docs/source/python/m-generation.rst
Comment thread docs/source/python/m-modelgenerator.rst
Comment thread docs/source/python/m-modelgenerator.rst Outdated
Comment thread docs/source/python/m-modelgenerator.rst Outdated
Comment thread docs/source/python/m-modelgenerator.rst
Comment thread docs/source/python/m-modelgenerator.rst
Comment thread docs/source/python/m-modelgenerator.rst
Comment thread docs/source/python/m-modelgenerator.rst Outdated
Comment thread docs/source/python/m-modelgenerator.rst Outdated
@HenrZu HenrZu force-pushed the 1512-Automatic-generation-of-ODE-model branch from 774e5fe to d552a34 Compare April 7, 2026 09:57
Copy link
Copy Markdown
Member

@mknaranja mknaranja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get memilio-modelgenerator: command not found after pip install -e pycode/memilio-generation and memilio-modelgenerator pycode/examples/modelgenerator/seir.yaml ./

Comment thread docs/source/python/m-generation.rst Outdated
Comment thread docs/source/python/m-modelgenerator.rst Outdated
Comment thread docs/source/python/m-modelgenerator.rst Outdated
Comment thread docs/source/python/m-modelgenerator.rst
Comment thread docs/source/python/m-modelgenerator.rst Outdated
Comment thread pycode/memilio-generation/tests/test_modelgenerator.py
Comment thread pycode/memilio-generation/tests/test_modelgenerator.py Outdated
Comment thread pycode/memilio-generation/tests/test_modelgenerator.py Outdated
Comment thread pycode/memilio-generation/tests/test_modelgenerator.py Outdated
Comment thread pycode/memilio-generation/memilio/modelgenerator/cli.py
Copy link
Copy Markdown
Contributor

@kilianvolmer kilianvolmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 null as indicator that there is no upper limit. Maybe this could be changed to None or 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?

Comment thread docs/source/python/m-modelgenerator.rst Outdated
Comment thread docs/source/python/m-modelgenerator.rst Outdated
Comment thread docs/source/python/m-modelgenerator.rst Outdated
HenrZu and others added 5 commits April 23, 2026 12:45
@HenrZu
Copy link
Copy Markdown
Contributor Author

HenrZu commented Apr 24, 2026

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 `null` as indicator that there is no upper limit. Maybe this could be changed to `None` or 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?

Great points, thank you.

Regarding the first point. Internally, PyYAML directly converts null to Python’s None as null is the yaml syntax for no value. None would be read in as "None".

@mknaranja
Copy link
Copy Markdown
Member

There are some minor inconsistencies with formatting. Could we apply clang-format on the created files?

grafik

Comment thread pycode/memilio-generation/memilio/modelgenerator/generator.py
Copy link
Copy Markdown
Member

@mknaranja mknaranja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pycode/examples/modelgenerator/seird.yaml
@HenrZu
Copy link
Copy Markdown
Contributor Author

HenrZu commented May 7, 2026

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.

  1. Clang format is now run (optionally) after rendering.

  2. Moved to Support probabilistic branching transitions in the model generator #1555

  3. See addition in modelgenerator rst

Comment thread docs/source/cpp/model_creation.rst Outdated
Co-authored-by: Kilian Volmer <13285635+kilianvolmer@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bindings extra 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.

Comment thread pycode/memilio-generation/memilio/modelgenerator/templates/parameters_h.jinja2 Outdated
Comment thread pycode/memilio-generation/memilio/modelgenerator/validator.py Outdated
Comment thread pycode/memilio-generation/memilio/modelgenerator/generator.py Outdated
Comment thread pycode/memilio-generation/memilio/modelgenerator/cli.py
Comment thread pycode/memilio-generation/memilio/modelgenerator/schema.py
@mknaranja mknaranja merged commit 0f118c2 into main May 12, 2026
76 checks passed
@mknaranja mknaranja deleted the 1512-Automatic-generation-of-ODE-model branch May 12, 2026 10:57
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.

Automatic generation of ODE model from predefined template

5 participants