catala/french_law/python
Louis Gesbert 4ae392c900 AST refactoring
Many changes got bundled in here and would be too tedious to separate.

Closes #330

See changes in `shared_ast/definitions.ml` to check the main point.

- the biggest change is a modification of the struct and enum types in
  expressions: they are now stored as `Map`s throughout passes, and no longer
  converted to indexed lists after scopelang. Their accessors are also changed,
  and tuples only exist in Lcalc (they're used for closure conversion).

  This implied adding some more information in the contexts, to keep the mapping
  between struct fields and scope output variables. It should also be much more
  robust (no longer relying on assumptions upon different orderings).

- another very pervasive change is more cosmetic: the rewrite of the main AST to
  use inline records, labelling individual subfields.

- moved the checks for correct definitions and accesses of structures from
  `Scope_to_dcalc` to `Typing`

- defining some new shallow iterators in module `Shared_ast.Expr`, and
  factorising a few same-pass rewriting functions accordingly (closure
  conversion, optimisations, etc.)

- some smaller style improvements (ensuring we use the proper compare/equal
  functions instead of `=` in a few `when` closes, for example)
2022-11-17 18:16:09 +01:00
..
cnaf_cross_tester A new case 2022-09-28 16:03:14 +02:00
src AST refactoring 2022-11-17 18:16:09 +01:00
.gitignore Various bugfixing and improvements for the Python backend 2021-06-25 00:16:21 +02:00
main.py Correctly bench 2022-09-26 13:28:07 +02:00
Makefile Correctly bench 2022-09-26 13:28:07 +02:00
README.md Fixes #307 2022-08-09 14:39:43 +02:00
requirements.txt reference runtime package in Makefile and requirements 2022-05-05 14:01:09 +02:00
setup_env.sh Shell script tweaks 2022-08-03 19:03:27 +02:00

Python French Law Library

This folder contains a ready-to-use Python library featuring French public algorithms coded up in Catala.

The Python version expected to run the Python code is above 3.6. For the commands noted below to run, you are expected to setup a virtual Python environment with virtualenv by running the setup_env.sh script.

Organization

Law source

The src/ folder contains the Python files generated by the Catala compiler. To update them from the Catala sources, invoke this command from the root of the repository:

make generate_french_law_library_python

The Python files generated by the Catala compiler depends on the catala.runtime package, whose source doe can be found in runtimes/python/catala from the root of the Catala repository.

All theses Python files feature type annotations which can be checked against using the following command inside this directory (french_law/python):

make type

API

To use the algorithms of this library, you can take a look at the example provided in main.py. All the algorithms are centralized with wrappers in api.py, as it is very important internally to wrap all of the input parameters using src/catala.py conversion functions.

You can benchmark the computation using the following command inside this directory (french_law/python):

make bench

Logging

The generated Catala code also features a logging feature that let you inspect each step of the computation, as well as the values flowing through it. You can directly retrieve a list of log events just after using a Catala-generated function, and display this list as you wish. An example of such a display can be showcases by using the following command inside this directory (french_law/python):

make show_log