Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions docs/source/python/m-generation.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
MEmilio Generation
===================

.. note::

The ``memilio-generation`` package contains two independent tools:

* **Model Generator:** generates a C++ compartmental model with Python bindings from a YAML/TOML configuration file. See :doc:`m-modelgenerator`.
* **Bindings Generator:** automatically generates Python bindings from existing C++ model source files using libclang. Described on this page.

.. toctree::
:maxdepth: 1
:hidden:

m-modelgenerator

.. _bindings-generator:

Bindings Generator
------------------

Overview
~~~~~~~~

This package provides an automatic code generator for Python bindings of the MEmilio C++ library.
It enables the automatic generation of a part of the :doc:`Python Bindings <m-simulation>` that is common across multiple models.
For a particular example, see the SEIR model with its files `oseir.cpp <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-simulation/memilio/simulation/bindings/models/oseir.cpp>`_ and `oseir.py <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-simulation/memilio/simulation/oseir.py>`_.
Expand All @@ -13,7 +34,7 @@ The following figure from Chapter 5 outlines the workflow of the generator. Blue


Dependencies
----------
~~~~~~~~~~~~

The package uses the `Clang C++ library <https://clang.llvm.org/>`_ and the `LibClang Python library <https://libclang.readthedocs.io/en/latest/index.html>`_ to analyze the C++ code of a model. Both need to be installed and share the same version.

Expand All @@ -33,7 +54,7 @@ For a successful build, the development libraries for Python need to be installe
If you want to try a different version, set your `libclang` version under ``dependencies`` in the `pyproject.toml <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-generation/pyproject.toml>`_ and change the clang command in ``create_ast`` in `ast.py <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-generation/memilio/generation/ast.py>`_.

Usage
-----
~~~~~

During the installation the package creates a compilation database (compile_commands.json) for the models of the `MEmilio C++ Library <https://github.com/SciCompMod/memilio/blob/main/cpp/>`_.

Expand All @@ -59,7 +80,7 @@ To use the visualization run the command:


Visualization
-------------
~~~~~~~~~~~~~

The package contains a `Visualization class <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-generation/memilio/generation/graph_visualization.py>`_ to display the generated AST.
This allows you to visualize the abstract syntax tree (AST) of the C++ model in different ways:
Expand All @@ -83,7 +104,7 @@ This means that any nodes beyond the specified depth (e.g., all nodes at level 3
Notice that the visualization as a PNG file should not print the whole AST, as it is not possible to display the whole AST in a single image.

Development
-----------
~~~~~~~~~~~

When implementing new model features you can follow these steps:

Expand Down
Loading
Loading